On Wed, Dec 8, 2021 at 4:30 PM Andrii Nakryiko <andrii@xxxxxxxxxx> wrote: > > Add new open options and per-program setters to control BTF and program > loading log verboseness and allow providing custom log buffers to capture logs > of interest. Note how custom log_buf and log_level are orthogonal, which > matches previous (alas less customizable) behavior of libbpf, even though it > sort of worked by accident: if someone specified log_level = 1 in > bpf_object__load_xattr(), first attempt to load any BPF program resulted in > wasted bpf() syscall with -EINVAL due to !!log_buf != !!log_level. Then on > retry libbpf would allocated log_buffer and try again, after which prog > loading would succeed and libbpf would print verbose program loading log > through its print callback. > > This behavior is now documented and made more efficient, not wasting > unnecessary syscall. But additionally, log_level can be controlled globally on > a per-bpf_object level through bpf_object_open_opts, as well as on > a per-program basis with bpf_program__set_log_buf() and > bpf_program__set_log_level() APIs. > > Now that we have a more future-proof way to set log_level, deprecate > bpf_object__load_xattr(). > > v1->v2: > - fix log_level == 0 handling of bpf_prog_load, add as patch #1 (Alexei); > - add comments explaining log_buf_size overflow prevention (Alexei). > Oh, the patch set was supposed to be marked with v2. I'll resend with proper v2 tag, sorry for spam. > Andrii Nakryiko (12): > libbpf: fix bpf_prog_load() log_buf logic for log_level 0 > libbpf: add OPTS-based bpf_btf_load() API > libbpf: allow passing preallocated log_buf when loading BTF into > kernel > libbpf: allow passing user log setting through bpf_object_open_opts > libbpf: improve logging around BPF program loading > libbpf: preserve kernel error code and remove kprobe prog type > guessing > libbpf: add per-program log buffer setter and getter > libbpf: deprecate bpf_object__load_xattr() > selftests/bpf: replace all uses of bpf_load_btf() with bpf_btf_load() > selftests/bpf: add test for libbpf's custom log_buf behavior > selftests/bpf: remove the only use of deprecated > bpf_object__load_xattr() > bpftool: switch bpf_object__load_xattr() to bpf_object__load() > > tools/bpf/bpftool/gen.c | 11 +- > tools/bpf/bpftool/prog.c | 24 +-- > tools/bpf/bpftool/struct_ops.c | 15 +- > tools/lib/bpf/bpf.c | 88 ++++++-- > tools/lib/bpf/bpf.h | 22 +- > tools/lib/bpf/btf.c | 78 ++++--- > tools/lib/bpf/libbpf.c | 194 ++++++++++++------ > tools/lib/bpf/libbpf.h | 49 ++++- > tools/lib/bpf/libbpf.map | 3 + > tools/lib/bpf/libbpf_internal.h | 1 + > tools/lib/bpf/libbpf_probes.c | 2 +- > .../selftests/bpf/map_tests/sk_storage_map.c | 2 +- > .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 6 +- > tools/testing/selftests/bpf/prog_tests/btf.c | 50 +++-- > .../selftests/bpf/prog_tests/log_buf.c | 137 +++++++++++++ > .../selftests/bpf/progs/test_log_buf.c | 24 +++ > tools/testing/selftests/bpf/test_verifier.c | 2 +- > tools/testing/selftests/bpf/testing_helpers.c | 10 +- > 18 files changed, 544 insertions(+), 174 deletions(-) > create mode 100644 tools/testing/selftests/bpf/prog_tests/log_buf.c > create mode 100644 tools/testing/selftests/bpf/progs/test_log_buf.c > > -- > 2.30.2 >