From: Alan Maguire <alan.maguire@oracle.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Quentin Monnet <qmo@kernel.org>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
dwarves <dwarves@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Thierry Treyer <ttreyer@meta.com>,
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
Subject: Re: [PATCH v8 bpf-next 01/10] btf: add kind layout encoding to UAPI
Date: Mon, 12 Jan 2026 17:47:03 +0000 [thread overview]
Message-ID: <c81494bb-1f2e-4677-a9c3-a438c4d9119c@oracle.com> (raw)
In-Reply-To: <CAADnVQLpGFkNnbex6CmbDjpPgXEH4TPvA9XrtY76SX_RaoRq9g@mail.gmail.com>
On 09/01/2026 18:34, Alexei Starovoitov wrote:
> On Fri, Jan 9, 2026 at 5:21 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>>
>> On 09/01/2026 01:40, Alexei Starovoitov wrote:
>>> On Thu, Jan 8, 2026 at 5:24 PM Andrii Nakryiko
>>> <andrii.nakryiko@gmail.com> wrote:
>>>>
>>>> On Thu, Jan 8, 2026 at 10:55 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>>>>>
>>>>> On 06/01/2026 01:19, Andrii Nakryiko wrote:
>>>>>> On Mon, Jan 5, 2026 at 4:51 PM Alexei Starovoitov
>>>>>> <alexei.starovoitov@gmail.com> wrote:
>>>>>>>
>>>>>>> On Mon, Jan 5, 2026 at 4:11 PM Andrii Nakryiko
>>>>>>> <andrii.nakryiko@gmail.com> wrote:
>>>>>>>>
>>>>>>>> On Tue, Dec 23, 2025 at 3:09 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>>>>>>>>>
>>>>>>>>> On 22/12/2025 19:03, Alexei Starovoitov wrote:
>>>>>>>>>> On Sun, Dec 21, 2025 at 10:58 PM Alan Maguire <alan.maguire@oracle.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Hold on. I'm missing how libbpf will sanitize things for older kernels?
>>>>>>>>>>>
>>>>>>>>>>> The sanitization we can get from layout info is for handling a kernel built with
>>>>>>>>>>> newer kernel/module BTF. The userspace tooling (libbpf and others) does not fully
>>>>>>>>>>> understand it due to the presence of new kinds. In such a case layout data gives us
>>>>>>>>>>> info to parse it by providing info on kind layout, and libbpf can sanitize it
>>>>>>>>>>> to be usable for some cases (where the type graph is not fatally compromised
>>>>>>>>>>> by the lack of a kind). This will always be somewhat limited, but it
>>>>>>>>>>> does provide more usability than we have today.
>>>>>>>>>>
>>>>>>>>>> I'm even more confused now. libbpf will sanitize BTF for the sake of
>>>>>>>>>> user space? That's not something it ever did. libbpf sanitizes BTF
>>>>>>>>>> only to
>>>>>>>>>
>>>>>>>>> Right; it's an extension of the sanitization concept from what it does today.
>>>>>>>>> Today we sanitize newer _program_ BTF to ensure it is acceptable to a kernel which
>>>>>>>>> lacks specific aspects of that BTF; the goal here is to support some simple sanitization
>>>>>>>>> of the newer _kernel_ BTF by libbpf to help tools (that know about kind layout but may lack
>>>>>>>>> latest kind info kernel has) to make that kernel BTF usable.
>>>>>>>>
>>>>>>>> Wait, is that really a goal? I get why Alexei is confused now :)
>>>>>>>>
>>>>>>>> I think we should stick to libbpf sanitizing only BPF program's BTFs
>>>>>>>> for the sake of loading it into the kernel. If some user space tool is
>>>>>>>> trying to work with kernel BTF that has BTF features that tool doesn't
>>>>>>>> support, then we only have two reasonable options: a) tool just fails
>>>>>>>> to process that BTF altogether or b) the tool is smart enough to
>>>>>>>> utilize BTF layout information to know which BTF types it can safely
>>>>>>>> skip (that's where those flags I argue for would be useful). In both
>>>>>>>> cases libbpf's btf__parse() will succeed because libbpf can utilize
>>>>>>>> layout info to construct a lookup table for btf__type_by_id(). And
>>>>>>>> libbpf doesn't need to do anything beyond that, IMO.
>>>>>>>>
>>>>>>>> We'll teach bpftool to dump as much of BTF as possible (I mean
>>>>>>>> `bpftool btf dump file`), so it's possible to get an idea of what part
>>>>>>>> of BTF is not supported and show those that we know about. We could
>>>>>>>> teach btf_dump to ignore those types that are "safe modifier-like
>>>>>>>> reference kind" (as marked with that flag I proposed earlier), so that
>>>>>>>> `format c` works as well (though I wouldn't recommend using such
>>>>>>>> output as a proper vmlinux.h, users should update bpftool ASAP for
>>>>>>>> such use cases).
>>>>>>>>
>>>>>>>> As far as the kernel is concerned, BTF layout is not used and should
>>>>>>>> not be used or trusted (it can be "spoofed" by the user). It can
>>>>>>>> validate it for sanity, but that's pretty much it. Other than that, if
>>>>>>>> the kernel doesn't *completely* understand every single piece of BTF,
>>>>>>>> it should reject it (and that's also why libbpf should sanitize BPF
>>>>>>>> object's BTF, of course).
>>>>>>>
>>>>>>> +1 to all of the above, except ok-to-skip flag, since I feel
>>>>>>> it will cause more bike sheding and arguing whether a particular
>>>>>>> new addition to BTF is skippable or not. Like upcoming location info.
>>>>>>
>>>>>> I was thinking about something like TYPE_TAG, where it's in the chain
>>>>>> of types and is unavoidable when processing STRUCT and its field.
>>>>>> Having a flag specifying that it's ref-like (so btf_type::type field
>>>>>> points to a valid type ID) would allow it to still make sense of the
>>>>>> entire struct and its fields, though you might be missing some
>>>>>> (presumably) optional and highly-specialized extra annotation.
>>>>>>
>>>>>> But it's fine not to add it, just some type graphs will be completely
>>>>>> unprocessable using old tools. Perhaps not such a big deal.
>>>>>>
>>>>>> I suspect all the newly added BTF kinds will be of "ok-to-skip" kind,
>>>>>> whether they are more like DECL_TAG (roots pointing to other types) or
>>>>>> TYPE_TAG (in the middle of type chain, being pointed to from STRUCT
>>>>>> fields, PROTO args, etc).
>>>>>>
>>>>>>> Is it skippable? kinda. Or, say, we decide to add vector types to BTF.
>>>>>>> Skippable? One might argue that they are while they are mandatory
>>>>>>> for some other use case.
>>>>>>> Looking at it differently, if the kernel is old and cannot understand that
>>>>>>> BTF feature the libbpf has to sanitize it no matter skippable or not.
>>>>>>> While from btf__parse() pov it also doesn't matter.
>>>>>>> btf_new()->btf_parse_hdr() will remember kind layout,
>>>>>>> and btf_parse_type_sec() can construct the index for the whole thing
>>>>>>> with layout info,
>>>>>>> while btf_validate_type() has to warn about unknown kind regardless
>>>>>>> of skippable flag. The tool (bpftool or else) needs to yell when
>>>>>>> final vmlinux.h is incomplete. Skipping printing modifier-like decl_tag
>>>>>>> is pretty bad for vmlinux.h. It's really not skippable (in my opinion)
>>>>>>> though one might argue that they are.
>>>>>>
>>>>>> Yeah, I agree about vmlinux.h. One way to enforce this would be to
>>>>>> have btf_dump emit something uncompilable as
>>>>>> "HERE_BE_DRAGONS_SKIPPED_SOMETHING" as if it was const/volatile
>>>>>> modified.
>>>>>>
>>>>>> But yeah, we don't want bikeshedding. It's fine.
>>>>>>
>>>>>
>>>>> Ok so is it best to leave out flags entirely then? If so where we
>>>>> are now is to have each kind layout entry have a string name offset,
>>>>> a singular element size and a vlen-specified object size. To be
>>>>> conservative it might make sense to allow 16 bits for each size field,
>>>>> leaving us with 64 bits per kind, 160 bytes in total for the 20 kinds.
>>>>> We could cut down further by leaving out kind name strings if needed.
>>>>
>>>> Are we sure we will *never* need flags? I'd probably stick to
>>>> single-byte sizes and have 2 bytes reserved for flags or whatever we
>>>> might need in the future?
>>>
>>> Just to clarify what I was saying.
>>> I think it's a good thing to have flags space and reserve it.
>>> I just struggle to see the value of 'ok-to-skip' flag.
>>>
>>> So 2 bytes of reserved space for flags makes sense to me.
>>
>> Ok sounds good; I think there is still value in having the single flag
>> that tells us that the type/size field in struct btf_type refers
>> to a type though, right?
>
> What's the value?
>
> I sort-of kinda see small value of a set of flags like:
> - this kind is a type (int, ptr, array, struct, func_proto)
> - this kind is a modifier of a type (volatile, const, restrict, type_tag)
>
> but then we cannot quite classify var, datasec, decl_tag, func..
>
> So it feels like it's getting into the bikeshed category again.
I suppose one value would be it would be easier to recognize pure reference kinds
since they'd have such a flag set and have no extra info. But I think at this point
we should just focus on support parsing of unknown BTF kinds via kind layout. I'll add
an empty flags field for now.
Alan
next prev parent reply other threads:[~2026-01-12 17:47 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 9:17 [PATCH v8 bpf-next 00/10] Add kind layout to BTF Alan Maguire
2025-12-15 9:17 ` [PATCH v8 bpf-next 01/10] btf: add kind layout encoding to UAPI Alan Maguire
2025-12-15 9:38 ` bot+bpf-ci
2025-12-16 19:23 ` Andrii Nakryiko
2025-12-19 13:15 ` Alan Maguire
2025-12-19 17:53 ` Andrii Nakryiko
2025-12-19 18:13 ` Alan Maguire
2025-12-19 18:19 ` Andrii Nakryiko
2025-12-19 18:22 ` Alan Maguire
2025-12-20 0:05 ` Alexei Starovoitov
2025-12-22 8:58 ` Alan Maguire
2025-12-22 19:03 ` Alexei Starovoitov
2025-12-23 11:09 ` Alan Maguire
2026-01-06 0:11 ` Andrii Nakryiko
2026-01-06 0:51 ` Alexei Starovoitov
2026-01-06 1:19 ` Andrii Nakryiko
2026-01-08 18:55 ` Alan Maguire
2026-01-09 1:24 ` Andrii Nakryiko
2026-01-09 1:40 ` Alexei Starovoitov
2026-01-09 13:20 ` Alan Maguire
2026-01-09 18:34 ` Alexei Starovoitov
2026-01-12 17:47 ` Alan Maguire [this message]
2025-12-15 9:17 ` [PATCH v8 bpf-next 02/10] libbpf: Support kind layout section handling in BTF Alan Maguire
2025-12-15 9:38 ` bot+bpf-ci
2025-12-15 16:03 ` Alan Maguire
2025-12-16 0:08 ` Eduard Zingerman
2025-12-16 6:01 ` Eduard Zingerman
2025-12-16 14:58 ` Alan Maguire
2025-12-16 19:34 ` Andrii Nakryiko
2025-12-19 13:34 ` Alan Maguire
2025-12-19 17:58 ` Andrii Nakryiko
2025-12-19 18:18 ` Alan Maguire
2025-12-19 18:21 ` Andrii Nakryiko
2025-12-19 18:36 ` Eduard Zingerman
2025-12-19 18:41 ` Andrii Nakryiko
2025-12-19 18:44 ` Eduard Zingerman
2025-12-15 9:17 ` [PATCH v8 bpf-next 03/10] libbpf: use kind layout to compute an unknown kind size Alan Maguire
2025-12-16 6:07 ` Eduard Zingerman
2025-12-16 15:00 ` Alan Maguire
2025-12-16 19:42 ` Andrii Nakryiko
2025-12-16 19:58 ` Eduard Zingerman
2025-12-16 21:11 ` Andrii Nakryiko
2025-12-16 21:21 ` Eduard Zingerman
2025-12-16 22:23 ` Andrii Nakryiko
2025-12-16 22:35 ` Eduard Zingerman
2025-12-16 23:00 ` Andrii Nakryiko
2025-12-16 23:36 ` Eduard Zingerman
2025-12-17 0:30 ` Andrii Nakryiko
2025-12-17 0:38 ` Eduard Zingerman
2025-12-16 19:37 ` Andrii Nakryiko
2025-12-15 9:17 ` [PATCH v8 bpf-next 04/10] libbpf: Add kind layout encoding support Alan Maguire
2025-12-16 5:58 ` Eduard Zingerman
2025-12-16 21:04 ` Andrii Nakryiko
2025-12-15 9:17 ` [PATCH v8 bpf-next 05/10] libbpf: BTF validation can use kind layout for unknown kinds Alan Maguire
2025-12-15 9:17 ` [PATCH v8 bpf-next 06/10] btf: support kernel parsing of BTF with kind layout Alan Maguire
2025-12-16 6:51 ` Eduard Zingerman
2025-12-16 21:21 ` Andrii Nakryiko
2025-12-16 21:25 ` Eduard Zingerman
2025-12-16 22:09 ` Andrii Nakryiko
2025-12-16 22:12 ` Eduard Zingerman
2025-12-15 9:17 ` [PATCH v8 bpf-next 07/10] selftests/bpf: test kind encoding/decoding Alan Maguire
2025-12-15 9:17 ` [PATCH v8 bpf-next 08/10] bpftool: add BTF dump "format meta" to dump header/metadata Alan Maguire
2025-12-15 9:52 ` bot+bpf-ci
2025-12-15 9:17 ` [PATCH v8 bpf-next 09/10] bpftool: Update doc to describe bpftool btf dump .. format metadata Alan Maguire
2025-12-15 9:17 ` [PATCH v8 bpf-next 10/10] kbuild, bpf: Specify "kind_layout" optional feature Alan Maguire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c81494bb-1f2e-4677-a9c3-a438c4d9119c@oracle.com \
--to=alan.maguire@oracle.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykyta.yatsenko5@gmail.com \
--cc=qmo@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=ttreyer@meta.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox