* [PATCH net] tcp: avoid table_perturb overflow on single node hosts
@ 2026-12-01 19:31 Amir Hosseini via B4 Relay
2026-12-02 9:51 ` Mike Rapoport
0 siblings, 1 reply; 2+ messages in thread
From: Amir Hosseini via B4 Relay @ 2026-12-01 19:31 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Muchun Song
Cc: Mike Rapoport, netdev, linux-mm, Amir Hosseini
From: Amir Hosseini <me@amir.fyi>
Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to
allocate table_perturb"), table_perturb is allocated with
alloc_large_system_hash(). On NUMA hosts it uses vmalloc(), but on
single node hosts it needs one contiguous 256KB block.
When there is no such block, for example after many HugeTLB pages were
reserved at boot, the table is made smaller without telling the caller.
__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 and
fail_page_alloc=1,100,1578,1. The table got half its size and the
kernel crashed in __inet_lookup_established().
Allocate the table the same way inet_ehash_locks_alloc() does. Use
vmalloc() on NUMA hosts as before, and kvmalloc() on other hosts. If
there is no contiguous block, kvmalloc() falls back to vmalloc().
The reproducer and testing were done with the help of Claude Code.
Fixes: e67b72b90b7e ("tcp: use alloc_large_system_hash() to allocate table_perturb")
Cc: stable@vger.kernel.org
Suggested-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/all/aw7fxwCeHX5jFYW1@kernel.org/
Signed-off-by: Amir Hosseini <me@amir.fyi>
---
Mike suggested kvmalloc_array() in the mm thread [1]. In 2022 Eric
preferred to spread this table over NUMA nodes [2], so this patch keeps
vmalloc() on NUMA hosts.
Since commit a06157804399 ("mm/vmalloc: request large order pages from
buddy allocator"), vmalloc() takes this table as one large page. So in
my 2 node test it stays on one node anyway, like the other boot time
hash tables.
[1] https://lore.kernel.org/all/20261123-mm-hash-low-limit-v1-1-8a803aa8ac70@amir.fyi/
[2] https://lore.kernel.org/all/CANn89iKeOfDNmy0zPWHctuUQMb4UTiGxza9j3QVMsjuXFmeuhQ@mail.gmail.com/
---
net/ipv4/inet_hashtables.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 860145d810ed..e6a531e1b2cf 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -1310,12 +1310,19 @@ 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);
+ if (num_online_nodes() > 1) {
+ /* Use vmalloc() to allow NUMA policy to spread pages
+ * on all available nodes if desired.
+ */
+ table_perturb = vmalloc_array(INET_TABLE_PERTURB_SIZE,
+ sizeof(*table_perturb));
+ }
+ if (!table_perturb)
+ 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: c712df600d056cc35ef7621e43c8e12513bae886
change-id: 20261201-tcp-perturb-kvmalloc-2e3de54b992b
Best regards,
--
Amir Hosseini <me@amir.fyi>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] tcp: avoid table_perturb overflow on single node hosts
2026-12-01 19:31 [PATCH net] tcp: avoid table_perturb overflow on single node hosts Amir Hosseini via B4 Relay
@ 2026-12-02 9:51 ` Mike Rapoport
0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2026-12-02 9:51 UTC (permalink / raw)
To: me
Cc: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Muchun Song, netdev, linux-mm
Hi Amir,
On Tue, Dec 01, 2026 at 07:31:32PM +0000, Amir Hosseini wrote:
>
> From: Amir Hosseini <me@amir.fyi>
>
> Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to
> allocate table_perturb"), table_perturb is allocated with
> alloc_large_system_hash(). On NUMA hosts it uses vmalloc(), but on
> single node hosts it needs one contiguous 256KB block.
It's vmalloc_huge() and it's used when hashdist is set, i.e. on 64-bit
with more than one node with memory.
> When there is no such block, for example after many HugeTLB pages were
> reserved at boot, the table is made smaller without telling the caller.
It's worth mentioning that alloc_large_system_hash() ignores low_limit
when it retries with smaller sizes.
...
> - 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);
> + if (num_online_nodes() > 1) {
> + /* Use vmalloc() to allow NUMA policy to spread pages
> + * on all available nodes if desired.
> + */
> + table_perturb = vmalloc_array(INET_TABLE_PERTURB_SIZE,
> + sizeof(*table_perturb));
> + }
I don't think the special case for NUMA makes sense.
Since commit a061578043993 ("mm/vmalloc: request large order pages from
buddy allocator") vmalloc takes large order blocks from the buddy
allocator, so vmalloc_array() gets the whole table as one block from one
node when it's available.
With the existing code, if there's a free order-6 block, it comes from
alloc_pages() with hashdist=0 and with hashdist=1 it's a single block
from vmalloc mapped with 4k pages.
If there's no such block, with hashdist=0 alloc_large_system_hash()
continues the loop and returns the largest block alloc_pages() can get,
and with hashdist=1 vmalloc is likely to succeed with several blocks
spread across the nodes and mapped with 4k pages.
With kvmalloc_array() a free order-6 block comes from kmalloc() ->
alloc_pages() and if there is no such block, several smaller blocks
come from vmalloc(), spread across the nodes and mapped with 4k pages.
So kvmalloc_array() never shrinks the table, prefers the linear map
when there's a contiguous block and spreads the table across the nodes
exactly in the case where hashdist=1 actually spreads it now.
Please drop the NUMA branch and just use kvmalloc_array().
> + if (!table_perturb)
> + table_perturb = kvmalloc_array(INET_TABLE_PERTURB_SIZE,
> + sizeof(*table_perturb),
> + GFP_KERNEL);
> + if (!table_perturb)
> + panic("TCP: failed to alloc table_perturb");
> }
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:31 [PATCH net] tcp: avoid table_perturb overflow on single node hosts Amir Hosseini via B4 Relay
2026-12-02 9:51 ` Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox