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

From: Donglin Peng
Date: Mon Nov 10 2025 - 21:15:25 EST


On Tue, Nov 11, 2025 at 4:44 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> On Mon, 2025-11-10 at 09:42 +0800, Donglin Peng wrote:
>
> [...]
>
> > [[Resending in plain text format - previous HTML email was rejected]
> >
> > Thanks for the feedback. Based on the previous discussions, I plan
> > to implement the following changes in the next version:
> >
> > 1. Modify the btf__permute interface to adopt the ID map approach, as
> > suggested by Andrii.
> >
> > 2. Remove the lazy sort check and move the verification to the BTF
> > parsing phase. This addresses two concerns: potential race conditions
> > with write operations and const-cast issues. The overhead is negligible
> > (approximately 1.4ms for vmlinux BTF).
> >
> > 3. Invoke the btf__permute interface to implement BTF sorting in resolve_btfids.
> >
> > I welcome any further suggestions.
>
> Hi Donglin,
>
> I think this summarizes the discussion pretty well.
> One thing to notice about (2): if sorting is done by resolve_btfids,
> there is no need to check for BTF being sorted in vmlinux BTF.
> So, maybe it's a good idea to skip this check for it, as Alexei suggested
> (but not for programs BTF).

Thanks. I noticed that we still need an additional iteration in
btf_parse_base() and
btf_parse_module() to compute nr_sorted_types for lookup performance
optimization.

Thanks,
Donglin
>
> Thanks,
> Eduard.