Re: [PATCH bpf-next v9 08/10] bpf: Skip anonymous types in type lookup for performance
From: Donglin Peng
Date: Wed Dec 17 2025 - 04:21:32 EST
On Wed, Dec 17, 2025 at 2:55 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> On Mon, 2025-12-08 at 14:23 +0800, Donglin Peng wrote:
>
> [...]
>
> > @@ -550,6 +550,11 @@ u32 btf_nr_types(const struct btf *btf)
> > return total;
> > }
> >
> > +u32 btf_sorted_start_id(const struct btf *btf)
> > +{
> > + return btf->sorted_start_id ?: (btf->start_id ?: 1);
> > +}
> > +
>
> I think that changes in this patch are correct. However, it seems
Thanks, I think the changes to btf_find_decl_tag_value and
btf_prepare_func_args will cause issues if the input btf is a
split BTF. We should search from its base BTF. Like this:
const struct btf *base_btf = btf;
while (btf_base_btf(base_btf))
base_btf = btf_base_btf(base_btf);
id = base_btf->sorted_start_id > 0 ? base_btf->sorted_start_id - 1 : 0;
> error prone to remember that sorted_start_id is always set for
> vmlinux/module BTF and might not be set for program BTF.
> Wdyt about using the above function everywhere instead of directly
> reading the field?
Agreed. If so, I think we need to add another helper function to check
whether the input BTF is sorted to improve code clarity.
bool btf_is_sorted(const struct btf *btf)
{
return btf->sorted_start_id > 0;
}
Besides, do you think we should reject loading a kernel module that is
not sorted?
Thanks,
Donglin
>
> > /*
> > * Assuming that types are sorted by name in ascending order.
> > */
>
> [...]