Re: [PATCH bpf 1/2] libbpf: Fix usdt attach failure when nop10 crosses page boundary

From: Andrii Nakryiko

Date: Tue Aug 25 2026 - 14:33:18 EST


On Tue, Aug 25, 2026 at 7:29 AM Jiayuan Chen <jiayuan.chen@xxxxxxxxx> wrote:
>
>
> On 8/25/26 9:58 PM, Jiri Olsa wrote:
> > On Mon, Aug 24, 2026 at 05:28:36PM +0800, Jiayuan Chen wrote:
> >> The kernel refuses to attach to a nop10 that crosses a page boundary,
> >> since it can't be atomically rewritten:
> >>
> >> /* can_optimize(), arch/x86/kernel/uprobes.c */
> >> /* We can't do cross page atomic writes yet. */
> >> return PAGE_SIZE - (vaddr & ~PAGE_MASK) >= OPT_INSN_SIZE;
> >>
> >> Whether the nop10 crosses a page is purely up to the binary layout, so
> >> this does happen in practice. libbpf doesn't check for it and blindly
> >> shifts the uprobe onto the nop10, and the attach then fails with
> >> -ENOTSUPP. Just keep the uprobe on the preceding 1-byte nop in that
> >> case, it works everywhere as a regular int3 uprobe.
> >>
> >> Fixes: 41a5c7df4466 ("libbpf: Add support to detect nop,nop5 instructions combo for usdt probe")
> >> Signed-off-by: Jiayuan Chen <jiayuan.chen@xxxxxxxxx>
> >> ---
> >> tools/lib/bpf/usdt.c | 23 +++++++++++++++++++++--
> >> 1 file changed, 21 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
> >> index 2e56e3ab5b6c..c266ac93cbdd 100644
> >> --- a/tools/lib/bpf/usdt.c
> >> +++ b/tools/lib/bpf/usdt.c
> >> @@ -614,11 +614,28 @@ static bool has_nop_combo(int fd, long off)
> >> return false;
> >> return memcmp(buf, nop_combo, 11) == 0;
> >> }
> >> +
> >> +/*
> >> + * The kernel refuses to attach to a nop10 that crosses a page boundary,
> >> + * as it can't be atomically rewritten. Page offset of the probe is the
> >> + * same in the file and in any mapping, so this can be checked statically.
> >> + */
> >> +static bool nop10_within_page(long off)
> >> +{
> >> + long page_sz = getpagesize();
> >> +
> >> + return off % page_sz + 10 <= page_sz;
> > could this be another check in has_nop_combo ? so we do not
> > need to introduce another stub

I'd go a step further and collapse three checks, including
man->has_uprobe_syscall, into a single "can we do uprobe nop
optimization" function?

> >
> > otherwise lgtm, thanks
> >
> > jirka
> >
> Thanks Jirka
>
> Sound reasonable, I will do it.
>