diff mbox series

[PATCHv3,perf/core,1/2] uprobes/x86: Add support to emulate nop instructions

Message ID 20250414083647.1234007-1-jolsa@kernel.org (mailing list archive)
State New
Headers show
Series [PATCHv3,perf/core,1/2] uprobes/x86: Add support to emulate nop instructions | expand

Commit Message

Jiri Olsa April 14, 2025, 8:36 a.m. UTC
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 <oleg@redhat.com>
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
v3 changes:
 - use insn->length as index to x86_nops [Andrii]

 arch/x86/kernel/uprobes.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Oleg Nesterov April 14, 2025, 12:55 p.m. UTC | #1
On 04/14, Jiri Olsa wrote:
>
> @@ -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;

Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Andrii Nakryiko April 14, 2025, 4:13 p.m. UTC | #2
On Mon, Apr 14, 2025 at 1:36 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> 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 <oleg@redhat.com>
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> v3 changes:
>  - use insn->length as index to x86_nops [Andrii]
>
>  arch/x86/kernel/uprobes.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index 9194695662b2..6d383839e839 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;
> +

LGTM, thanks!

Acked-by: Andrii Nakryiko <andrii@kernel.org>


>         switch (opc1) {
>         case 0xeb:      /* jmp 8 */
>         case 0xe9:      /* jmp 32 */
> --
> 2.49.0
>
diff mbox series

Patch

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 9194695662b2..6d383839e839 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 */