All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel Müller" <deso@posteo.net>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>,
	Joanne Koong <joannelkoong@gmail.com>,
	Quentin Monnet <quentin@isovalent.com>
Subject: Re: [PATCH bpf-next v2 2/9] bpftool: Honor BPF_CORE_TYPE_MATCHES relocation
Date: Mon, 27 Jun 2022 16:50:31 +0000	[thread overview]
Message-ID: <20220627165031.pkn4rzx2wxghqi7e@muellerd-fedora-MJ0AC3F3> (raw)
In-Reply-To: <CAEf4BzasPaUkz9=1NwUp7MSeCM28W-24BBB_jrO9WDeXXTtOeQ@mail.gmail.com>

On Fri, Jun 24, 2022 at 02:25:50PM -0700, Andrii Nakryiko wrote:
> On Thu, Jun 23, 2022 at 2:22 PM Daniel Müller <deso@posteo.net> wrote:
> >
> > bpftool needs to know about the newly introduced BPF_CORE_TYPE_MATCHES
> > relocation for its 'gen min_core_btf' command to work properly in the
> > present of this relocation.
> > Specifically, we need to make sure to mark types and fields so that they
> > are present in the minimized BTF for "type match" checks to work out.
> > However, contrary to the existing btfgen_record_field_relo, we need to
> > rely on the BTF -- and not the spec -- to find fields. With this change
> > we handle this new variant correctly. The functionality will be tested
> > with follow on changes to BPF selftests, which already run against a
> > minimized BTF created with bpftool.
> >
> > Cc: Quentin Monnet <quentin@isovalent.com>
> > Signed-off-by: Daniel Müller <deso@posteo.net>
> > ---
> >  tools/bpf/bpftool/gen.c | 107 ++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 107 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> > index 480cbd8..6cd0ed 100644
> > --- a/tools/bpf/bpftool/gen.c
> > +++ b/tools/bpf/bpftool/gen.c
> > @@ -1856,6 +1856,111 @@ static int btfgen_record_field_relo(struct btfgen_info *info, struct bpf_core_sp
> >         return 0;
> >  }
> >
> > +/* Mark types, members, and member types. Compared to btfgen_record_field_relo,
> > + * this function does not rely on the target spec for inferring members, but
> > + * uses the associated BTF.
> > + *
> > + * The `behind_ptr` argument is used to stop marking of composite types reached
> > + * through a pointer. This way, we keep can keep BTF size in check while
> > + * providing reasonable match semantics.
> > + */
> > +static int btfgen_mark_types_match(struct btfgen_info *info, __u32 type_id, bool behind_ptr)
> > +{
> > +       const struct btf_type *btf_type;
> > +       struct btf *btf = info->src_btf;
> > +       struct btf_type *cloned_type;
> > +       int i, err;
> > +
> > +       if (type_id == 0)
> > +               return 0;
> > +
> > +       btf_type = btf__type_by_id(btf, type_id);
> > +       /* mark type on cloned BTF as used */
> > +       cloned_type = (struct btf_type *)btf__type_by_id(info->marked_btf, type_id);
> > +       cloned_type->name_off = MARKED;
> > +
> > +       switch (btf_kind(btf_type)) {
> > +       case BTF_KIND_UNKN:
> > +       case BTF_KIND_INT:
> > +       case BTF_KIND_FLOAT:
> > +       case BTF_KIND_ENUM:
> > +       case BTF_KIND_ENUM64:
> > +               break;
> > +       case BTF_KIND_STRUCT:
> > +       case BTF_KIND_UNION: {
> > +               struct btf_member *m = btf_members(btf_type);
> > +               __u16 vlen = btf_vlen(btf_type);
> > +
> > +               if (behind_ptr)
> > +                       break;
> > +
> > +               for (i = 0; i < vlen; i++, m++) {
> > +                       /* mark member */
> > +                       btfgen_mark_member(info, type_id, i);
> > +
> > +                       /* mark member's type */
> > +                       err = btfgen_mark_types_match(info, m->type, false);
> > +                       if (err)
> > +                               return err;
> > +               }
> > +               break;
> > +       }
> > +       case BTF_KIND_CONST:
> > +       case BTF_KIND_FWD:
> > +       case BTF_KIND_VOLATILE:
> > +       case BTF_KIND_TYPEDEF:
> 
> BTF_KIND_RESTRICT is missing?

Good catch. It's missing in btfgen_mark_type as well. Will add it.

> > +               return btfgen_mark_types_match(info, btf_type->type, false);
> > +       case BTF_KIND_PTR:
> > +               return btfgen_mark_types_match(info, btf_type->type, true);
> > +       case BTF_KIND_ARRAY: {
> > +               struct btf_array *array;
> > +
> > +               array = btf_array(btf_type);
> > +               /* mark array type */
> > +               err = btfgen_mark_types_match(info, array->type, false);
> > +               /* mark array's index type */
> > +               err = err ? : btfgen_mark_types_match(info, array->index_type, false);
> > +               if (err)
> > +                       return err;
> > +               break;
> > +       }
> 
> [...]

  reply	other threads:[~2022-06-27 16:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 21:21 [PATCH bpf-next v2 0/9] Introduce type match support Daniel Müller
2022-06-23 21:21 ` [PATCH bpf-next v2 1/9] bpf: Introduce TYPE_MATCH related constants/macros Daniel Müller
2022-06-23 21:21 ` [PATCH bpf-next v2 2/9] bpftool: Honor BPF_CORE_TYPE_MATCHES relocation Daniel Müller
2022-06-24 11:37   ` Quentin Monnet
2022-06-27 16:43     ` Daniel Müller
2022-06-24 21:25   ` Andrii Nakryiko
2022-06-27 16:50     ` Daniel Müller [this message]
2022-06-23 21:21 ` [PATCH bpf-next v2 3/9] bpf: Introduce btf_int_bits() function Daniel Müller
2022-06-23 21:22 ` [PATCH bpf-next v2 4/9] libbpf: Add type match support Daniel Müller
2022-06-24 21:39   ` Andrii Nakryiko
2022-06-27 21:28     ` Daniel Müller
2022-06-23 21:22 ` [PATCH bpf-next v2 5/9] bpf: " Daniel Müller
2022-06-23 21:22 ` [PATCH bpf-next v2 6/9] libbpf: Honor TYPE_MATCH relocation Daniel Müller
2022-06-24 21:41   ` Andrii Nakryiko
2022-06-23 21:22 ` [PATCH bpf-next v2 7/9] selftests/bpf: Add type-match checks to type-based tests Daniel Müller
2022-06-23 21:22 ` [PATCH bpf-next v2 8/9] selftests/bpf: Add test checking more characteristics Daniel Müller
2022-06-23 21:22 ` [PATCH bpf-next v2 9/9] selftests/bpf: Add nested type to type based tests Daniel Müller
2022-06-24 21:45   ` Andrii Nakryiko
2022-06-27 23:06     ` Daniel Müller

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=20220627165031.pkn4rzx2wxghqi7e@muellerd-fedora-MJ0AC3F3 \
    --to=deso@posteo.net \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joannelkoong@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=quentin@isovalent.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.