From: Mike Rapoport <rppt@kernel.org>
To: me@amir.fyi
Cc: Eric Dumazet <edumazet@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Muchun Song <muchun.song@linux.dev>,
netdev@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts
Date: Thu, 3 Dec 2026 13:09:47 +0200 [thread overview]
Message-ID: <axFN-7lcSvotpJ2H@kernel.org> (raw)
In-Reply-To: <20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi>
On Wed, Dec 02, 2026 at 07:35:03PM +0000, Amir Hosseini via B4 Relay wrote:
> From: Amir Hosseini <me@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: stable@vger.kernel.org
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Link: https://lore.kernel.org/all/aw7fxwCeHX5jFYW1@kernel.org/
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Amir Hosseini <me@amir.fyi>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> 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 <me@amir.fyi>
>
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-12-03 11:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 19:35 [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts Amir Hosseini via B4 Relay
2026-12-03 11:09 ` Mike Rapoport [this message]
2026-12-03 11:13 ` Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axFN-7lcSvotpJ2H@kernel.org \
--to=rppt@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-mm@kvack.org \
--cc=me@amir.fyi \
--cc=muchun.song@linux.dev \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox