Re: [PATCH v4 1/3] libbpf: load vmlinux BTF in gen_loader mode for struct_ops
From: bot+bpf-ci
Date: Wed May 27 2026 - 09:44:47 EST
> commit 29cedaf6d7d80a7e880a2e639f40fbafcbaf2e65
> Author: Siddharth Nayyar <sidnayyar@xxxxxxxxxx>
> Date: Wed May 27 12:52:57 2026 +0000
>
> libbpf: load vmlinux BTF in gen_loader mode for struct_ops
>
> During light skeleton generation (`bpftool gen skeleton -L`), libbpf
> runs in gen_loader mode. Previously, `bpf_object__load_vmlinux_btf()`
> completely bypassed loading the kernel vmlinux BTF (`obj->btf_vmlinux`)
> if `gen_loader` was active.
>
> However, BPF `struct_ops` maps (such as `sched_ext_ops` maps) require
> resolving the kernel-side struct type IDs and member sizes at
> compile/skeleton generation time. Without loading `btf_vmlinux`, libbpf
> cannot query the kernel BTF types, causing light skeleton generation for
> `struct_ops` to fail or omit crucial type information.
>
> Fix this by modifying the check to load `btf_vmlinux` even in
> `gen_loader` mode if the BPF object contains `struct_ops` maps.
>
> Signed-off-by: Siddharth Nayyar <sidnayyar@xxxxxxxxxx>
Alexei Starovoitov requested in v3 review that a selftest be added to
prove struct_ops light skeletons work end-to-end:
"The selftest is mandatory to prove that."
https://lore.kernel.org/bpf/CAADnVQ+AA_fmRw7uRwdL2TMyMbpWeebOQKb=0wvpKiQR6Ee5xQ@xxxxxxxxxxxxxx/
This requirement has not been addressed in v4. Should a selftest be added
to demonstrate that struct_ops light skeletons work correctly with this
change?
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ab2071fdd3e8..420d37f215ea 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3544,15 +3544,20 @@ static bool prog_needs_vmlinux_btf(struct bpf_program *prog)
> return false;
> }
>
> -static bool map_needs_vmlinux_btf(struct bpf_map *map)
> +static bool obj_maps_need_vmlinux_btf(const struct bpf_object *obj)
> {
> - return bpf_map__is_struct_ops(map);
> + struct bpf_map *map;
> +
> + bpf_object__for_each_map(map, obj) {
> + if (bpf_map__is_struct_ops(map))
> + return true;
> + }
> + return false;
> }
>
> static bool obj_needs_vmlinux_btf(const struct bpf_object *obj)
> {
> struct bpf_program *prog;
> - struct bpf_map *map;
> int i;
>
> /* CO-RE relocations need kernel BTF, only when btf_custom_path
> @@ -3577,12 +3582,7 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj)
> return true;
> }
>
> - bpf_object__for_each_map(map, obj) {
> - if (map_needs_vmlinux_btf(map))
> - return true;
> - }
> -
> - return false;
> + return obj_maps_need_vmlinux_btf(obj);
> }
>
> static int bpf_object__load_vmlinux_btf(struct bpf_object *obj, bool force)
> @@ -3590,7 +3590,11 @@ static int bpf_object__load_vmlinux_btf(struct bpf_object *obj, bool force)
> int err;
>
> /* btf_vmlinux could be loaded earlier */
> - if (obj->btf_vmlinux || obj->gen_loader)
> + if (obj->btf_vmlinux)
> + return 0;
> +
> + /* only struct_ops maps need btf_vmlinux in gen_loader */
> + if (obj->gen_loader && !obj_maps_need_vmlinux_btf(obj))
> return 0;
>
> if (!force && !obj_needs_vmlinux_btf(obj))
This looks like a bug fix for gen_loader mode with struct_ops maps.
Multiple CI reviews (v1 and v3) noted that this should include:
Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
https://lore.kernel.org/bpf/b4b4ca51ae8e281a37707cbcd2ba8349dabc6c630e96461929be0872fd8ed0e6@xxxxxxxxxxxxxxx/
Should this tag be added to indicate it fixes a limitation in the original
gen_loader implementation?
---
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/26512949106