From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Yonghong Song <yhs@fb.com>, Jiri Olsa <olsajiri@gmail.com>,
dwarves@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH] btf_loader: support BTF_KIND_ENUM64 was Re: [PATCH dwarves v2 0/2] btf: support BTF_KIND_ENUM64
Date: Wed, 6 Jul 2022 12:51:53 -0300 [thread overview]
Message-ID: <YsWvmRKaCbjf0XXB@kernel.org> (raw)
In-Reply-To: <CAEf4BzananDqBJyfu8n3VATNULd5ZgY2GrEYGvGSS_5dMW3mpw@mail.gmail.com>
Em Tue, Jul 05, 2022 at 09:28:05PM -0700, Andrii Nakryiko escreveu:
> On Wed, Jun 29, 2022 at 9:56 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Wed, Jun 29, 2022 at 01:30:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > ⬢[acme@toolbox pahole]$ pdwtags -F btf vmlinux-v5.18-rc7+ | grep -B10 -A5 BPF_F_CTXLEN_MASK
> > > BTF: idx: 4173, Unknown kind 19
> > > BTF: idx: 4975, Unknown kind 19
> > > BTF: idx: 6673, Unknown kind 19
> > > BTF: idx: 27413, Unknown kind 19
> > > BTF: idx: 30626, Unknown kind 19
> > > BTF: idx: 30829, Unknown kind 19
> > > BTF: idx: 38040, Unknown kind 19
> > > BTF: idx: 56969, Unknown kind 19
> > > BTF: idx: 83004, Unknown kind 19
> > > ⬢[acme@toolbox pahole]$
> > >
> > > Ok, I need to update pahole's BTF loader to support:
> > >
> > > lib/bpf/src/btf.h:#define BTF_KIND_ENUM64 19 /* Enum for up-to 64bit values */
> > >
> > >
> > > Working on it now.
> >
> > ⬢[acme@toolbox pahole]$ pdwtags -F btf vmlinux-v5.18-rc7+ | grep -B5 -A5 BPF_F_CTXLEN_MASK
> >
> > /* 27413 */
> > enum {
> > BPF_F_INDEX_MASK = 4294967295,
> > BPF_F_CURRENT_CPU = 4294967295,
> > BPF_F_CTXLEN_MASK = 4503595332403200,
> > } __attribute__((__packed__)); /* size: 8 */
> >
> > /* 27414 */
> > enum {
> > BPF_F_GET_BRANCH_RECORDS_SIZE = 1,
> > ⬢[acme@toolbox pahole]$
> >
> > Quick patch here, please Ack, if possible:
> >
>
> two minor nits, but looks good overall:
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
Thanks for reviewing it!
> > diff --git a/btf_loader.c b/btf_loader.c
> > index b5d444643adf30b1..e57ecce2cde26e4e 100644
> > --- a/btf_loader.c
> > +++ b/btf_loader.c
> > @@ -312,6 +312,49 @@ out_free:
> > return -ENOMEM;
> > }
> >
> > +static struct enumerator *enumerator__new64(const char *name, uint64_t value)
> > +{
> > + struct enumerator *en = tag__alloc(sizeof(*en));
> > +
> > + if (en != NULL) {
> > + en->name = name;
> > + en->value = value; // Value is already 64-bit, as this is used with DWARF as well
> > + en->tag.tag = DW_TAG_enumerator;
> > + }
> > +
> > + return en;
> > +}
> > +
> > +static int create_new_enumeration64(struct cu *cu, const struct btf_type *tp, uint32_t id)
> > +{
> > + struct btf_enum64 *ep = btf_enum64(tp);
> > + uint16_t i, vlen = btf_vlen(tp);
> > + struct type *enumeration = type__new(DW_TAG_enumeration_type,
> > + cu__btf_str(cu, tp->name_off),
> > + tp->size ? tp->size * 8 : (sizeof(int) * 8));
>
> tp->size should always be valid, so this fall back to sizeof(int)
> isn't necessary
This was just a copy from the create_new_enumeration() one, will remove
it there as well as a prep patch, then not have it in the 64-bit
version.
> > +
> > + if (enumeration == NULL)
> > + return -ENOMEM;
> > +
> > + for (i = 0; i < vlen; i++) {
> > + const char *name = cu__btf_str(cu, ep[i].name_off);
> > + uint64_t value = ((uint64_t)ep[i].val_hi32) << 32 | ep[i].val_lo32;
>
> use btf_enum64_value() defined in libbpf's btf.h header
Great, will pick that
> > + struct enumerator *enumerator = enumerator__new64(name, value);
> > +
> > + if (enumerator == NULL)
> > + goto out_free;
> > +
> > + enumeration__add(enumeration, enumerator);
> > + }
> > +
> > + cu__add_tag_with_id(cu, &enumeration->namespace.tag, id);
> > +
> > + return 0;
> > +out_free:
> > + enumeration__delete(enumeration);
> > + return -ENOMEM;
> > +}
> > +
> > static int create_new_subroutine_type(struct cu *cu, const struct btf_type *tp, uint32_t id)
> > {
> > struct ftype *proto = tag__alloc(sizeof(*proto));
> > @@ -419,6 +462,9 @@ static int btf__load_types(struct btf *btf, struct cu *cu)
> > case BTF_KIND_ENUM:
> > err = create_new_enumeration(cu, type_ptr, type_index);
> > break;
> > + case BTF_KIND_ENUM64:
> > + err = create_new_enumeration64(cu, type_ptr, type_index);
> > + break;
> > case BTF_KIND_FWD:
> > err = create_new_forward_decl(cu, type_ptr, type_index);
> > break;
--
- Arnaldo
prev parent reply other threads:[~2022-07-06 15:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 23:03 [PATCH dwarves v2 0/2] btf: support BTF_KIND_ENUM64 Yonghong Song
2022-06-15 23:03 ` [PATCH dwarves v2 1/2] libbpf: Sync with latest libbpf repo Yonghong Song
2022-06-15 23:03 ` [PATCH dwarves v2 2/2] btf: Support BTF_KIND_ENUM64 Yonghong Song
2022-06-27 22:30 ` Andrii Nakryiko
2022-06-28 6:19 ` Yonghong Song
2022-06-28 9:51 ` [PATCH dwarves v2 0/2] btf: support BTF_KIND_ENUM64 Jiri Olsa
2022-06-29 16:30 ` Arnaldo Carvalho de Melo
2022-06-29 16:56 ` [PATCH] btf_loader: support BTF_KIND_ENUM64 was " Arnaldo Carvalho de Melo
2022-07-06 4:28 ` Andrii Nakryiko
2022-07-06 15:51 ` Arnaldo Carvalho de Melo [this message]
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=YsWvmRKaCbjf0XXB@kernel.org \
--to=acme@kernel.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=olsajiri@gmail.com \
--cc=yhs@fb.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