Article View: linux.kernel.netdev
Article #26913Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 11:54
Date: Fri, 04 Dec 2026 11:54
112 lines
12235 bytes
12235 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] Incomplete fix: the TCP BPF iterator keeps the same
kvmalloc(GFP_NOWAIT)-under-BH-spinlock deadlock that this patch…
--
bpf: udp: Do not call kvmalloc while holding BH spin lock
With this patch, bpf_iter_udp_realloc_batch() uses kmalloc instead of
kvmalloc when it is called with GFP_NOWAIT. That call happens while the
UDP bucket lock is held with BH disabled. The vmalloc fallback in kvmalloc
takes plain spinlocks, so it can deadlock against softirq users of the
same bucket lock.
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index d784faf939c3b..613ea92e95b18 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -3886,8 +3886,12 @@ static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter,
> {
> union bpf_udp_iter_batch_item *new_batch;
>
> - new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
> - flags | __GFP_NOWARN);
> + if (flags != GFP_NOWAIT)
> + new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
> + flags | __GFP_NOWARN);
> + else
> + new_batch = kmalloc_objs(*new_batch, new_batch_sz,
> + flags | __GFP_NOWARN);
[Severity: High]
Does the TCP BPF iterator need the same change? The TCP twin of this
helper in net/ipv4/tcp_ipv4.c still calls kvmalloc unconditionally:
net/ipv4/tcp_ipv4.c:bpf_iter_tcp_realloc_batch() {
...
new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
flags | __GFP_NOWARN);
...
}
bpf_iter_tcp_batch() calls it with GFP_NOWAIT while it still holds the
bucket lock:
net/ipv4/tcp_ipv4.c:bpf_iter_tcp_batch() {
...
/* Batch size was still too small. Hold onto the lock while we try
* again with a larger batch to make sure the current bucket's size
* does not change in the meantime.
*/
err = bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT);
...
}
For established and request sockets, that lock is the ehash bucket lock.
It is taken with BH disabled, as bpf_iter_tcp_unlock_bucket() shows:
spin_unlock_bh(inet_ehash_lockp(hinfo, st->bucket));
The softirq path takes the same ehash lock with a plain spin_lock(). One
example is inet_ehash_insert(), which runs from tcp_v4_syn_recv_sock() and
from request socket hashing.
Suppose the batch is larger than PAGE_SIZE (more than 512 items) and the
GFP_NOWAIT kmalloc fails. Then __kvmalloc_node_noprof() falls back to
__vmalloc_node_range_noprof() with the same flags. vmalloc takes plain
spinlocks such as free_vmap_area_lock without disabling BH.
Could this deadlock the same way as the UDP case described in the commit
message?
CPU0
bpf_iter_tcp_batch()
spin_lock_bh(ehash bucket lock)
bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT)
kvmalloc -> __vmalloc_node_range_noprof()
spin_lock(&free_vmap_area_lock) <- spins
CPU1
holds free_vmap_area_lock with BH enabled
<irq, softirq runs on irq_exit>
tcp_v4_syn_recv_sock()
inet_ehash_insert()
spin_lock(same ehash bucket lock) <- spins
As far as I can tell, TCP is the only other caller under net/ that passes
GFP_NOWAIT to a realloc_batch helper. The Fixes tag points at
c6307674ed82, which made both iterators reach this path.
Would it make sense to fix bpf_iter_tcp_realloc_batch() in the same patch?
If not, could the commit message mention TCP, so that backports don't
treat the regression as fully closed?
> if (!new_batch)
> return -ENOMEM;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/aw6KwbtmeFFSf_MS%40gondor.apana.org.au
Technical Details
Message-ID:
<179638527524.3146.15958336218339553970@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377315-linux-kernel-netdev=dewy.ruReferences:
<aw6KwbtmeFFSf_MS@gondor.apana.org.au>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377315-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock Date: Fri, 04 Dec 2026 11:54:35 +0000 Organization: Usenet Network Message-ID: <179638527524.3146.15958336218339553970@kernel.org> References: <aw6KwbtmeFFSf_MS@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2755259"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:XfaX8HRY5B2XUvL3zBO96ykHtm8= sha256:KBrZLsNBYNaTCl6fFXh7Uo1m0TMeggfGRBe9+s0UjTY= sha1:p8fqj0VWfuBA5AqsaZ0WhDHsK64= sha256:IpXeHHbOv4XDzJ+4JSxB5NDUdSqhjcTXil/SO1C8FK8= 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 E6575117BD6; Fri, 4 Dec 2026 14:55:00 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.541 X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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, URIBL_BLOCKED=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 R2lES4AWcU5Z; Fri, 4 Dec 2026 14:54:53 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377315-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id D05BD117BD2; Fri, 4 Dec 2026 14:54:43 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 973763BB24; Fri, 4 Dec 2026 11:54:38 +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=1796385278; b=eB1vbnMfaH9bw1viINZ0Dp223zeF1SsaCzS/KtQyuIOExGloQdlMK5xZ5MWTKyHG1Cz4 EvlZwztxHxZpbBK1Mkb71LBKDXFrPmdR+D9B6upYXiBbmsQDTKVUc4XvLMrAclNQ9KxJo 9cMhbNkOrBUclQ0ckuFNtnqaGVo04x6TDr3a8VcY3dGqD/EGFeFFqSMpE9FVPT6j31+c0 fBkTnFUkuuQ7JJ3JJU+XlyNBNtfUOr9Qu/bZF1bL5E7A94b4TQZA+kX64iH46iFAOZyrx zSJ7q3Ki/dftZANvv3SZzfMvzMku4rL5s0GRryAaPCGPoAZOCTMRIlYR8mphFBpVVtg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385278; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=nvxWEYPgo1pZ3qhhzxTOrISOWTDamUtyFgIQ/pmRtIY=; b=IoulXlRmAP/shkMGQtP7AYWvIUVjfocEIhsb/h3bjpqdcgru6Ve7PjwTQp59ZNDrJu3k D9GMLqjiYsFHqAkNZxQ/fzuwm15VpY4Y3GC++4P4QsAylyHBvFJqR47FMToPJUc4RhCub tx+u3OL3wJzebf940W1AttbJupZCQknAGtvuUyYXlonECn/DCXtjX51w+C1n9ui96BtMG G2pI/8c2GO/WmNO/0ob7snKs6wxNQ9uHIxN/WCNsc2JO6S5tPwDtYuNVRCuT3b1a1rUbJ NZA+NrVcXPichJMO1ISa8FYUW5BFNpm5ZEGnuijJbXu9oK76pPmGPXNkQNuoVpqMyHQ== 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="fx3VvDc/"; 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 1FCEA606A683; Fri, 4 Dec 2026 11:54:38 +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=fx3VvDc/ 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=1796385277; b=laj6BtRr7Ie+tZv19n1ilIezMqis1dZBZTqZ3ZRTgdCSG+EmmVqlavsRJgu5oc7iBNyI BimffpkvgrDTth9BKrO3/+ashqx4BGtTvUwBw/+VKtm0tPnlY8+c95a6w+wRjUFRiOS6a emg3IMQNu73jhCieXQTvNYxSpg4ib9t93OB6wB/HoHAP3/VsejtsD3nLhPRUx9YhAXufW hVx+2kLKvCgP7cgODEZN9GdG+YIPMhpDnLHg1tgL+kEDoWDQONjcdLQvh8DNwLoErcQN+ vfvEeGjID0QTMZifpGI6F2QeAqHUSA9sAQ4fo37nE+kyDJtarGFbl3EDZW4uHFWsvfw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385277; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=nvxWEYPgo1pZ3qhhzxTOrISOWTDamUtyFgIQ/pmRtIY=; b=eF/jwJ5UrU/jHWRe4qPa5YMTMrl6kpSdyfBP3+AQZ+F05Lz9ygKS9nuC36DLlgKsOe6G ucItJ8rfQ5zAB6IT/UIEVwQRgGjTF4vQN+zAbvQVn8MfYdoJPUa9W7iBZY2J9oPIU7KA+ proJoGKc/n6fD5erRBYmT5Cfxeg8yQQgltx1znlHtrWnfxwQVw9FBzXHZ4dDTXLYpZyCC LfuYRZ9LCyv0Xje3v86xN8FMnbZTPdZyu5nN9OBBZFXUYNn3iwvzon+6s6BaykmM3p67k HlM+OHj9EOpSA5N5VIP3nWdEojLBYWGwLiT7Ki2bl6Av90GE14n4CTHmTOd4aPyo3iA== 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="fx3VvDc/"; 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 3FC49606A322; Fri, 4 Dec 2026 11:54:37 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8F5D1F000C2; Fri, 4 Dec 2026 11:54:35 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385277; bh=nvxWEYPgo1pZ3qhhzxTOrISOWTDamUtyFgIQ/pmRtIY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fx3VvDc/8zeDqVepmWs0WsPUx/J5Qnmqxz2+Wb4h8klHLnGFpSZ0v++G7N5EzCNoB dL1bpBN23QhDUtmsdUqkB9hRKU1Ku1OAWeeJXC8AhASSkRTl9RRxxLq0dU2pck70my 0zOaiK7MXWEAHeVooMCFl11zmo4M7SomWfsZizwPAyGyCp/Mq1XhJyAF8/yeodRNp7 N3LCmSs3IEDXXHyzVYMBJXwBoQlJ4DiFOd7oZhaOOw4EsPAlpEaGEYZCBC8EiCTWgZ JiLBpvkSQs5AHJO7P7yMfZVOf8k2Y7fEQAPNWWvfRiNPC/m7bq93lUXL8UP6UxdwvN +jFs5sbWNffYA== X-Cc: urezki@gmail.com, netdev@vger.kernel.org, willemdebruijn.kernel@gmail.com, torvalds@linux-foundation.org, liam@infradead.org, dave@stgolabs.net, mhocko@suse.com, bhe@redhat.com, glider@google.com, ryabinin.a.a@gmail.com, elver@google.com, mhocko@kernel.org, linux-crypto@vger.kernel.org, akpm@linux-foundation.org, tgraf@suug.ch, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, ljs@kernel.org, mason@kernel.org, aliceryhl@google.com, andrewjballance@gmail.com, stable@vger.kernel.org, david@kernel.org, jordan@jrife.io, martin.lau@kernel.org, kuba@kernel.org X-In-Reply-To: <aw6KwbtmeFFSf_MS@gondor.apana.org.au> X-sashiko-severity: High 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