]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary
authorAndrii Nakryiko <andrii@kernel.org>
Mon, 9 May 2022 00:41:47 +0000 (17:41 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 9 May 2022 15:15:32 +0000 (17:15 +0200)
commitead9e6c5d27cd6ec28c11123d1ccbc9f6256edcb
tree5f04c8a136130cb7f7d95fceed57c1322ebaf213
parent4c97c663c2d58530b019d24596b5f89f6e78fc1d
libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary

Kernel imposes a pretty particular restriction on ringbuf map size. It
has to be a power-of-2 multiple of page size. While generally this isn't
hard for user to satisfy, sometimes it's impossible to do this
declaratively in BPF source code or just plain inconvenient to do at
runtime.

One such example might be BPF libraries that are supposed to work on
different architectures, which might not agree on what the common page
size is.

Let libbpf find the right size for user instead, if it turns out to not
satisfy kernel requirements. If user didn't set size at all, that's most
probably a mistake so don't upsize such zero size to one full page,
though. Also we need to be careful about not overflowing __u32
max_entries.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220509004148.1801791-9-andrii@kernel.org
tools/lib/bpf/libbpf.c