> On Dec 3, 2026, at 03:35, Amir Hosseini via B4 Relay <devn…@kernel.org> wrote:
>
> From: Amir Hosseini <m…@amir.fyi>
>
> 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: stab…@vger.kernel.org
> Suggested-by: Mike Rapoport <rp…@kernel.org>
> Link: https://lore.kernel.org/all/aw7f…@kernel.org/
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Amir Hosseini <m…@amir.fyi>
Acked-by: Muchun Song (ByteDance) <much…@linux.dev>
Thanks.