public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat•com>
To: Andrii Nakryiko <andriin@fb•com>,
	bpf@vger•kernel.org, netdev@vger•kernel.org, ast@fb•com,
	daniel@iogearbox•net
Cc: andrii.nakryiko@gmail•com, kernel-team@fb•com,
	Andrii Nakryiko <andriin@fb•com>
Subject: Re: [PATCH bpf-next] libbpf: add BTF-defined map-in-map support
Date: Wed, 22 Apr 2020 13:19:18 +0200	[thread overview]
Message-ID: <87mu737op5.fsf@toke.dk> (raw)
In-Reply-To: <20200422051006.1152644-1-andriin@fb.com>

Andrii Nakryiko <andriin@fb•com> writes:

> As discussed at LPC 2019 ([0]), this patch brings (a quite belated) support
> for declarative BTF-defined map-in-map support in libbpf. It allows to define
> ARRAY_OF_MAPS and HASH_OF_MAPS BPF maps without any user-space initialization
> code involved.
>
> Additionally, it allows to initialize outer map's slots with references to
> respective inner maps at load time, also completely declaratively.
>
> Despite a weak type system of C, the way BTF-defined map-in-map definition
> works, it's actually quite hard to accidentally initialize outer map with
> incompatible inner maps. This being C, of course, it's still possible, but
> even that would be caught at load time and error returned with helpful debug
> log pointing exactly to the slot that failed to be initialized.
>
> Here's the relevant part of libbpf debug log showing pretty clearly of what's
> going on with map-in-map initialization:
>
> libbpf: .maps relo #0: for 6 value 0 rel.r_offset 96 name 260 ('inner_map1')
> libbpf: .maps relo #0: map 'outer_arr' slot [0] points to map 'inner_map1'
> libbpf: .maps relo #1: for 7 value 32 rel.r_offset 112 name 249 ('inner_map2')
> libbpf: .maps relo #1: map 'outer_arr' slot [2] points to map 'inner_map2'
> libbpf: .maps relo #2: for 7 value 32 rel.r_offset 144 name 249 ('inner_map2')
> libbpf: .maps relo #2: map 'outer_hash' slot [0] points to map 'inner_map2'
> libbpf: .maps relo #3: for 6 value 0 rel.r_offset 176 name 260 ('inner_map1')
> libbpf: .maps relo #3: map 'outer_hash' slot [4] points to map 'inner_map1'
> libbpf: map 'inner_map1': created successfully, fd=4
> libbpf: map 'inner_map2': created successfully, fd=5
> libbpf: map 'outer_arr': created successfully, fd=7
> libbpf: map 'outer_arr': slot [0] set to map 'inner_map1' fd=4
> libbpf: map 'outer_arr': slot [2] set to map 'inner_map2' fd=5
> libbpf: map 'outer_hash': created successfully, fd=8
> libbpf: map 'outer_hash': slot [0] set to map 'inner_map2' fd=5
> libbpf: map 'outer_hash': slot [4] set to map 'inner_map1' fd=4
>
> See also included selftest with some extra comments explaining extra details
> of usage.

Could you please put an example of usage in the commit message as well?
Easier to find that way, especially if the selftests are not handy (such
as in the libbpf github repo).

-Toke


  reply	other threads:[~2020-04-22 11:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22  5:10 [PATCH bpf-next] libbpf: add BTF-defined map-in-map support Andrii Nakryiko
2020-04-22 11:19 ` Toke Høiland-Jørgensen [this message]
2020-04-22 17:30   ` Andrii Nakryiko

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=87mu737op5.fsf@toke.dk \
    --to=toke@redhat$(echo .)com \
    --cc=andrii.nakryiko@gmail$(echo .)com \
    --cc=andriin@fb$(echo .)com \
    --cc=ast@fb$(echo .)com \
    --cc=bpf@vger$(echo .)kernel.org \
    --cc=daniel@iogearbox$(echo .)net \
    --cc=kernel-team@fb$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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