From: netdev-bot+sashiko@kernel.org
To: herbert@gondor.apana.org.au
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
Subject: Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
Date: Fri, 04 Dec 2026 11:54:35 +0000 [thread overview]
Message-ID: <179638527524.3146.15958336218339553970@kernel.org> (raw)
In-Reply-To: <aw6KwbtmeFFSf_MS@gondor.apana.org.au>
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
prev parent reply other threads:[~2026-12-04 11:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <auaFhOa5EBz4gJwK@gondor.apana.org.au>
[not found] ` <xdzcyoou73blpfdlgy47i2ktrcsffnclerzojpgrxphid54gjc@nicdcvzqx447>
[not found] ` <auqtTjXhD8is-y9f@gondor.apana.org.au>
[not found] ` <CAHk-=wiE0KG+jkhmJWifXuAVivtB63WCWtdEpGAex7-T0SHd2g@mail.gmail.com>
[not found] ` <aurAxRpCwzeyXeVj@gondor.apana.org.au>
[not found] ` <CAHk-=wgPvbYRcKpQ8WTH-EYZRgMG0KSH+cZxY5-Hyf+X7JjWsw@mail.gmail.com>
[not found] ` <aurJZ81qnbiHH_P1@gondor.apana.org.au>
[not found] ` <ausS3LQNkdc6lBy3@milan>
[not found] ` <auxDm_YO4oACA_d2@gondor.apana.org.au>
[not found] ` <auzOjphJ8DWpXwUy@milan>
2026-12-01 8:52 ` [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock Herbert Xu
2026-12-01 8:54 ` netdev-bot+sinfo
2026-12-01 8:58 ` Herbert Xu
2026-12-01 17:01 ` Linus Torvalds
2026-12-01 23:18 ` Herbert Xu
2026-12-04 11:54 ` netdev-bot+sashiko [this message]
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=179638527524.3146.15958336218339553970@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=andrewjballance@gmail.com \
--cc=bhe@redhat.com \
--cc=dave@stgolabs.net \
--cc=david@kernel.org \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=jordan@jrife.io \
--cc=kuba@kernel.org \
--cc=liam@infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=maple-tree@lists.infradead.org \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=netdev@vger.kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tgraf@suug.ch \
--cc=torvalds@linux-foundation.org \
--cc=urezki@gmail.com \
--cc=willemdebruijn.kernel@gmail.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