Skip to contentSkip to conversation

bpf: Remove migrate_disable in kprobe_multi_link_prog_run

PATCH Superseded Tao Chen 3 participants 4 messages Aug 5, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tao Chen

author
#0 lore raw

PATCH 1/1 bpf: Remove migrate_disable in kprobe_multi_link_prog_run

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")
---
 kernel/trace/bpf_trace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/trace/bpf_trace.c +7 -2
index 3ae52978cae..1993fc62539 100644
@@ -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);
Signature · 1 line
2.48.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · 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")
Acked-by on v1 1/1
#2 lore raw
In reply to Tao Chen
Quoted 8 lines · 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")

thanks,
jirka

Quoted 9 lines
---
 kernel/trace/bpf_trace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/trace/bpf_trace.c +0 -0
index 3ae52978cae..1993fc62539 100644

kernel/trace/bpf_trace.c kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, · line 2739

Quoted 7 lines
kernel/trace/bpf_trace.c +3 -1
@@ -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/

Quoted 17 lines
kernel/trace/bpf_trace.c +4 -1
+	 * 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);
Signature · 1 line
2.48.1
author
#3 lore raw
Quoted 28 lines · Jiri Olsa
Quoted 8 lines · 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")

thanks,
jirka

Quoted 12 lines
---
  kernel/trace/bpf_trace.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
kernel/trace/bpf_trace.c +0 -0
index 3ae52978cae..1993fc62539 100644
@@ -2734,14 +2734,19 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
  		goto out;
  	}
 
Quoted 7 lines

kernel/trace/bpf_trace.c kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, · line 2739

Quoted 4 lines
kernel/trace/bpf_trace.c +3 -1
-	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.

Quoted 18 lines
Quoted 18 lines
kernel/trace/bpf_trace.c +4 -1
+	 * 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);
Signature · 1 line
2.48.1
Signature · 2 lines
Best Regards
Tao Chen