From: Jiri Olsa Date: Mon, 14 Apr 2025 08:36:46 +0000 (+0200) Subject: uprobes/x86: Add support to emulate NOP instructions X-Git-Tag: v6.16-rc1~196^2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=610f6e14c29dc7f9637e8d9481e9f241f355e2e4;p=thirdparty%2Fkernel%2Flinux.git 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. Suggested-by: Oleg Nesterov Suggested-by: Andrii Nakryiko Signed-off-by: Jiri Olsa Signed-off-by: Ingo Molnar Reviewed-by: Oleg Nesterov Acked-by: Andrii Nakryiko Cc: Alan Maguire Cc: Hao Luo Cc: John Fastabend Cc: Masami Hiramatsu Cc: Song Liu Cc: Steven Rostedt Cc: Yonghong Song Link: https://lore.kernel.org/r/20250414083647.1234007-1-jolsa@kernel.org --- diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index 9194695662b26..6d383839e8393 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -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 */