* [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops
@ 2026-05-24 11:26 Siddharth Nayyar
2026-05-24 11:42 ` Alexei Starovoitov
2026-05-24 12:08 ` bot+bpf-ci
0 siblings, 2 replies; 3+ messages in thread
From: Siddharth Nayyar @ 2026-05-24 11:26 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa
Cc: bpf, linux-kernel, gprocida, maennich, Siddharth Nayyar
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 actually requires kernel vmlinux BTF
(e.g. contains `struct_ops` maps).
Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
---
tools/lib/bpf/libbpf.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3a80a018fc7d..cb1b7ea884a7 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3590,7 +3590,10 @@ 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;
+
+ if (obj->gen_loader && !obj_needs_vmlinux_btf(obj))
return 0;
if (!force && !obj_needs_vmlinux_btf(obj))
---
base-commit: c6e99c10fd9855082568cbd71bb2cc5dc90eda53
change-id: 20260522-libbpf-load-vmlinux-btf-in-gen_loader-mode-4474834aa467
Best regards,
--
Siddharth Nayyar <sidnayyar@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops
2026-05-24 11:26 [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops Siddharth Nayyar
@ 2026-05-24 11:42 ` Alexei Starovoitov
2026-05-24 12:08 ` bot+bpf-ci
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2026-05-24 11:42 UTC (permalink / raw)
To: Siddharth Nayyar
Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa, bpf, LKML, gprocida,
maennich
On Sun, May 24, 2026 at 1:26 PM Siddharth Nayyar <sidnayyar@google.com> wrote:
>
> 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 actually requires kernel vmlinux BTF
> (e.g. contains `struct_ops` maps).
>
> Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
> ---
> tools/lib/bpf/libbpf.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 3a80a018fc7d..cb1b7ea884a7 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3590,7 +3590,10 @@ 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;
> +
> + if (obj->gen_loader && !obj_needs_vmlinux_btf(obj))
> return 0;
That's a step, but please provide an end-to-end solution
where struct-ops and sched-ext programs are supported
in lksel mode.
This step alone may be more confusing to users than helpful.
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops
2026-05-24 11:26 [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops Siddharth Nayyar
2026-05-24 11:42 ` Alexei Starovoitov
@ 2026-05-24 12:08 ` bot+bpf-ci
1 sibling, 0 replies; 3+ messages in thread
From: bot+bpf-ci @ 2026-05-24 12:08 UTC (permalink / raw)
To: sidnayyar, andrii, eddyz87, ast, daniel, martin.lau, memxor,
song, yonghong.song, jolsa
Cc: bpf, linux-kernel, gprocida, maennich, sidnayyar, ast, andrii,
daniel, martin.lau, eddyz87, yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2655 bytes --]
> commit c1abfce71ecf8c95413f5afe0d153662877e0ad0
> Author: Siddharth Nayyar <sidnayyar@google.com>
>
> 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 actually requires kernel vmlinux BTF
> (e.g. contains `struct_ops` maps).
>
> Signed-off-by: Siddharth Nayyar <sidnayyar@google.com>
This looks like a bug fix for gen_loader mode with struct_ops maps. Should
this include:
Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ab2071fdd3e8..6163e53a2056 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3590,7 +3590,10 @@ 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;
> +
> + if (obj->gen_loader && !obj_needs_vmlinux_btf(obj))
> return 0;
>
> if (!force && !obj_needs_vmlinux_btf(obj))
Alexei Starovoitov raised a design concern about this approach in v1. He
requested an end-to-end solution where struct-ops and sched-ext programs are
fully supported in light skeleton (lksel) mode, rather than just this
incremental fix. His specific comment was: "That's a step, but please provide
an end-to-end solution where struct-ops and sched-ext programs are supported
in lksel mode. This step alone may be more confusing to users than helpful."
This feedback has not been addressed - no v2 was posted and no author response
was provided.
Reference: https://lore.kernel.org/bpf/CAADnVQ+M6pJJJ_YY5QO_EYJyDfd=TNs=A1xFB9_RFLTqaM=w_g@mail.gmail.com/
---
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/26360291945
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-24 12:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-24 11:26 [PATCH] libbpf: load vmlinux BTF in gen_loader mode for struct_ops Siddharth Nayyar
2026-05-24 11:42 ` Alexei Starovoitov
2026-05-24 12:08 ` bot+bpf-ci
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®