Re: [RFC PATCH bpf-next v3 3/3] libbpf: Auto-upgrade kprobes to multi-kprobes when supported
From: Varun R Mallya
Date: Fri Apr 10 2026 - 03:36:23 EST
On Fri, Apr 03, 2026 at 01:35:31PM +0000, bot+bpf-ci@xxxxxxxxxx wrote:
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index bc749b9c291e..f566527d95f3 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
>
> [ ... ]
>
> > @@ -11841,6 +11867,30 @@ 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) {
>
> [ ... ]
>
> > + if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI) {
> > + pr_warn("prog '%s': multi-kprobe upgrade failed (off=%lu, mode=%d); use SEC(\"kprobe.single\")\n",
> > + prog->name, offset, attach_mode);
>
> Should this use %zu instead of %lu for offset? It is declared as
> size_t in this function, and the existing pr_warn() calls further
> down use %zx for the same variable.
Valid, I'll do that too.
> > + return libbpf_err_ptr(-ENOTSUP);
> > + }
>
> [ ... ]
>
> > @@ -12297,14 +12347,24 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf
> > *link = NULL;
> >
> > /* no auto-attach for SEC("kprobe") and SEC("kretprobe") */
> > - if (strcmp(prog->sec_name, "kprobe") == 0 || strcmp(prog->sec_name, "kretprobe") == 0)
> > + if (strcmp(prog->sec_name, "kprobe") == 0 ||
> > + strcmp(prog->sec_name, "kretprobe") == 0 ||
> > + strcmp(prog->sec_name, "kprobe.single") == 0 ||
> > + strcmp(prog->sec_name, "kretprobe.single") == 0)
> > return 0;
>
> The comment above still only mentions SEC("kprobe") and
> SEC("kretprobe"). Could it be updated to also mention the .single
> variants that are now handled here?
>
This seems valid, I'll add this into the next version.
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/23947048141