bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel T. Lee" <danieltimlee@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>,
	Martin Lau <kafai@fb.com>
Subject: Re: Where can I find the map's BTF type key/value specification?
Date: Tue, 13 Oct 2020 14:13:01 +0900	[thread overview]
Message-ID: <CAEKGpzg3WV2ffuapR+eif32XCnGb=KW9OQ7zYEZu8Z4RqqVEYQ@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzYzhykW_VC8Q-Sa5x9u+MdEO0zfmrgbkShSQDH4F5AsMw@mail.gmail.com>

On Sun, Oct 11, 2020 at 9:06 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sat, Oct 10, 2020 at 3:50 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
> >
> > I'm looking for how BTF type definition '__type(key, int)' is being changed
> > to '__uint(key_size, sizeof(int))'. (Not exactly "changed" but wonder how
> > it can be considered the same)
>
> __type(key, int) captures both BTF ID of key and determines key_size
> based on that type. You can specify both key and key_size, but that's
> unnecessary (and resulting key size still has to match).
>
> >
> >     __uint(type, BPF_MAP_TYPE_ARRAY);
> >     __type(key, int);          => __uint(key_size, sizeof(int))
> >     __type(value, u32);    => __uint(value_size, sizeof(u32))
> >     __uint(max_entries, 2);
> >
> > Whether the specific map type supports BTF or not can be inferred from
> > the file in kernel/bpf/*map.c and by checking each MAP type's
> > bpf_map_ops .map_check_btf pointer is initialized as map_check_no_btf.
> >
> > But how can I figure out that specific types of map support BTF types for
> > key/value? And how can I determine how this BTF key/value type is
> > converted?
>
> I think you answered your own question, you just search whether each
> map implements .map_check_btf that allows key/value BTF type ID. E.g.,
> see array_map_check_btf, which allows key/value type ID. And compare
> to how perf_event_array_map_ops use map_check_no_btf for its
> .map_check_btf callback.
>
> So you can search for all struct bpf_map_ops declarations to see
> operations for all map types, and then see what's there for
> .map_check_btf. Ideally we should extend all maps to support BTF type
> ID for key/value, but no one signed up to do that. If you are
> interested, that should be a good way to contribute to kernel itself.
>
> >
> > I am aware that BTF information is created in the form of a compact
> > type by using pahole to deduplicate repeated types, strings information
> > from DWARF information. However, looking at the *btf or pahole file
> > in dwarves repository, it seemed that it was not responsible for the
> > conversion of the BTF key/value.
> >
> > The remaining guess is that LLVM's BPF target compiler is responsible
> > for this, or it's probably somewhere in the kernel, but I'm not sure
> > where it is.
>
> BTF for the BPF program is emitted by Clang itself when you specify
> `-target bpf -g`. pahole is used to convert kernel's (vmlinux) DWARF
> into BTF and embed it into vmlinux image.
>
> As for key/value BTF type id for maps, that's libbpf parsing map
> definition and recording type IDs. So there are a few things playing
> together. See abd29c931459 ("libbpf: allow specifying map definitions
> using BTF") that introduced this feature.
>
> >
> > --
> > Best,
> > Daniel T. Lee


Thank you for taking the time and effort for the answer.
After following the implementation of key/value BTF type ID, A rough picture
began to be drawn.

What I didn't know well was clearly understood thanks to your explanation.

I'll look forward to contributing to this in the foreseeable future.

-- 
Best,
Daniel T. Lee

      reply	other threads:[~2020-10-13  5:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10 10:50 Where can I find the map's BTF type key/value specification? Daniel T. Lee
2020-10-11  0:06 ` Andrii Nakryiko
2020-10-13  5:13   ` Daniel T. Lee [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='CAEKGpzg3WV2ffuapR+eif32XCnGb=KW9OQ7zYEZu8Z4RqqVEYQ@mail.gmail.com' \
    --to=danieltimlee@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@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).