From: Amir Hosseini Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to allocate table_perturb"), table_perturb comes from alloc_large_system_hash(). On 64-bit hosts with more than one node with memory, hashdist is set and the table comes from vmalloc_huge(). Everywhere else it needs one contiguous 256KB block. When that block isn't there, for example after many HugeTLB pages were reserved at boot, alloc_large_system_hash() retries with smaller sizes and ignores low_limit. The caller is never told. __inet_hash_connect() still uses all INET_TABLE_PERTURB_SIZE entries, so the first connect() writes past the end of the table. I hit this on a single node QEMU guest with KASAN, using fail_page_alloc to fail just this allocation. The table was halved to 32768 entries and the kernel crashed on the first connect(). Switch to kvmalloc_array(). If a contiguous block is free, the table comes from the linear map. If not, kvmalloc_array() falls back to vmalloc(). Either way the table keeps its full size. kvmalloc_array() was also proposed in 2022, but alloc_large_system_hash() was picked because it spread the table across NUMA nodes. That changed with commit a06157804399 ("mm/vmalloc: request large order pages from buddy allocator"). Now vmalloc() takes the whole table as one block from one node when it can, and only spreads the pages when there is no such block. That is the same case where kvmalloc_array() falls back to vmalloc(), so NUMA hosts lose nothing. Fixes: e67b72b90b7e ("tcp: use alloc_large_system_hash() to allocate table_perturb") Cc: stable@vger.kernel.org Suggested-by: Mike Rapoport Link: https://lore.kernel.org/all/aw7fxwCeHX5jFYW1@kernel.org/ Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Amir Hosseini --- I also tried a 2 node guest. When I forced vmalloc() to use smaller blocks, the table was split evenly across both nodes. The low_limit loop itself is fixed in a separate mm patch [1]. The 2022 discussion where alloc_large_system_hash() was picked is in [2]. [1] https://lore.kernel.org/all/20261202-mm-hash-low-limit-v2-1-44a8d2426acd@amir.fyi/ [2] https://lore.kernel.org/all/CANn89iKeOfDNmy0zPWHctuUQMb4UTiGxza9j3QVMsjuXFmeuhQ@mail.gmail.com/ --- Changes in v2: - Drop the NUMA branch, use kvmalloc_array() everywhere (Mike) - Explain why NUMA hosts keep the same spreading - Say that alloc_large_system_hash() ignores low_limit, and fix the hashdist wording (Mike) - Link to v1: https://patch.msgid.link/20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi --- net/ipv4/inet_hashtables.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 860145d810ed..59507d78b42f 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -1310,12 +1310,10 @@ void __init inet_hashinfo2_init(struct inet_hashinfo *h, const char *name, } /* this one is used for source ports of outgoing connections */ - table_perturb = alloc_large_system_hash("Table-perturb", - sizeof(*table_perturb), - INET_TABLE_PERTURB_SIZE, - 0, 0, NULL, NULL, - INET_TABLE_PERTURB_SIZE, - INET_TABLE_PERTURB_SIZE); + table_perturb = kvmalloc_array(INET_TABLE_PERTURB_SIZE, + sizeof(*table_perturb), GFP_KERNEL); + if (!table_perturb) + panic("TCP: failed to alloc table_perturb"); } int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo) --- base-commit: b6c8f45ed340f00bf2004d407cf7316fe3e24c48 change-id: 20261201-tcp-perturb-kvmalloc-2e3de54b992b Best regards, -- Amir Hosseini