mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Take the RCU lock inside the raw_tp recursion guard
@ 2026-11-30 15:17 Sechang Lim
  0 siblings, 0 replies; only message in thread
From: Sechang Lim @ 2026-11-30 15:17 UTC (permalink / raw)
  To: bpf
  Cc: rostedt, mhiramat, mathieu.desnoyers, ast, daniel, andrii,
	martin.lau, eddyz87, memxor, song, yonghong.song, jolsa, kpsingh,
	matt, ihor.solodrai, emil, linux-trace-kernel, linux-kernel

__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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30 15:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 15:17 [PATCH bpf] bpf: Take the RCU lock inside the raw_tp recursion guard Sechang Lim

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®