mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sechang Lim <rhkrqnwk98@gmail.com>
To: bpf@vger.kernel.org
Cc: rostedt@goodmis.org, mhiramat@kernel.org,
	mathieu.desnoyers@efficios.com, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev,
	eddyz87@gmail.com, memxor@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, jolsa@kernel.org, kpsingh@kernel.org,
	matt@bobrowski.net, ihor.solodrai@linux.dev,
	emil@etsalapatis.com, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH bpf] bpf: Take the RCU lock inside the raw_tp recursion guard
Date: Mon, 30 Nov 2026 15:17:50 +0000	[thread overview]
Message-ID: <20261130151752.1529419-1-rhkrqnwk98@gmail.com> (raw)

__bpf_trace_run() takes the RCU read lock before
bpf_prog_get_recursion_context() and drops it after
bpf_prog_put_recursion_context(). With lockdep, rcu_read_unlock() hits
the lock_release tracepoint, so a raw_tp program attached there runs
again from its own unlock until the stack overflows, even when the
program is empty. lock_acquire recurses the same way.

Disable migration first, check the recursion guard, and take the RCU
read lock inside it.

Fixes: f7d327654b88 ("bpf: Have __bpf_trace_run() use rcu_read_lock_dont_migrate()")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 kernel/trace/bpf_trace.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 19e6b51bb2f0..69cc4d23ff3d 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2134,33 +2134,31 @@ void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
 	struct bpf_run_ctx *old_run_ctx;
 	struct bpf_trace_run_ctx run_ctx;
 
-	if (sleepable) {
+	if (sleepable)
 		scp = rcu_read_lock_tasks_trace();
-		migrate_disable();
-	} else {
-		rcu_read_lock_dont_migrate();
-	}
+	migrate_disable();
 
 	if (unlikely(!bpf_prog_get_recursion_context(prog))) {
 		bpf_prog_inc_misses_counter(prog);
 		goto out;
 	}
 
+	if (!sleepable)
+		rcu_read_lock();
 	run_ctx.bpf_cookie = link->cookie;
 	old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
 
 	(void)bpf_prog_run(prog, args);
 
 	bpf_reset_run_ctx(old_run_ctx);
+	if (!sleepable)
+		rcu_read_unlock();
 out:
 	bpf_prog_put_recursion_context(prog);
 
-	if (sleepable) {
-		migrate_enable();
+	migrate_enable();
+	if (sleepable)
 		rcu_read_unlock_tasks_trace(scp);
-	} else {
-		rcu_read_unlock_migrate();
-	}
 }
 
 #define UNPACK(...)			__VA_ARGS__
-- 
2.56.1


                 reply	other threads:[~2026-11-30 15:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130151752.1529419-1-rhkrqnwk98@gmail.com \
    --to=rhkrqnwk98@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=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=matt@bobrowski.net \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=song@kernel.org \
    --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®