bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Dave Marchevsky <davemarchevsky@fb.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 2/3] selftests/bpf: add libbpf feature-probing API selftests
Date: Fri, 17 Dec 2021 09:09:55 -0800	[thread overview]
Message-ID: <CAEf4BzaDJOj-7B_OvUzLvhVTgcMrZ-QLRBKNXMa3p+2WXzrEQw@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzZydhBisHacU9Rjf1ZWik1_aUeiy6ANRfaUkebo7cYq5Q@mail.gmail.com>

On Thu, Dec 16, 2021 at 4:42 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Thu, Dec 16, 2021 at 4:21 PM Dave Marchevsky <davemarchevsky@fb.com> wrote:
> >
> > On 12/16/21 2:04 AM, Andrii Nakryiko wrote:
> > > Add selftests for prog/map/prog+helper feature probing APIs. Prog and
> > > map selftests are designed in such a way that they will always test all
> > > the possible prog/map types, based on running kernel's vmlinux BTF enum
> > > definition. This way we'll always be sure that when adding new BPF
> > > program types or map types, libbpf will be always updated accordingly to
> > > be able to feature-detect them.
> > >
> > > BPF prog_helper selftest will have to be manually extended with
> > > interesting and important prog+helper combinations, it's easy, but can't
> > > be completely automated.
> > >
> > > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > > ---
> >
> > [...]
> >
> > > +     for (e = btf_enum(t), i = 0, n = btf_vlen(t); i < n; e++, i++) {
> > > +             const char *prog_type_name = btf__str_by_offset(btf, e->name_off);
> > > +             enum bpf_prog_type prog_type = (enum bpf_prog_type)e->val;
> > > +             int res;
> > > +
> > > +             if (prog_type == BPF_PROG_TYPE_UNSPEC)
> > > +                     continue;
> > > +
> > > +             if (!test__start_subtest(prog_type_name))
> > > +                     continue;
> > > +
> > > +             res = libbpf_probe_bpf_prog_type(prog_type, NULL);
> > > +             ASSERT_EQ(res, 1, prog_type_name);
> > > +     }
> >
> > I like how easy BTF makes this.
> > Maybe worth trying to probe one-past-the-end of enum to confirm it fails as
> > expected?
> >
>
> Yeah, sure, not a bad idea, I'll add in v2.

Couldn't do it :( Because selftest is using running kernel's BTF to
find out maximum BPF map type. But that maximum on a slightly outdated
kernel could be something that libbpf actually knows about and
supports (because it was compiled against the latest kernel UAPI
headers). So at run time libbpf returns 0 (correct answer, not
map/prog is not supported), but not the expected -EOPNOTSUPP. And I
don't want to hardcode the maximum enum values (like
BPF_MAP_TYPE_BLOOM_FILTER, as of now), because every time we add new
map we'll need to fix selftests in the same patch, which is a bit
annoying, I think.

If we had equivalents of __BPF_FUNC_MAX_ID for bpf_map_type and
bpf_prog_type, we could have just used those constants, so maybe we
should do that instead?

Regardless, I'm sending selftests as they are right now and we can
follow up with UAPI additions and selftests improvements separately.

>
> > Regardless,
> >
> > Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
> >
> > > +cleanup:
> > > +     btf__free(btf);
> > > +}
> >
> > [...]

  reply	other threads:[~2021-12-17 17:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16  7:04 [PATCH bpf-next 0/3] Revamp and fix libbpf's feature-probing APIs Andrii Nakryiko
2021-12-16  7:04 ` [PATCH bpf-next 1/3] libbpf: rework " Andrii Nakryiko
2021-12-17  0:10   ` Dave Marchevsky
2021-12-17  0:41     ` Andrii Nakryiko
2021-12-17  7:07       ` Dave Marchevsky
2021-12-16  7:04 ` [PATCH bpf-next 2/3] selftests/bpf: add libbpf feature-probing API selftests Andrii Nakryiko
2021-12-17  0:21   ` Dave Marchevsky
2021-12-17  0:42     ` Andrii Nakryiko
2021-12-17 17:09       ` Andrii Nakryiko [this message]
2021-12-16  7:04 ` [PATCH bpf-next 3/3] bpftool: reimplement large insn size limit feature probing Andrii Nakryiko
2021-12-17  0:36   ` Dave Marchevsky

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=CAEf4BzaDJOj-7B_OvUzLvhVTgcMrZ-QLRBKNXMa3p+2WXzrEQw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=kernel-team@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;
as well as URLs for NNTP newsgroup(s).