* Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
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-04 11:54 ` netdev-bot+sashiko
2 siblings, 1 reply; 6+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 8:54 UTC (permalink / raw)
To: Herbert Xu
Cc: Uladzislau Rezki, netdev, Willem de Bruijn, Linus Torvalds,
Liam R. Howlett (Google), Davidlohr Bueso, Michal Hocko,
Baoquan He, Alexander Potapenko, Andrey Ryabinin, Marco Elver,
Michal Hocko, Linux Crypto Mailing List, Andrew Morton,
Thomas Graf, linux-mm, linux-kernel, maple-tree, Lorenzo Stoakes,
Chris Mason, Alice Ryhl, Andrew Ballance, stable,
David Hildenbrand (Arm), Jordan Rife, Martin KaFai Lau
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
2026-12-01 8:54 ` netdev-bot+sinfo
@ 2026-12-01 8:58 ` Herbert Xu
0 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2026-12-01 8:58 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Uladzislau Rezki, netdev, Willem de Bruijn, Linus Torvalds,
Liam R. Howlett (Google), Davidlohr Bueso, Michal Hocko,
Baoquan He, Alexander Potapenko, Andrey Ryabinin, Marco Elver,
Michal Hocko, Linux Crypto Mailing List, Andrew Morton,
Thomas Graf, linux-mm, linux-kernel, maple-tree, Lorenzo Stoakes,
Chris Mason, Alice Ryhl, Andrew Ballance, stable,
David Hildenbrand (Arm), Jordan Rife, Martin KaFai Lau
On Tue, Dec 01, 2026 at 08:54:49AM +0000, netdev-bot+sinfo@kernel.org wrote:
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - Whether the issue was actually triggered, or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
The same issue was triggered on rhashtable. The UDP bpf path has
exactly the same setup so it is vulnerable to the same issue.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
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 17:01 ` Linus Torvalds
2026-12-01 23:18 ` Herbert Xu
2026-12-04 11:54 ` netdev-bot+sashiko
2 siblings, 1 reply; 6+ messages in thread
From: Linus Torvalds @ 2026-12-01 17:01 UTC (permalink / raw)
To: Herbert Xu
Cc: Uladzislau Rezki, netdev, Willem de Bruijn,
Liam R. Howlett (Google), Davidlohr Bueso, Michal Hocko,
Baoquan He, Alexander Potapenko, Andrey Ryabinin, Marco Elver,
Michal Hocko, Linux Crypto Mailing List, Andrew Morton,
Thomas Graf, linux-mm, linux-kernel, maple-tree, Lorenzo Stoakes,
Chris Mason, Alice Ryhl, Andrew Ballance, stable,
David Hildenbrand (Arm), Jordan Rife, Martin KaFai Lau
On Tue, 1 Dec 2026 at 00:52, Herbert Xu <herbert@gondor.apana.org.au> wrote:
>
> Fix the UDP path to not call kvmalloc when BH spin locks are held.
Bah. I don't love your previous patch, but it's better than this one.
So I applied the one to just not support kvmalloc in irq context.
Linus
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
2026-12-01 17:01 ` Linus Torvalds
@ 2026-12-01 23:18 ` Herbert Xu
0 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2026-12-01 23:18 UTC (permalink / raw)
To: Linus Torvalds
Cc: Uladzislau Rezki, netdev, Willem de Bruijn,
Liam R. Howlett (Google), Davidlohr Bueso, Michal Hocko,
Baoquan He, Alexander Potapenko, Andrey Ryabinin, Marco Elver,
Michal Hocko, Linux Crypto Mailing List, Andrew Morton,
Thomas Graf, linux-mm, linux-kernel, maple-tree, Lorenzo Stoakes,
Chris Mason, Alice Ryhl, Andrew Ballance, stable,
David Hildenbrand (Arm), Jordan Rife, Martin KaFai Lau
On Tue, Dec 01, 2026 at 09:01:10AM -0800, Linus Torvalds wrote:
>
> Bah. I don't love your previous patch, but it's better than this one.
>
> So I applied the one to just not support kvmalloc in irq context.
Thanks Linus!
So just in case there is any confusion I am withdrawing this patch
to bpf UDP.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
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 17:01 ` Linus Torvalds
@ 2026-12-04 11:54 ` netdev-bot+sashiko
2 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 11:54 UTC (permalink / raw)
To: herbert
Cc: urezki, netdev, willemdebruijn.kernel, torvalds, liam, dave,
mhocko, bhe, glider, ryabinin.a.a, elver, mhocko, linux-crypto,
akpm, tgraf, linux-mm, linux-kernel, maple-tree, ljs, mason,
aliceryhl, andrewjballance, stable, david, jordan, martin.lau,
kuba
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
^ permalink raw reply [flat|nested] 6+ messages in thread