From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FCA0606A322 for ; Thu, 3 Dec 2026 11:09:59 +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 kanga.kvack.org (Postfix) id 404006B05B3; Thu, 3 Dec 2026 06:09:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B4166B05B4; Thu, 3 Dec 2026 06:09:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27C816B05B5; Thu, 3 Dec 2026 06:09:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E1DD16B05B3 for ; Thu, 3 Dec 2026 06:09:57 -0500 (EST) Received: from smtpin16.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6DF03A065D for ; Thu, 3 Dec 2026 11:09:57 +0000 (UTC) X-FDA: 85502402034.16.79094A7 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf30.hostedemail.com (Postfix) with ESMTP id D23048000C for ; Thu, 3 Dec 2026 11:09:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=hSYDLjep; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796296195; b=8gZU1iylj3YnnGNX/dcZLOwIV1BbxKzIzCwHwna3jrHTdRyo0gh/5MHzswQsNOdKMDzDze Vwon54MT+BqeyJZiLD6BLB4WKd6xIMIZAMkJRkADzYPruZkONsMdsSuF05JEggqvh8l5H/ J4jc4yp4qa/lOWngxdPq0rgleHtuYk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796296195; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y5aFVciITNA2J0MuwDodPNKbItQpQQTSEYxu707X9HU=; b=eaZo6FLX1HlBUB2BrO4VKediCju/wXX4lBMp3y163Pv/ClUw57oZuHVSRzL/2ULWWmaAkD c3OrZnv7BwPW9T+P/hOJySNeNTa1HwbWPNv/vDcI29Kwe0f6vKpfDnZTX35M81vXYGSQE1 HtqkrQzOkxOq/j3ZuobQwM+IWraPucI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=hSYDLjep; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 6951D61E5D; Thu, 3 Dec 2026 11:09:55 +0000 (UTC) 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-Archived-By: 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> X-Stat-Signature: 1mxqc1bgdz7cxexnztn3ro319ojp4x9b X-Rspamd-Queue-Id: D23048000C X-Rspam-User: X-Rspamd-Server: rspam01 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796296195-653457 X-HE-Meta: U2FsdGVkX1//uUmcC43PjeMugyEvOQnwV8ZXlD/6k0eGP6EFPHlj56OA+GI6MZ/8Xua5O2+z/z+MzupMhnj+KhAGQRF5DSRTXOhs/FAn5OCFuLc9bkx24yyKwx7KOXVqXQ9uDrLHBJztWZA2nWokWpTvBVjYcUGq1D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4cQOeVYk9nTKdPg0QVHNg5QpuuyjoUKQ9p0j65SnNQFJPxRyWzxrdzXv5Q5mJrJwWQgP7Lqvjo2/kyJshMsaGBGH47LkK7Uy5R9mEEHaylODPpHZhS1dNNJV8O5cv8CqyUk6+QXDuNL9yKvTko8GJjzeh+anI5sKW0h/HA2u1MA3wbmNrVavr8KX8LWoRB+0xYg0wo6edTexUvTgh0fH7kMjtJ1q8ANgyHeruAVgvOXUcjekZDq4dx6aCGpafaecF4UtphJQP8RbmzrNpzGw1FsdTLYssMWPzcGUlUvPmq2EXWsc6/ftTK0BpPXV+jFU4rbu5WuGRKWeg23JsKUMR2o5QV306nDVkuGBjQf6kFdDT/ZD/mAqPZ9cTmK81czGjClCKVHxwUeKTkag== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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.