Re: [PATCH v16 bpf-next 1/9] btf: Add BTF kind layout encoding to UAPI

[email protected] Thu, 26 Mar 2026 15:53:17 +0000 (UTC)
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <bd1688717a1d23adc4c0b7065c880526312122d910e37f72e12885ff5d5047b4@mail.kernel.org>
> diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
> index 266d4ffa6c077..638615ebddc22 100644
> --- a/tools/include/uapi/linux/btf.h
> +++ b/tools/include/uapi/linux/btf.h

[ ... ]

> @@ -19,6 +29,8 @@ struct btf_header {
>  	__u32	type_len;	/* length of type section	*/
>  	__u32	str_off;	/* offset of string section	*/
>  	__u32	str_len;	/* length of string section	*/
> +	__u32	layout_off;	/* offset of layout section	*/
> +	__u32	layout_len;	/* length of layout section	*/
>  };

Adding these two fields changes sizeof(struct btf_header) from 24
to 32 bytes.  In libbpf's btf_parse_hdr(), the non-native endian
path has a strict equality check:

tools/lib/bpf/btf.c:btf_parse_hdr() {
    if (hdr->magic == bswap_16(BTF_MAGIC)) {
        btf->swapped_endian = true;
        if (bswap_32(hdr->hdr_len) != sizeof(struct btf_header)) {
            ...
            return -ENOTSUP;
        }
    ...
}

All existing cross-endian BTF has hdr_len=24.  After this UAPI
change, sizeof(struct btf_header) becomes 32, so
bswap_32(24) != 32 and the check rejects them.

Would it make sense to update this check in the same patch as
the header change?  As-is, recompiling libbpf with the new
header breaks loading of any pre-existing non-native-endian
BTF data.

This appears to be addressed in the next patch in the series,
d51f2326465ba ("libbpf: Support layout section handling in BTF"),
which relaxes the check to a minimum size comparison.


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