Re: [RFC PATCH bpf-next v3 1/3] libbpf: Auto-upgrade uprobes to multi-uprobes when supported
From: bot+bpf-ci
Date: Fri Apr 03 2026 - 09:39:33 EST
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 42bdba4efd0c..bc749b9c291e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -12812,6 +12830,27 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,
> func_offset += sym_off;
> }
>
> + /* This provides backwards compatibility to programs using uprobe, but
> + * have been auto-upgraded to multi uprobe.
> + */
> + if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI) {
> + LIBBPF_OPTS(bpf_uprobe_multi_opts, multi_opts);
> + __u64 bpf_cookie;
> +
> + multi_opts.cnt = 1;
> + multi_opts.retprobe = OPTS_GET(opts, retprobe, false);
> + if (func_offset || func_name)
> + multi_opts.offsets = &func_offset;
> + if (ref_ctr_off)
> + multi_opts.ref_ctr_offsets = &ref_ctr_off;
> +
> + bpf_cookie = OPTS_GET(opts, bpf_cookie, 0);
> + if (bpf_cookie)
> + multi_opts.cookies = &bpf_cookie;
> +
> + return bpf_program__attach_uprobe_multi(prog, pid, binary_path,
> + NULL, &multi_opts);
> + }
> legacy = determine_uprobe_perf_type() < 0;
> switch (attach_mode) {
> case PROBE_ATTACH_MODE_LEGACY:
Should the redirect to bpf_program__attach_uprobe_multi() take attach_mode
into account?
The attach_mode field is extracted from opts earlier in this function:
attach_mode = OPTS_GET(opts, attach_mode, PROBE_ATTACH_MODE_DEFAULT);
but the multi-uprobe redirect returns before the switch(attach_mode) is
ever reached. If a caller explicitly passes PROBE_ATTACH_MODE_LEGACY or
PROBE_ATTACH_MODE_PERF, that request is silently ignored and the
attachment goes through the multi-uprobe path regardless.
The kernel's __perf_event_set_bpf_prog() does not check
prog->expected_attach_type for KPROBE programs, so perf-event-based
attachment would still work for auto-upgraded programs if the code were
to fall through.
For example, test_attach_probe_manual() in
prog_tests/attach_probe.c calls bpf_program__attach_uprobe_opts()
with PROBE_ATTACH_MODE_LEGACY and PROBE_ATTACH_MODE_PERF on programs
using SEC("uprobe") and SEC("uretprobe") from
progs/test_attach_probe_manual.c. After auto-upgrade, these tests
would silently use multi-uprobe attachment instead of exercising the
requested attachment modes.
Would it make sense to skip the multi-uprobe redirect when attach_mode
is explicitly set to a non-default value, something like:
if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI &&
attach_mode == PROBE_ATTACH_MODE_DEFAULT) {
This would preserve the transparent upgrade for the common case while
still respecting explicit attachment mode requests.
---
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