Re: [PATCH RFC bpf-next] libbpf: implement BTF field iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 2, 2024 at 5:41 AM Jiri Olsa <olsajiri@xxxxxxxxx> wrote:
>
> On Fri, May 31, 2024 at 06:45:05PM -0700, Andrii Nakryiko wrote:
> > Switch from callback-based iteration over BTF type ID and string offset
> > fields to an iterator-based approach.
> >
> > Switch all existing internal use cases to this new iterator.
> >
> > We have .BTF.ext fields iteration, those could be switched to
> > iterator-based implementation as well, but this is left as a follow up.
> >
> > We also convert bpftool's use of this libbpf-internal API.
> >
> > Cc: Eduard Zingerman <eddyz87@xxxxxxxxx>
> > Cc: Alan Maguire <alan.maguire@xxxxxxxxxx>
> > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
> > ---
> >  tools/bpf/bpftool/gen.c         |  17 +-
> >  tools/lib/bpf/btf.c             | 334 ++++++++++++++++++--------------
> >  tools/lib/bpf/libbpf_internal.h |  26 ++-
> >  tools/lib/bpf/linker.c          |  55 +++---
> >  4 files changed, 253 insertions(+), 179 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> > index b3979ddc0189..7b9c0255a2cf 100644
> > --- a/tools/bpf/bpftool/gen.c
> > +++ b/tools/bpf/bpftool/gen.c
> > @@ -2379,15 +2379,6 @@ static int btfgen_record_obj(struct btfgen_info *info, const char *obj_path)
> >       return err;
> >  }
> >
> > -static int btfgen_remap_id(__u32 *type_id, void *ctx)
> > -{
> > -     unsigned int *ids = ctx;
> > -
> > -     *type_id = ids[*type_id];
> > -
> > -     return 0;
> > -}
> > -
> >  /* Generate BTF from relocation information previously recorded */
> >  static struct btf *btfgen_get_btf(struct btfgen_info *info)
> >  {
> > @@ -2466,11 +2457,13 @@ static struct btf *btfgen_get_btf(struct btfgen_info *info)
> >
> >       /* second pass: fix up type ids */
> >       for (i = 1; i < btf__type_cnt(btf_new); i++) {
> > +             struct btf_field_iter it;
> >               struct btf_type *btf_type = (struct btf_type *) btf__type_by_id(btf_new, i);
> > +             __u32 *type_id;
> >
> > -             err = btf_type_visit_type_ids(btf_type, btfgen_remap_id, ids);
> > -             if (err)
> > -                     goto err_out;
> > +             btf_field_iter_init(&it, btf_type, BTF_FIELD_ITER_IDS);
>
> lgtm, should we check return value from btf_field_iter_init?

yeah, it should never fail, but if BTF is corrupted it might, so
better safe than sorry, I'll add checks

>
> jirka
>
> > +             while ((type_id = btf_field_iter_next(&it)))
> > +                     *type_id = ids[*type_id];
> >       }
> >
> >       free(ids);
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index 2d0840ef599a..0c39f9b3f98b 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -1739,9 +1739,8 @@ struct btf_pipe {
> >       struct hashmap *str_off_map; /* map string offsets from src to dst */
> >  };
> >

[...] (trimming is good)





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux