From: Varun R Mallya <varunrmallya@gmail.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: andrii@kernel.org, alan.maguire@oracle.com,
yonghong.song@linux.dev, song@kernel.org, bpf@vger.kernel.org,
ast@kernel.org, daniel@iogearbox.net, memxor@gmail.com,
eddyz87@gmail.com, martin.lau@linux.dev,
menglong8.dong@gmail.com, puranjay@kernel.org, bjorn@kernel.org,
leon.hwang@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next v2 3/3] libbpf: Auto-upgrade kprobes to multi-kprobes when supported
Date: Wed, 1 Apr 2026 16:23:03 +0530 [thread overview]
Message-ID: <aczsqSHLdM1KtFFH@computer> (raw)
In-Reply-To: <acqOcnYHvG4GUgwN@krava>
On Mon, Mar 30, 2026 at 04:53:38PM +0200, Jiri Olsa wrote:
> On Mon, Mar 30, 2026 at 04:30:19PM +0530, Varun R Mallya wrote:
> > + const char *sec_name = prog->sec_name;
> > + /* Here, we filter out for k[ret]probe or "k[ret]probe/"
> > + * but we leave out anything with an '@'
> > + * in it as kprobe_multi does not support versioned
> > + * symbols, so we don't upgrade. Also for '+' as we do not
>
> hum, kprobe versioned symbols?
Thanks for catching that! Removed.
> > + (sec_name[9] == '/' || sec_name[9] == '\0'))) &&
> > + !strchr(sec_name, '@') &&
> > + !strchr( sec_name, '+') &&
> > + !(prog->prog_flags & BPF_F_SLEEPABLE))
>
> is this check necessary?
I had to add that check because selftests/bpf/prog_tests/attach_probe.c
was failing. Sleepable kprobes are not supposed to attach successfully,
but since this was upgraded to multi, it was doing so. So, I had to stop
all sleepable kprobes from being upgraded to maintain compatibility.
I'd like to know if kprobe_multi is even allowed to be sleepable. I
could not really find any selftests or patches for sleepable kprobe_multi
functionality anywhere, so I just want to check if this is not actually
intended behaviour and we are missing a check somewhere.
> > + prog->expected_attach_type = BPF_TRACE_KPROBE_MULTI;
> > + }
> > +
>
> maybe add the upgrade logic into separate function, like
>
> static int upgrade_program(struct bpf_program *prog)
I am thinking of making the return type void though.
I see that there is int everywhere else, but it does not make sense to me
to return an int here since I'm not doing any operation in here that
could return an error. Should I keep it as int or make it void ??
>
> > err = bpf_object__sanitize_prog(obj, prog);
> > if (err)
> > return err;
> > @@ -9924,10 +9942,12 @@ static const struct bpf_sec_def section_defs[] = {
> > SEC_DEF("sk_reuseport/migrate", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, SEC_ATTACHABLE),
> > SEC_DEF("sk_reuseport", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT, SEC_ATTACHABLE),
> > SEC_DEF("kprobe+", KPROBE, 0, SEC_NONE, attach_kprobe),
> > + SEC_DEF("kprobe.single+", KPROBE, 0, SEC_NONE, attach_kprobe),
> > SEC_DEF("uprobe+", KPROBE, 0, SEC_NONE, attach_uprobe),
> > SEC_DEF("uprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe),
> > SEC_DEF("uprobe.single+", KPROBE, 0, SEC_NONE, attach_uprobe),
> > SEC_DEF("kretprobe+", KPROBE, 0, SEC_NONE, attach_kprobe),
> > + SEC_DEF("kretprobe.single+", KPROBE, 0, SEC_NONE, attach_kprobe),
> > SEC_DEF("uretprobe+", KPROBE, 0, SEC_NONE, attach_uprobe),
> > SEC_DEF("uretprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe),
> > SEC_DEF("uretprobe.single+", KPROBE, 0, SEC_NONE, attach_uprobe),
> > @@ -11769,6 +11789,25 @@ bpf_program__attach_kprobe_opts(const struct bpf_program *prog,
> > offset = OPTS_GET(opts, offset, 0);
> > pe_opts.bpf_cookie = OPTS_GET(opts, bpf_cookie, 0);
> >
> > + /* This provides backwards compatibility to programs using kprobe, but
> > + * have been auto-upgraded to multi kprobe.
> > + */
> > + if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI &&
> > + offset == 0 && attach_mode == PROBE_ATTACH_MODE_DEFAULT) {
> > + LIBBPF_OPTS(bpf_kprobe_multi_opts, multi_opts);
> > + const char *syms[1] = { func_name };
> > + __u64 bpf_cookie;
> > +
> > + multi_opts.retprobe = OPTS_GET(opts, retprobe, false);
> > + multi_opts.syms = syms;
>
> could we do directly:
>
> multi_opts.syms = &func_name;
>
> jirka
Implemented.
next prev parent reply other threads:[~2026-04-01 10:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 11:00 [RFC PATCH bpf-next v2 0/3] Upgrading uprobe and kprobe to their `multi` counterparts Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 1/3] libbpf: Auto-upgrade uprobes to multi-uprobes when supported Varun R Mallya
2026-03-30 11:47 ` bot+bpf-ci
2026-03-30 14:52 ` Jiri Olsa
2026-04-01 9:56 ` Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 2/3] libbpf: Add FEAT_KPROBE_MULTI_LINK feature probe Varun R Mallya
2026-03-30 14:42 ` Leon Hwang
2026-04-01 9:57 ` Varun R Mallya
2026-03-30 14:52 ` Jiri Olsa
2026-04-01 9:49 ` Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 3/3] libbpf: Auto-upgrade kprobes to multi-kprobes when supported Varun R Mallya
2026-03-30 11:47 ` bot+bpf-ci
2026-04-01 9:59 ` Varun R Mallya
2026-03-30 14:53 ` Jiri Olsa
2026-04-01 10:53 ` Varun R Mallya [this message]
2026-04-01 11:11 ` Varun R Mallya
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=aczsqSHLdM1KtFFH@computer \
--to=varunrmallya@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=menglong8.dong@gmail.com \
--cc=olsajiri@gmail.com \
--cc=puranjay@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@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