BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCHv3 07/12] selftests/bpf: Emit nop,nop10 instructions combo for x86_64 arch
Date: Mon, 25 May 2026 17:43:55 +0200	[thread overview]
Message-ID: <ahRuO6X_Kox3tVXH@krava> (raw)
In-Reply-To: <20260521132121.EEB4E1F000E9@smtp.kernel.org>

On Thu, May 21, 2026 at 01:21:21PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Changing the USDT_NOP macro to emit a 10-byte NOP breaks libbpf discovery, disables kernel uprobe optimizations, and relies on an architecturally unsafe patching concept.
> --

all the other changes are in other commits, I keep the changes separated
for now, we can squash them later if we think it's good idea

jirka

> 
> commit 963f950434fd00b2b52a00da58d5968fea9d4ebc
> Author: Jiri Olsa <jolsa@kernel.org>
> 
> selftests/bpf: Emit nop,nop10 instructions combo for x86_64 arch
> 
> This commit updates the USDT_NOP macro for x86_64 to emit a 1-byte nop
> followed by a 10-byte nop. This is intended to test new uprobe
> optimization support in the kernel.
> 
> > diff --git a/tools/testing/selftests/bpf/usdt.h b/tools/testing/selftests/bpf/usdt.h
> > --- a/tools/testing/selftests/bpf/usdt.h
> > +++ b/tools/testing/selftests/bpf/usdt.h
> [ ... ]
> > @@ -313,7 +313,7 @@ struct usdt_sema { volatile unsigned short active; };
> >  #if defined(__ia64__) || defined(__s390__) || defined(__s390x__)
> >  #define USDT_NOP			nop 0
> >  #elif defined(__x86_64__)
> > -#define USDT_NOP                       .byte 0x90, 0x0f, 0x1f, 0x44, 0x00, 0x0 /* nop, nop5 */
> > +#define USDT_NOP                       .byte 0x90, 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 /* nop, nop10 */
> 
> [Severity: Medium]
> Does this change to a 10-byte nop break the libbpf discovery logic?
> 
> Looking at has_nop_combo() in tools/lib/bpf/usdt.c, it seems to
> explicitly check for the 6-byte sequence (0x90, 0x0f, 0x1f, 0x44, 0x00, 0x00).
> 
> If has_nop_combo() returns false, the target IP won't advance to the
> multi-byte nop, leaving the probe at the 1-byte instruction.
> 
> Since the kernel's can_optimize() in arch/x86/kernel/uprobes.c requires
> an instruction length of 5, does this cause the selftest to silently
> degrade to the slower int3 breakpoint path rather than testing the
> intended optimization?
> 
> Additionally, is it safe to replace a 10-byte nop with a 5-byte call on
> x86_64?
> 
> The 5-byte call pushes IP + 5 to the stack. When the uprobe trampoline
> returns, execution would resume at IP + 5, which lands exactly in the
> middle of the 10-byte nop sequence.
> 
> Could those remaining 5 bytes (0x00, 0x00, 0x00, 0x00, 0x00) be
> incorrectly decoded, leading to unexpected behavior like memory
> corruption or application crashes?
> 
> Would using two consecutive 5-byte nops instead of a single 10-byte
> nop safely provide the padding needed for a 5-byte patch?
> 
> >  #else
> >  #define USDT_NOP			nop
> >  #endif
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260521124411.31133-8-jolsa@kernel.org?part=1

  reply	other threads:[~2026-05-25 15:43 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 12:43 [PATCHv3 00/12] uprobes/x86: Fix red zone issue for optimized uprobes Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 01/12] uprobes/x86: Use proper mm_struct in __in_uprobe_trampoline Jiri Olsa
2026-05-22 18:50   ` Andrii Nakryiko
2026-05-21 12:44 ` [PATCHv3 02/12] uprobes/x86: Remove struct uprobe_trampoline object Jiri Olsa
2026-05-21 13:26   ` bot+bpf-ci
2026-05-24 22:13     ` Jiri Olsa
2026-05-22 18:50   ` Andrii Nakryiko
2026-05-21 12:44 ` [PATCHv3 03/12] uprobes/x86: Allow to copy uprobe trampolines on fork Jiri Olsa
2026-05-22 18:50   ` Andrii Nakryiko
2026-05-24 21:54     ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 04/12] uprobes/x86: Move optimized uprobe from nop5 to nop10 Jiri Olsa
2026-05-21 13:35   ` Peter Zijlstra
2026-05-22 21:19     ` Jiri Olsa
2026-05-22 18:50   ` Andrii Nakryiko
2026-05-22 21:19     ` Jiri Olsa
2026-05-26  9:19       ` Peter Zijlstra
2026-05-26 10:19         ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 05/12] libbpf: Change has_nop_combo to work on top of nop10 Jiri Olsa
2026-05-21 13:01   ` sashiko-bot
2026-05-22 18:52   ` Andrii Nakryiko
2026-05-22 21:28     ` Jiri Olsa
2026-05-26 14:26       ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 06/12] libbpf: Detect uprobe syscall with new error Jiri Olsa
2026-05-21 13:26   ` bot+bpf-ci
2026-05-21 13:29   ` sashiko-bot
2026-05-25 15:44     ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 07/12] selftests/bpf: Emit nop,nop10 instructions combo for x86_64 arch Jiri Olsa
2026-05-21 13:21   ` sashiko-bot
2026-05-25 15:43     ` Jiri Olsa [this message]
2026-05-26 10:58     ` Jakub Sitnicki
2026-05-26 14:30       ` Jiri Olsa
2026-05-21 13:26   ` bot+bpf-ci
2026-05-26 10:58   ` Jakub Sitnicki
2026-05-21 12:44 ` [PATCHv3 08/12] selftests/bpf: Change uprobe syscall tests to use nop10 Jiri Olsa
2026-05-21 13:05   ` sashiko-bot
2026-05-21 13:26   ` bot+bpf-ci
2026-05-22 18:57   ` Andrii Nakryiko
2026-05-25 15:44     ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 09/12] selftests/bpf: Change uprobe/usdt trigger bench code " Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 10/12] selftests/bpf: Add reattach tests for uprobe syscall Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 11/12] selftests/bpf: Add tests for uprobe nop10 red zone clobbering Jiri Olsa
2026-05-21 13:26   ` bot+bpf-ci
2026-05-25 15:44     ` Jiri Olsa
2026-05-21 12:44 ` [PATCHv3 12/12] selftests/bpf: Add tests for forked/cloned optimized uprobes Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahRuO6X_Kox3tVXH@krava \
    --to=olsajiri@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox