Re: [PATCH bpf-next v10 07/13] btf: Verify BTF Sorting
From: Andrii Nakryiko
Date: Thu Dec 18 2025 - 18:46:46 EST
On Thu, Dec 18, 2025 at 3:31 AM Donglin Peng <dolinux.peng@xxxxxxxxx> wrote:
>
> From: pengdonglin <pengdonglin@xxxxxxxxxx>
>
> This patch checks whether the BTF is sorted by name in ascending order.
> If sorted, binary search will be used when looking up types.
>
> Specifically, vmlinux and kernel module BTFs are always sorted during
> the build phase with anonymous types placed before named types, so we
> only need to identify the starting ID of named types.
>
> Cc: Eduard Zingerman <eddyz87@xxxxxxxxx>
> Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
> Cc: Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx>
> Cc: Alan Maguire <alan.maguire@xxxxxxxxxx>
> Cc: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
> Cc: Xiaoqin Zhang <zhangxiaoqin@xxxxxxxxxx>
> Signed-off-by: pengdonglin <pengdonglin@xxxxxxxxxx>
> ---
> kernel/bpf/btf.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 56 insertions(+)
>
please make sure to apply feedback received for libbpf-side
implementation for kernel-side implementations as well
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 0394f0c8ef74..a9e2345558c0 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -550,6 +550,60 @@ u32 btf_nr_types(const struct btf *btf)
> return total;
> }
>
[...]