From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Donglin Peng <dolinux.peng@gmail.com>,
bot+bpf-ci@kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
zhangxiaoqin@xiaomi.com, LKML <linux-kernel@vger.kernel.org>,
bpf <bpf@vger.kernel.org>,
Alan Maguire <alan.maguire@oracle.com>,
Song Liu <song@kernel.org>, pengdonglin <pengdonglin@xiaomi.com>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Chris Mason <clm@meta.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>
Subject: Re: [PATCH v5 6/7] btf: Add lazy sorting validation for binary search
Date: Fri, 07 Nov 2025 11:51:27 -0800 [thread overview]
Message-ID: <6cbeb051a6bebb75032bc724ad10efed5b65cbf7.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQKbgno=yGjshJpo+fwRDMTfXXVPWq0eh7avBj154dCq_g@mail.gmail.com>
On Fri, 2025-11-07 at 11:01 -0800, Alexei Starovoitov wrote:
> On Fri, Nov 7, 2025 at 10:58 AM Eduard Zingerman <eddyz87@gmail.com>
> wrote:
> >
> > 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?
>
> Yes. The module build is supposed to use the kernel build tree where
> kernel BTF expectations will match resolve_btfid actions.
> Just like compiler and config flags should be the same.
There is also program BTF. E.g. btf_find_by_name_kind() is called for
program BTF in bpf_check_attach_target(). I think it would be fine to
check program BTF for being sorted at the BTF load time.
next prev parent reply other threads:[~2025-11-07 19:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 13:19 [PATCH v5 0/7] BTF performance optimizations with permutation and binary search Donglin Peng
2025-11-06 13:19 ` [PATCH v5 1/7] libbpf: Extract BTF type remapping logic into helper function Donglin Peng
2025-11-06 13:19 ` [PATCH v5 2/7] libbpf: Add BTF permutation support for type reordering Donglin Peng
2025-11-06 13:47 ` bot+bpf-ci
2025-11-07 7:12 ` Donglin Peng
2025-11-06 13:19 ` [PATCH v5 3/7] libbpf: Optimize type lookup with binary search for sorted BTF Donglin Peng
2025-11-06 13:40 ` bot+bpf-ci
2025-11-07 7:29 ` Donglin Peng
2025-11-06 13:19 ` [PATCH v5 4/7] libbpf: Implement lazy sorting validation for binary search optimization Donglin Peng
2025-11-06 13:19 ` [PATCH v5 5/7] btf: Optimize type lookup with binary search Donglin Peng
2025-11-06 13:19 ` [PATCH v5 6/7] btf: Add lazy sorting validation for " Donglin Peng
2025-11-06 13:47 ` bot+bpf-ci
2025-11-07 7:08 ` Donglin Peng
2025-11-07 18:19 ` Eduard Zingerman
2025-11-07 18:54 ` Alexei Starovoitov
2025-11-07 18:58 ` Eduard Zingerman
2025-11-07 19:01 ` Alexei Starovoitov
2025-11-07 19:51 ` Eduard Zingerman [this message]
2025-11-10 1:42 ` Donglin Peng
2025-11-10 20:44 ` Eduard Zingerman
2025-11-11 2:07 ` Donglin Peng
2025-11-06 13:19 ` [PATCH v5 7/7] selftests/bpf: Add test cases for btf__permute functionality Donglin Peng
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=6cbeb051a6bebb75032bc724ad10efed5b65cbf7.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=dolinux.peng@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=pengdonglin@xiaomi.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
--cc=zhangxiaoqin@xiaomi.com \
/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