Article View: linux.kernel.netdev
Article #26287Re: [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts
From: Mike Rapoport
Date: Thu, 03 Dec 2026 11:09
Date: Thu, 03 Dec 2026 11:09
96 lines
11922 bytes
11922 bytes
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.
Technical Details
Message-ID:
<axFN-7lcSvotpJ2H@kernel.org>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376502-linux-kernel-netdev=dewy.ruReferences:
<20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376502-linux-kernel-netdev=dewy.ru From: rppt@kernel.org (Mike Rapoport) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts Date: Thu, 3 Dec 2026 13:09:47 +0200 Organization: Usenet Network Message-ID: <axFN-7lcSvotpJ2H@kernel.org> References: <20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="2468468"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:W4LJn36zub6vKkqqx9wzc3ncMpw= sha256:EFscEohotX14V8Iy6r+1AzkXWZcwyneKCcwffuFC3Ug= sha1:sZ93IFsCnB2T39z1KhL0J6fs4j4= sha256:moBF30zelh8FwqZ0iGVMN6hrsn29mLk10xEr3Y+yxq8= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id EE3A81178E1; Thu, 3 Dec 2026 14:10:11 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9HMkMHHkFJuw; Thu, 3 Dec 2026 14:10:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376502-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id A16A31178C0; Thu, 3 Dec 2026 14:10:00 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 8D48926244; Thu, 3 Dec 2026 11:09:58 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796296196; b=W2CjHrMsSn3bHoO9agtz2kFnkWC8h5GJd0T4XELcw1UMqX/Z8ZWH2WddaQvhfmXS2oJI wNSJg5wz5b2pYsimHjhK8gJSNzTqeUBwSIg3VhfwCfi6yyflfiMmrA4vAGR6IXJ/B7uDU lyjz3sR3+g7W30Bgqxi4NcC7dPThpNV8l8DGBp05tPf/WTkJcihR5PAEcwHKFTzp0YiiW ER8CwguQNSsUuCbEJMPBiXk5/fnF7QzukkkLGdphWPDkAIXwJo/vy4x0nnz9zgQXTCC8e 5210AWgpevXo3TnVe25MkpgN2+1vjDmXeD2yqMSrhYEuOCUrKEAxshJ/5AwKZXo4jXA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296196; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=y5aFVciITNA2J0MuwDodPNKbItQpQQTSEYxu707X9HU=; b=sqlN9a8Vbd7rkxfD0fnZGrPIcTln3kCeJGzDnIwuCOmVfB6Yhrmr/XzOTWNtbev6x9KN PwHfohtXYoyC3sCBsXeXyn/RuSdkZNgVeNHZvFjlSTRpHHUJFukZlBYjDIvl8Rx4r81m5 7GJAUPzhMdKzwj48fFoOJdYbv5ftul5j26BXWFrt/ssqVYwnB2PfoX8Y0ckNxigvsXXLU UgMGTAIlRtAxPm+IdWc24oe2BKcvdYaMclWmur2z45h6YyK64kGIiEFiU1JjuYHLJApcn a1fX60MHTjCZIBF69MT2JE9VH8fpkQmOrtD1GA0ZHZzBCvK6pGSaRXbA0Hn7gDsaw5g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hSYDLjep; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D0EC606A333; Thu, 3 Dec 2026 11:09:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hSYDLjep X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796296195; b=484hFm49h1bxNGl4fjLuFcIeqFXpLmmD9PJaxfcbVwGRxVD/w99/p+xV4MpdPU2cwx9T p612p9NmpgIcvTgZpBY40ZagHvqQA+Scm3lTBR74RUm3qJSS8+rg4IVLCy4gogRr2zuxy HsTps5uujab2TixrLM0nL0n03crpN0Kbz/xFziatYWQut2yhEI+71Sbf/QLdjRwILZmAT RTjEV0BB6TppcX964BUsRlDDrwifjFa8X/Gorv33LV+8LIH4OB3bn5p4/5UHVW9OicK2Y L1Pry63m/AU/A9v411Vi3fIw5PYiQvn6RQAKqaZTpquAxzkijdeEibwjfvIDpHAel8A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296195; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=y5aFVciITNA2J0MuwDodPNKbItQpQQTSEYxu707X9HU=; b=1qiqw27pA1nfcZx5j1NiXV37VyYz0qwclLUEDhLkoAXsZKGeUkHyIxUvWHDJBRKdZ0B+ 4lBWsXWqTgP7B6DT7JjfDwIKrzxB/RJPMKxvlBaI4sP2rGzwI/nWb7Qq30NeZ4ib9rIRl dkn7k2lLKSuPthnBLJVvqJxjjz0uu9+a0ZA5W/SSED4mf1zDEAEo9RDv5E99a+lgIDKyC lCYkF6HB3AISs9sSZJqIREsIATFKfP1Tuh/9fzLTKsWbZgy07+WzrMvSK6Cup+LSCx8qF 9j+Q+5cc8Y208loQW8R5FM68COqsEzkocQ5UjMpfjWoaMvPnSYhl3CXrbSBNMthEEzA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hSYDLjep; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A19C606A32C for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 11:09:55 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16E931F000C1; Thu, 3 Dec 2026 11:09:50 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796296195; bh=y5aFVciITNA2J0MuwDodPNKbItQpQQTSEYxu707X9HU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=hSYDLjepwbKMWQGTb5kN3Ya31BF4AjkP8xNRNloIs57aenQ+jn2kU/AuGZe+/jwSe ZEZVYPlk6uDbdYRHgjhGn3yvDycKD2S8nZcyUMC8Ydc+3cJPPjMyGFHOzSKzRBQuCM SUjf1f0TAtkUGrKfKWEBABYQ85pXmZY1loXg7AcLpvKTpJK9p3Oh8nZrnzntFtjvBx tBstYrwt7JW/zO0je6bJEiDja0zP9/fGjmbqbUy06tXa4mk4YlpmA7Yo72s3uDAv6H CwjTtF8av/CVnOiNGTO2XCyEnjehZPsBjg9fCASgDeiw5P8t/OS8F4TgAoUy+HAPcC JC+2eSG73f/cQ== X-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 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi>