bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run
@ 2025-08-05 12:23 Tao Chen
  2025-08-05 15:48 ` Yonghong Song
  2025-08-05 16:04 ` Jiri Olsa
  0 siblings, 2 replies; 4+ messages in thread
From: Tao Chen @ 2025-08-05 12:23 UTC (permalink / raw)
  To: song, jolsa, ast, daniel, andrii, martin.lau, eddyz87,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo,
	mattbobrowski, rostedt, mhiramat, mathieu.desnoyers
  Cc: bpf, linux-kernel, linux-trace-kernel, Tao Chen

bpf program should run under migration disabled, kprobe_multi_link_prog_run
called the way from graph tracer, which disables preemption in
function_graph_enter_regs, as Jiri and Yonghong suggested, there is no
need to use migrate_disable. As a result, some overhead maybe will be
reduced.

Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/trace/bpf_trace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 3ae52978cae..1993fc62539 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2734,14 +2734,19 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
 		goto out;
 	}
 
-	migrate_disable();
+	/*
+	 * bpf program should run under migration disabled, kprobe_multi_link_prog_run
+	 * called the way from graph tracer, which disables preemption in
+	 * function_graph_enter_regs, so there is no need to use migrate_disable.
+	 * Accessing the above percpu data bpf_prog_active is also safe for the same
+	 * reason.
+	 */
 	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();
-	migrate_enable();
 
  out:
 	__this_cpu_dec(bpf_prog_active);
-- 
2.48.1


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

* Re: [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run
  2025-08-05 12:23 [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run Tao Chen
@ 2025-08-05 15:48 ` Yonghong Song
  2025-08-05 16:04 ` Jiri Olsa
  1 sibling, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2025-08-05 15:48 UTC (permalink / raw)
  To: Tao Chen, song, jolsa, ast, daniel, andrii, martin.lau, eddyz87,
	john.fastabend, kpsingh, sdf, haoluo, mattbobrowski, rostedt,
	mhiramat, mathieu.desnoyers
  Cc: bpf, linux-kernel, linux-trace-kernel



On 8/5/25 5:23 AM, Tao Chen wrote:
> bpf program should run under migration disabled, kprobe_multi_link_prog_run
> called the way from graph tracer, which disables preemption in
> function_graph_enter_regs, as Jiri and Yonghong suggested, there is no
> need to use migrate_disable. As a result, some overhead maybe will be
> reduced.
>
> Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>

Acked-by: Yonghong Song <yonghong.song@linux.dev>


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

* Re: [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run
  2025-08-05 12:23 [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run Tao Chen
  2025-08-05 15:48 ` Yonghong Song
@ 2025-08-05 16:04 ` Jiri Olsa
  2025-08-05 16:17   ` Tao Chen
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2025-08-05 16:04 UTC (permalink / raw)
  To: Tao Chen
  Cc: song, ast, daniel, andrii, martin.lau, eddyz87, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, mattbobrowski, rostedt,
	mhiramat, mathieu.desnoyers, bpf, linux-kernel,
	linux-trace-kernel

On Tue, Aug 05, 2025 at 08:23:12PM +0800, Tao Chen wrote:
> bpf program should run under migration disabled, kprobe_multi_link_prog_run
> called the way from graph tracer, which disables preemption in
> function_graph_enter_regs, as Jiri and Yonghong suggested, there is no
> need to use migrate_disable. As a result, some overhead maybe will be
> reduced.
> 
> Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> ---
>  kernel/trace/bpf_trace.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 3ae52978cae..1993fc62539 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2734,14 +2734,19 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
>  		goto out;
>  	}
>  
> -	migrate_disable();
> +	/*
> +	 * bpf program should run under migration disabled, kprobe_multi_link_prog_run
> +	 * called the way from graph tracer, which disables preemption in

nit, s/called the way/called all the way/


> +	 * function_graph_enter_regs, so there is no need to use migrate_disable.
> +	 * Accessing the above percpu data bpf_prog_active is also safe for the same
> +	 * reason.
> +	 */
>  	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();
> -	migrate_enable();
>  
>   out:
>  	__this_cpu_dec(bpf_prog_active);
> -- 
> 2.48.1
> 

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

* Re: [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run
  2025-08-05 16:04 ` Jiri Olsa
@ 2025-08-05 16:17   ` Tao Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Tao Chen @ 2025-08-05 16:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: song, ast, daniel, andrii, martin.lau, eddyz87, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, mattbobrowski, rostedt,
	mhiramat, mathieu.desnoyers, bpf, linux-kernel,
	linux-trace-kernel

在 2025/8/6 00:04, Jiri Olsa 写道:
> On Tue, Aug 05, 2025 at 08:23:12PM +0800, Tao Chen wrote:
>> bpf program should run under migration disabled, kprobe_multi_link_prog_run
>> called the way from graph tracer, which disables preemption in
>> function_graph_enter_regs, as Jiri and Yonghong suggested, there is no
>> need to use migrate_disable. As a result, some overhead maybe will be
>> reduced.
>>
>> Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> thanks,
> jirka
> 
> 
>> ---
>>   kernel/trace/bpf_trace.c | 9 +++++++--
>>   1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 3ae52978cae..1993fc62539 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -2734,14 +2734,19 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
>>   		goto out;
>>   	}
>>   
>> -	migrate_disable();
>> +	/*
>> +	 * bpf program should run under migration disabled, kprobe_multi_link_prog_run
>> +	 * called the way from graph tracer, which disables preemption in
> 
> nit, s/called the way/called all the way/
> 

will fix it, thanks.

> 
>> +	 * function_graph_enter_regs, so there is no need to use migrate_disable.
>> +	 * Accessing the above percpu data bpf_prog_active is also safe for the same
>> +	 * reason.
>> +	 */
>>   	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();
>> -	migrate_enable();
>>   
>>    out:
>>   	__this_cpu_dec(bpf_prog_active);
>> -- 
>> 2.48.1
>>


-- 
Best Regards
Tao Chen

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

end of thread, other threads:[~2025-08-05 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 12:23 [PATCH bpf-next] bpf: Remove migrate_disable in kprobe_multi_link_prog_run Tao Chen
2025-08-05 15:48 ` Yonghong Song
2025-08-05 16:04 ` Jiri Olsa
2025-08-05 16:17   ` Tao Chen

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).