lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAErzpms0T9KWqzm3TBnEcYrfwvn+rQwsUDjQQuMrC7VLqsXwKQ@mail.gmail.com>
Date: Sat, 20 Dec 2025 22:27:00 +0800
From: Donglin Peng <dolinux.peng@...il.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: ast@...nel.org, eddyz87@...il.com, zhangxiaoqin@...omi.com, 
	ihor.solodrai@...ux.dev, linux-kernel@...r.kernel.org, bpf@...r.kernel.org, 
	pengdonglin <pengdonglin@...omi.com>, Alan Maguire <alan.maguire@...cle.com>
Subject: Re: [PATCH bpf-next v10 09/13] bpf: Optimize the performance of find_bpffs_btf_enums

On Fri, Dec 19, 2025 at 1:41 PM Donglin Peng <dolinux.peng@...il.com> wrote:
>
> On Fri, Dec 19, 2025 at 8:02 AM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
> >
> > On Thu, Dec 18, 2025 at 3:31 AM Donglin Peng <dolinux.peng@...il.com> wrote:
> > >
> > > From: pengdonglin <pengdonglin@...omi.com>
> > >
> > > Currently, vmlinux BTF is unconditionally sorted during
> > > the build phase. The function btf_find_by_name_kind
> > > executes the binary search branch, so find_bpffs_btf_enums
> > > can be optimized by using btf_find_by_name_kind.
> > >
> > > Cc: Eduard Zingerman <eddyz87@...il.com>
> > > Cc: Alexei Starovoitov <ast@...nel.org>
> > > Cc: Andrii Nakryiko <andrii.nakryiko@...il.com>
> > > Cc: Alan Maguire <alan.maguire@...cle.com>
> > > Cc: Ihor Solodrai <ihor.solodrai@...ux.dev>
> > > Cc: Xiaoqin Zhang <zhangxiaoqin@...omi.com>
> > > Signed-off-by: pengdonglin <pengdonglin@...omi.com>
> > > Acked-by: Eduard Zingerman <eddyz87@...il.com>
> > > ---
> > >  kernel/bpf/inode.c | 42 +++++++++++++++++++-----------------------
> > >  1 file changed, 19 insertions(+), 23 deletions(-)
> > >
> > > diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
> > > index 9f866a010dad..050fde1cf211 100644
> > > --- a/kernel/bpf/inode.c
> > > +++ b/kernel/bpf/inode.c
> > > @@ -600,10 +600,18 @@ struct bpffs_btf_enums {
> > >
> > >  static int find_bpffs_btf_enums(struct bpffs_btf_enums *info)
> > >  {
> > > +       struct {
> > > +               const struct btf_type **type;
> > > +               const char *name;
> > > +       } btf_enums[] = {
> > > +               {&info->cmd_t,          "bpf_cmd"},
> > > +               {&info->map_t,          "bpf_map_type"},
> > > +               {&info->prog_t,         "bpf_prog_type"},
> > > +               {&info->attach_t,       "bpf_attach_type"},
> > > +       };
> > >         const struct btf *btf;
> > >         const struct btf_type *t;
> > > -       const char *name;
> > > -       int i, n;
> > > +       int i, id;
> > >
> > >         memset(info, 0, sizeof(*info));
> > >
> > > @@ -615,30 +623,18 @@ static int find_bpffs_btf_enums(struct bpffs_btf_enums *info)
> > >
> > >         info->btf = btf;
> > >
> > > -       for (i = 1, n = btf_nr_types(btf); i < n; i++) {
> > > -               t = btf_type_by_id(btf, i);
> > > -               if (!btf_type_is_enum(t))
> > > -                       continue;
> > > +       for (i = 0; i < ARRAY_SIZE(btf_enums); i++) {
> > > +               id = btf_find_by_name_kind(btf, btf_enums[i].name,
> > > +                                          BTF_KIND_ENUM);
> > > +               if (id < 0)
> > > +                       goto out;
> > >
> > > -               name = btf_name_by_offset(btf, t->name_off);
> > > -               if (!name)
> > > -                       continue;
> >
> > return -ESRCH, why goto at all?

Thanks, will do.

> >
> > > -
> > > -               if (strcmp(name, "bpf_cmd") == 0)
> > > -                       info->cmd_t = t;
> > > -               else if (strcmp(name, "bpf_map_type") == 0)
> > > -                       info->map_t = t;
> > > -               else if (strcmp(name, "bpf_prog_type") == 0)
> > > -                       info->prog_t = t;
> > > -               else if (strcmp(name, "bpf_attach_type") == 0)
> > > -                       info->attach_t = t;
> > > -               else
> > > -                       continue;
> > > -
> > > -               if (info->cmd_t && info->map_t && info->prog_t && info->attach_t)
> > > -                       return 0;
> > > +               t = btf_type_by_id(btf, id);
> > > +               *btf_enums[i].type = t;
> >
> > nit: drop t local variable, just assign directly:
> >
> > *btf_enums[i].type = btf_type_by_id(btf, id);
>
> Thanks, I will do it.
>
> >
> > >         }
> > >
> > > +       return 0;
> > > +out:
> > >         return -ESRCH;
> > >  }
> > >
> > > --
> > > 2.34.1
> > >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ