uprobes/x86: Add support to emulate nop instructions
Jiri Olsa
reviewerPATCH v3 1/2 uprobes/x86: Add support to emulate nop instructions
Adding support to emulate all nop instructions as the original uprobe instruction.
This change speeds up uprobe on top of all nop instructions and is a preparation for usdt probe optimization, that will be done on top of nop5 instruction.
With this change the usdt probe on top of nop5 won't take the performance hit compared to usdt probe on top of standard nop instruction.
---
v3 changes:
- use insn->length as index to x86_nops [Andrii]
arch/x86/kernel/uprobes.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/uprobes.c +5 -0
@@ -840,6 +840,11 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)insn_byte_t p;int i; +/* x86_nops[insn->length]; same as jmp with .offs = 0 */ +if (insn->length <=ASM_NOP_MAX && + !memcmp (insn->kaddr, x86_nops[insn->length], insn->length)) + goto setup; +switch (opc1) {case 0xeb :/* jmp 8 */ case 0xe9 :/* jmp 32 */
Signature · 1 line
2.49.0
Jiri Olsa
reviewerPATCH v3 2/2 selftests/bpf: Add 5-byte nop uprobe trigger bench
Add 5-byte nop uprobe trigger bench (x86_64 specific) to measure uprobes/uretprobes on top of nop5 instruction.
--- tools/testing/selftests/bpf/bench.c | 12 ++++++ .../selftests/bpf/benchs/bench_trigger.c | 42 +++++++++++++++++++ .../selftests/bpf/benchs/run_bench_uprobes.sh | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bench.c +12 -0
@@ -526,6 +526,12 @@ extern const struct bench bench_trig_uprobe_multi_push;extern const struct bench bench_trig_uretprobe_multi_push;extern const struct bench bench_trig_uprobe_multi_ret;extern const struct bench bench_trig_uretprobe_multi_ret; +#ifdef __x86_64__ +extern const struct bench bench_trig_uprobe_nop5; +extern const struct bench bench_trig_uretprobe_nop5; +extern const struct bench bench_trig_uprobe_multi_nop5; +extern const struct bench bench_trig_uretprobe_multi_nop5; +#endif extern const struct bench bench_rb_libbpf;extern const struct bench bench_rb_custom;
@@ -586,6 +592,12 @@ static const struct bench *benchs[] = { &bench_trig_uretprobe_multi_push, &bench_trig_uprobe_multi_ret, &bench_trig_uretprobe_multi_ret, +#ifdef __x86_64__ + &bench_trig_uprobe_nop5, + &bench_trig_uretprobe_nop5, + &bench_trig_uprobe_multi_nop5, + &bench_trig_uretprobe_multi_nop5, +#endif/* ringbuf/perfbuf benchmarks */ &bench_rb_libbpf, &bench_rb_custom,
tools/testing/selftests/bpf/benchs/bench_trigger.c +42 -0
57 lines not on this page · raw message
tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh +1 -1
@@ -2,7 +2,7 @@ set -eufo pipefail -for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret} +for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5} do summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-) printf "%-15s: %s\n" $i "$summary"
Signature · 1 line
2.49.0
Re: [PATCHv3 perf/core 2/2] selftests/bpf: Add 5-byte nop uprobe trigger bench
Quoted 11 lines · Jiri Olsa
Add 5-byte nop uprobe trigger bench (
x86_64specific) to measure uprobes/uretprobes on top of nop5 instruction.Signed-off-by Jiri Olsa <[email protected]>--- tools/testing/selftests/bpf/bench.c | 12 ++++++ .../selftests/bpf/benchs/bench_trigger.c | 42 +++++++++++++++++++ .../selftests/bpf/benchs/run_bench_uprobes.sh | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-)
LGTM. Should we land this benchmark patch through the bpf-next tree? It won't break anything, just will be slower until patch #1 gets into bpf-next as well, which is fine.
Ingo or Peter, any objections to me routing this patch separately through bpf-next?
But either way:
[...]
Ingo Molnar
AppliedRe: [PATCHv3 perf/core 2/2] selftests/bpf: Add 5-byte nop uprobe trigger bench
Quoted 17 lines · Andrii Nakryiko
Quoted 11 lines · Jiri Olsa
Add 5-byte nop uprobe trigger bench (
x86_64specific) to measure uprobes/uretprobes on top of nop5 instruction.Signed-off-by Jiri Olsa <[email protected]>--- tools/testing/selftests/bpf/bench.c | 12 ++++++ .../selftests/bpf/benchs/bench_trigger.c | 42 +++++++++++++++++++ .../selftests/bpf/benchs/run_bench_uprobes.sh | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-)LGTM. Should we land this benchmark patch through the bpf-next tree? It won't break anything, just will be slower until patch #1 gets into bpf-next as well, which is fine.
Quoted 6 lines
Ingo or Peter, any objections to me routing this patch separately through bpf-next?
But either way:
Acked-by Andrii Nakryiko <[email protected]>
I've applied this to the perf tree with a few readability edits to the changelogs and the new tags added in.
Thanks,
Ingo
[tip: perf/core] selftests/bpf: Add 5-byte NOP uprobe trigger benchmark
In reply to Jiri OlsaThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: fe8e5a3215ccd8e54ce0a9df1b89d4ab42ad8fec Gitweb: https://git.kernel.org/tip/fe8e5a3215ccd8e54ce0a9df1b89d4ab42ad8fec Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 14 Apr 2025 10:36:47 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 18 Apr 2025 09:03:45 +02:00
selftests/bpf: Add 5-byte NOP uprobe trigger benchmark
Add a 5-byte NOP uprobe trigger benchmark (x86_64 specific) to measure uprobes/uretprobes on top of NOP5 instructions.
--- tools/testing/selftests/bpf/bench.c | 12 ++- tools/testing/selftests/bpf/benchs/bench_trigger.c | 42 ++++++++- tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bench.c +12 -0
@@ -526,6 +526,12 @@ extern const struct bench bench_trig_uprobe_multi_push;extern const struct bench bench_trig_uretprobe_multi_push;extern const struct bench bench_trig_uprobe_multi_ret;extern const struct bench bench_trig_uretprobe_multi_ret; +#ifdef __x86_64__ +extern const struct bench bench_trig_uprobe_nop5; +extern const struct bench bench_trig_uretprobe_nop5; +extern const struct bench bench_trig_uprobe_multi_nop5; +extern const struct bench bench_trig_uretprobe_multi_nop5; +#endif extern const struct bench bench_rb_libbpf;extern const struct bench bench_rb_custom;
@@ -586,6 +592,12 @@ static const struct bench *benchs[] = { &bench_trig_uretprobe_multi_push, &bench_trig_uprobe_multi_ret, &bench_trig_uretprobe_multi_ret, +#ifdef __x86_64__ + &bench_trig_uprobe_nop5, + &bench_trig_uretprobe_nop5, + &bench_trig_uprobe_multi_nop5, + &bench_trig_uretprobe_multi_nop5, +#endif/* ringbuf/perfbuf benchmarks */ &bench_rb_libbpf, &bench_rb_custom,
tools/testing/selftests/bpf/benchs/bench_trigger.c +42 -0
57 lines not on this page · raw message
tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh +1 -1
@@ -2,7 +2,7 @@ set -eufo pipefail -for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret} +for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5} do summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-) printf "%-15s: %s\n" $i "$summary"
arch/x86/kernel/uprobes.c static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn) · line 846
Quoted 9 lines · Jiri Olsa
arch/x86/kernel/uprobes.c +4
-0@@ -840,6 +840,11 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)insn_byte_t p;int i; +/* x86_nops[insn->length]; same as jmp with .offs = 0 */ +if (insn->length <=ASM_NOP_MAX && + !memcmp (insn->kaddr, x86_nops[insn->length], insn->length)) + goto setup;
Quoted 26 lines · Jiri Olsa
Adding support to emulate all nop instructions as the original uprobe instruction.
This change speeds up uprobe on top of all nop instructions and is a preparation for usdt probe optimization, that will be done on top of nop5 instruction.
With this change the usdt probe on top of nop5 won't take the performance hit compared to usdt probe on top of standard nop instruction.
Suggested-by Oleg Nesterov <[email protected]>Suggested-by Andrii Nakryiko <[email protected]>Signed-off-by Jiri Olsa <[email protected]>---
v3 changes:
- useinsn->lengthas index tox86_nops[Andrii]arch/x86/kernel/uprobes.c | 5 +++++ 1 file changed, 5 insertions(+)arch/x86/kernel/uprobes.c +0
-0
arch/x86/kernel/uprobes.c static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn) · line 847
Quoted 8 lines
arch/x86/kernel/uprobes.c +5
-0@@ -840,6 +840,11 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)insn_byte_t p;int i; +/* x86_nops[insn->length]; same as jmp with .offs = 0 */ +if (insn->length <=ASM_NOP_MAX && + !memcmp (insn->kaddr, x86_nops[insn->length], insn->length)) + goto setup; +
LGTM, thanks!
Quoted 6 lines
arch/x86/kernel/uprobes.c +0
-1switch (opc1) {case 0xeb :/* jmp 8 */ case 0xe9 :/* jmp 32 */ --2.49.0
[tip: perf/core] uprobes/x86: Add support to emulate NOP instructions
In reply to Jiri OlsaThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 610f6e14c29dc7f9637e8d9481e9f241f355e2e4 Gitweb: https://git.kernel.org/tip/610f6e14c29dc7f9637e8d9481e9f241f355e2e4 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 14 Apr 2025 10:36:46 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 18 Apr 2025 09:03:05 +02:00
uprobes/x86: Add support to emulate NOP instructions
Add support to emulate all NOP instructions as the original uprobe instruction.
This change speeds up uprobe on top of all NOP instructions and is a preparation for usdt probe optimization, that will be done on top of NOP5 instructions.
With this change the usdt probe on top of NOP5s won't take the performance hit compared to usdt probe on top of standard NOP instructions.
--- arch/x86/kernel/uprobes.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/uprobes.c +5 -0
@@ -840,6 +840,11 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)insn_byte_t p;int i; +/* x86_nops[insn->length]; same as jmp with .offs = 0 */ +if (insn->length <=ASM_NOP_MAX && + !memcmp (insn->kaddr, x86_nops[insn->length], insn->length)) + goto setup; +switch (opc1) {case 0xeb :/* jmp 8 */ case 0xe9 :/* jmp 32 */