Re: [PATCH v9 bpf-next 01/10] btf: add BTF kind layout encoding to UAPI

[email protected]
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <53fd1afa60a674667754fb1d92f3385d695c7db4a2ff2cb92e73ab9390d7a78b@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

[ ... struct btf_layout addition ... ]

> @@ -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 layout_off and layout_len to struct btf_header changes
sizeof(struct btf_header) from 24 to 32 bytes.  Existing libbpf
code in tools/lib/bpf/btf.c uses sizeof(struct btf_header) in two
checks inside btf_parse_hdr() that will regress at this point in the
series:

The minimum size check:

    if (btf->raw_size < sizeof(struct btf_header)) {

now requires 32 bytes instead of 24, so won't this reject valid
BTF blobs produced by older toolchains whose headers are only 24
bytes?

The cross-endian strict equality check:

    if (bswap_32(hdr->hdr_len) != sizeof(struct btf_header)) {

now compares against 32 instead of 24, so won't this reject all
cross-endian BTF that has hdr_len set to 24?  This looks like it
would break all non-native-endian BTF loading until the next commit
(fcaa86ee9542 "libbpf: Support layout section handling in BTF")
updates these checks to use offsetofend(struct btf_header, str_len).

These are bisection regressions -- at this commit, libbpf cannot load
any BTF produced before layout support was added.  The fix in
fcaa86ee9542 is already present in the series, but could these two
commits be reordered or squashed so that the UAPI change and the
libbpf compatibility fix land together?


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

AI-authorship-score: low
AI-authorship-explanation: Standard kernel commit style with specific lore references and appropriate tags; no AI indicators.
issues-found: 2
issue-severity-score: medium
issue-severity-explanation: Bisection regressions that break libbpf BTF loading for all pre-layout BTF blobs and all cross-endian BTF, though both are fixed by the next commit 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.