Netdev List
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Uladzislau Rezki <urezki@gmail.com>,
	netdev@vger.kernel.org,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	"Liam R. Howlett (Google)" <liam@infradead.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Michal Hocko <mhocko@suse.com>, Baoquan He <bhe@redhat.com>,
	Alexander Potapenko <glider@google.com>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Marco Elver <elver@google.com>, Michal Hocko <mhocko@kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Graf <tgraf@suug.ch>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	maple-tree@lists.infradead.org, Lorenzo Stoakes <ljs@kernel.org>,
	Chris Mason <mason@kernel.org>, Alice Ryhl <aliceryhl@google.com>,
	Andrew Ballance <andrewjballance@gmail.com>,
	stable@vger.kernel.org,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	Jordan Rife <jordan@jrife.io>,
	Martin KaFai Lau <martin.lau@kernel.org>
Subject: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
Date: Tue, 1 Dec 2026 16:52:17 +0800	[thread overview]
Message-ID: <aw6KwbtmeFFSf_MS@gondor.apana.org.au> (raw)
In-Reply-To: <auzOjphJ8DWpXwUy@milan>

On Thu, Nov 05, 2026 at 07:44:30PM +0100, Uladzislau Rezki wrote:
> On Thu, Nov 05, 2026 at 04:51:39PM +0800, Herbert Xu wrote:
> > On Wed, Nov 04, 2026 at 12:11:24PM +0100, Uladzislau Rezki wrote:
>
> > > net/ipv4/udp.c:
> > >     err = bpf_iter_udp_realloc_batch(iter, batch_sks, GFP_NOWAIT);
> > 
> > This looks buggy in exactly the same way as rhashtable.  It's
> > called under spin_lock_bh, and the same lock can be taken on
> > the softirq path on another CPU.

Since we're not making any progress on resolving this within kvmalloc,
let's fix UDP to not call kvmalloc with GFP_NOWAIT.

---8<---
Even though kvmalloc was modified to support being called with
non-blocking flags such as GFP_NOWAIT and GFP_ATOMIC, it cannot
do so safely when used inside spin locks that may be taken from
soft or hard IRQs.  Doing so can lead to dead-lock because the
kvmalloc code takes naked spin locks without disabling soft or
hard IRQs.

Fix the UDP path to not call kvmalloc when BH spin locks are held.

Fixes: c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index d784faf939c3..613ea92e95b1 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);
 	if (!new_batch)
 		return -ENOMEM;
 
-- 
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

       reply	other threads:[~2026-12-01  8:52 UTC|newest]

Thread overview: 3+ 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                   ` Herbert Xu [this message]
2026-12-01  8:54                     ` [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock netdev-bot+sinfo
2026-12-01  8:58                       ` Herbert Xu

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=aw6KwbtmeFFSf_MS@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --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=jordan@jrife.io \
    --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