libbpf: Handle missing BPF_OBJ_GET_INFO_BY_FD gracefully in perf_buffer
authorAndrii Nakryiko <andriin@fb.com>
Wed, 8 Jul 2020 01:53:17 +0000 (18:53 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 8 Jul 2020 22:44:45 +0000 (00:44 +0200)
commit0e289487308236903b19273f2ddb4f0adf732b9e
treec90853607b25de230a8a343f38b222d66f72ec0e
parentfcda189a5133b6fe50eb63d1062a15be4df9e3de
libbpf: Handle missing BPF_OBJ_GET_INFO_BY_FD gracefully in perf_buffer

perf_buffer__new() is relying on BPF_OBJ_GET_INFO_BY_FD availability for few
sanity checks. OBJ_GET_INFO for maps is actually much more recent feature than
perf_buffer support itself, so this causes unnecessary problems on old kernels
before BPF_OBJ_GET_INFO_BY_FD was added.

This patch makes those sanity checks optional and just assumes best if command
is not supported. If user specified something incorrectly (e.g., wrong map
type), kernel will reject it later anyway, except user won't get a nice
explanation as to why it failed. This seems like a good trade off for
supporting perf_buffer on old kernels.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200708015318.3827358-6-andriin@fb.com
tools/lib/bpf/libbpf.c