libbpf: Fix BPF_MAP_TYPE_PERF_EVENT_ARRAY auto-pinning
authorStijn Tintel <stijn@linux-ipv6.be>
Fri, 25 Feb 2022 15:23:55 +0000 (17:23 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 28 Feb 2022 16:20:52 +0000 (17:20 +0100)
commita4fbfdd7a160eccaafc093eb5b34f838b1ca0bf0
treeb5e4090496ae35296de1307aa6231a17fa339152
parent07609c193a0cfd1e3532a7dd81383c9d458f485c
libbpf: Fix BPF_MAP_TYPE_PERF_EVENT_ARRAY auto-pinning

When a BPF map of type BPF_MAP_TYPE_PERF_EVENT_ARRAY doesn't have the
max_entries parameter set, the map will be created with max_entries set
to the number of available CPUs. When we try to reuse such a pinned map,
map_is_reuse_compat will return false, as max_entries in the map
definition differs from max_entries of the existing map, causing the
following error:

  libbpf: couldn't reuse pinned map at '/sys/fs/bpf/m_logging': parameter mismatch

Fix this by overwriting max_entries in the map definition. For this to
work, we need to do this in bpf_object__create_maps, before calling
bpf_object__reuse_map.

Fixes: 57a00f41644f ("libbpf: Add auto-pinning of maps when loading BPF objects")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20220225152355.315204-1-stijn@linux-ipv6.be
tools/lib/bpf/libbpf.c