bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: remove unnecessary rcu_read_lock in kprobe_multi_link_prog_run
@ 2025-08-27 12:38 Menglong Dong
  2025-08-27 16:21 ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Menglong Dong @ 2025-08-27 12:38 UTC (permalink / raw)
  To: jolsa
  Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, mattbobrowski, rostedt,
	mhiramat, mathieu.desnoyers, bpf, linux-kernel,
	linux-trace-kernel

Preemption is disabled in ftrace graph, which indicate rcu_read_lock. So
the rcu_read_lock is not needed in fprobe_entry(), and it is not needed
in kprobe_multi_link_prog_run() neither.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 kernel/trace/bpf_trace.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 606007c387c5..0e79fa84a634 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2741,12 +2741,10 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
 		goto out;
 	}
 
-	rcu_read_lock();
 	regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
 	old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
 	err = bpf_prog_run(link->link.prog, regs);
 	bpf_reset_run_ctx(old_run_ctx);
-	rcu_read_unlock();
 
  out:
 	__this_cpu_dec(bpf_prog_active);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: remove unnecessary rcu_read_lock in kprobe_multi_link_prog_run
  2025-08-27 12:38 [PATCH bpf-next] bpf: remove unnecessary rcu_read_lock in kprobe_multi_link_prog_run Menglong Dong
@ 2025-08-27 16:21 ` Alexei Starovoitov
  2025-08-28  1:03   ` Menglong Dong
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2025-08-27 16:21 UTC (permalink / raw)
  To: Menglong Dong
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Matt Bobrowski,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, bpf, LKML,
	linux-trace-kernel

On Wed, Aug 27, 2025 at 5:38 AM Menglong Dong <menglong8.dong@gmail.com> wrote:
>
> Preemption is disabled in ftrace graph, which indicate rcu_read_lock. So
> the rcu_read_lock is not needed in fprobe_entry(), and it is not needed
> in kprobe_multi_link_prog_run() neither.

kprobe_busy_begin() doing preempt_disable() is an implementation
detail that might change.
Having explicit rcu_read_lock() doesn't hurt.
It's a nop anyway in PREEMPT_NONE.

pw-bot: cr

> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> ---
>  kernel/trace/bpf_trace.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 606007c387c5..0e79fa84a634 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2741,12 +2741,10 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
>                 goto out;
>         }
>
> -       rcu_read_lock();
>         regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
>         old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
>         err = bpf_prog_run(link->link.prog, regs);
>         bpf_reset_run_ctx(old_run_ctx);
> -       rcu_read_unlock();
>
>   out:
>         __this_cpu_dec(bpf_prog_active);
> --
> 2.51.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: remove unnecessary rcu_read_lock in kprobe_multi_link_prog_run
  2025-08-27 16:21 ` Alexei Starovoitov
@ 2025-08-28  1:03   ` Menglong Dong
  0 siblings, 0 replies; 3+ messages in thread
From: Menglong Dong @ 2025-08-28  1:03 UTC (permalink / raw)
  To: Menglong Dong, Alexei Starovoitov
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Matt Bobrowski,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, bpf, LKML,
	linux-trace-kernel

On 2025/8/28 00:21 Alexei Starovoitov <alexei.starovoitov@gmail.com> write:
> On Wed, Aug 27, 2025 at 5:38 AM Menglong Dong <menglong8.dong@gmail.com> wrote:
> >
> > Preemption is disabled in ftrace graph, which indicate rcu_read_lock. So
> > the rcu_read_lock is not needed in fprobe_entry(), and it is not needed
> > in kprobe_multi_link_prog_run() neither.
> 
> kprobe_busy_begin() doing preempt_disable() is an implementation
> detail that might change.
> Having explicit rcu_read_lock() doesn't hurt.
> It's a nop anyway in PREEMPT_NONE.

Ok, I see. Thanks~

> 
> pw-bot: cr
> 
> > Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> > ---
> >  kernel/trace/bpf_trace.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index 606007c387c5..0e79fa84a634 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -2741,12 +2741,10 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
> >                 goto out;
> >         }
> >
> > -       rcu_read_lock();
> >         regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
> >         old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
> >         err = bpf_prog_run(link->link.prog, regs);
> >         bpf_reset_run_ctx(old_run_ctx);
> > -       rcu_read_unlock();
> >
> >   out:
> >         __this_cpu_dec(bpf_prog_active);
> > --
> > 2.51.0
> >
> 
> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-28  1:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 12:38 [PATCH bpf-next] bpf: remove unnecessary rcu_read_lock in kprobe_multi_link_prog_run Menglong Dong
2025-08-27 16:21 ` Alexei Starovoitov
2025-08-28  1:03   ` Menglong Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).