Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Have __bpf_trace_run() use rcu_read_lock_dont_migrate()

In order to switch the protection of tracepoint callbacks from
preempt_disable() to srcu_read_lock_fast() the BPF callback from
tracepoints needs to have migration prevention as the BPF programs expect
to stay on the same CPU as they execute. Put together the RCU protection
with migration prevention and use rcu_read_lock_dont_migrate() in
__bpf_trace_run(). This will allow tracepoints callbacks to be
preemptible.

Link: https://lore.kernel.org/all/CAADnVQKvY026HSFGOsavJppm3-Ajm-VsLzY-OeFUe+BaKMRnDg@mail.gmail.com/

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20260126231256.335034877@kernel.org
Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+2 -3
+2 -3
kernel/trace/bpf_trace.c
··· 2062 2062 struct bpf_run_ctx *old_run_ctx; 2063 2063 struct bpf_trace_run_ctx run_ctx; 2064 2064 2065 - cant_sleep(); 2065 + rcu_read_lock_dont_migrate(); 2066 2066 if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { 2067 2067 bpf_prog_inc_misses_counter(prog); 2068 2068 goto out; ··· 2071 2071 run_ctx.bpf_cookie = link->cookie; 2072 2072 old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx); 2073 2073 2074 - rcu_read_lock(); 2075 2074 (void) bpf_prog_run(prog, args); 2076 - rcu_read_unlock(); 2077 2075 2078 2076 bpf_reset_run_ctx(old_run_ctx); 2079 2077 out: 2080 2078 this_cpu_dec(*(prog->active)); 2079 + rcu_read_unlock_migrate(); 2081 2080 } 2082 2081 2083 2082 #define UNPACK(...) __VA_ARGS__