2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 04:34:11 +08:00
linux-next/tools/include/uapi/linux
Daniel Borkmann 4a8f87e60f bpf: Allow for map-in-map with dynamic inner array map entries
Recent work in f4d0525921 ("bpf: Add map_meta_equal map ops") and 134fede4ee
("bpf: Relax max_entries check for most of the inner map types") added support
for dynamic inner max elements for most map-in-map types. Exceptions were maps
like array or prog array where the map_gen_lookup() callback uses the maps'
max_entries field as a constant when emitting instructions.

We recently implemented Maglev consistent hashing into Cilium's load balancer
which uses map-in-map with an outer map being hash and inner being array holding
the Maglev backend table for each service. This has been designed this way in
order to reduce overall memory consumption given the outer hash map allows to
avoid preallocating a large, flat memory area for all services. Also, the
number of service mappings is not always known a-priori.

The use case for dynamic inner array map entries is to further reduce memory
overhead, for example, some services might just have a small number of back
ends while others could have a large number. Right now the Maglev backend table
for small and large number of backends would need to have the same inner array
map entries which adds a lot of unneeded overhead.

Dynamic inner array map entries can be realized by avoiding the inlined code
generation for their lookup. The lookup will still be efficient since it will
be calling into array_map_lookup_elem() directly and thus avoiding retpoline.
The patch adds a BPF_F_INNER_MAP flag to map creation which therefore skips
inline code generation and relaxes array_map_meta_equal() check to ignore both
maps' max_entries. This also still allows to have faster lookups for map-in-map
when BPF_F_INNER_MAP is not specified and hence dynamic max_entries not needed.

Example code generation where inner map is dynamic sized array:

  # bpftool p d x i 125
  int handle__sys_enter(void * ctx):
  ; int handle__sys_enter(void *ctx)
     0: (b4) w1 = 0
  ; int key = 0;
     1: (63) *(u32 *)(r10 -4) = r1
     2: (bf) r2 = r10
  ;
     3: (07) r2 += -4
  ; inner_map = bpf_map_lookup_elem(&outer_arr_dyn, &key);
     4: (18) r1 = map[id:468]
     6: (07) r1 += 272
     7: (61) r0 = *(u32 *)(r2 +0)
     8: (35) if r0 >= 0x3 goto pc+5
     9: (67) r0 <<= 3
    10: (0f) r0 += r1
    11: (79) r0 = *(u64 *)(r0 +0)
    12: (15) if r0 == 0x0 goto pc+1
    13: (05) goto pc+1
    14: (b7) r0 = 0
    15: (b4) w6 = -1
  ; if (!inner_map)
    16: (15) if r0 == 0x0 goto pc+6
    17: (bf) r2 = r10
  ;
    18: (07) r2 += -4
  ; val = bpf_map_lookup_elem(inner_map, &key);
    19: (bf) r1 = r0                               | No inlining but instead
    20: (85) call array_map_lookup_elem#149280     | call to array_map_lookup_elem()
  ; return val ? *val : -1;                        | for inner array lookup.
    21: (15) if r0 == 0x0 goto pc+1
  ; return val ? *val : -1;
    22: (61) r6 = *(u32 *)(r0 +0)
  ; }
    23: (bc) w0 = w6
    24: (95) exit

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201010234006.7075-4-daniel@iogearbox.net
2020-10-11 10:21:04 -07:00
..
tc_act net: Move all TC actions identifiers to one place 2019-02-10 09:28:43 -08:00
bpf_common.h bpf: Sync kernel ABI header with tooling header for bpf_common.h 2018-02-09 00:24:38 +01:00
bpf_perf_event.h selftests/bpf: sync kernel headers and introduce arch support in Makefile 2017-12-05 15:02:41 +01:00
bpf.h bpf: Allow for map-in-map with dynamic inner array map entries 2020-10-11 10:21:04 -07:00
btf.h libbpf: Sanitize global functions 2020-01-10 17:20:07 +01:00
const.h tools headers: Grab copy of linux/const.h, needed by linux/bits.h 2019-08-20 12:08:23 -03:00
erspan.h tools, include: Grab a copy of linux/erspan.h 2018-04-30 17:56:24 +02:00
ethtool.h libbpf: add support for using AF_XDP sockets 2019-02-25 23:21:42 +01:00
fadvise.h tools headers uapi: Grab a copy of fadvise.h 2018-12-18 16:17:40 -03:00
fcntl.h tools headers API: Update faccessat2 affected files 2020-06-09 12:40:03 -03:00
filter.h tools: bpf: Use local copy of headers including uapi/linux/filter.h 2020-07-21 10:50:35 +01:00
fs.h tools headers UAPI: Sync linux/fs.h with the kernel sources 2020-06-17 13:23:02 -03:00
fscrypt.h tools headers UAPI: Sync linux/fscrypt.h with the kernel sources 2020-06-09 12:40:04 -03:00
hw_breakpoint.h tools/headers: Synchronize kernel ABI headers 2017-11-04 09:27:46 +01:00
if_link.h net: bridge: Add port attribute IFLA_BRPORT_MRP_IN_OPEN 2020-07-14 13:46:43 -07:00
if_tun.h selftests/bpf: fix compilation error for flow_dissector.c 2019-05-29 15:15:07 +02:00
if_xdp.h xsk: Add new statistics 2020-07-13 15:32:56 -07:00
in.h tools headers UAPI: update linux/in.h copy 2020-09-14 19:06:41 -03:00
kcmp.h tools headers: Synchronize kernel ABI headers wrt SPDX tags 2017-11-28 14:29:20 -03:00
kvm.h tools headers UAPI: Sync kvm.h headers with the kernel sources 2020-09-14 19:02:18 -03:00
lirc.h media: rc: rcmm decoder and encoder 2019-02-18 15:39:49 -05:00
mman.h tools headers UAPI: Sync linux/mman.h with the kernel 2020-04-14 09:04:53 -03:00
mount.h tools include UAPI: Update copy of files related to new fspick, fsmount, fsconfig, fsopen, move_mount and open_tree syscalls 2019-05-28 09:49:03 -03:00
netlink.h net: netlink: rename NETLINK_DUMP_STRICT_CHK -> NETLINK_GET_STRICT_CHK 2018-12-14 11:44:31 -08:00
openat2.h tools include UAPI: Sync x86's syscalls_64.tbl, generic unistd.h and fcntl.h to pick up openat2 and pidfd_getfd 2020-02-11 16:41:06 -03:00
perf_event.h perf tools: Correct SNOOPX field offset 2020-09-01 12:19:16 -03:00
pkt_cls.h net: sched: remove NET_CLS_IND config option 2019-06-15 14:06:13 -07:00
pkt_sched.h bpf: pull in pkt_sched.h header for tooling to fix bpftool build 2019-01-18 15:16:36 -08:00
prctl.h tools headers UAPI: Sync prctl.h with the kernel sources 2020-02-11 16:41:50 -03:00
sched.h tools headers UAPI: Sync sched.h with the kernel 2020-04-14 09:01:08 -03:00
seg6_local.h selftests/bpf: missing headers test_lwt_seg6local 2018-05-28 17:41:00 +02:00
seg6.h selftests/bpf: missing headers test_lwt_seg6local 2018-05-28 17:41:00 +02:00
stat.h tools headers uapi: Sync linux/stat.h with the kernel sources 2020-06-09 12:40:03 -03:00
tls.h bpf, tls: add tls header to tools infrastructure 2018-10-16 08:10:01 -07:00
types.h tools/bpf: Move linux/types.h for selftests and bpftool 2020-03-13 20:56:34 +01:00
usbdevice_fs.h tools headers uapi: Sync linux/usbdevice_fs.h with the kernel sources 2019-09-30 17:29:02 -03:00
vhost.h tools include UAPI: Sync linux/vhost.h with the kernel sources 2020-08-12 08:57:07 -03:00