Re: [PATCH v11 bpf-next 1/8] btf: add BTF kind layout encoding to UAPI

[email protected]
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <ab4012acbb2b4a94c2e676d063d06353f91d383e8e462bd077185ad577f2eb93@mail.kernel.org>
> diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
> index 266d4ffa6c07..638615ebddc2 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 against sizeof(struct btf_header):

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 data has hdr_len=24.  After this UAPI
change, sizeof(struct btf_header) becomes 32, so the check rejects
any pre-existing non-native-endian BTF.

This is addressed in the next patch in the series, 5b3c2181ddc2
("libbpf: Support layout section handling in BTF"), which relaxes
the check to a minimum size comparison using
offsetofend(struct btf_header, str_len), and also adds the missing
layout_off/layout_len byte-swapping in btf_bswap_hdr().


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

AI-authorship-score: low
AI-authorship-explanation: Standard UAPI structure definition from a known kernel developer with prior lore discussion links and Suggested-by tag, consistent with human authorship.
issues-found: 1
issue-severity-score: medium
issue-severity-explanation: UAPI header change increases sizeof(struct btf_header), breaking libbpf cross-endian BTF loading for all pre-existing non-native-endian BTF data; fixed in the next patch in the series.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.