From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCHv3 bpf-next 3/5] libbpf: Add support to detect nop,nop5 instructions combo for usdt probe
Date: Thu, 12 Feb 2026 15:08:32 +0100 [thread overview]
Message-ID: <aY3e4F51mNpqMMOO@krava> (raw)
In-Reply-To: <CAEf4BzbFjXDiQUcZbxpceVTGLa4UGvm76sAuGXEFVREj9FLoJw@mail.gmail.com>
On Wed, Feb 11, 2026 at 01:45:12PM -0800, Andrii Nakryiko wrote:
> On Wed, Feb 11, 2026 at 12:49 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Adding support to detect nop,nop5 instructions combo for usdt probe
> > by checking on probe's following nop5 instruction.
> >
> > When the nop,nop5 combo is detected together with uprobe syscall,
> > we can place the probe on top of nop5 and get it optimized.
> >
> > [1] https://github.com/libbpf/usdt
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/lib/bpf/usdt.c | 55 ++++++++++++++++++++++++++++++++++++++++----
> > 1 file changed, 51 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
> > index d1524f6f54ae..4e5f70bb4c31 100644
> > --- a/tools/lib/bpf/usdt.c
> > +++ b/tools/lib/bpf/usdt.c
> > @@ -262,6 +262,7 @@ struct usdt_manager {
> > bool has_bpf_cookie;
> > bool has_sema_refcnt;
> > bool has_uprobe_multi;
> > + bool has_uprobe_syscall;
> > };
> >
> > struct usdt_manager *usdt_manager_new(struct bpf_object *obj)
> > @@ -301,6 +302,13 @@ struct usdt_manager *usdt_manager_new(struct bpf_object *obj)
> > * usdt probes.
> > */
> > man->has_uprobe_multi = kernel_supports(obj, FEAT_UPROBE_MULTI_LINK);
> > +
> > + /*
> > + * Detect kernel support for uprobe() syscall, it's presence means we can
> > + * take advantage of faster nop5 uprobe handling.
> > + * Added in: 56101b69c919 ("uprobes/x86: Add uprobe syscall to speed up uprobe")
> > + */
> > + man->has_uprobe_syscall = kernel_supports(obj, FEAT_UPROBE_SYSCALL);
> > return man;
> > }
> >
> > @@ -585,13 +593,42 @@ static int parse_usdt_note(GElf_Nhdr *nhdr, const char *data, size_t name_off,
> >
> > static int parse_usdt_spec(struct usdt_spec *spec, const struct usdt_note *note, __u64 usdt_cookie);
> >
> > -static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const char *path, pid_t pid,
> > - const char *usdt_provider, const char *usdt_name, __u64 usdt_cookie,
> > - struct usdt_target **out_targets, size_t *out_target_cnt)
> > +#if defined(__x86_64__)
> > +static bool has_nop_combo(int fd, long off)
> > +{
> > + static unsigned char nop_combo[6] = {
> > + 0x90, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nop,nop5 */
> > + };
> > + unsigned char buf[6] = {};
> > +
> > + /*
> > + * We are using file descriptor that backs Elf object,
> > + * let's dup it to be on the safe side.
> > + */
> > + fd = dup(fd);
> > + if (fd < 0)
> > + return false;
> > + if (lseek(fd, off, SEEK_SET) == off)
> > + read(fd, buf, 6);
> > + close(fd);
>
> ugh, use pread() instead of all this ? I wouldn't bother with short
> read handling, if we didn't get 6 bytes, so be it, no nop5.
ok, that's simpler, will change
thanks,
jirka
>
> > + return memcmp(buf, nop_combo, 6) == 0;
> > +}
> > +#else
> > +static bool has_nop_combo(int fd, long off)
> > +{
> > + return false;
> > +}
> > +#endif
> > +
>
> [...]
next prev parent reply other threads:[~2026-02-12 14:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 8:48 [PATCHv3 bpf-next 0/5] libbpf: Make optimized uprobes backward compatible Jiri Olsa
2026-02-11 8:48 ` [PATCHv3 bpf-next 1/5] selftests/bpf: Emit nop,nop5 instructions combo for x86_64 arch Jiri Olsa
2026-02-11 8:48 ` [PATCHv3 bpf-next 2/5] libbpf: Add uprobe syscall feature detection Jiri Olsa
2026-02-11 21:45 ` Andrii Nakryiko
2026-02-12 14:08 ` Jiri Olsa
2026-02-11 8:48 ` [PATCHv3 bpf-next 3/5] libbpf: Add support to detect nop,nop5 instructions combo for usdt probe Jiri Olsa
2026-02-11 21:45 ` Andrii Nakryiko
2026-02-12 14:08 ` Jiri Olsa [this message]
2026-02-11 8:48 ` [PATCHv3 bpf-next 4/5] selftests/bpf: Add test for checking correct nop of optimized usdt Jiri Olsa
2026-02-11 9:13 ` bot+bpf-ci
2026-02-11 21:45 ` Andrii Nakryiko
2026-02-12 14:10 ` Jiri Olsa
2026-02-11 8:48 ` [PATCHv3 bpf-next 5/5] selftests/bpf: Add usdt trigger bench Jiri Olsa
2026-02-11 21:45 ` Andrii Nakryiko
2026-02-12 14:09 ` 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=aY3e4F51mNpqMMOO@krava \
--to=olsajiri@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.