From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Thu, 3 Dec 2026 11:09:55 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16E931F000C1; Thu, 3 Dec 2026 11:09:50 +0000 (UTC) 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== Date: Thu, 3 Dec 2026 13:09:47 +0200 From: Mike Rapoport To: me@amir.fyi Cc: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Muchun Song , netdev@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH net v2] tcp: avoid table_perturb overflow on single node hosts Message-ID: References: <20261202-tcp-perturb-kvmalloc-v2-1-03af5be7b237@amir.fyi> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > > 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 Acked-by: Mike Rapoport (Microsoft) > --- > 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 > > -- Sincerely yours, Mike.