bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Quentin Monnet <quentin@isovalent.com>,
	open list <linux-kernel@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [RFC bpf-next 3/3] selftests/bpf: verify module-specific types can be shown via bpf_snprintf_btf
Date: Fri, 13 Nov 2020 23:01:48 -0800	[thread overview]
Message-ID: <CAEf4BzZdE4b5JFBvsvAFL-iSkKs7C-iE1UegiKU-X=wZdz+a_g@mail.gmail.com> (raw)
In-Reply-To: <1605291013-22575-4-git-send-email-alan.maguire@oracle.com>

On Fri, Nov 13, 2020 at 10:11 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> Verify that specifying a module name in "struct btf_ptr *" along
> with a type id of a module-specific type will succeed.
>
> veth_stats_rx() is chosen because its function signature consists
> of a module-specific type "struct veth_stats" and a kernel-specific
> one "struct net_device".
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
>  .../selftests/bpf/prog_tests/snprintf_btf_mod.c    | 96 ++++++++++++++++++++++
>  tools/testing/selftests/bpf/progs/btf_ptr.h        |  1 +
>  tools/testing/selftests/bpf/progs/veth_stats_rx.c  | 73 ++++++++++++++++
>  3 files changed, 170 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf_btf_mod.c
>  create mode 100644 tools/testing/selftests/bpf/progs/veth_stats_rx.c
>

[...]

> +       err = veth_stats_rx__load(skel);
> +       if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err))
> +               goto cleanup;
> +
> +       bss = skel->bss;
> +
> +       bss->veth_stats_btf_id = btf__find_by_name(veth_btf, "veth_stats");

This is really awkward that this needs to be done from user-space.
Libbpf will be able to do this regardless of whether the type is in
vmlinux or kernel module. See my comments on patch #1.

> +
> +       if (CHECK(bss->veth_stats_btf_id <= 0, "find 'struct veth_stats'",
> +                 "could not find 'struct veth_stats' in veth BTF: %d",
> +                 bss->veth_stats_btf_id))
> +               goto cleanup;
> +

[...]

> +       btf_ids[0] = veth_stats_btf_id;
> +       ptrs[0] = (void *)PT_REGS_PARM1_CORE(ctx);
> +#if __has_builtin(__builtin_btf_type_id)

nit: there are a bunch of selftests that just assume we have this
built-in, so I don't think you need to guard it with #if here.

> +       btf_ids[1] = bpf_core_type_id_kernel(struct net_device);
> +       ptrs[1] = (void *)PT_REGS_PARM2_CORE(ctx);
> +#endif

[...]

      reply	other threads:[~2020-11-14  7:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 18:10 [RFC bpf-next 0/3] bpf: support module BTF in btf display helpers Alan Maguire
2020-11-13 18:10 ` [RFC bpf-next 1/3] bpf: add module support to " Alan Maguire
2020-11-14  6:58   ` Andrii Nakryiko
2020-11-14 16:04     ` Alexei Starovoitov
2020-11-15  4:13       ` Yonghong Song
2020-11-15 10:53         ` Alan Maguire
2020-11-17 23:56           ` Andrii Nakryiko
2020-11-13 18:10 ` [RFC bpf-next 2/3] libbpf: bpf__find_by_name[_kind] should use btf__get_nr_types() Alan Maguire
2020-11-14  6:46   ` Andrii Nakryiko
2020-11-13 18:10 ` [RFC bpf-next 3/3] selftests/bpf: verify module-specific types can be shown via bpf_snprintf_btf Alan Maguire
2020-11-14  7:01   ` Andrii Nakryiko [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='CAEf4BzZdE4b5JFBvsvAFL-iSkKs7C-iE1UegiKU-X=wZdz+a_g@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=quentin@isovalent.com \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.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;
as well as URLs for NNTP newsgroup(s).