Extend the rv userspace tool to load BPF monitors, those can be found in specific locations (e.g. /usr/share/rv/bpf_monitors/) and are plain object files including BTF data.
This type of BPF monitors can be generated from rvgen using the -b flag just like in-kernel monitors and, after manual adaptation, can be built and run transparently by the rv userspace tool. Only DA monitors are supported (as they are the only class the rv tool currenly supports) and the tool aims to work in the same way for both in-kernel and BPF monitors. The da_monitor header is adapted to be included directly in BPF programs and share as much logic as possible. BPF monitors are implemented purely in BPF and as such require the rv userspace tool for any operation: * listing: find properly formatted objects in specific locations * running: load trace handlers for events * tracing: read event/errors from the ring buffer * reactors: link a react() function over the object Selftests (make -C tools/verification/rv check) are present to validate and demonstrate the usage, which is mostly equivalent to the standard rv tool usage. Patch 1 adds tracepoints required in a later monitor example. Patch 2 improves the rv tool selftest reporting. Patches 3-4 prepare the kernel headers for BPF support. Patch 5 adds a feature check for tools/build. Patch 6-8 prepare and add support for BPF monitors in the rv tool. Patch 9-11 prepare and include BPF monitors examples. Patch 12 adds support for BPF reactors. Patch 13 adds support for generating BPF monitors in rvgen. Patch 14-15 adds BPF selftests (make check) for the rv and rvgen tools. Changes since RFC [1]: * Drop struct_ops integration to favour a BPF-only implementation. * Implement BPF reactors with a dynamic linker. * Don't pin programs and maps. * Improve handler performance when not tracing. [1] - https://lore.kernel.org/lkml/[email protected] To: [email protected] To: [email protected] Cc: Steven Rostedt <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Nam Cao <[email protected]> Cc: Wen Yang <[email protected]> Cc: Tobias Schaffner <[email protected]> Cc: Viktor Malik <[email protected]> Gabriele Monaco (14): tools/rv: Skip empty pid error in selftest if command failed rv: Refactor da_trace() functions to get strings internally rv: Cast result of model_get_*_name() tools/rv: Move argument parsing from in_kernel to utils tools/build: Add a feature test for bpftool-btf tools/rv: Implement BPF monitor discovery and listing tools/rv: Implement BPF monitor loading and tracing tools/rv: Copy stripped bpf_atomic.h from libarena tools/rv: Add BPF monitors tools/rv: Define CONFIG_X86_64 statically for BPF monitors tools/rv: Add reactors support to BPF monitors verification/rvgen: Add support for BPF monitors tools/rv: Add selftest for rv bpf monitors verification/rvgen: Add selftest for rvgen -b Nam Cao (1): sched: Add task enqueue/dequeue trace points include/rv/automata.h | 4 +- include/rv/da_monitor.h | 61 +- include/trace/events/sched.h | 8 + kernel/sched/core.c | 12 +- kernel/sched/sched.h | 2 + tools/build/Makefile.feature | 1 + tools/build/feature/Makefile | 7 +- tools/verification/models/nohz.dot | 16 + tools/verification/models/tqueue.dot | 15 + tools/verification/rv/Makefile | 54 +- tools/verification/rv/Makefile.config | 49 + tools/verification/rv/Makefile.rv | 10 + tools/verification/rv/bpf_monitors/.gitignore | 2 + .../verification/rv/bpf_monitors/bpf_atomic.h | 105 ++ .../rv/bpf_monitors/da_monitor_bpf.h | 374 +++++++ tools/verification/rv/bpf_monitors/nohz.c | 42 + tools/verification/rv/bpf_monitors/nohz.h | 49 + tools/verification/rv/bpf_monitors/tqueue.c | 30 + tools/verification/rv/bpf_monitors/tqueue.h | 47 + tools/verification/rv/bpf_reactors/.gitignore | 2 + tools/verification/rv/bpf_reactors/panic.c | 15 + tools/verification/rv/bpf_reactors/printk.c | 13 + tools/verification/rv/include/bpf_monitor.h | 22 + tools/verification/rv/include/utils.h | 19 +- tools/verification/rv/src/Build | 5 + tools/verification/rv/src/bpf_monitor.c | 982 ++++++++++++++++++ tools/verification/rv/src/in_kernel.c | 176 +--- tools/verification/rv/src/rv.c | 5 + tools/verification/rv/src/utils.c | 98 +- tools/verification/rv/tests/rv_list.t | 6 +- tools/verification/rv/tests/rv_mon.t | 61 +- tools/verification/rvgen/__main__.py | 15 +- tools/verification/rvgen/rvgen/dot2c.py | 15 +- tools/verification/rvgen/rvgen/dot2k.py | 22 +- tools/verification/rvgen/rvgen/generator.py | 26 +- .../rvgen/rvgen/templates/dot2k/main_bpf.c | 21 + .../tests/golden/da_bpf_cpu/da_bpf_cpu.c | 35 + .../tests/golden/da_bpf_cpu/da_bpf_cpu.h | 47 + .../tests/golden/da_bpf_obj/da_bpf_obj.c | 49 + .../tests/golden/da_bpf_obj/da_bpf_obj.h | 47 + .../verification/rvgen/tests/rvgen_monitor.t | 11 + tools/verification/tests/engine.sh | 5 +- 42 files changed, 2392 insertions(+), 193 deletions(-) create mode 100644 tools/verification/models/nohz.dot create mode 100644 tools/verification/models/tqueue.dot create mode 100644 tools/verification/rv/bpf_monitors/.gitignore create mode 100644 tools/verification/rv/bpf_monitors/bpf_atomic.h create mode 100644 tools/verification/rv/bpf_monitors/da_monitor_bpf.h create mode 100644 tools/verification/rv/bpf_monitors/nohz.c create mode 100644 tools/verification/rv/bpf_monitors/nohz.h create mode 100644 tools/verification/rv/bpf_monitors/tqueue.c create mode 100644 tools/verification/rv/bpf_monitors/tqueue.h create mode 100644 tools/verification/rv/bpf_reactors/.gitignore create mode 100644 tools/verification/rv/bpf_reactors/panic.c create mode 100644 tools/verification/rv/bpf_reactors/printk.c create mode 100644 tools/verification/rv/include/bpf_monitor.h create mode 100644 tools/verification/rv/src/bpf_monitor.c create mode 100644 tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h base-commit: 238650ef6c7c7cca08e032527329424c9fbd70e5 -- 2.55.0
