Re: [PATCH v2 bpf-next 3/3] libbpf: add BTF-defined map-in-map support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrii Nakryiko <andriin@xxxxxx> 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.
>
> As an example, here's a rather advanced HASH_OF_MAPS declaration and
> initialization example, filling slots #0 and #4 with two inner maps:
>
>   #include <bpf/bpf_helpers.h>
>
>   struct inner_map {
>           __uint(type, BPF_MAP_TYPE_ARRAY);
>           __uint(max_entries, 1);
>           __type(key, int);
>           __type(value, int);
>   } inner_map1 SEC(".maps"),
>     inner_map2 SEC(".maps");
>
>   struct outer_hash {
>           __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
>           __uint(max_entries, 5);
>           __uint(key_size, sizeof(int));
>           __inner(values, struct inner_map);
>   } outer_hash SEC(".maps") = {
>           .values = {
>                   [0] = &inner_map2,
>                   [4] = &inner_map1,
>           },
>   };

I like the syntax (well, to the extent you can 'like' C syntax and its
esoteric (ab)uses), and am only mildly horrified at what it takes to
achieve it ;)

Acked-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux