mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ömer Mete Kaya" <omermetekaya0@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net
Cc: john.fastabend@gmail.com, andrii@kernel.org, eddyz87@gmail.com,
	memxor@gmail.com, martin.lau@linux.dev, song@kernel.org,
	yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
	ihor.solodrai@linux.dev, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Ömer Mete Kaya" <omermetekaya0@gmail.com>,
	syzbot+fd7e415d891073b83e1f@syzkaller.appspotmail.com
Subject: [PATCH bpf] bpf: Fix smp_processor_id() warning in rhtab_delete_elem()
Date: Mon, 28 Sep 2026 20:31:36 +0300	[thread overview]
Message-ID: <20260928173703.504474-1-omermetekaya0@gmail.com> (raw)

bpf_mem_cache_free_rcu() uses this_cpu_ptr() which requires preemption
to be disabled. In rhtab_delete_elem(), this call happens after
bpf_enable_instrumentation(), so preemption is re-enabled at that
point and this_cpu_ptr() triggers:

  BUG: using smp_processor_id() in preemptible [00000000] code

Fix by moving all post-delete cleanup — rhtab_read_elem_value(),
check_and_init_map_value(), bpf_obj_cancel_fields(), and
bpf_mem_cache_free_rcu() — inside the bpf_disable_instrumentation()
section, before bpf_enable_instrumentation() is called.

This is consistent with __htab_map_lookup_and_delete_batch() which
wraps the entire batch operation including element freeing under
bpf_disable_instrumentation().

Fixes: 6905f8601298 ("bpf: Allow special fields in resizable hashtab")
Reported-by: syzbot+fd7e415d891073b83e1f@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fd7e415d891073b83e1f
Signed-off-by: Ömer Mete Kaya <omermetekaya0@gmail.com>
---
Tested with syzkaller:
- Before the fix: the reported warning was reproduced reliably.
- After the fix: the warning was no longer reproducible.

 kernel/bpf/hashtab.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index f744a42bb813..8cc07e54daaa 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -2979,19 +2979,18 @@ static int rhtab_delete_elem(struct bpf_rhtab *rhtab, struct rhtab_elem *elem, v
 	else
 		err = rhashtable_remove_fast(&rhtab->ht, &elem->node, rhtab_params);

-	bpf_enable_instrumentation();
-
-	if (err)
-		return err;
-
-	if (copy) {
-		rhtab_read_elem_value(&rhtab->map, copy, elem, flags);
-		check_and_init_map_value(&rhtab->map, copy);
+	if (!err) {
+		if (copy) {
+			rhtab_read_elem_value(&rhtab->map, copy, elem, flags);
+			check_and_init_map_value(&rhtab->map, copy);
+		}
+		bpf_obj_cancel_fields(&rhtab->map,
+				      rhtab_elem_value(elem, rhtab->map.key_size));
+		bpf_mem_cache_free_rcu(&rhtab->ma, elem);
 	}
-	bpf_obj_cancel_fields(&rhtab->map,
-			      rhtab_elem_value(elem, rhtab->map.key_size));
-	bpf_mem_cache_free_rcu(&rhtab->ma, elem);
-	return 0;
+
+	bpf_enable_instrumentation();
+	return err;
 }

 static long rhtab_map_delete_elem(struct bpf_map *map, void *key)
--
2.55.0


             reply	other threads:[~2026-09-28 17:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 17:31 Ömer Mete Kaya [this message]
2026-09-28 18:16 ` bot+bpf-ci
2026-09-29  6:09 ` Alexei Starovoitov

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=20260928173703.504474-1-omermetekaya0@gmail.com \
    --to=omermetekaya0@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=syzbot+fd7e415d891073b83e1f@syzkaller.appspotmail.com \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®