| fd5425b6 | 07-Aug-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
docs, resolve_btfids: Document kfunc BTF annotation emission
resolve_btfids now emits the bpf_kfunc and bpf_fastcall BTF decl tags and the arena address_space(1) type attribute for kfuncs, which wer
docs, resolve_btfids: Document kfunc BTF annotation emission
resolve_btfids now emits the bpf_kfunc and bpf_fastcall BTF decl tags and the arena address_space(1) type attribute for kfuncs, which were previously produced by pahole.
Reflect this in the in-tree comments and documentation.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://patch.msgid.link/20260807032029.78092-7-ihor.solodrai@linux.dev Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
show more ...
|
| 69239310 | 07-Aug-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Emit bpf_kfunc and bpf_fastcall decl tags
Emit the bpf_kfunc decl tag for every discovered kfunc, and bpf_fastcall for kfuncs flagged KF_FASTCALL. These were previously produced by p
resolve_btfids: Emit bpf_kfunc and bpf_fastcall decl tags
Emit the bpf_kfunc decl tag for every discovered kfunc, and bpf_fastcall for kfuncs flagged KF_FASTCALL. These were previously produced by pahole under --btf_features=decl_tag_kfuncs.
resolve_btfids now discovers kfuncs from the BTF ID sets [1] and becomes the source of truth for their annotations.
Drop decl_tag_kfuncs pahole feature flag from scripts/Makefile.btf
[1] https://lore.kernel.org/all/20260722233518.778854-1-ihor.solodrai@linux.dev/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://patch.msgid.link/20260807032029.78092-5-ihor.solodrai@linux.dev Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
show more ...
|
| 27a78c2e | 07-Aug-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Process KF_ARENA_* flags in resolve_btfids
For kfuncs flagged with KF_ARENA_RET, KF_ARENA_ARG1 or KF_ARENA_ARG2, the address_space(1) attribute (a type tag with kflag=1) must be emit
resolve_btfids: Process KF_ARENA_* flags in resolve_btfids
For kfuncs flagged with KF_ARENA_RET, KF_ARENA_ARG1 or KF_ARENA_ARG2, the address_space(1) attribute (a type tag with kflag=1) must be emitted for the corresponding type in BTF. This was previously done by pahole via the "attributes" BTF feature [1].
Implement the emission of the arena attributes in resolve_btfids: for flagged kfuncs create a new function prototype with updated BTF types. The original proto may be shared with sibling FUNCs, so it is not modified in place.
Emission is unconditional: kbuild controls the pahole flags, so the input BTF is expected to not have these attributes. Invalid declarations are reported as errors.
Drop the "attributes" pahole feature from scripts/Makefile.btf resolve_btfids now emits them for all supported pahole versions.
[1] https://lore.kernel.org/dwarves/20250228194654.1022535-1-ihor.solodrai@linux.dev/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://patch.msgid.link/20260807032029.78092-3-ihor.solodrai@linux.dev Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
show more ...
|
| 140a3479 | 23-Jul-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Enforce consistent kfunc flags across BTF ID sets
A kfunc may be listed in several BTF ID sets, which is expected because different kfuncs are available to BPF programs depending on
resolve_btfids: Enforce consistent kfunc flags across BTF ID sets
A kfunc may be listed in several BTF ID sets, which is expected because different kfuncs are available to BPF programs depending on their type.
However kfunc flags across different BTF ID sets must be consistent [1]. The flags should be considered a part of the kfunc declaration, because they influence its BTF representation and verifier handling.
Enforce the kfunc flag consistency in resolve_btifds by hard failing on error and blocking kernel (or module) build.
[1] https://lore.kernel.org/bpf/9b2196dd-443b-4632-ae11-030cdbdc59b4@linux.dev/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260722233518.778854-9-ihor.solodrai@linux.dev
show more ...
|
| f9f60d41 | 23-Jul-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Discover kfuncs from BTF ID sets
collect_kfuncs() currently uses bpf_kfunc decl tags to identify the list of kfuncs. The decl tags are generated by pahole, which makes current implem
resolve_btfids: Discover kfuncs from BTF ID sets
collect_kfuncs() currently uses bpf_kfunc decl tags to identify the list of kfuncs. The decl tags are generated by pahole, which makes current implementation implicitly rely on those tags being generated.
The authoritative source, used by the the BPF verifier for kfunc registration, of functions being BPF kfuncs are BTF_KFUNCS_START()/END() declarations. These are BTF_ID_SET8 under the hood. Currently resolve_btfids reads kfunc flags from these sets, and populates them with BTF IDs.
Implement kfunc discovery from BTF_ID_SET8 symbols in resolve_btfids, removing the dependency on pahole's emmission of decl tags.
Walk BTF_ID_KIND_SET8 sets, and use the address-to-symbol index to look up set entry's BTF_ID symbol name (before .BTF_ids is patched), recording the paired flags directly. This makes find_kfunc_flags() helper unnecessary, so it's removed.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260722233518.778854-8-ihor.solodrai@linux.dev
show more ...
|
| 91efe50e | 23-Jul-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Fix the _impl lookup for module BTF
process_kfunc_with_implicit_args() skips generating <name>_impl function when one already exists for backwards compatibility.
It uses btf__find_b
resolve_btfids: Fix the _impl lookup for module BTF
process_kfunc_with_implicit_args() skips generating <name>_impl function when one already exists for backwards compatibility.
It uses btf__find_by_name_kind(), which searches the base BTF before the split BTF. When resolve_btfids processes a module, a same-named _impl in vmlinux would be found and the module's own counterpart would not be created.
Fix by using btf__find_by_name_kind_own() for the lookup.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260722233518.778854-6-ihor.solodrai@linux.dev
show more ...
|
| e4293c31 | 23-Jul-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Keep collected kfuncs in a rbtree
Store collected kfuncs in a rbtree keyed by BTF ID instead of a dynamically grown array. This allows for efficient deduplication for kfuncs declared
resolve_btfids: Keep collected kfuncs in a rbtree
Store collected kfuncs in a rbtree keyed by BTF ID instead of a dynamically grown array. This allows for efficient deduplication for kfuncs declared in multiple sets, which is needed for subsequent patches [1].
[1] https://lore.kernel.org/bpf/CAEf4BzaLzX3mXvQzxv+gbmZOh84XvYofLjMSWFYghNjS-ohEZg@mail.gmail.com/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260722233518.778854-4-ihor.solodrai@linux.dev
show more ...
|
| c5ab68a5 | 23-Jul-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Index BTF ID symbols by address
Keep an address-sorted index of parsed .BTF_ids symbols so that the original BTF_ID symbol name can be recovered from an entry address.
Use the index
resolve_btfids: Index BTF ID symbols by address
Keep an address-sorted index of parsed .BTF_ids symbols so that the original BTF_ID symbol name can be recovered from an entry address.
Use the index in find_kfunc_flags() to scan BTF_SET8_KFUNCS entries directly and match each entry back to the requested kfunc.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Reviewed-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20260722233518.778854-3-ihor.solodrai@linux.dev
show more ...
|
| c5c1e313 | 23-Feb-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Fix memory leaks reported by ASAN
Running resolve_btfids with ASAN reveals memory leaks in btf_id handling.
- Change get_id() to use a local buffer - Make btf_id__add() strdup the n
resolve_btfids: Fix memory leaks reported by ASAN
Running resolve_btfids with ASAN reveals memory leaks in btf_id handling.
- Change get_id() to use a local buffer - Make btf_id__add() strdup the name internally - Add btf_id__free_all() that frees all nodese of a tree - Call the cleanup function on exit for every tree
Acked-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260223190736.649171-8-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 9d199965 | 20-Jan-2026 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Support for KF_IMPLICIT_ARGS
Implement BTF modifications in resolve_btfids to support BPF kernel functions with implicit arguments.
For a kfunc marked with KF_IMPLICIT_ARGS flag, a
resolve_btfids: Support for KF_IMPLICIT_ARGS
Implement BTF modifications in resolve_btfids to support BPF kernel functions with implicit arguments.
For a kfunc marked with KF_IMPLICIT_ARGS flag, a new function prototype is added to BTF that does not have implicit arguments. The kfunc's prototype is then updated to a new one in BTF. This prototype is the intended interface for the BPF programs.
A <func_name>_impl function is added to BTF to make the original kfunc prototype searchable for the BPF verifier. If a <func_name>_impl function already exists in BTF, its interpreted as a legacy case, and this step is skipped.
Whether an argument is implicit is determined by its type: currently only `struct bpf_prog_aux *` is supported.
As a result, the BTF associated with kfunc is changed from
__bpf_kfunc bpf_foo(int arg1, struct bpf_prog_aux *aux);
into
bpf_foo_impl(int arg1, struct bpf_prog_aux *aux); __bpf_kfunc bpf_foo(int arg1);
For more context see previous discussions and patches [1][2].
[1] https://lore.kernel.org/dwarves/ba1650aa-fafd-49a8-bea4-bdddee7c38c9@linux.dev/ [2] https://lore.kernel.org/bpf/20251029190113.3323406-1-ihor.solodrai@linux.dev/
Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260120222638.3976562-6-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 1a8fa7fa | 31-Dec-2025 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Implement --patch_btfids
Recent changes in BTF generation [1] rely on ${OBJCOPY} command to update .BTF_ids section data in target ELF files.
This exposed a bug in llvm-objcopy --up
resolve_btfids: Implement --patch_btfids
Recent changes in BTF generation [1] rely on ${OBJCOPY} command to update .BTF_ids section data in target ELF files.
This exposed a bug in llvm-objcopy --update-section code path, that may lead to corruption of a target ELF file. Specifically, because of the bug st_shndx of some symbols may be (incorrectly) set to 0xffff (SHN_XINDEX) [2][3].
While there is a pending fix for LLVM, it'll take some time before it lands (likely in 22.x). And the kernel build must keep working with older LLVM toolchains in the foreseeable future.
Using GNU objcopy for .BTF_ids update would work, but it would require changes to LLVM-based build process, likely breaking existing build environments as discussed in [2].
To work around llvm-objcopy bug, implement --patch_btfids code path in resolve_btfids as a drop-in replacement for:
${OBJCOPY} --update-section .BTF_ids=${btf_ids} ${elf}
Which works specifically for .BTF_ids section:
${RESOLVE_BTFIDS} --patch_btfids ${btf_ids} ${elf}
This feature in resolve_btfids can be removed at some point in the future, when llvm-objcopy with a relevant bugfix becomes common.
[1] https://lore.kernel.org/bpf/20251219181321.1283664-1-ihor.solodrai@linux.dev/ [2] https://lore.kernel.org/bpf/20251224005752.201911-1-ihor.solodrai@linux.dev/ [3] https://github.com/llvm/llvm-project/issues/168060#issuecomment-3533552952
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20251231012558.1699758-1-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 522397d0 | 19-Dec-2025 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Change in-place update with raw binary output
Currently resolve_btfids updates .BTF_ids section of an ELF file in-place, based on the contents of provided BTF, usually within the sam
resolve_btfids: Change in-place update with raw binary output
Currently resolve_btfids updates .BTF_ids section of an ELF file in-place, based on the contents of provided BTF, usually within the same input file, and optionally a BTF base.
Change resolve_btfids behavior to enable BTF transformations as part of its main operation. To achieve this, in-place ELF write in resolve_btfids is replaced with generation of the following binaries: * ${1}.BTF with .BTF section data * ${1}.BTF_ids with .BTF_ids section data if it existed in ${1} * ${1}.BTF.base with .BTF.base section data for out-of-tree modules
The execution of resolve_btfids and consumption of its output is orchestrated by scripts/gen-btf.sh introduced in this patch.
The motivation for emitting binary data is that it allows simplifying resolve_btfids implementation by delegating ELF update to the $OBJCOPY tool [1], which is already widely used across the codebase.
There are two distinct paths for BTF generation and resolve_btfids application in the kernel build: for vmlinux and for kernel modules.
For the vmlinux binary a .BTF section is added in a roundabout way to ensure correct linking. The patch doesn't change this approach, only the implementation is a little different.
Before this patch it worked as follows:
* pahole consumed .tmp_vmlinux1 [2] and added .BTF section with llvm-objcopy [3] to it * then everything except the .BTF section was stripped from .tmp_vmlinux1 into a .tmp_vmlinux1.bpf.o object [2], later linked into vmlinux * resolve_btfids was executed later on vmlinux.unstripped [4], updating it in-place
After this patch gen-btf.sh implements the following:
* pahole consumes .tmp_vmlinux1 and produces a *detached* file with raw BTF data * resolve_btfids consumes .tmp_vmlinux1 and detached BTF to produce (potentially modified) .BTF, and .BTF_ids sections data * a .tmp_vmlinux1.bpf.o object is then produced with objcopy copying BTF output of resolve_btfids * .BTF_ids data gets embedded into vmlinux.unstripped in link-vmlinux.sh by objcopy --update-section
For kernel modules, creating a special .bpf.o file is not necessary, and so embedding of sections data produced by resolve_btfids is straightforward with objcopy.
With this patch an ELF file becomes effectively read-only within resolve_btfids, which allows deleting elf_update() call and satellite code (like compressed_section_fix [5]).
Endianness handling of .BTF_ids data is also changed. Previously the "flags" part of the section was bswapped in sets_patch() [6], and then Elf_Type was modified before elf_update() to signal to libelf that bswap may be necessary. With this patch we explicitly bswap entire data buffer on load and on dump.
[1] https://lore.kernel.org/bpf/131b4190-9c49-4f79-a99d-c00fac97fa44@linux.dev/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/link-vmlinux.sh?h=v6.18#n110 [3] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/tree/btf_encoder.c?h=v1.31#n1803 [4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/link-vmlinux.sh?h=v6.18#n284 [5] https://lore.kernel.org/bpf/20200819092342.259004-1-jolsa@kernel.org/ [6] https://lore.kernel.org/bpf/cover.1707223196.git.vmalik@redhat.com/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Alan Maguire <alan.maguire@oracle.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20251219181825.1289460-3-ihor.solodrai@linux.dev
show more ...
|
| fb348d4f | 19-Dec-2025 |
Ihor Solodrai <ihor.solodrai@linux.dev> |
resolve_btfids: Always build with -Wall -Werror
resolve_btfids builds without compiler warnings currently, so let's enforce this for future changes with '-Wall -Werror' flags [1].
[1] https://lore.
resolve_btfids: Always build with -Wall -Werror
resolve_btfids builds without compiler warnings currently, so let's enforce this for future changes with '-Wall -Werror' flags [1].
[1] https://lore.kernel.org/bpf/1957a60b-6c45-42a7-b525-a6e335a735ff@linux.dev/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Alan Maguire <alan.maguire@oracle.com> Link: https://lore.kernel.org/bpf/20251219181321.1283664-5-ihor.solodrai@linux.dev
show more ...
|