Re: [PATCH v5 6/7] btf: Add lazy sorting validation for binary search

From: Eduard Zingerman

Date: Fri Nov 07 2025 - 13:58:31 EST


On Fri, 2025-11-07 at 10:54 -0800, Alexei Starovoitov wrote:

[...]

> > > > > @@ -610,7 +674,7 @@ s32 btf_find_by_name_kind(const struct
> > > > > btf
> > > > > *btf, const char *name, u8 kind)
> > > > >                       goto out;
> > > > >       }
> > > > >
> > > > > -     if (btf->nr_sorted_types != BTF_NEED_SORT_CHECK) {
> > > > > +     if (btf_check_sorted((struct btf *)btf)) {
> > > >                                   ^
> > > >
> > > > The const cast here enables the concurrent writes discussed
> > > > above.
> > > > Is
> > > > there a reason to mark the btf parameter as const if we're
> > > > modifying it?
> > >
> > > Hi team, is casting away const an acceptable approach for our
> > > codebase?
> >
> > Casting away const is undefined behaviour, e.g. see paragraph
> > 6.7.3.6
> > N1570 ISO/IEC 9899:201x Programming languages — C.
> >
> > Both of the problems above can be avoided if kernel will do sorted
> > check non-lazily. But Andrii and Alexei seem to like that property.
>
> Ihor is going to move BTF manipulations into resolve_btfid.
> Sorting of BTF should be in resolve_btfid as well.
> This way the build process will guarantee that BTF is sorted
> to the kernel liking. So the kernel doesn't even need to check
> that BTF is sorted.

This would be great.
Does this imply that module BTFs are sorted too?