Re: [RFC PATCH bpf-next 04/12] bpf: Create insn_array map for bpf SDT probe

From: bot+bpf-ci

Date: Sat Jun 27 2026 - 11:34:57 EST


> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 327c9d412fe8..3f8b12a1eb8b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c

[ ... ]

> @@ -6686,6 +6692,131 @@ static int create_jt_map(struct bpf_object *obj, struct bpf_program *prog, struc
> return err;
> }
>
> +static int bpf_object__resolve_sdt_progs(struct bpf_object *obj)
> +{
> + int i, j;
> + struct bpf_light_subprog *sp;
> +
> + for (i = 0; i < obj->sdt_entry_cnt; i++) {
> + struct sdt_entry *e = &obj->sdt_entries[i];
> + struct bpf_program *prog, *subprog;
> +
> + prog = find_prog_by_sec_insn(obj, e->sec_idx, e->insn_idx);
> + if (!prog) {
> + pr_warn("sdt: probe '%s' at sec %u insn %llu not found in any program\n",
> + e->name, (unsigned)e->sec_idx, (unsigned long long)e->insn_idx);
> + return -EINVAL;
> + }
> +
> + /* resolve subprog probe in the main prog that absorbed the subprog */
> + if (prog_is_subprog(obj, prog) && prog->absorbed_by != -1) {
> + subprog = prog;
> + prog = &obj->programs[prog->absorbed_by];

Can a subprog that holds an SDT probe be absorbed into more than one main
program?

bpf_object__relocate_calls() resets every subprog's sub_insn_off to 0
before relocating each main program, and bpf_object__reloc_code() then
appends a fresh copy of the subprog's code into every main program that
calls it. In that case the same probe instruction ends up in several main
programs.

Here resolve only attributes the probe to a single program via
prog->absorbed_by, and create_sdt_maps below populates only that one
program's map. Would the other main programs that also contain a copy of
the probe instruction end up with no entry in their SDT map, so the probe
is silently missing there?

[ ... ]

> @@ -7135,6 +7266,8 @@ bpf_object__reloc_code(struct bpf_object *obj, struct bpf_program *main_prog,
> err = bpf_object__append_subprog_code(obj, main_prog, subprog);
> if (err)
> return err;
> + if (subprog->absorbed_by == -1)
> + subprog->absorbed_by = main_prog - obj->programs;

Since absorbed_by is only set when it is still -1, it records the first
main program that absorbs the subprog. Is that the reason later main
programs that also append a copy of the subprog do not get an SDT entry?


---
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/28292842584