* [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 02/18] tools/rv: Skip empty pid error in selftest if command failed Gabriele Monaco
` (16 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Masami Hiramatsu, Ingo Molnar, Peter Zijlstra
Cc: Nam Cao, K Prateek Nayak, Gabriele Monaco, Alexei Starovoitov,
Wen Yang, Tobias Schaffner, Viktor Malik, John Ogness
From: Nam Cao <namcao@linutronix.de>
Add trace points into enqueue_task() and dequeue_task().
Signed-off-by: Nam Cao <namcao@linutronix.de>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Co-developed-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
include/trace/events/sched.h | 8 ++++++++
kernel/sched/core.c | 12 +++++++++++-
kernel/sched/sched.h | 2 ++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 535860581f15..d6e41edc25d2 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -896,6 +896,14 @@ DECLARE_TRACE(sched_set_need_resched,
TP_PROTO(struct task_struct *tsk, int cpu, int tif),
TP_ARGS(tsk, cpu, tif));
+DECLARE_TRACE(sched_enqueue,
+ TP_PROTO(struct task_struct *tsk, int cpu),
+ TP_ARGS(tsk, cpu));
+
+DECLARE_TRACE(sched_dequeue,
+ TP_PROTO(struct task_struct *tsk, int cpu),
+ TP_ARGS(tsk, cpu));
+
#define DL_OTHER 0
#define DL_TASK 1
#define DL_SERVER_FAIR 2
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 515b9d0353ce..69800a8dec05 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -121,6 +121,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_compute_energy_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_entry_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_exit_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_set_need_resched_tp);
+EXPORT_TRACEPOINT_SYMBOL_GPL(sched_enqueue_tp);
+EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dequeue_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_throttle_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_replenish_tp);
EXPORT_TRACEPOINT_SYMBOL_GPL(sched_dl_update_tp);
@@ -2184,6 +2186,9 @@ unsigned long get_wchan(struct task_struct *p)
void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
{
+ if (trace_sched_enqueue_tp_enabled() && !(flags & ENQUEUE_DELAYED))
+ trace_call__sched_enqueue_tp(p, cpu_of(rq));
+
if (!(flags & ENQUEUE_NOCLOCK))
update_rq_clock(rq);
@@ -2210,6 +2215,8 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
*/
inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
{
+ bool ret;
+
if (sched_core_enabled(rq))
sched_core_dequeue(rq, p, flags);
@@ -2226,7 +2233,10 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
* and mark the task ->sched_delayed.
*/
uclamp_rq_dec(rq, p);
- return p->sched_class->dequeue_task(rq, p, flags);
+ ret = p->sched_class->dequeue_task(rq, p, flags);
+ if (trace_sched_dequeue_tp_enabled() && !(flags & DEQUEUE_SLEEP))
+ trace_call__sched_dequeue_tp(p, cpu_of(rq));
+ return ret;
}
void activate_task(struct rq *rq, struct task_struct *p, int flags)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index a4e6696e3a51..d22e6c6d1b2d 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3148,6 +3148,8 @@ static inline void sub_nr_running(struct rq *rq, unsigned count)
static inline void __block_task(struct rq *rq, struct task_struct *p)
{
+ trace_sched_dequeue_tp(p, cpu_of(rq));
+
if (p->sched_contributes_to_load)
rq->nr_uninterruptible++;
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 02/18] tools/rv: Skip empty pid error in selftest if command failed
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 03/18] rv: Add wrapper macros for monitor tracepoint definitions Gabriele Monaco
` (15 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco, Nam Cao
Cc: Alexei Starovoitov, Wen Yang, Tobias Schaffner, Viktor Malik,
Peter Zijlstra, John Ogness
Some rv userspace selftests rely on the pid of the rv process to match
with the output and fail prematurely in case the pid was not found.
If the rv process failed, however, it's likely it will terminate before
catching the pid, and the test reports empty pid ignoring the error that
caused the process to fail.
Report empty pid only when the rv process succeeds and continue showing
exit code and output otherwise.
Fixes: 92f0ce552990 ("tools/rv: Add selftests")
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/tests/engine.sh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/verification/tests/engine.sh b/tools/verification/tests/engine.sh
index cfdf2180aad8..4dad43b0b822 100644
--- a/tools/verification/tests/engine.sh
+++ b/tools/verification/tests/engine.sh
@@ -60,8 +60,9 @@ _check() {
failbuf=''
fail=0
- # Suppress any other error if a needed pid is empty
- if [ -z "$pid" ] && grep -q "\$pid" <<< "$patterns"; then
+ # Suppress any other error if a needed pid is empty and there was no other error
+ if [ -z "$pid" ] && grep -q "\$pid" <<< "$patterns" \
+ && [ $exitcode -eq "$expected_exitcode" ]; then
result=''
failure "# Empty pid for $command"
return 1
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 03/18] rv: Add wrapper macros for monitor tracepoint definitions
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 02/18] tools/rv: Skip empty pid error in selftest if command failed Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 04/18] rv: Propagate const to model strings and tracepoints Gabriele Monaco
` (14 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco, Masami Hiramatsu
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Currently, each monitor trace header repeats DEFINE_EVENT with explicit
TP_PROTO and TP_ARGS matching the respective event class. This
introduces boilerplate across monitors and makes changing the underlying
prototype cumbersome as every monitor's trace header must be updated
individually.
Add wrapper macros in rv_trace.h that wrap DEFINE_EVENT with the shared
prototypes and argument lists.
Update all monitor trace headers, the rvgen code generation templates,
and the test golden files to use these helper macros.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
.../trace/rv/monitors/nomiss/nomiss_trace.h | 14 ++----
kernel/trace/rv/monitors/nrp/nrp_trace.h | 9 +---
kernel/trace/rv/monitors/opid/opid_trace.h | 14 ++----
.../rv/monitors/pagefault/pagefault_trace.h | 8 +---
kernel/trace/rv/monitors/sco/sco_trace.h | 9 +---
kernel/trace/rv/monitors/scpd/scpd_trace.h | 9 +---
kernel/trace/rv/monitors/sleep/sleep_trace.h | 8 +---
kernel/trace/rv/monitors/snep/snep_trace.h | 9 +---
kernel/trace/rv/monitors/snroc/snroc_trace.h | 9 +---
kernel/trace/rv/monitors/sssw/sssw_trace.h | 9 +---
kernel/trace/rv/monitors/stall/stall_trace.h | 14 ++----
kernel/trace/rv/monitors/sts/sts_trace.h | 9 +---
.../trace/rv/monitors/wakeup/wakeup_trace.h | 8 +---
kernel/trace/rv/monitors/wip/wip_trace.h | 9 +---
kernel/trace/rv/monitors/wwnr/wwnr_trace.h | 9 +---
kernel/trace/rv/rv_trace.h | 44 +++++++++++++++++++
tools/verification/rvgen/rvgen/dot2k.py | 28 ------------
tools/verification/rvgen/rvgen/generator.py | 14 +++---
.../rvgen/rvgen/templates/dot2k/trace.h | 7 +--
.../rvgen/templates/dot2k/trace_hybrid.h | 11 ++---
.../rvgen/rvgen/templates/ltl2k/trace.h | 8 +---
.../tests/golden/da_global/da_global_trace.h | 9 +---
.../da_perobj_parent/da_perobj_parent_trace.h | 9 +---
.../da_pertask_desc/da_pertask_desc_trace.h | 9 +---
.../tests/golden/ha_percpu/ha_percpu_trace.h | 14 ++----
.../golden/ltl_pertask/ltl_pertask_trace.h | 8 +---
.../test_bak_kunit/test_bak_kunit_trace.h | 8 +---
.../tests/golden/test_da/test_da_trace.h | 9 +---
.../test_da_kunit/test_da_kunit_trace.h | 9 +---
.../tests/golden/test_ha/test_ha_trace.h | 14 ++----
.../test_ha_kunit/test_ha_kunit_trace.h | 14 ++----
.../tests/golden/test_ltl/test_ltl_trace.h | 8 +---
.../test_ltl_kunit/test_ltl_kunit_trace.h | 8 +---
33 files changed, 116 insertions(+), 262 deletions(-)
diff --git a/kernel/trace/rv/monitors/nomiss/nomiss_trace.h b/kernel/trace/rv/monitors/nomiss/nomiss_trace.h
index 42e7efaca4e7..2863b905e0db 100644
--- a/kernel/trace/rv/monitors/nomiss/nomiss_trace.h
+++ b/kernel/trace/rv/monitors/nomiss/nomiss_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_NOMISS
-DEFINE_EVENT(event_da_monitor_id, event_nomiss,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_nomiss,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
-
-DEFINE_EVENT(error_env_da_monitor_id, error_env_nomiss,
- TP_PROTO(int id, char *state, char *event, char *env),
- TP_ARGS(id, state, event, env));
+DEFINE_DA_EVENT_ID(event_nomiss);
+DEFINE_DA_ERROR_ID(error_nomiss);
+DEFINE_HA_ERROR_ENV_ID(error_env_nomiss);
#endif /* CONFIG_RV_MON_NOMISS */
diff --git a/kernel/trace/rv/monitors/nrp/nrp_trace.h b/kernel/trace/rv/monitors/nrp/nrp_trace.h
index 2e13497de3b6..3d85bdcbcd90 100644
--- a/kernel/trace/rv/monitors/nrp/nrp_trace.h
+++ b/kernel/trace/rv/monitors/nrp/nrp_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_NRP
-DEFINE_EVENT(event_da_monitor_id, event_nrp,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_nrp,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_nrp);
+DEFINE_DA_ERROR_ID(error_nrp);
#endif /* CONFIG_RV_MON_NRP */
diff --git a/kernel/trace/rv/monitors/opid/opid_trace.h b/kernel/trace/rv/monitors/opid/opid_trace.h
index b04005b64208..914763d5dbf4 100644
--- a/kernel/trace/rv/monitors/opid/opid_trace.h
+++ b/kernel/trace/rv/monitors/opid/opid_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_OPID
-DEFINE_EVENT(event_da_monitor, event_opid,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_opid,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
-
-DEFINE_EVENT(error_env_da_monitor, error_env_opid,
- TP_PROTO(char *state, char *event, char *env),
- TP_ARGS(state, event, env));
+DEFINE_DA_EVENT(event_opid);
+DEFINE_DA_ERROR(error_opid);
+DEFINE_HA_ERROR_ENV(error_env_opid);
#endif /* CONFIG_RV_MON_OPID */
diff --git a/kernel/trace/rv/monitors/pagefault/pagefault_trace.h b/kernel/trace/rv/monitors/pagefault/pagefault_trace.h
index fe1f82597b1a..4b49ddbbb244 100644
--- a/kernel/trace/rv/monitors/pagefault/pagefault_trace.h
+++ b/kernel/trace/rv/monitors/pagefault/pagefault_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_PAGEFAULT
-DEFINE_EVENT(event_ltl_monitor_id, event_pagefault,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_pagefault,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_pagefault);
+DEFINE_LTL_ERROR_ID(error_pagefault);
#endif /* CONFIG_RV_MON_PAGEFAULT */
diff --git a/kernel/trace/rv/monitors/sco/sco_trace.h b/kernel/trace/rv/monitors/sco/sco_trace.h
index b711cd9024ec..36ec9b876df5 100644
--- a/kernel/trace/rv/monitors/sco/sco_trace.h
+++ b/kernel/trace/rv/monitors/sco/sco_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SCO
-DEFINE_EVENT(event_da_monitor, event_sco,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_sco,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_sco);
+DEFINE_DA_ERROR(error_sco);
#endif /* CONFIG_RV_MON_SCO */
diff --git a/kernel/trace/rv/monitors/scpd/scpd_trace.h b/kernel/trace/rv/monitors/scpd/scpd_trace.h
index 6b0f4aa4732e..ad330701eb2d 100644
--- a/kernel/trace/rv/monitors/scpd/scpd_trace.h
+++ b/kernel/trace/rv/monitors/scpd/scpd_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SCPD
-DEFINE_EVENT(event_da_monitor, event_scpd,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_scpd,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_scpd);
+DEFINE_DA_ERROR(error_scpd);
#endif /* CONFIG_RV_MON_SCPD */
diff --git a/kernel/trace/rv/monitors/sleep/sleep_trace.h b/kernel/trace/rv/monitors/sleep/sleep_trace.h
index 22eaf31da987..44a22828a810 100644
--- a/kernel/trace/rv/monitors/sleep/sleep_trace.h
+++ b/kernel/trace/rv/monitors/sleep/sleep_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SLEEP
-DEFINE_EVENT(event_ltl_monitor_id, event_sleep,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_sleep,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_sleep);
+DEFINE_LTL_ERROR_ID(error_sleep);
#endif /* CONFIG_RV_MON_SLEEP */
diff --git a/kernel/trace/rv/monitors/snep/snep_trace.h b/kernel/trace/rv/monitors/snep/snep_trace.h
index 01aad49a949a..94edc47b30b9 100644
--- a/kernel/trace/rv/monitors/snep/snep_trace.h
+++ b/kernel/trace/rv/monitors/snep/snep_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SNEP
-DEFINE_EVENT(event_da_monitor, event_snep,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_snep,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_snep);
+DEFINE_DA_ERROR(error_snep);
#endif /* CONFIG_RV_MON_SNEP */
diff --git a/kernel/trace/rv/monitors/snroc/snroc_trace.h b/kernel/trace/rv/monitors/snroc/snroc_trace.h
index 50114cef5122..20462159988a 100644
--- a/kernel/trace/rv/monitors/snroc/snroc_trace.h
+++ b/kernel/trace/rv/monitors/snroc/snroc_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SNROC
-DEFINE_EVENT(event_da_monitor_id, event_snroc,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_snroc,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_snroc);
+DEFINE_DA_ERROR_ID(error_snroc);
#endif /* CONFIG_RV_MON_SNROC */
diff --git a/kernel/trace/rv/monitors/sssw/sssw_trace.h b/kernel/trace/rv/monitors/sssw/sssw_trace.h
index 6c03cfc6960b..26cffbf9ed62 100644
--- a/kernel/trace/rv/monitors/sssw/sssw_trace.h
+++ b/kernel/trace/rv/monitors/sssw/sssw_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_SSSW
-DEFINE_EVENT(event_da_monitor_id, event_sssw,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_sssw,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_sssw);
+DEFINE_DA_ERROR_ID(error_sssw);
#endif /* CONFIG_RV_MON_SSSW */
diff --git a/kernel/trace/rv/monitors/stall/stall_trace.h b/kernel/trace/rv/monitors/stall/stall_trace.h
index 6a7cc1b1d040..9da0aedf01c1 100644
--- a/kernel/trace/rv/monitors/stall/stall_trace.h
+++ b/kernel/trace/rv/monitors/stall/stall_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_STALL
-DEFINE_EVENT(event_da_monitor_id, event_stall,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_stall,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
-
-DEFINE_EVENT(error_env_da_monitor_id, error_env_stall,
- TP_PROTO(int id, char *state, char *event, char *env),
- TP_ARGS(id, state, event, env));
+DEFINE_DA_EVENT_ID(event_stall);
+DEFINE_DA_ERROR_ID(error_stall);
+DEFINE_HA_ERROR_ENV_ID(error_env_stall);
#endif /* CONFIG_RV_MON_STALL */
diff --git a/kernel/trace/rv/monitors/sts/sts_trace.h b/kernel/trace/rv/monitors/sts/sts_trace.h
index d78beb58d5b3..5b7d5e359290 100644
--- a/kernel/trace/rv/monitors/sts/sts_trace.h
+++ b/kernel/trace/rv/monitors/sts/sts_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_STS
-DEFINE_EVENT(event_da_monitor, event_sts,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_sts,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_sts);
+DEFINE_DA_ERROR(error_sts);
#endif /* CONFIG_RV_MON_STS */
diff --git a/kernel/trace/rv/monitors/wakeup/wakeup_trace.h b/kernel/trace/rv/monitors/wakeup/wakeup_trace.h
index 7e056183f920..817826d77341 100644
--- a/kernel/trace/rv/monitors/wakeup/wakeup_trace.h
+++ b/kernel/trace/rv/monitors/wakeup/wakeup_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_WAKEUP
-DEFINE_EVENT(event_ltl_monitor_id, event_wakeup,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_wakeup,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_wakeup);
+DEFINE_LTL_ERROR_ID(error_wakeup);
#endif /* CONFIG_RV_MON_WAKEUP */
diff --git a/kernel/trace/rv/monitors/wip/wip_trace.h b/kernel/trace/rv/monitors/wip/wip_trace.h
index aa2162f47a4c..454333ea51e3 100644
--- a/kernel/trace/rv/monitors/wip/wip_trace.h
+++ b/kernel/trace/rv/monitors/wip/wip_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_WIP
-DEFINE_EVENT(event_da_monitor, event_wip,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_wip,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_wip);
+DEFINE_DA_ERROR(error_wip);
#endif /* CONFIG_RV_MON_WIP */
diff --git a/kernel/trace/rv/monitors/wwnr/wwnr_trace.h b/kernel/trace/rv/monitors/wwnr/wwnr_trace.h
index fc97ec7476ad..c395bb01542b 100644
--- a/kernel/trace/rv/monitors/wwnr/wwnr_trace.h
+++ b/kernel/trace/rv/monitors/wwnr/wwnr_trace.h
@@ -6,11 +6,6 @@
#ifdef CONFIG_RV_MON_WWNR
/* id is the pid of the task */
-DEFINE_EVENT(event_da_monitor_id, event_wwnr,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_wwnr,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_wwnr);
+DEFINE_DA_ERROR_ID(error_wwnr);
#endif /* CONFIG_RV_MON_WWNR */
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 2f8a932432c9..36e7c78c046e 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -57,6 +57,17 @@ DECLARE_EVENT_CLASS(error_da_monitor,
__get_str(state))
);
+#define DEFINE_DA_EVENT(name) \
+ DEFINE_EVENT(event_da_monitor, name, \
+ TP_PROTO(char *state, char *event, \
+ char *next_state, bool final_state), \
+ TP_ARGS(state, event, next_state, final_state))
+
+#define DEFINE_DA_ERROR(name) \
+ DEFINE_EVENT(error_da_monitor, name, \
+ TP_PROTO(char *state, char *event), \
+ TP_ARGS(state, event))
+
#include <monitors/wip/wip_trace.h>
#include <monitors/sco/sco_trace.h>
#include <monitors/scpd/scpd_trace.h>
@@ -90,6 +101,11 @@ DECLARE_EVENT_CLASS(error_env_da_monitor,
__get_str(env))
);
+#define DEFINE_HA_ERROR_ENV(name) \
+ DEFINE_EVENT(error_env_da_monitor, name, \
+ TP_PROTO(char *state, char *event, char *env), \
+ TP_ARGS(state, event, env))
+
#include <monitors/opid/opid_trace.h>
// Add new monitors based on CONFIG_HA_MON_EVENTS_IMPLICIT here
@@ -152,6 +168,17 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
__get_str(state))
);
+#define DEFINE_DA_EVENT_ID(name) \
+ DEFINE_EVENT(event_da_monitor_id, name, \
+ TP_PROTO(int id, char *state, char *event, \
+ char *next_state, bool final_state), \
+ TP_ARGS(id, state, event, next_state, final_state))
+
+#define DEFINE_DA_ERROR_ID(name) \
+ DEFINE_EVENT(error_da_monitor_id, name, \
+ TP_PROTO(int id, char *state, char *event), \
+ TP_ARGS(id, state, event))
+
#include <monitors/wwnr/wwnr_trace.h>
#include <monitors/snroc/snroc_trace.h>
#include <monitors/nrp/nrp_trace.h>
@@ -187,6 +214,11 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,
__get_str(env))
);
+#define DEFINE_HA_ERROR_ENV_ID(name) \
+ DEFINE_EVENT(error_env_da_monitor_id, name, \
+ TP_PROTO(int id, char *state, char *event, char *env), \
+ TP_ARGS(id, state, event, env))
+
#include <monitors/stall/stall_trace.h>
#include <monitors/nomiss/nomiss_trace.h>
// Add new monitors based on CONFIG_HA_MON_EVENTS_ID here
@@ -239,6 +271,18 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id,
TP_printk("%s[%d]: violation detected", __get_str(comm), __entry->pid)
);
+
+#define DEFINE_LTL_EVENT_ID(name) \
+ DEFINE_EVENT(event_ltl_monitor_id, name, \
+ TP_PROTO(struct task_struct *task, char *states, \
+ char *atoms, char *next), \
+ TP_ARGS(task, states, atoms, next))
+
+#define DEFINE_LTL_ERROR_ID(name) \
+ DEFINE_EVENT(error_ltl_monitor_id, name, \
+ TP_PROTO(struct task_struct *task), \
+ TP_ARGS(task))
+
#include <monitors/pagefault/pagefault_trace.h>
#include <monitors/sleep/sleep_trace.h>
#include <monitors/wakeup/wakeup_trace.h>
diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/rvgen/rvgen/dot2k.py
index fd3254ea5b4d..b48895b93c8a 100644
--- a/tools/verification/rvgen/rvgen/dot2k.py
+++ b/tools/verification/rvgen/rvgen/dot2k.py
@@ -125,34 +125,6 @@ class dot2k(Monitor, Dot2c):
return "da_monitor_id"
return "da_monitor"
- def fill_tracepoint_args_skel(self, tp_type: str) -> str:
- buff = []
- tp_args_event = [
- ("char *", "state"),
- ("char *", "event"),
- ("char *", "next_state"),
- ("bool ", "final_state"),
- ]
- tp_args_error = [
- ("char *", "state"),
- ("char *", "event"),
- ]
- tp_args_error_env = tp_args_error + [("char *", "env")]
- tp_args_dict = {
- "event": tp_args_event,
- "error": tp_args_error,
- "error_env": tp_args_error_env
- }
- tp_args_id = ("int ", "id")
- tp_args = tp_args_dict[tp_type]
- if self._is_id_monitor():
- tp_args.insert(0, tp_args_id)
- tp_proto_c = ", ".join([a + b for a, b in tp_args])
- tp_args_c = ", ".join([b for a, b in tp_args])
- buff.append(f" TP_PROTO({tp_proto_c}),")
- buff.append(f" TP_ARGS({tp_args_c})")
- return '\n'.join(buff)
-
def _fill_hybrid_definitions(self) -> list:
"""Stub, not valid for deterministic automata"""
return []
diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verification/rvgen/rvgen/generator.py
index 45e2bab26cb5..626bb7ce90ee 100644
--- a/tools/verification/rvgen/rvgen/generator.py
+++ b/tools/verification/rvgen/rvgen/generator.py
@@ -111,9 +111,6 @@ class RVGenerator:
def fill_monitor_class(self):
return "NotImplemented"
- def fill_tracepoint_args_skel(self, tp_type):
- return "NotImplemented"
-
def fill_monitor_deps(self):
buff = []
buff.append(" # XXX: add dependencies if there")
@@ -227,20 +224,19 @@ class Monitor(RVGenerator):
super().__init__(extra_params)
self.trace_h = self._read_template_file("trace.h")
+ def _is_id_monitor(self):
+ return False
+
def fill_trace_h(self):
trace_h = self.trace_h
monitor_class = self.fill_monitor_class()
+ macro_suffix = "_ID" if self._is_id_monitor() else ""
monitor_class_type = self.fill_monitor_class_type()
- tracepoint_args_skel_event = self.fill_tracepoint_args_skel("event")
- tracepoint_args_skel_error = self.fill_tracepoint_args_skel("error")
- tracepoint_args_skel_error_env = self.fill_tracepoint_args_skel("error_env")
trace_h = trace_h.replace("%%MODEL_NAME%%", self.name)
trace_h = trace_h.replace("%%MODEL_NAME_UP%%", self.name.upper())
trace_h = trace_h.replace("%%MONITOR_CLASS%%", monitor_class)
trace_h = trace_h.replace("%%MONITOR_CLASS_TYPE%%", monitor_class_type)
- trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_EVENT%%", tracepoint_args_skel_event)
- trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_ERROR%%", tracepoint_args_skel_error)
- trace_h = trace_h.replace("%%TRACEPOINT_ARGS_SKEL_ERROR_ENV%%", tracepoint_args_skel_error_env)
+ trace_h = trace_h.replace("%%MACRO_SUFFIX%%", macro_suffix)
return trace_h
def print_files(self):
diff --git a/tools/verification/rvgen/rvgen/templates/dot2k/trace.h b/tools/verification/rvgen/rvgen/templates/dot2k/trace.h
index 87d3a1308926..44ef49457bbe 100644
--- a/tools/verification/rvgen/rvgen/templates/dot2k/trace.h
+++ b/tools/verification/rvgen/rvgen/templates/dot2k/trace.h
@@ -5,9 +5,6 @@
*/
#ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%%
-DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%,
-%%TRACEPOINT_ARGS_SKEL_EVENT%%);
-
-DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%,
-%%TRACEPOINT_ARGS_SKEL_ERROR%%);
+DEFINE_DA_EVENT%%MACRO_SUFFIX%%(event_%%MODEL_NAME%%);
+DEFINE_DA_ERROR%%MACRO_SUFFIX%%(error_%%MODEL_NAME%%);
#endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */
diff --git a/tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h b/tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h
index c8290e9ba2f4..6b49529bc0e5 100644
--- a/tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h
+++ b/tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h
@@ -5,12 +5,7 @@
*/
#ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%%
-DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%,
-%%TRACEPOINT_ARGS_SKEL_EVENT%%);
-
-DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%,
-%%TRACEPOINT_ARGS_SKEL_ERROR%%);
-
-DEFINE_EVENT(error_env_%%MONITOR_CLASS%%, error_env_%%MODEL_NAME%%,
-%%TRACEPOINT_ARGS_SKEL_ERROR_ENV%%);
+DEFINE_DA_EVENT%%MACRO_SUFFIX%%(event_%%MODEL_NAME%%);
+DEFINE_DA_ERROR%%MACRO_SUFFIX%%(error_%%MODEL_NAME%%);
+DEFINE_HA_ERROR_ENV%%MACRO_SUFFIX%%(error_env_%%MODEL_NAME%%);
#endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */
diff --git a/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h b/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h
index 49394c4b0f1c..47266a383ac9 100644
--- a/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h
+++ b/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%%
-DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_%%MODEL_NAME%%);
+DEFINE_LTL_ERROR_ID(error_%%MODEL_NAME%%);
#endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */
diff --git a/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h b/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h
index 4d2730b71dd0..4be02dfaed97 100644
--- a/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h
+++ b/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_DA_GLOBAL
-DEFINE_EVENT(event_da_monitor, event_da_global,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_da_global,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_da_global);
+DEFINE_DA_ERROR(error_da_global);
#endif /* CONFIG_RV_MON_DA_GLOBAL */
diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h
index 59bfca8f73d2..6e99897f51d1 100644
--- a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h
+++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_DA_PEROBJ_PARENT
-DEFINE_EVENT(event_da_monitor_id, event_da_perobj_parent,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_da_perobj_parent,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_da_perobj_parent);
+DEFINE_DA_ERROR_ID(error_da_perobj_parent);
#endif /* CONFIG_RV_MON_DA_PEROBJ_PARENT */
diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h
index 4e6086c4d86e..2198f0626fb5 100644
--- a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h
+++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_DA_PERTASK_DESC
-DEFINE_EVENT(event_da_monitor_id, event_da_pertask_desc,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_da_pertask_desc,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
+DEFINE_DA_EVENT_ID(event_da_pertask_desc);
+DEFINE_DA_ERROR_ID(error_da_pertask_desc);
#endif /* CONFIG_RV_MON_DA_PERTASK_DESC */
diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h
index 074ddff6a60d..374c5daa9c30 100644
--- a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h
+++ b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_HA_PERCPU
-DEFINE_EVENT(event_da_monitor, event_ha_percpu,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_ha_percpu,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
-
-DEFINE_EVENT(error_env_da_monitor, error_env_ha_percpu,
- TP_PROTO(char *state, char *event, char *env),
- TP_ARGS(state, event, env));
+DEFINE_DA_EVENT(event_ha_percpu);
+DEFINE_DA_ERROR(error_ha_percpu);
+DEFINE_HA_ERROR_ENV(error_env_ha_percpu);
#endif /* CONFIG_RV_MON_HA_PERCPU */
diff --git a/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h
index ebd53621a5b1..34eb6cda2026 100644
--- a/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h
+++ b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_LTL_PERTASK
-DEFINE_EVENT(event_ltl_monitor_id, event_ltl_pertask,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_ltl_pertask,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_ltl_pertask);
+DEFINE_LTL_ERROR_ID(error_ltl_pertask);
#endif /* CONFIG_RV_MON_LTL_PERTASK */
diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_trace.h b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_trace.h
index b984208838c4..580de388f415 100644
--- a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_TEST_BAK_KUNIT
-DEFINE_EVENT(event_ltl_monitor_id, event_test_bak_kunit,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_test_bak_kunit,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_test_bak_kunit);
+DEFINE_LTL_ERROR_ID(error_test_bak_kunit);
#endif /* CONFIG_RV_MON_TEST_BAK_KUNIT */
diff --git a/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h b/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h
index 8bd67115d244..77107e1033ac 100644
--- a/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_TEST_DA
-DEFINE_EVENT(event_da_monitor, event_test_da,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_test_da,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_test_da);
+DEFINE_DA_ERROR(error_test_da);
#endif /* CONFIG_RV_MON_TEST_DA */
diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_trace.h b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_trace.h
index 16804a79e834..8ef5c32e9224 100644
--- a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_trace.h
@@ -5,11 +5,6 @@
*/
#ifdef CONFIG_RV_MON_TEST_DA_KUNIT
-DEFINE_EVENT(event_da_monitor, event_test_da_kunit,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor, error_test_da_kunit,
- TP_PROTO(char *state, char *event),
- TP_ARGS(state, event));
+DEFINE_DA_EVENT(event_test_da_kunit);
+DEFINE_DA_ERROR(error_test_da_kunit);
#endif /* CONFIG_RV_MON_TEST_DA_KUNIT */
diff --git a/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h b/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h
index 381bafcb3322..77623246b4b6 100644
--- a/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_TEST_HA
-DEFINE_EVENT(event_da_monitor_id, event_test_ha,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_test_ha,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
-
-DEFINE_EVENT(error_env_da_monitor_id, error_env_test_ha,
- TP_PROTO(int id, char *state, char *event, char *env),
- TP_ARGS(id, state, event, env));
+DEFINE_DA_EVENT_ID(event_test_ha);
+DEFINE_DA_ERROR_ID(error_test_ha);
+DEFINE_HA_ERROR_ENV_ID(error_env_test_ha);
#endif /* CONFIG_RV_MON_TEST_HA */
diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_trace.h b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_trace.h
index 6c13ee0068d3..9de08745e46e 100644
--- a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_trace.h
@@ -5,15 +5,7 @@
*/
#ifdef CONFIG_RV_MON_TEST_HA_KUNIT
-DEFINE_EVENT(event_da_monitor_id, event_test_ha_kunit,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
- TP_ARGS(id, state, event, next_state, final_state));
-
-DEFINE_EVENT(error_da_monitor_id, error_test_ha_kunit,
- TP_PROTO(int id, char *state, char *event),
- TP_ARGS(id, state, event));
-
-DEFINE_EVENT(error_env_da_monitor_id, error_env_test_ha_kunit,
- TP_PROTO(int id, char *state, char *event, char *env),
- TP_ARGS(id, state, event, env));
+DEFINE_DA_EVENT_ID(event_test_ha_kunit);
+DEFINE_DA_ERROR_ID(error_test_ha_kunit);
+DEFINE_HA_ERROR_ENV_ID(error_env_test_ha_kunit);
#endif /* CONFIG_RV_MON_TEST_HA_KUNIT */
diff --git a/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h
index 3571b004c114..72609d3d5570 100644
--- a/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_TEST_LTL
-DEFINE_EVENT(event_ltl_monitor_id, event_test_ltl,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_test_ltl,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_test_ltl);
+DEFINE_LTL_ERROR_ID(error_test_ltl);
#endif /* CONFIG_RV_MON_TEST_LTL */
diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_trace.h b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_trace.h
index a054d5b2c0ea..039fd38dde9f 100644
--- a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_trace.h
+++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_trace.h
@@ -5,10 +5,6 @@
*/
#ifdef CONFIG_RV_MON_TEST_LTL_KUNIT
-DEFINE_EVENT(event_ltl_monitor_id, event_test_ltl_kunit,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
- TP_ARGS(task, states, atoms, next));
-DEFINE_EVENT(error_ltl_monitor_id, error_test_ltl_kunit,
- TP_PROTO(struct task_struct *task),
- TP_ARGS(task));
+DEFINE_LTL_EVENT_ID(event_test_ltl_kunit);
+DEFINE_LTL_ERROR_ID(error_test_ltl_kunit);
#endif /* CONFIG_RV_MON_TEST_LTL_KUNIT */
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 04/18] rv: Propagate const to model strings and tracepoints
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (2 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 03/18] rv: Add wrapper macros for monitor tracepoint definitions Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs Gabriele Monaco
` (13 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco, Masami Hiramatsu
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Functions like model_get_event_name() and model_get_state_name() are
shared with BPF monitors, however those programs don't play nice with
string pointers without fixed length and the event_name and state_name
arrays need to be defined differently. This gets the compiler to notice
those are const char and the above function discard the const qualifier.
Mark all monitor strings in headers as const and propagate the change to
all callers, including all tracepoints.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
include/rv/automata.h | 4 +-
include/rv/da_monitor.h | 12 +++---
include/rv/ha_monitor.h | 10 ++---
kernel/trace/rv/monitors/nomiss/nomiss.h | 6 +--
kernel/trace/rv/monitors/nrp/nrp.h | 4 +-
kernel/trace/rv/monitors/opid/opid.h | 6 +--
kernel/trace/rv/monitors/sco/sco.h | 4 +-
kernel/trace/rv/monitors/scpd/scpd.h | 4 +-
kernel/trace/rv/monitors/snep/snep.h | 4 +-
kernel/trace/rv/monitors/snroc/snroc.h | 4 +-
kernel/trace/rv/monitors/sssw/sssw.h | 4 +-
kernel/trace/rv/monitors/stall/stall.h | 6 +--
kernel/trace/rv/monitors/sts/sts.h | 4 +-
kernel/trace/rv/monitors/wip/wip.h | 4 +-
kernel/trace/rv/monitors/wwnr/wwnr.h | 4 +-
kernel/trace/rv/rv_reactors.c | 2 +-
kernel/trace/rv/rv_trace.h | 39 ++++++++++---------
tools/verification/rvgen/rvgen/dot2c.py | 6 +--
.../rvgen/tests/golden/da_global/da_global.h | 4 +-
.../da_perobj_parent/da_perobj_parent.h | 4 +-
.../golden/da_pertask_desc/da_pertask_desc.h | 4 +-
.../rvgen/tests/golden/ha_percpu/ha_percpu.h | 6 +--
.../rvgen/tests/golden/test_da/test_da.h | 4 +-
.../golden/test_da_kunit/test_da_kunit.h | 4 +-
.../rvgen/tests/golden/test_ha/test_ha.h | 6 +--
.../golden/test_ha_kunit/test_ha_kunit.h | 6 +--
26 files changed, 84 insertions(+), 81 deletions(-)
diff --git a/include/rv/automata.h b/include/rv/automata.h
index 4a4eb40cf09a..e4afd5ba1d06 100644
--- a/include/rv/automata.h
+++ b/include/rv/automata.h
@@ -22,7 +22,7 @@
/*
* model_get_state_name - return the (string) name of the given state
*/
-static char *model_get_state_name(enum states state)
+static const char *model_get_state_name(enum states state)
{
if ((state < 0) || (state >= STATE_MAX))
return "INVALID";
@@ -33,7 +33,7 @@ static char *model_get_state_name(enum states state)
/*
* model_get_event_name - return the (string) name of the given event
*/
-static char *model_get_event_name(enum events event)
+static const char *model_get_event_name(enum events event)
{
if ((event < 0) || (event >= EVENT_MAX))
return "INVALID";
diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h
index 6fc5ef8142ac..fc830c9f5046 100644
--- a/include/rv/da_monitor.h
+++ b/include/rv/da_monitor.h
@@ -633,8 +633,8 @@ static inline void da_monitor_destroy(void)
*/
static inline void da_trace_event(struct da_monitor *da_mon,
- char *curr_state, char *event,
- char *next_state, bool is_final,
+ const char *curr_state, const char *event,
+ const char *next_state, bool is_final,
da_id_type id)
{
CONCATENATE(trace_event_, MONITOR_NAME)(curr_state, event, next_state,
@@ -642,7 +642,7 @@ static inline void da_trace_event(struct da_monitor *da_mon,
}
static inline void da_trace_error(struct da_monitor *da_mon,
- char *curr_state, char *event,
+ const char *curr_state, const char *event,
da_id_type id)
{
CONCATENATE(trace_error_, MONITOR_NAME)(curr_state, event);
@@ -662,8 +662,8 @@ static inline da_id_type da_get_id(struct da_monitor *da_mon)
*/
static inline void da_trace_event(struct da_monitor *da_mon,
- char *curr_state, char *event,
- char *next_state, bool is_final,
+ const char *curr_state, const char *event,
+ const char *next_state, bool is_final,
da_id_type id)
{
CONCATENATE(trace_event_, MONITOR_NAME)(id, curr_state, event,
@@ -671,7 +671,7 @@ static inline void da_trace_event(struct da_monitor *da_mon,
}
static inline void da_trace_error(struct da_monitor *da_mon,
- char *curr_state, char *event,
+ const char *curr_state, const char *event,
da_id_type id)
{
CONCATENATE(trace_error_, MONITOR_NAME)(id, curr_state, event);
diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h
index 6e1c7fe5449a..0952a3f161c3 100644
--- a/include/rv/ha_monitor.h
+++ b/include/rv/ha_monitor.h
@@ -87,7 +87,7 @@ _Static_assert(offsetof(struct ha_monitor, da_mon) == 0,
* environment constraint is false. This function can be called also with no
* event from a timer (state constraints only).
*/
-static void ha_react(enum states curr_state, enum events event, char *env)
+static void ha_react(enum states curr_state, enum events event, const char *env)
{
rv_react(&rv_this,
"rv: monitor %s does not allow event %s on state %s with env %s\n",
@@ -98,13 +98,13 @@ static void ha_react(enum states curr_state, enum events event, char *env)
#else /* CONFIG_RV_REACTOR */
-static void ha_react(enum states curr_state, enum events event, char *env) { }
+static void ha_react(enum states curr_state, enum events event, const char *env) { }
#endif
/*
* model_get_state_name - return the (string) name of the given state
*/
-static char *model_get_env_name(enum envs env)
+static const char *model_get_env_name(enum envs env)
{
if ((env < 0) || (env >= ENV_MAX))
return "INVALID";
@@ -227,7 +227,7 @@ static inline void ha_get_env_string(struct seq_buf *s,
#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
static inline void ha_trace_error_env(struct ha_monitor *ha_mon,
- char *curr_state, char *event, char *env,
+ const char *curr_state, const char *event, const char *env,
da_id_type id)
{
CONCATENATE(trace_error_env_, MONITOR_NAME)(curr_state, event, env);
@@ -237,7 +237,7 @@ static inline void ha_trace_error_env(struct ha_monitor *ha_mon,
#define ha_get_target(ha_mon) da_get_target(&ha_mon->da_mon)
static inline void ha_trace_error_env(struct ha_monitor *ha_mon,
- char *curr_state, char *event, char *env,
+ const char *curr_state, const char *event, const char *env,
da_id_type id)
{
CONCATENATE(trace_error_env_, MONITOR_NAME)(id, curr_state, event, env);
diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.h b/kernel/trace/rv/monitors/nomiss/nomiss.h
index 3d1b436194d7..0e74a27bc38c 100644
--- a/kernel/trace/rv/monitors/nomiss/nomiss.h
+++ b/kernel/trace/rv/monitors/nomiss/nomiss.h
@@ -41,9 +41,9 @@ _Static_assert(env_max_stored_nomiss <= MAX_HA_ENV_LEN, "Not enough slots");
#define HA_CLK_NS
struct automaton_nomiss {
- char *state_names[state_max_nomiss];
- char *event_names[event_max_nomiss];
- char *env_names[env_max_nomiss];
+ const char *state_names[state_max_nomiss];
+ const char *event_names[event_max_nomiss];
+ const char *env_names[env_max_nomiss];
unsigned char function[state_max_nomiss][event_max_nomiss];
unsigned char initial_state;
bool final_states[state_max_nomiss];
diff --git a/kernel/trace/rv/monitors/nrp/nrp.h b/kernel/trace/rv/monitors/nrp/nrp.h
index 3270d4c0139f..f6c1ec62233d 100644
--- a/kernel/trace/rv/monitors/nrp/nrp.h
+++ b/kernel/trace/rv/monitors/nrp/nrp.h
@@ -26,8 +26,8 @@ enum events_nrp {
};
struct automaton_nrp {
- char *state_names[state_max_nrp];
- char *event_names[event_max_nrp];
+ const char *state_names[state_max_nrp];
+ const char *event_names[event_max_nrp];
unsigned char function[state_max_nrp][event_max_nrp];
unsigned char initial_state;
bool final_states[state_max_nrp];
diff --git a/kernel/trace/rv/monitors/opid/opid.h b/kernel/trace/rv/monitors/opid/opid.h
index fb0aa4c28aa6..42680aa81f33 100644
--- a/kernel/trace/rv/monitors/opid/opid.h
+++ b/kernel/trace/rv/monitors/opid/opid.h
@@ -30,9 +30,9 @@ enum envs_opid {
_Static_assert(env_max_stored_opid <= MAX_HA_ENV_LEN, "Not enough slots");
struct automaton_opid {
- char *state_names[state_max_opid];
- char *event_names[event_max_opid];
- char *env_names[env_max_opid];
+ const char *state_names[state_max_opid];
+ const char *event_names[event_max_opid];
+ const char *env_names[env_max_opid];
unsigned char function[state_max_opid][event_max_opid];
unsigned char initial_state;
bool final_states[state_max_opid];
diff --git a/kernel/trace/rv/monitors/sco/sco.h b/kernel/trace/rv/monitors/sco/sco.h
index bac3beb51e72..65bcfcb136b7 100644
--- a/kernel/trace/rv/monitors/sco/sco.h
+++ b/kernel/trace/rv/monitors/sco/sco.h
@@ -23,8 +23,8 @@ enum events_sco {
};
struct automaton_sco {
- char *state_names[state_max_sco];
- char *event_names[event_max_sco];
+ const char *state_names[state_max_sco];
+ const char *event_names[event_max_sco];
unsigned char function[state_max_sco][event_max_sco];
unsigned char initial_state;
bool final_states[state_max_sco];
diff --git a/kernel/trace/rv/monitors/scpd/scpd.h b/kernel/trace/rv/monitors/scpd/scpd.h
index d6329da2671b..e9742c2789f7 100644
--- a/kernel/trace/rv/monitors/scpd/scpd.h
+++ b/kernel/trace/rv/monitors/scpd/scpd.h
@@ -24,8 +24,8 @@ enum events_scpd {
};
struct automaton_scpd {
- char *state_names[state_max_scpd];
- char *event_names[event_max_scpd];
+ const char *state_names[state_max_scpd];
+ const char *event_names[event_max_scpd];
unsigned char function[state_max_scpd][event_max_scpd];
unsigned char initial_state;
bool final_states[state_max_scpd];
diff --git a/kernel/trace/rv/monitors/snep/snep.h b/kernel/trace/rv/monitors/snep/snep.h
index 357520a5b3d1..fabc363684d2 100644
--- a/kernel/trace/rv/monitors/snep/snep.h
+++ b/kernel/trace/rv/monitors/snep/snep.h
@@ -24,8 +24,8 @@ enum events_snep {
};
struct automaton_snep {
- char *state_names[state_max_snep];
- char *event_names[event_max_snep];
+ const char *state_names[state_max_snep];
+ const char *event_names[event_max_snep];
unsigned char function[state_max_snep][event_max_snep];
unsigned char initial_state;
bool final_states[state_max_snep];
diff --git a/kernel/trace/rv/monitors/snroc/snroc.h b/kernel/trace/rv/monitors/snroc/snroc.h
index 88b7328ad31a..12aa743e4f19 100644
--- a/kernel/trace/rv/monitors/snroc/snroc.h
+++ b/kernel/trace/rv/monitors/snroc/snroc.h
@@ -23,8 +23,8 @@ enum events_snroc {
};
struct automaton_snroc {
- char *state_names[state_max_snroc];
- char *event_names[event_max_snroc];
+ const char *state_names[state_max_snroc];
+ const char *event_names[event_max_snroc];
unsigned char function[state_max_snroc][event_max_snroc];
unsigned char initial_state;
bool final_states[state_max_snroc];
diff --git a/kernel/trace/rv/monitors/sssw/sssw.h b/kernel/trace/rv/monitors/sssw/sssw.h
index 1a4b806061c3..ad8d7a18c52d 100644
--- a/kernel/trace/rv/monitors/sssw/sssw.h
+++ b/kernel/trace/rv/monitors/sssw/sssw.h
@@ -31,8 +31,8 @@ enum events_sssw {
};
struct automaton_sssw {
- char *state_names[state_max_sssw];
- char *event_names[event_max_sssw];
+ const char *state_names[state_max_sssw];
+ const char *event_names[event_max_sssw];
unsigned char function[state_max_sssw][event_max_sssw];
unsigned char initial_state;
bool final_states[state_max_sssw];
diff --git a/kernel/trace/rv/monitors/stall/stall.h b/kernel/trace/rv/monitors/stall/stall.h
index 638520cb1082..ce38b6b2311e 100644
--- a/kernel/trace/rv/monitors/stall/stall.h
+++ b/kernel/trace/rv/monitors/stall/stall.h
@@ -33,9 +33,9 @@ enum envs_stall {
_Static_assert(env_max_stored_stall <= MAX_HA_ENV_LEN, "Not enough slots");
struct automaton_stall {
- char *state_names[state_max_stall];
- char *event_names[event_max_stall];
- char *env_names[env_max_stall];
+ const char *state_names[state_max_stall];
+ const char *event_names[event_max_stall];
+ const char *env_names[env_max_stall];
unsigned char function[state_max_stall][event_max_stall];
unsigned char initial_state;
bool final_states[state_max_stall];
diff --git a/kernel/trace/rv/monitors/sts/sts.h b/kernel/trace/rv/monitors/sts/sts.h
index 6f7b2d9d72e6..74397c37cb0e 100644
--- a/kernel/trace/rv/monitors/sts/sts.h
+++ b/kernel/trace/rv/monitors/sts/sts.h
@@ -31,8 +31,8 @@ enum events_sts {
};
struct automaton_sts {
- char *state_names[state_max_sts];
- char *event_names[event_max_sts];
+ const char *state_names[state_max_sts];
+ const char *event_names[event_max_sts];
unsigned char function[state_max_sts][event_max_sts];
unsigned char initial_state;
bool final_states[state_max_sts];
diff --git a/kernel/trace/rv/monitors/wip/wip.h b/kernel/trace/rv/monitors/wip/wip.h
index b4c3eea94c86..b65baeae5419 100644
--- a/kernel/trace/rv/monitors/wip/wip.h
+++ b/kernel/trace/rv/monitors/wip/wip.h
@@ -23,8 +23,8 @@ enum events_wip {
};
struct automaton_wip {
- char *state_names[state_max_wip];
- char *event_names[event_max_wip];
+ const char *state_names[state_max_wip];
+ const char *event_names[event_max_wip];
unsigned char function[state_max_wip][event_max_wip];
unsigned char initial_state;
bool final_states[state_max_wip];
diff --git a/kernel/trace/rv/monitors/wwnr/wwnr.h b/kernel/trace/rv/monitors/wwnr/wwnr.h
index a28006512c9b..06d724ac1182 100644
--- a/kernel/trace/rv/monitors/wwnr/wwnr.h
+++ b/kernel/trace/rv/monitors/wwnr/wwnr.h
@@ -23,8 +23,8 @@ enum events_wwnr {
};
struct automaton_wwnr {
- char *state_names[state_max_wwnr];
- char *event_names[event_max_wwnr];
+ const char *state_names[state_max_wwnr];
+ const char *event_names[event_max_wwnr];
unsigned char function[state_max_wwnr][event_max_wwnr];
unsigned char initial_state;
bool final_states[state_max_wwnr];
diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c
index 8e57a95d446b..8988b9ab2a40 100644
--- a/kernel/trace/rv/rv_reactors.c
+++ b/kernel/trace/rv/rv_reactors.c
@@ -71,7 +71,7 @@
*/
static LIST_HEAD(rv_reactors_list);
-static struct rv_reactor *get_reactor_rdef_by_name(char *name)
+static struct rv_reactor *get_reactor_rdef_by_name(const char *name)
{
struct rv_reactor *r;
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 36e7c78c046e..24d4b94a54a5 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -11,7 +11,8 @@
#ifdef CONFIG_DA_MON_EVENTS_IMPLICIT
DECLARE_EVENT_CLASS(event_da_monitor,
- TP_PROTO(char *state, char *event, char *next_state, bool final_state),
+ TP_PROTO(const char *state, const char *event,
+ const char *next_state, bool final_state),
TP_ARGS(state, event, next_state, final_state),
@@ -38,7 +39,7 @@ DECLARE_EVENT_CLASS(event_da_monitor,
DECLARE_EVENT_CLASS(error_da_monitor,
- TP_PROTO(char *state, char *event),
+ TP_PROTO(const char *state, const char *event),
TP_ARGS(state, event),
@@ -59,13 +60,13 @@ DECLARE_EVENT_CLASS(error_da_monitor,
#define DEFINE_DA_EVENT(name) \
DEFINE_EVENT(event_da_monitor, name, \
- TP_PROTO(char *state, char *event, \
- char *next_state, bool final_state), \
+ TP_PROTO(const char *state, const char *event, \
+ const char *next_state, bool final_state), \
TP_ARGS(state, event, next_state, final_state))
#define DEFINE_DA_ERROR(name) \
DEFINE_EVENT(error_da_monitor, name, \
- TP_PROTO(char *state, char *event), \
+ TP_PROTO(const char *state, const char *event), \
TP_ARGS(state, event))
#include <monitors/wip/wip_trace.h>
@@ -79,7 +80,7 @@ DECLARE_EVENT_CLASS(error_da_monitor,
/* For simplicity this class is marked as DA although relevant only for HA */
DECLARE_EVENT_CLASS(error_env_da_monitor,
- TP_PROTO(char *state, char *event, char *env),
+ TP_PROTO(const char *state, const char *event, const char *env),
TP_ARGS(state, event, env),
@@ -103,7 +104,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor,
#define DEFINE_HA_ERROR_ENV(name) \
DEFINE_EVENT(error_env_da_monitor, name, \
- TP_PROTO(char *state, char *event, char *env), \
+ TP_PROTO(const char *state, const char *event, const char *env), \
TP_ARGS(state, event, env))
#include <monitors/opid/opid_trace.h>
@@ -116,7 +117,8 @@ DECLARE_EVENT_CLASS(error_env_da_monitor,
#ifdef CONFIG_DA_MON_EVENTS_ID
DECLARE_EVENT_CLASS(event_da_monitor_id,
- TP_PROTO(int id, char *state, char *event, char *next_state, bool final_state),
+ TP_PROTO(int id, const char *state, const char *event,
+ const char *next_state, bool final_state),
TP_ARGS(id, state, event, next_state, final_state),
@@ -146,7 +148,7 @@ DECLARE_EVENT_CLASS(event_da_monitor_id,
DECLARE_EVENT_CLASS(error_da_monitor_id,
- TP_PROTO(int id, char *state, char *event),
+ TP_PROTO(int id, const char *state, const char *event),
TP_ARGS(id, state, event),
@@ -170,13 +172,13 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
#define DEFINE_DA_EVENT_ID(name) \
DEFINE_EVENT(event_da_monitor_id, name, \
- TP_PROTO(int id, char *state, char *event, \
- char *next_state, bool final_state), \
+ TP_PROTO(int id, const char *state, const char *event, \
+ const char *next_state, bool final_state), \
TP_ARGS(id, state, event, next_state, final_state))
#define DEFINE_DA_ERROR_ID(name) \
DEFINE_EVENT(error_da_monitor_id, name, \
- TP_PROTO(int id, char *state, char *event), \
+ TP_PROTO(int id, const char *state, const char *event), \
TP_ARGS(id, state, event))
#include <monitors/wwnr/wwnr_trace.h>
@@ -189,7 +191,7 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
/* For simplicity this class is marked as DA although relevant only for HA */
DECLARE_EVENT_CLASS(error_env_da_monitor_id,
- TP_PROTO(int id, char *state, char *event, char *env),
+ TP_PROTO(int id, const char *state, const char *event, const char *env),
TP_ARGS(id, state, event, env),
@@ -216,7 +218,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,
#define DEFINE_HA_ERROR_ENV_ID(name) \
DEFINE_EVENT(error_env_da_monitor_id, name, \
- TP_PROTO(int id, char *state, char *event, char *env), \
+ TP_PROTO(int id, const char *state, const char *event, const char *env), \
TP_ARGS(id, state, event, env))
#include <monitors/stall/stall_trace.h>
@@ -229,7 +231,8 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,
#ifdef CONFIG_LTL_MON_EVENTS_ID
DECLARE_EVENT_CLASS(event_ltl_monitor_id,
- TP_PROTO(struct task_struct *task, char *states, char *atoms, char *next),
+ TP_PROTO(struct task_struct *task, const char *states,
+ const char *atoms, const char *next),
TP_ARGS(task, states, atoms, next),
@@ -274,8 +277,8 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id,
#define DEFINE_LTL_EVENT_ID(name) \
DEFINE_EVENT(event_ltl_monitor_id, name, \
- TP_PROTO(struct task_struct *task, char *states, \
- char *atoms, char *next), \
+ TP_PROTO(struct task_struct *task, const char *states, \
+ const char *atoms, const char *next), \
TP_ARGS(task, states, atoms, next))
#define DEFINE_LTL_ERROR_ID(name) \
@@ -293,7 +296,7 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id,
/* Tracepoint useful for monitors development, currenly only used in DA */
TRACE_EVENT(rv_retries_error,
- TP_PROTO(char *name, char *event),
+ TP_PROTO(const char *name, const char *event),
TP_ARGS(name, event),
diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/rvgen/rvgen/dot2c.py
index 22938ce1bf6c..c6bd4d00d92e 100644
--- a/tools/verification/rvgen/rvgen/dot2c.py
+++ b/tools/verification/rvgen/rvgen/dot2c.py
@@ -111,10 +111,10 @@ class Dot2c(Automata):
min_type = self.get_minimun_type()
buff = []
buff.append(f"struct {self.struct_automaton_def} {{")
- buff.append(f"\tchar *state_names[state_max{self.enum_suffix}];")
- buff.append(f"\tchar *event_names[event_max{self.enum_suffix}];")
+ buff.append(f"\tconst char *state_names[state_max{self.enum_suffix}];")
+ buff.append(f"\tconst char *event_names[event_max{self.enum_suffix}];")
if self.is_hybrid_automata():
- buff.append(f"\tchar *env_names[env_max{self.enum_suffix}];")
+ buff.append(f"\tconst char *env_names[env_max{self.enum_suffix}];")
buff.append(f"\t{min_type} function[state_max{self.enum_suffix}][event_max{self.enum_suffix}];")
buff.append(f"\t{min_type} initial_state;")
buff.append(f"\tbool final_states[state_max{self.enum_suffix}];")
diff --git a/tools/verification/rvgen/tests/golden/da_global/da_global.h b/tools/verification/rvgen/tests/golden/da_global/da_global.h
index 40b1f1c0c681..3faf0c92b8b0 100644
--- a/tools/verification/rvgen/tests/golden/da_global/da_global.h
+++ b/tools/verification/rvgen/tests/golden/da_global/da_global.h
@@ -22,8 +22,8 @@ enum events_da_global {
};
struct automaton_da_global {
- char *state_names[state_max_da_global];
- char *event_names[event_max_da_global];
+ const char *state_names[state_max_da_global];
+ const char *event_names[event_max_da_global];
unsigned char function[state_max_da_global][event_max_da_global];
unsigned char initial_state;
bool final_states[state_max_da_global];
diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h
index 3c8dc3b22443..8027c4eec979 100644
--- a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h
+++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h
@@ -24,8 +24,8 @@ enum events_da_perobj_parent {
};
struct automaton_da_perobj_parent {
- char *state_names[state_max_da_perobj_parent];
- char *event_names[event_max_da_perobj_parent];
+ const char *state_names[state_max_da_perobj_parent];
+ const char *event_names[event_max_da_perobj_parent];
unsigned char function[state_max_da_perobj_parent][event_max_da_perobj_parent];
unsigned char initial_state;
bool final_states[state_max_da_perobj_parent];
diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h
index 837b238754b0..3e4501795f4a 100644
--- a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h
+++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h
@@ -24,8 +24,8 @@ enum events_da_pertask_desc {
};
struct automaton_da_pertask_desc {
- char *state_names[state_max_da_pertask_desc];
- char *event_names[event_max_da_pertask_desc];
+ const char *state_names[state_max_da_pertask_desc];
+ const char *event_names[event_max_da_pertask_desc];
unsigned char function[state_max_da_pertask_desc][event_max_da_pertask_desc];
unsigned char initial_state;
bool final_states[state_max_da_pertask_desc];
diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h
index 2538db4f6a26..ee8aa72d6d5a 100644
--- a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h
+++ b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h
@@ -36,9 +36,9 @@ _Static_assert(env_max_stored_ha_percpu <= MAX_HA_ENV_LEN, "Not enough slots");
#define HA_CLK_NS
struct automaton_ha_percpu {
- char *state_names[state_max_ha_percpu];
- char *event_names[event_max_ha_percpu];
- char *env_names[env_max_ha_percpu];
+ const char *state_names[state_max_ha_percpu];
+ const char *event_names[event_max_ha_percpu];
+ const char *env_names[env_max_ha_percpu];
unsigned char function[state_max_ha_percpu][event_max_ha_percpu];
unsigned char initial_state;
bool final_states[state_max_ha_percpu];
diff --git a/tools/verification/rvgen/tests/golden/test_da/test_da.h b/tools/verification/rvgen/tests/golden/test_da/test_da.h
index d55795efbb61..d4a230a1173d 100644
--- a/tools/verification/rvgen/tests/golden/test_da/test_da.h
+++ b/tools/verification/rvgen/tests/golden/test_da/test_da.h
@@ -22,8 +22,8 @@ enum events_test_da {
};
struct automaton_test_da {
- char *state_names[state_max_test_da];
- char *event_names[event_max_test_da];
+ const char *state_names[state_max_test_da];
+ const char *event_names[event_max_test_da];
unsigned char function[state_max_test_da][event_max_test_da];
unsigned char initial_state;
bool final_states[state_max_test_da];
diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h
index 290a9454caa4..ef98895fac1b 100644
--- a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h
+++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h
@@ -22,8 +22,8 @@ enum events_test_da_kunit {
};
struct automaton_test_da_kunit {
- char *state_names[state_max_test_da_kunit];
- char *event_names[event_max_test_da_kunit];
+ const char *state_names[state_max_test_da_kunit];
+ const char *event_names[event_max_test_da_kunit];
unsigned char function[state_max_test_da_kunit][event_max_test_da_kunit];
unsigned char initial_state;
bool final_states[state_max_test_da_kunit];
diff --git a/tools/verification/rvgen/tests/golden/test_ha/test_ha.h b/tools/verification/rvgen/tests/golden/test_ha/test_ha.h
index 949fa4453403..eb90c0600a69 100644
--- a/tools/verification/rvgen/tests/golden/test_ha/test_ha.h
+++ b/tools/verification/rvgen/tests/golden/test_ha/test_ha.h
@@ -36,9 +36,9 @@ _Static_assert(env_max_stored_test_ha <= MAX_HA_ENV_LEN, "Not enough slots");
#define HA_CLK_NS
struct automaton_test_ha {
- char *state_names[state_max_test_ha];
- char *event_names[event_max_test_ha];
- char *env_names[env_max_test_ha];
+ const char *state_names[state_max_test_ha];
+ const char *event_names[event_max_test_ha];
+ const char *env_names[env_max_test_ha];
unsigned char function[state_max_test_ha][event_max_test_ha];
unsigned char initial_state;
bool final_states[state_max_test_ha];
diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h
index 5c428f818bdf..153533e5d47a 100644
--- a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h
+++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h
@@ -36,9 +36,9 @@ _Static_assert(env_max_stored_test_ha_kunit <= MAX_HA_ENV_LEN, "Not enough slots
#define HA_CLK_NS
struct automaton_test_ha_kunit {
- char *state_names[state_max_test_ha_kunit];
- char *event_names[event_max_test_ha_kunit];
- char *env_names[env_max_test_ha_kunit];
+ const char *state_names[state_max_test_ha_kunit];
+ const char *event_names[event_max_test_ha_kunit];
+ const char *env_names[env_max_test_ha_kunit];
unsigned char function[state_max_test_ha_kunit][event_max_test_ha_kunit];
unsigned char initial_state;
bool final_states[state_max_test_ha_kunit];
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (3 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 04/18] rv: Propagate const to model strings and tracepoints Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 22:09 ` kernel test robot
2026-11-26 12:59 ` [PATCH v3 06/18] tools/build: Add a feature test for bpftool-btf Gabriele Monaco
` (12 subsequent siblings)
17 siblings, 1 reply; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco, Masami Hiramatsu
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add event_monitor and error_monitor tracepoints, carrying a monitor
name and a single formatted message. These tracepoints aim to replace
the per-monitor tracepoints for a set of monitors (now BPF only) and are
generic enough to allow reporting from different monitor classes.
Add also bpf_rv_event_monitor() / bpf_rv_error_monitor() kfuncs wrapping
them, so BPF monitors can emit similar events to in-kernel monitors.
Userspace callers need now to use ftrace filters to get the right events
but events and errors are separate channels to ease the most common
filtering and account for dramatically different volume (errors are
rare).
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
kernel/trace/rv/Makefile | 1 +
kernel/trace/rv/rv_bpf.c | 76 ++++++++++++++++++++++++++++++++++++++
kernel/trace/rv/rv_trace.h | 37 +++++++++++++++++++
3 files changed, 114 insertions(+)
create mode 100644 kernel/trace/rv/rv_bpf.c
diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
index c895d81dfdad..588250ce3fa9 100644
--- a/kernel/trace/rv/Makefile
+++ b/kernel/trace/rv/Makefile
@@ -3,6 +3,7 @@
ccflags-y += -I $(src) # needed for trace events
obj-$(CONFIG_RV) += rv.o
+obj-$(CONFIG_RV) += rv_bpf.o
obj-$(CONFIG_RV_MON_WIP) += monitors/wip/wip.o
obj-$(CONFIG_RV_MON_WWNR) += monitors/wwnr/wwnr.o
obj-$(CONFIG_RV_MON_SCHED) += monitors/sched/sched.o
diff --git a/kernel/trace/rv/rv_bpf.c b/kernel/trace/rv/rv_bpf.c
new file mode 100644
index 000000000000..f39f33335c71
--- /dev/null
+++ b/kernel/trace/rv/rv_bpf.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * BPF kfuncs for Runtime Verification (RV)
+ */
+
+#include <linux/init.h>
+#include <linux/bpf.h>
+#include <linux/btf.h>
+#include <linux/btf_ids.h>
+#include <rv_trace.h>
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_rv_event_monitor - emit an RV monitor event tracepoint
+ *
+ * @msg must be NULL-terminated, drop the event if it isn't. This happens by
+ * construction if using snprintf-like functions and passing the right @msg__sz
+ * to both.
+ *
+ * @mon__str: name of the monitor
+ * @msg: message string
+ * @msg__sz: message string size
+ *
+ * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
+ */
+__bpf_kfunc int bpf_rv_event_monitor(const char *mon__str, const int *id__nullable,
+ const char *msg, u32 msg__sz)
+{
+ if (strnlen(msg, msg__sz) == msg__sz)
+ return -EINVAL;
+
+ trace_event_monitor(mon__str, id__nullable, msg);
+ return 0;
+}
+
+/**
+ * bpf_rv_error_monitor - emit an RV monitor error tracepoint
+ *
+ * @msg must be NULL-terminated, drop the event if it isn't. This happens by
+ * construction if using snprintf-like functions and passing the right @msg__sz
+ * to both.
+ *
+ * @mon__str: name of the monitor
+ * @msg: message string
+ * @msg__sz: message string size
+ *
+ * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
+ */
+__bpf_kfunc int bpf_rv_error_monitor(const char *mon__str, const int *id__nullable,
+ const char *msg, u32 msg__sz)
+{
+ if (strnlen(msg, msg__sz) == msg__sz)
+ return -EINVAL;
+
+ trace_error_monitor(mon__str, id__nullable, msg);
+ return 0;
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(bpf_rv_kfunc_ids)
+BTF_ID_FLAGS(func, bpf_rv_event_monitor)
+BTF_ID_FLAGS(func, bpf_rv_error_monitor)
+BTF_KFUNCS_END(bpf_rv_kfunc_ids)
+
+static const struct btf_kfunc_id_set bpf_rv_kfunc_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_rv_kfunc_ids,
+};
+
+static int __init bpf_rv_kfunc_init(void)
+{
+ return register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_rv_kfunc_set);
+}
+late_initcall(bpf_rv_kfunc_init);
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 24d4b94a54a5..9fa9e1230e84 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -292,6 +292,43 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id,
// Add new monitors based on CONFIG_LTL_MON_EVENTS_ID here
#endif /* CONFIG_LTL_MON_EVENTS_ID */
+DECLARE_EVENT_CLASS(event_template_monitor,
+
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+
+ TP_ARGS(mon, id, msg),
+
+ TP_STRUCT__entry(
+ __string( mon, mon )
+ __field( u8, has_id )
+ __field( int, id )
+ __string( msg, msg )
+ ),
+
+ TP_fast_assign(
+ __assign_str(mon);
+ __entry->has_id = !!id;
+ __entry->id = id ? *id : 0;
+ __assign_str(msg);
+ ),
+
+ /*
+ * The id is used only for filters, if it is of interest in the format,
+ * callers should pass it to the msg too.
+ */
+ TP_printk("%s: %s",
+ __get_str(mon),
+ __get_str(msg))
+);
+
+DEFINE_EVENT(event_template_monitor, event_monitor,
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+ TP_ARGS(mon, id, msg));
+
+DEFINE_EVENT(event_template_monitor, error_monitor,
+ TP_PROTO(const char *mon, const int *id, const char *msg),
+ TP_ARGS(mon, id, msg));
+
#ifdef CONFIG_RV_MON_MAINTENANCE_EVENTS
/* Tracepoint useful for monitors development, currenly only used in DA */
TRACE_EVENT(rv_retries_error,
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
2026-11-26 12:59 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs Gabriele Monaco
@ 2026-11-26 22:09 ` kernel test robot
0 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2026-11-26 22:09 UTC (permalink / raw)
To: Gabriele Monaco, linux-kernel, linux-trace-kernel, bpf,
Steven Rostedt, Masami Hiramatsu
Cc: oe-kbuild-all, Alexei Starovoitov, Nam Cao, Wen Yang,
Tobias Schaffner, Viktor Malik, Peter Zijlstra, John Ogness
Hi Gabriele,
kernel test robot noticed the following build warnings:
[auto build test WARNING on b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f]
url: https://github.com/intel-lab-lkp/linux/commits/Gabriele-Monaco/sched-Add-task-enqueue-dequeue-trace-points/20261126-135947
base: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
patch link: https://lore.kernel.org/r/20261126130004.127155-6-gmonaco%40redhat.com
patch subject: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
config: loongarch-randconfig-1000-20261127 (https://download.01.org/0day-ci/archive/20261127/20261127053433.PIs3CD9x-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261127/20261127053433.PIs3CD9x-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261127053433.PIs3CD9x-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> Warning: kernel/trace/rv/rv_bpf.c:28 function parameter 'id__nullable' not described in 'bpf_rv_event_monitor'
>> Warning: kernel/trace/rv/rv_bpf.c:51 function parameter 'id__nullable' not described in 'bpf_rv_error_monitor'
>> Warning: kernel/trace/rv/rv_bpf.c:28 function parameter 'id__nullable' not described in 'bpf_rv_event_monitor'
>> Warning: kernel/trace/rv/rv_bpf.c:51 function parameter 'id__nullable' not described in 'bpf_rv_error_monitor'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 06/18] tools/build: Add a feature test for bpftool-btf
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (4 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 07/18] tools/rv: Move argument parsing from in_kernel to utils Gabriele Monaco
` (11 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf
Cc: Gabriele Monaco, Steven Rostedt, Alexei Starovoitov, Nam Cao,
Wen Yang, Tobias Schaffner, Viktor Malik, Peter Zijlstra,
John Ogness
RV can run bpf monitors and also build them, only the latter requires
the vmlinux.h from bpftool btf.
Add a feature so that RV can be built with BPF support without having to
build in-tree BPF monitors if not supported on the system.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/build/Makefile.feature | 1 +
tools/build/feature/Makefile | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index c010049d9720..79e08fc62bb5 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -129,6 +129,7 @@ FEATURE_TESTS_EXTRA := \
libdebuginfod \
clang-bpf-co-re \
bpftool-skeletons \
+ bpftool-btf \
libunwind \
libunwind-debug-frame \
$(foreach arch,$(LIBUNWIND_ARCHS),libunwind-$(arch) libunwind-debug-frame-$(arch))
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 359da8b98bc5..e021846fb662 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -71,7 +71,8 @@ FILES= \
test-libpfm4.bin \
test-rust.bin \
test-libopenssl.bin \
- test-bpftool-skeletons.bin
+ test-bpftool-skeletons.bin \
+ test-bpftool-btf.bin
FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -370,6 +371,10 @@ $(OUTPUT)test-bpftool-skeletons.bin:
{ $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons'; } \
> $(@:.bin=.make.output) 2>&1 && touch $@
+$(OUTPUT)test-bpftool-btf.bin:
+ $(SYSTEM_BPFTOOL) btf help \
+ > $(@:.bin=.make.output) 2>&1 && touch $@
+
# Testing Rust is special: we don't compile anything, it's enough to check the
# compiler presence. Compiling a test code for this purposes is problematic,
# because Rust will emit a dependency file without any external references,
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 07/18] tools/rv: Move argument parsing from in_kernel to utils
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (5 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 06/18] tools/build: Add a feature test for bpftool-btf Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 08/18] tools/rv: Move monitor trace handling to trace.c Gabriele Monaco
` (10 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
The configuration of the in-kernel RV monitor is relying on global
variables, some static and some extern and the argument parsing occurs
there. That's not scalable especially if the configuration needs to be
shared by other monitor implementations (e.g. BPF).
Move the common argument parsing in utils and use a global struct for
the configuration. Implementation-specific configuration such as the
reactors are still handled in the in-kernel source.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/include/utils.h | 17 ++-
tools/verification/rv/src/in_kernel.c | 176 ++++++--------------------
tools/verification/rv/src/utils.c | 95 +++++++++++++-
3 files changed, 149 insertions(+), 139 deletions(-)
diff --git a/tools/verification/rv/include/utils.h b/tools/verification/rv/include/utils.h
index f24ae8282bd2..61f77a72a1a2 100644
--- a/tools/verification/rv/include/utils.h
+++ b/tools/verification/rv/include/utils.h
@@ -1,8 +1,23 @@
// SPDX-License-Identifier: GPL-2.0
+#include <stdbool.h>
+
#define MAX_PATH 1024
void debug_msg(const char *fmt, ...);
void err_msg(const char *fmt, ...);
+void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...);
+int parse_arguments(char *monitor_name, int argc, char **argv);
+
+void ikm_usage_print_reactors(void);
-extern int config_debug;
+struct config {
+ bool debug;
+ bool is_container;
+ bool trace;
+ int has_id;
+ int my_pid;
+ char *initial_reactor;
+ char *reactor;
+};
+extern struct config config;
diff --git a/tools/verification/rv/src/in_kernel.c b/tools/verification/rv/src/in_kernel.c
index e6dea4040f8f..90c340a73c76 100644
--- a/tools/verification/rv/src/in_kernel.c
+++ b/tools/verification/rv/src/in_kernel.c
@@ -4,7 +4,6 @@
*
* Copyright (C) 2022 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
*/
-#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -16,14 +15,6 @@
#include <utils.h>
#include <rv.h>
-static int config_has_id;
-static int config_is_container;
-static int config_my_pid;
-static int config_trace;
-
-static char *config_initial_reactor;
-static char *config_reactor;
-
/*
* __ikm_read_enable - reads monitor's enable status
*
@@ -66,7 +57,7 @@ static int __ikm_find_monitor_name(char *monitor_name, char *out_name)
if (!available_monitors)
return -1;
- config_is_container = 0;
+ config.is_container = 0;
cursor = available_monitors;
while ((line = strsep(&cursor, "\n"))) {
char *colon = strchr(line, ':');
@@ -83,7 +74,7 @@ static int __ikm_find_monitor_name(char *monitor_name, char *out_name)
/* If there are children, they are on the next line. */
line = strsep(&cursor, "\n");
if (line && !strncmp(line, monitor_name, len) && line[len] == ':')
- config_is_container = 1;
+ config.is_container = 1;
}
found = 1;
@@ -391,7 +382,7 @@ int ikm_list_monitors(char *container)
static void ikm_print_header(struct trace_seq *s)
{
trace_seq_printf(s, "%16s-%-8s %5s %5s ", "<TASK>", "PID", "[CPU]", "TYPE");
- if (config_has_id)
+ if (config.has_id)
trace_seq_printf(s, "%8s ", "ID");
trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
@@ -402,7 +393,7 @@ static void ikm_print_header(struct trace_seq *s)
trace_seq_printf(s, "%16s %-8s %5s %5s ", " | ", " | ", " | ", " | ");
- if (config_has_id)
+ if (config.has_id)
trace_seq_printf(s, "%8s ", " | ");
trace_seq_printf(s, "%24s %-24s %-24s %s\n",
@@ -431,25 +422,25 @@ ikm_event_handler(struct trace_seq *s, struct tep_record *record,
int val;
bool missing_id;
- if (config_has_id)
+ if (config.has_id)
missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
- if (config_has_id && (config_my_pid == id))
+ if (config.has_id && (config.my_pid == id))
return 0;
- else if (config_my_pid == pid)
+ else if (config.my_pid == pid)
return 0;
tep_print_event(trace_event->tep, s, record, "%16s-%-8d [%.3d] ",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU);
- if (config_is_container)
+ if (config.is_container)
tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
else
trace_seq_printf(s, "event ");
- if (config_has_id) {
+ if (config.has_id) {
if (missing_id)
/* placeholder if we are dealing with a mixed-type container*/
trace_seq_printf(s, " ");
@@ -490,24 +481,24 @@ ikm_error_handler(struct trace_seq *s, struct tep_record *record,
int val;
bool missing_id;
- if (config_has_id)
+ if (config.has_id)
missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
- if (config_has_id && config_my_pid == id)
+ if (config.has_id && config.my_pid == id)
return 0;
- else if (config_my_pid == pid)
+ else if (config.my_pid == pid)
return 0;
trace_seq_printf(s, "%8lld [%03d] ", pid, cpu);
- if (config_is_container)
+ if (config.is_container)
tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
else
trace_seq_printf(s, "error ");
- if (config_has_id) {
+ if (config.has_id) {
if (missing_id)
/* placeholder if we are dealing with a mixed-type container*/
trace_seq_printf(s, " ");
@@ -548,8 +539,8 @@ static int ikm_enable_trace_events(char *monitor_name, struct trace_instance *in
ikm_error_handler, NULL);
/* set if at least 1 monitor has id in case of a container */
- config_has_id = ikm_has_id(monitor_name);
- if (config_has_id < 0)
+ config.has_id = ikm_has_id(monitor_name);
+ if (config.has_id < 0)
return -1;
@@ -596,7 +587,7 @@ static struct trace_instance *ikm_setup_trace_instance(char *monitor_name)
struct trace_instance *inst;
int retval;
- if (!config_trace)
+ if (!config.trace)
return NULL;
/* alloc data */
@@ -610,7 +601,7 @@ static struct trace_instance *ikm_setup_trace_instance(char *monitor_name)
if (retval)
goto out_free;
- if (config_is_container)
+ if (config.is_container)
retval = ikm_enable_trace_container(monitor_name, inst);
else
retval = ikm_enable_trace_events(monitor_name, inst);
@@ -645,7 +636,7 @@ static void ikm_destroy_trace_instance(struct trace_instance *inst)
/*
* ikm_usage_print_reactors - print all available reactors, one per line.
*/
-static void ikm_usage_print_reactors(void)
+void ikm_usage_print_reactors(void)
{
char *reactors = tracefs_instance_file_read(NULL, "rv/available_reactors", NULL);
char *start, *end;
@@ -669,106 +660,6 @@ static void ikm_usage_print_reactors(void)
fprintf(stderr, "\n");
}
-/*
- * ikm_usage - print usage
- */
-static void ikm_usage(int exit_val, char *monitor_name, const char *fmt, ...)
-{
-
- char message[1024];
- va_list ap;
- int i;
-
- static const char *const usage[] = {
- "",
- " -h/--help: print this menu and the reactor list",
- " -r/--reactor 'reactor': enables the 'reactor'",
- " -s/--self: when tracing (-t), also trace rv command",
- " -t/--trace: trace monitor's event",
- " -v/--verbose: print debug messages",
- "",
- NULL,
- };
-
- va_start(ap, fmt);
- vsnprintf(message, sizeof(message), fmt, ap);
- va_end(ap);
-
- fprintf(stderr, " %s\n", message);
-
- fprintf(stderr, "\n usage: rv mon %s [-h] [-q] [-r reactor] [-s] [-v]", monitor_name);
-
- for (i = 0; usage[i]; i++)
- fprintf(stderr, "%s\n", usage[i]);
-
- ikm_usage_print_reactors();
- exit(exit_val);
-}
-
-/*
- * parse_arguments - parse arguments and set config
- */
-static int parse_arguments(char *monitor_name, int argc, char **argv)
-{
- int c, retval;
-
- config_my_pid = getpid();
-
- while (1) {
- static struct option long_options[] = {
- {"help", no_argument, 0, 'h'},
- {"reactor", required_argument, 0, 'r'},
- {"self", no_argument, 0, 's'},
- {"trace", no_argument, 0, 't'},
- {"verbose", no_argument, 0, 'v'},
- {0, 0, 0, 0}
- };
-
- /* getopt_long stores the option index here. */
- int option_index = 0;
-
- c = getopt_long(argc, argv, "hr:stv", long_options, &option_index);
-
- /* detect the end of the options. */
- if (c == -1)
- break;
-
- switch (c) {
- case 'h':
- ikm_usage(0, monitor_name, "help:");
- break;
- case 'r':
- config_reactor = optarg;
- break;
- case 's':
- config_my_pid = -1;
- break;
- case 't':
- config_trace = 1;
- break;
- case 'v':
- config_debug = 1;
- break;
- }
- }
-
- if (config_reactor) {
- config_initial_reactor = ikm_get_current_reactor(monitor_name);
- if (!config_initial_reactor)
- ikm_usage(1, monitor_name,
- "ikm: failed to read current reactor, are reactors enabled?");
-
- retval = ikm_write_reactor(monitor_name, config_reactor);
- if (retval <= 0)
- ikm_usage(1, monitor_name,
- "ikm: failed to set %s reactor, is it available?",
- config_reactor);
- }
-
- debug_msg("ikm: my pid is %d\n", config_my_pid);
-
- return 0;
-}
/**
* ikm_run_monitor - apply configs and run the monitor
@@ -805,9 +696,22 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
/* we should be good to go */
retval = parse_arguments(full_name, argc, argv);
if (retval)
- ikm_usage(1, nested_name, "ikm: failed parsing arguments");
+ mon_usage(1, nested_name, "ikm: failed parsing arguments");
+
+ if (config.reactor) {
+ config.initial_reactor = ikm_get_current_reactor(full_name);
+ if (!config.initial_reactor)
+ mon_usage(1, full_name,
+ "ikm: failed to read current reactor, are reactors enabled?");
+
+ retval = ikm_write_reactor(full_name, config.reactor);
+ if (retval <= 0)
+ mon_usage(1, full_name,
+ "ikm: failed to set %s reactor, is it available?",
+ config.reactor);
+ }
- if (config_trace) {
+ if (config.trace) {
inst = ikm_setup_trace_instance(nested_name);
if (!inst)
goto out_free_instance;
@@ -817,11 +721,11 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
if (retval < 0)
goto out_free_instance;
- if (config_trace)
+ if (config.trace)
ikm_print_header(inst->seq);
while (!should_stop()) {
- if (config_trace) {
+ if (config.trace) {
retval = tracefs_iterate_raw_events(inst->tep,
inst->inst,
NULL,
@@ -840,14 +744,14 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
ikm_disable(full_name);
ikm_destroy_trace_instance(inst);
- if (config_reactor && config_initial_reactor)
- ikm_write_reactor(full_name, config_initial_reactor);
+ if (config.reactor && config.initial_reactor)
+ ikm_write_reactor(full_name, config.initial_reactor);
return 1;
out_free_instance:
ikm_destroy_trace_instance(inst);
- if (config_reactor && config_initial_reactor)
- ikm_write_reactor(full_name, config_initial_reactor);
+ if (config.reactor && config.initial_reactor)
+ ikm_write_reactor(full_name, config.initial_reactor);
return -1;
}
diff --git a/tools/verification/rv/src/utils.c b/tools/verification/rv/src/utils.c
index 5677b439dc2f..e19dd65ec789 100644
--- a/tools/verification/rv/src/utils.c
+++ b/tools/verification/rv/src/utils.c
@@ -5,11 +5,14 @@
* Copyright (C) 2022 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
*/
+#include <getopt.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
#include <utils.h>
-int config_debug;
+struct config config;
#define MAX_MSG_LENGTH 1024
@@ -36,7 +39,7 @@ void debug_msg(const char *fmt, ...)
char message[MAX_MSG_LENGTH];
va_list ap;
- if (!config_debug)
+ if (!config.debug)
return;
va_start(ap, fmt);
@@ -45,3 +48,91 @@ void debug_msg(const char *fmt, ...)
fprintf(stderr, "%s", message);
}
+
+/*
+ * mon_usage - print usage
+ */
+void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...)
+{
+
+ char message[1024];
+ va_list ap;
+ int i;
+
+ static const char *const usage[] = {
+ "",
+ " -h/--help: print this menu and the reactor list",
+ " -r/--reactor 'reactor': enables the 'reactor'",
+ " -s/--self: when tracing (-t), also trace rv command",
+ " -t/--trace: trace monitor's event",
+ " -v/--verbose: print debug messages",
+ "",
+ NULL,
+ };
+
+ va_start(ap, fmt);
+ vsnprintf(message, sizeof(message), fmt, ap);
+ va_end(ap);
+
+ fprintf(stderr, " %s\n", message);
+
+ fprintf(stderr, "\n usage: rv mon %s [-h] [-q] [-r reactor] [-s] [-v]", monitor_name);
+
+ for (i = 0; usage[i]; i++)
+ fprintf(stderr, "%s\n", usage[i]);
+
+ ikm_usage_print_reactors();
+ exit(exit_val);
+}
+
+/*
+ * parse_arguments - parse arguments and set config
+ */
+int parse_arguments(char *monitor_name, int argc, char **argv)
+{
+ int c;
+
+ config.my_pid = getpid();
+
+ while (1) {
+ static struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"reactor", required_argument, 0, 'r'},
+ {"self", no_argument, 0, 's'},
+ {"trace", no_argument, 0, 't'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+ };
+
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+
+ c = getopt_long(argc, argv, "hr:stv", long_options, &option_index);
+
+ /* detect the end of the options. */
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ mon_usage(0, monitor_name, "help:");
+ break;
+ case 'r':
+ config.reactor = optarg;
+ break;
+ case 's':
+ config.my_pid = -1;
+ break;
+ case 't':
+ config.trace = 1;
+ break;
+ case 'v':
+ config.debug = 1;
+ break;
+ }
+ }
+
+ debug_msg("ikm: my pid is %d\n", config.my_pid);
+
+ return 0;
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 08/18] tools/rv: Move monitor trace handling to trace.c
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (6 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 07/18] tools/rv: Move argument parsing from in_kernel to utils Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing Gabriele Monaco
` (9 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Move the rv monitor tracing functions from in_kernel.c to trace.c so
it can be shared with other monitor backends, e.g. BPF monitors that
emit tracepoints.
No functional changes but minor simplifications:
- simplify ambiguous destruction path and use trace inst on stack
- more consistent argument order
- fix minor style issues
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/include/trace.h | 4 +-
tools/verification/rv/src/in_kernel.c | 295 +-------------------------
tools/verification/rv/src/trace.c | 290 +++++++++++++++++++++++--
3 files changed, 280 insertions(+), 309 deletions(-)
diff --git a/tools/verification/rv/include/trace.h b/tools/verification/rv/include/trace.h
index 8d89e8c303fa..e3d65ff3d544 100644
--- a/tools/verification/rv/include/trace.h
+++ b/tools/verification/rv/include/trace.h
@@ -9,8 +9,10 @@ struct trace_instance {
};
int trace_instance_init(struct trace_instance *trace, char *name);
-int trace_instance_start(struct trace_instance *trace);
void trace_instance_destroy(struct trace_instance *trace);
int collect_registered_events(struct tep_event *event, struct tep_record *record,
int cpu, void *context);
+
+void trace_print_header(struct trace_seq *s);
+int trace_instance_setup(struct trace_instance *inst, char *name);
diff --git a/tools/verification/rv/src/in_kernel.c b/tools/verification/rv/src/in_kernel.c
index 90c340a73c76..79f2d308e14d 100644
--- a/tools/verification/rv/src/in_kernel.c
+++ b/tools/verification/rv/src/in_kernel.c
@@ -9,7 +9,6 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
-#include <dirent.h>
#include <trace.h>
#include <utils.h>
@@ -304,29 +303,6 @@ static char *ikm_get_current_reactor(char *monitor_name)
return curr_reactor;
}
-static int ikm_has_id(char *monitor_name)
-{
- char path[MAX_PATH];
- char *format;
- int has_id;
-
- snprintf(path, MAX_PATH, "events/rv/event_%s/format", monitor_name);
- format = tracefs_instance_file_read(NULL, path, NULL);
- if (!format) {
- err_msg("ikm: fail reading monitor's %s format event file\n", monitor_name);
- return -1;
- }
-
- /* print fmt: "%d: %s x %s -> %s %s", REC->id, ... */
- has_id = !!strstr(format, "REC->id");
-
- debug_msg("ikm: monitor %s has id: %s\n", monitor_name, has_id ? "yes" : "no");
-
- free(format);
-
- return has_id;
-}
-
/**
* ikm_list_monitors - list all available monitors
*
@@ -379,260 +355,6 @@ int ikm_list_monitors(char *container)
return 0;
}
-static void ikm_print_header(struct trace_seq *s)
-{
- trace_seq_printf(s, "%16s-%-8s %5s %5s ", "<TASK>", "PID", "[CPU]", "TYPE");
- if (config.has_id)
- trace_seq_printf(s, "%8s ", "ID");
-
- trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
- "STATE",
- "EVENT",
- "NEXT_STATE",
- "FINAL");
-
- trace_seq_printf(s, "%16s %-8s %5s %5s ", " | ", " | ", " | ", " | ");
-
- if (config.has_id)
- trace_seq_printf(s, "%8s ", " | ");
-
- trace_seq_printf(s, "%24s %-24s %-24s %s\n",
- " | ",
- " | ",
- " | ",
- "|");
-
-}
-
-/*
- * ikm_event_handler - callback to handle event events
- *
- * Called any time a rv:"monitor"_event events is generated.
- * It parses and prints event.
- */
-static int
-ikm_event_handler(struct trace_seq *s, struct tep_record *record,
- struct tep_event *trace_event, void *context)
-{
- /* if needed: struct trace_instance *inst = context; */
- char *state, *event, *next_state;
- unsigned long long final_state;
- unsigned long long pid;
- unsigned long long id;
- int val;
- bool missing_id;
-
- if (config.has_id)
- missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
-
- tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
-
- if (config.has_id && (config.my_pid == id))
- return 0;
- else if (config.my_pid == pid)
- return 0;
-
- tep_print_event(trace_event->tep, s, record, "%16s-%-8d [%.3d] ",
- TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU);
-
- if (config.is_container)
- tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
- else
- trace_seq_printf(s, "event ");
-
- if (config.has_id) {
- if (missing_id)
- /* placeholder if we are dealing with a mixed-type container*/
- trace_seq_printf(s, " ");
- else
- trace_seq_printf(s, "%8llu ", id);
- }
-
- state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
- event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
- next_state = tep_get_field_raw(s, trace_event, "next_state", record, &val, 0);
- tep_get_field_val(s, trace_event, "final_state", record, &final_state, 1);
-
- trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
- state,
- event,
- next_state,
- final_state ? "Y" : "N");
-
- trace_seq_do_printf(s);
- trace_seq_reset(s);
-
- return 0;
-}
-
-/*
- * ikm_error_handler - callback to handle error events
- *
- * Called any time a rv:"monitor"_errors events is generated.
- * It parses and prints event.
- */
-static int
-ikm_error_handler(struct trace_seq *s, struct tep_record *record,
- struct tep_event *trace_event, void *context)
-{
- unsigned long long pid, id;
- int cpu = record->cpu;
- char *state, *event;
- int val;
- bool missing_id;
-
- if (config.has_id)
- missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
-
- tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
-
- if (config.has_id && config.my_pid == id)
- return 0;
- else if (config.my_pid == pid)
- return 0;
-
- trace_seq_printf(s, "%8lld [%03d] ", pid, cpu);
-
- if (config.is_container)
- tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
- else
- trace_seq_printf(s, "error ");
-
- if (config.has_id) {
- if (missing_id)
- /* placeholder if we are dealing with a mixed-type container*/
- trace_seq_printf(s, " ");
- else
- trace_seq_printf(s, "%8llu ", id);
- }
-
- state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
- event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
-
- trace_seq_printf(s, "%24s x %s\n", state, event);
-
- trace_seq_do_printf(s);
- trace_seq_reset(s);
-
- return 0;
-}
-
-static int ikm_enable_trace_events(char *monitor_name, struct trace_instance *inst)
-{
- char event[MAX_DA_NAME_LEN + 7]; /* max(error_,event_) + '0' = 7 */
- int retval;
-
- snprintf(event, sizeof(event), "event_%s", monitor_name);
- retval = tracefs_event_enable(inst->inst, "rv", event);
- if (retval)
- return -1;
-
- tep_register_event_handler(inst->tep, -1, "rv", event,
- ikm_event_handler, NULL);
-
- snprintf(event, sizeof(event), "error_%s", monitor_name);
- retval = tracefs_event_enable(inst->inst, "rv", event);
- if (retval)
- return -1;
-
- tep_register_event_handler(inst->tep, -1, "rv", event,
- ikm_error_handler, NULL);
-
- /* set if at least 1 monitor has id in case of a container */
- config.has_id = ikm_has_id(monitor_name);
- if (config.has_id < 0)
- return -1;
-
-
- return 0;
-}
-
-static int ikm_enable_trace_container(char *monitor_name,
- struct trace_instance *inst)
-{
- DIR *dp;
- char *abs_path, rv_path[MAX_PATH];
- struct dirent *ep;
- int retval = 0;
-
- snprintf(rv_path, MAX_PATH, "rv/monitors/%s", monitor_name);
- abs_path = tracefs_instance_get_file(NULL, rv_path);
- if (!abs_path)
- return -1;
- dp = opendir(abs_path);
- if (!dp)
- goto out_free;
-
- while (!retval && (ep = readdir(dp))) {
- if (ep->d_type != DT_DIR || ep->d_name[0] == '.')
- continue;
- retval = ikm_enable_trace_events(ep->d_name, inst);
- }
-
- closedir(dp);
-out_free:
- free(abs_path);
- return retval;
-}
-
-/*
- * ikm_setup_trace_instance - set up a tracing instance to collect data
- *
- * Create a trace instance, enable rv: events and enable the trace.
- *
- * Returns the trace_instance * with all set, NULL otherwise.
- */
-static struct trace_instance *ikm_setup_trace_instance(char *monitor_name)
-{
- struct trace_instance *inst;
- int retval;
-
- if (!config.trace)
- return NULL;
-
- /* alloc data */
- inst = calloc(1, sizeof(*inst));
- if (!inst) {
- err_msg("ikm: failed to allocate trace instance");
- goto out_err;
- }
-
- retval = trace_instance_init(inst, monitor_name);
- if (retval)
- goto out_free;
-
- if (config.is_container)
- retval = ikm_enable_trace_container(monitor_name, inst);
- else
- retval = ikm_enable_trace_events(monitor_name, inst);
- if (retval)
- goto out_inst;
-
- /* ready to enable */
- tracefs_trace_on(inst->inst);
-
- return inst;
-
-out_inst:
- trace_instance_destroy(inst);
-out_free:
- free(inst);
-out_err:
- return NULL;
-}
-
-/**
- * ikm_destroy_trace_instance - destroy a previously created instance
- */
-static void ikm_destroy_trace_instance(struct trace_instance *inst)
-{
- if (!inst)
- return;
-
- trace_instance_destroy(inst);
- free(inst);
-}
-
/*
* ikm_usage_print_reactors - print all available reactors, one per line.
*/
@@ -669,7 +391,7 @@ void ikm_usage_print_reactors(void)
*/
int ikm_run_monitor(char *monitor_name, int argc, char **argv)
{
- struct trace_instance *inst = NULL;
+ struct trace_instance inst = {0};
char *nested_name, full_name[2*MAX_DA_NAME_LEN];
int retval;
@@ -712,8 +434,7 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
}
if (config.trace) {
- inst = ikm_setup_trace_instance(nested_name);
- if (!inst)
+ if (trace_instance_setup(&inst, nested_name))
goto out_free_instance;
}
@@ -722,16 +443,16 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
goto out_free_instance;
if (config.trace)
- ikm_print_header(inst->seq);
+ trace_print_header(inst.seq);
while (!should_stop()) {
if (config.trace) {
- retval = tracefs_iterate_raw_events(inst->tep,
- inst->inst,
+ retval = tracefs_iterate_raw_events(inst.tep,
+ inst.inst,
NULL,
0,
collect_registered_events,
- inst);
+ &inst);
if (retval) {
err_msg("ikm: error reading trace buffer\n");
break;
@@ -742,7 +463,7 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
}
ikm_disable(full_name);
- ikm_destroy_trace_instance(inst);
+ trace_instance_destroy(&inst);
if (config.reactor && config.initial_reactor)
ikm_write_reactor(full_name, config.initial_reactor);
@@ -750,7 +471,7 @@ int ikm_run_monitor(char *monitor_name, int argc, char **argv)
return 1;
out_free_instance:
- ikm_destroy_trace_instance(inst);
+ trace_instance_destroy(&inst);
if (config.reactor && config.initial_reactor)
ikm_write_reactor(full_name, config.initial_reactor);
return -1;
diff --git a/tools/verification/rv/src/trace.c b/tools/verification/rv/src/trace.c
index 1b9f9bfa1893..aa4bb73624ec 100644
--- a/tools/verification/rv/src/trace.c
+++ b/tools/verification/rv/src/trace.c
@@ -5,34 +5,16 @@
* Copyright (C) 2022 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
*/
-#include <sys/sendfile.h>
#include <tracefs.h>
-#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
+#include <dirent.h>
#include <errno.h>
#include <rv.h>
#include <trace.h>
#include <utils.h>
-/*
- * create_instance - create a trace instance with *instance_name
- */
-static struct tracefs_instance *create_instance(char *instance_name)
-{
- return tracefs_instance_create(instance_name);
-}
-
-/*
- * destroy_instance - remove a trace instance and free the data
- */
-static void destroy_instance(struct tracefs_instance *inst)
-{
- tracefs_instance_destroy(inst);
- tracefs_instance_free(inst);
-}
-
/**
* collect_registered_events - call the existing callback function for the event
*
@@ -64,8 +46,12 @@ collect_registered_events(struct tep_event *event, struct tep_record *record,
*/
void trace_instance_destroy(struct trace_instance *trace)
{
+ if (!trace)
+ return;
+
if (trace->inst) {
- destroy_instance(trace->inst);
+ tracefs_instance_destroy(trace->inst);
+ tracefs_instance_free(trace->inst);
trace->inst = NULL;
}
@@ -101,7 +87,7 @@ int trace_instance_init(struct trace_instance *trace, char *name)
trace_seq_init(trace->seq);
- trace->inst = create_instance(name);
+ trace->inst = tracefs_instance_create(name);
if (!trace->inst)
goto out_err;
@@ -131,3 +117,265 @@ int trace_instance_start(struct trace_instance *trace)
{
return tracefs_trace_on(trace->inst);
}
+
+static int monitor_has_id(char *name)
+{
+ char path[MAX_PATH];
+ char *format;
+ int has_id;
+
+ snprintf(path, MAX_PATH, "events/rv/event_%s/format", name);
+ format = tracefs_instance_file_read(NULL, path, NULL);
+ if (!format) {
+ err_msg("rv: fail reading monitor's %s format event file\n", name);
+ return -1;
+ }
+
+ /* print fmt: "%d: %s x %s -> %s %s", REC->id, ... */
+ has_id = !!strstr(format, "REC->id");
+
+ debug_msg("rv: monitor %s has id: %s\n", name, has_id ? "yes" : "no");
+
+ free(format);
+
+ return has_id;
+}
+
+/**
+ * trace_print_header - print the header of the monitor events output
+ *
+ * Print the column header of the rv monitor events output: task, pid,
+ * cpu and event type, followed by the state machine transition
+ * (state x event -> next state and final). The ID column is printed
+ * only if the monitor's events have an id field.
+ */
+void trace_print_header(struct trace_seq *s)
+{
+ trace_seq_printf(s, "%16s-%-8s %5s %5s ", "<TASK>", "PID", "[CPU]", "TYPE");
+ if (config.has_id)
+ trace_seq_printf(s, "%8s ", "ID");
+
+ trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
+ "STATE",
+ "EVENT",
+ "NEXT_STATE",
+ "FINAL");
+
+ trace_seq_printf(s, "%16s %-8s %5s %5s ", " | ", " | ", " | ", " | ");
+
+ if (config.has_id)
+ trace_seq_printf(s, "%8s ", " | ");
+
+ trace_seq_printf(s, "%24s %-24s %-24s %s\n",
+ " | ",
+ " | ",
+ " | ",
+ "|");
+}
+
+/*
+ * da_event_handler - callback to handle event events
+ *
+ * Called any time a rv:"monitor"_event events is generated.
+ * It parses and prints event.
+ */
+static int da_event_handler(struct trace_seq *s, struct tep_record *record,
+ struct tep_event *trace_event, void *context)
+{
+ char *state, *event, *next_state;
+ unsigned long long final_state;
+ unsigned long long pid;
+ unsigned long long id;
+ int val;
+ bool missing_id;
+
+ if (config.has_id)
+ missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
+
+ tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
+
+ if (config.has_id && (config.my_pid == id))
+ return 0;
+ else if (config.my_pid == pid)
+ return 0;
+
+ tep_print_event(trace_event->tep, s, record, "%16s-%-8d [%.3d] ",
+ TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU);
+
+ if (config.is_container)
+ tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
+ else
+ trace_seq_printf(s, "event ");
+
+ if (config.has_id) {
+ if (missing_id)
+ /* placeholder if we are dealing with a mixed-type container*/
+ trace_seq_printf(s, " ");
+ else
+ trace_seq_printf(s, "%8llu ", id);
+ }
+
+ state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
+ event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
+ next_state = tep_get_field_raw(s, trace_event, "next_state", record, &val, 0);
+ tep_get_field_val(s, trace_event, "final_state", record, &final_state, 1);
+
+ trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
+ state,
+ event,
+ next_state,
+ final_state ? "Y" : "N");
+
+ trace_seq_do_printf(s);
+ trace_seq_reset(s);
+
+ return 0;
+}
+
+/*
+ * da_error_handler - callback to handle error events
+ *
+ * Called any time a rv:"monitor"_errors events is generated.
+ * It parses and prints event.
+ */
+static int da_error_handler(struct trace_seq *s, struct tep_record *record,
+ struct tep_event *trace_event, void *context)
+{
+ unsigned long long pid, id;
+ int cpu = record->cpu;
+ char *state, *event;
+ int val;
+ bool missing_id;
+
+ if (config.has_id)
+ missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
+
+ tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
+
+ if (config.has_id && config.my_pid == id)
+ return 0;
+ else if (config.my_pid == pid)
+ return 0;
+
+ trace_seq_printf(s, "%8lld [%03d] ", pid, cpu);
+
+ if (config.is_container)
+ tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
+ else
+ trace_seq_printf(s, "error ");
+
+ if (config.has_id) {
+ if (missing_id)
+ /* placeholder if we are dealing with a mixed-type container*/
+ trace_seq_printf(s, " ");
+ else
+ trace_seq_printf(s, "%8llu ", id);
+ }
+
+ state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
+ event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
+
+ trace_seq_printf(s, "%24s x %s\n", state, event);
+
+ trace_seq_do_printf(s);
+ trace_seq_reset(s);
+
+ return 0;
+}
+
+/**
+ * trace_enable_monitor_events - enable a monitor's events in a trace instance
+ *
+ * Enable the rv:event_"monitor" and rv:error_"monitor" events in the
+ * given trace instance, and register the callbacks that parse and
+ * print these events.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+static int trace_enable_monitor_events(struct trace_instance *inst, char *name)
+{
+ char event[MAX_DA_NAME_LEN + 7]; /* max(error_,event_) + '0' = 7 */
+ int retval;
+
+ snprintf(event, sizeof(event), "event_%s", name);
+ retval = tracefs_event_enable(inst->inst, "rv", event);
+ if (retval)
+ return -1;
+
+ tep_register_event_handler(inst->tep, -1, "rv", event,
+ da_event_handler, NULL);
+
+ snprintf(event, sizeof(event), "error_%s", name);
+ retval = tracefs_event_enable(inst->inst, "rv", event);
+ if (retval)
+ return -1;
+
+ tep_register_event_handler(inst->tep, -1, "rv", event,
+ da_error_handler, NULL);
+
+ /* set if at least 1 monitor has id in case of a container */
+ config.has_id = monitor_has_id(name);
+ if (config.has_id < 0)
+ return -1;
+
+ return 0;
+}
+
+static int trace_enable_container_events(struct trace_instance *inst, char *name)
+{
+ DIR *dp;
+ char *abs_path, rv_path[MAX_PATH];
+ struct dirent *ep;
+ int retval = 0;
+
+ snprintf(rv_path, MAX_PATH, "rv/monitors/%s", name);
+ abs_path = tracefs_instance_get_file(NULL, rv_path);
+ if (!abs_path)
+ return -1;
+ dp = opendir(abs_path);
+ free(abs_path);
+ if (!dp)
+ return -1;
+
+ while (!retval && (ep = readdir(dp))) {
+ if (ep->d_type != DT_DIR || ep->d_name[0] == '.')
+ continue;
+ retval = trace_enable_monitor_events(inst, ep->d_name);
+ }
+
+ closedir(dp);
+ return retval;
+}
+
+/*
+ * trace_instance_setup - set up a tracing instance to collect data
+ *
+ * Create a trace instance, enable rv: events and enable the trace.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int trace_instance_setup(struct trace_instance *inst, char *name)
+{
+ int retval;
+
+ if (!config.trace)
+ return -1;
+
+ retval = trace_instance_init(inst, name);
+ if (retval)
+ return -1;
+
+ if (config.is_container)
+ retval = trace_enable_container_events(inst, name);
+ else
+ retval = trace_enable_monitor_events(inst, name);
+ if (retval) {
+ trace_instance_destroy(inst);
+ return -1;
+ }
+
+ /* ready to enable */
+ tracefs_trace_on(inst->inst);
+
+ return 0;
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (7 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 08/18] tools/rv: Move monitor trace handling to trace.c Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing Gabriele Monaco
` (8 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Implement the BPF monitor listing functionality that scans for compiled
BPF monitor object files and displays them in the monitor list.
If enabled, running rv list shows in-kernel and BPF monitors found in
/usr/share/rv/bpf_monitors/ or in ./bpf_monitors/ relative to the RV
binary's location (used during development).
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/Makefile | 4 +-
tools/verification/rv/Makefile.config | 23 ++
tools/verification/rv/include/bpf_monitor.h | 14 ++
tools/verification/rv/src/Build | 5 +
tools/verification/rv/src/bpf_monitor.c | 240 ++++++++++++++++++++
tools/verification/rv/src/rv.c | 2 +
6 files changed, 287 insertions(+), 1 deletion(-)
create mode 100644 tools/verification/rv/include/bpf_monitor.h
create mode 100644 tools/verification/rv/src/bpf_monitor.c
diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 8ae5fc0d1d17..0a8c7a656f7f 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -32,8 +32,10 @@ DOCSRC := ../../../Documentation/tools/rv/
FEATURE_TESTS := libtraceevent
FEATURE_TESTS += libtracefs
+FEATURE_TESTS += libbpf
FEATURE_DISPLAY := libtraceevent
FEATURE_DISPLAY += libtracefs
+FEATURE_DISPLAY += libbpf
all: $(RV)
@@ -57,7 +59,7 @@ endif
CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
-export CFLAGS OUTPUT srctree
+export CFLAGS OUTPUT srctree BUILD_BPF
$(RV): $(RV_IN)
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RV) $(RV_IN) $(EXTLIBS)
diff --git a/tools/verification/rv/Makefile.config b/tools/verification/rv/Makefile.config
index 066302230eb2..0600170ac217 100644
--- a/tools/verification/rv/Makefile.config
+++ b/tools/verification/rv/Makefile.config
@@ -43,6 +43,29 @@ else
$(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
endif
+ifndef BUILD_BPF
+ # BPF monitors are optional but enabled by default
+ BUILD_BPF := 1
+endif
+
+ifeq ($(BUILD_BPF),0)
+ $(info BPF monitor support disabled, building without BPF monitor support.)
+endif
+
+$(call feature_check,libbpf)
+ifeq ($(feature-libbpf), 1)
+ $(call detected,CONFIG_LIBBPF)
+else
+ $(info libbpf is missing, building without BPF monitor support.)
+ $(info Please install libbpf-dev/libbpf-devel)
+ BUILD_BPF := 0
+endif
+
+ifeq ($(BUILD_BPF),1)
+ CFLAGS += -DHAVE_LIBBPF
+ $(call lib_setup,bpf)
+endif
+
ifeq ($(STOP_ERROR),1)
$(error Please, check the errors above.)
endif
diff --git a/tools/verification/rv/include/bpf_monitor.h b/tools/verification/rv/include/bpf_monitor.h
new file mode 100644
index 000000000000..e58bc45c5f75
--- /dev/null
+++ b/tools/verification/rv/include/bpf_monitor.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef _BPF_MONITOR_H
+#define _BPF_MONITOR_H
+
+#ifdef HAVE_LIBBPF
+int bpf_list_monitors(char *container);
+#else
+static inline int bpf_list_monitors(char *container)
+{
+ return 0;
+}
+#endif /* HAVE_LIBBPF */
+
+#endif
diff --git a/tools/verification/rv/src/Build b/tools/verification/rv/src/Build
index d781983c1a79..326503c22915 100644
--- a/tools/verification/rv/src/Build
+++ b/tools/verification/rv/src/Build
@@ -1,4 +1,9 @@
rv-y += trace.o
rv-y += utils.o
rv-y += in_kernel.o
+
+ifeq ($(BUILD_BPF),1)
+ rv-y += bpf_monitor.o
+endif
+
rv-y += rv.o
diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c
new file mode 100644
index 000000000000..a5767617c720
--- /dev/null
+++ b/tools/verification/rv/src/bpf_monitor.c
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * BPF monitor support: allows rv to control BPF monitors.
+ *
+ * Copyright (C) 2026 Red Hat Inc, Gabriele Monaco <gmonaco@redhat.com>
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <libgen.h>
+#include <errno.h>
+#include <bpf/libbpf.h>
+#include <bpf/bpf.h>
+#include <bpf/btf.h>
+
+#include <bpf_monitor.h>
+#include <utils.h>
+#include <rv.h>
+
+static char bpf_base_paths[][MAX_PATH] = {
+ ".",
+ "/etc/rv",
+ "/usr/local/share/rv",
+ "/usr/share/rv",
+ "", /* Marker */
+};
+
+/* Path used for development, searched first */
+#define DEVEL_PATH 0
+
+#define RV_LOCK_DIR "/run/rv"
+
+/*
+ * bpf_lock_acquire - take the ownership lock for a monitor
+ *
+ * The lock is held for the whole monitor lifetime and released by the kernel
+ * when the process exits, including on crashes. The lock file is never
+ * removed: unlinking it would allow two processes to lock different inodes.
+ *
+ * Returns the fd if the lock was acquired, -errno on error, -EAGAIN means busy.
+ */
+static int bpf_lock_acquire(const char *monitor_name)
+{
+ struct flock fl = { .l_type = F_WRLCK, .l_whence = SEEK_SET };
+ char path[MAX_PATH];
+ int fd, ret;
+
+ snprintf(path, MAX_PATH, "%s/%s.lock", RV_LOCK_DIR, monitor_name);
+
+ if (mkdir(RV_LOCK_DIR, 0700) && errno != EEXIST)
+ return -errno;
+
+ fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC | O_NOFOLLOW, 0600);
+ if (fd < 0)
+ return -errno;
+
+ if (fcntl(fd, F_OFD_SETLK, &fl)) {
+ ret = errno;
+ close(fd);
+ return -ret;
+ }
+
+ return fd;
+}
+
+/*
+ * bpf_lock_is_held - check if a monitor is owned by a running process
+ *
+ * Use F_OFD_GETLK to query the lock without disturbing the owner.
+ *
+ * Returns 1 if the monitor is locked, 0 otherwise.
+ */
+static int bpf_lock_is_held(const char *monitor_name)
+{
+ struct flock fl = { .l_type = F_WRLCK, .l_whence = SEEK_SET };
+ char path[MAX_PATH];
+ int fd, ret;
+
+ snprintf(path, MAX_PATH, "%s/%s.lock", RV_LOCK_DIR, monitor_name);
+
+ fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
+ if (fd < 0)
+ return 0;
+
+ ret = fcntl(fd, F_OFD_GETLK, &fl);
+ close(fd);
+
+ return ret ? 0 : fl.l_type != F_UNLCK;
+}
+
+/*
+ * bpf_read_desc - read monitors' description
+ *
+ * Return the provided string containing the monitor's description, NULL
+ * otherwise.
+ */
+static char *bpf_read_desc(char *desc, struct bpf_object *obj, const char *monitor_name)
+{
+ struct bpf_map *map = bpf_object__find_map_by_name(obj, ".rodata.description");
+ const char *desc_data;
+ size_t desc_size;
+
+ if (!map) {
+ debug_msg("bpf: cannot find description for %s\n",
+ monitor_name);
+ return NULL;
+ }
+ desc_data = bpf_map__initial_value(map, &desc_size);
+ if (!desc_data || desc_size == 0) {
+ debug_msg("bpf: empty description for %s\n", monitor_name);
+ *desc = 0;
+ return desc;
+ }
+
+ if (desc_size >= MAX_DESCRIPTION)
+ desc_size = MAX_DESCRIPTION - 1;
+ strncpy(desc, desc_data, desc_size);
+ desc[desc_size] = '\0';
+
+ return desc;
+}
+
+/*
+ * bpf_fill_base_paths - fill the path for development builds
+ *
+ * RV searches for BPF monitors on absolute paths on the system as well
+ * as in the same directory of the rv binary. This is useful when running
+ * rv from the kernel tree. This function resolves the right location.
+ */
+static void bpf_fill_base_paths(void)
+{
+ char tmp_path[MAX_PATH], *dir;
+ ssize_t len;
+
+ len = readlink("/proc/self/exe", tmp_path, MAX_PATH);
+ if (len > 0 && len != MAX_PATH) {
+ tmp_path[len] = '\0';
+ dir = dirname(tmp_path);
+ snprintf(bpf_base_paths[DEVEL_PATH], MAX_PATH, "%s", dir);
+ }
+}
+
+static void bpf_object_iterate_path(const char *base_path, const char *subdir,
+ void (*action)(const char *name, struct bpf_object *obj))
+{
+ char path[MAX_PATH];
+ struct dirent *entry;
+ DIR *dir;
+ char *ext;
+
+ snprintf(path, sizeof(path), "%s/%s", base_path, subdir);
+ dir = opendir(path);
+ if (!dir) {
+ debug_msg("bpf: error opening directory: %s\n", path);
+ return;
+ }
+
+ while ((entry = readdir(dir)) != NULL) {
+ size_t size;
+ struct bpf_object *obj;
+ char name[MAX_DA_NAME_LEN], obj_path[MAX_PATH];
+
+ if (entry->d_name[0] == '.')
+ continue;
+
+ ext = strrchr(entry->d_name, '.');
+ if (!ext || strcmp(ext, ".o") != 0)
+ continue;
+
+ size = (size_t)(ext - entry->d_name);
+ if (size >= MAX_DA_NAME_LEN) {
+ err_msg("bpf: name too long, skipping %s/%s\n", path,
+ entry->d_name);
+ continue;
+ }
+ memcpy(name, entry->d_name, size);
+ name[size] = '\0';
+
+ size = snprintf(obj_path, sizeof(obj_path), "%s/%s", path,
+ entry->d_name);
+ obj = bpf_object__open_file(obj_path, NULL);
+ if (!obj || size >= MAX_PATH) {
+ err_msg("bpf: error opening object file %s: %s\n",
+ obj_path, strerror(errno));
+ continue;
+ }
+
+ action(name, obj);
+
+ bpf_object__close(obj);
+ }
+
+ closedir(dir);
+}
+
+static void list_monitor_action(const char *name, struct bpf_object *obj)
+{
+ char desc[MAX_DESCRIPTION];
+
+ if (!bpf_read_desc(desc, obj, name)) {
+ err_msg("bpf: monitor %s does not have desc map, bug?\n", name);
+ return;
+ }
+
+ printf("%-*s %s %s\n", MAX_DA_NAME_LEN, name,
+ desc, bpf_lock_is_held(name) ? "[ON]" : "[OFF]");
+}
+
+/*
+ * list_monitors_from_path - list monitors from a specific base path
+ */
+static void list_monitors_from_path(const char *base_path)
+{
+ bpf_object_iterate_path(base_path, "bpf_monitors", list_monitor_action);
+}
+
+/*
+ * bpf_list_monitors - list available BPF monitors from all sources
+ *
+ * @container: BPF monitors are not nested, skip listing.
+ *
+ * Returns 0 on success
+ */
+int bpf_list_monitors(char *container)
+{
+ if (container)
+ return 0;
+ bpf_fill_base_paths();
+ for (int i = 0; bpf_base_paths[i][0]; i++)
+ list_monitors_from_path(bpf_base_paths[i]);
+
+ return 0;
+}
diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c
index 09e0d8598619..7c4a2e49ff9d 100644
--- a/tools/verification/rv/src/rv.c
+++ b/tools/verification/rv/src/rv.c
@@ -13,6 +13,7 @@
#include <trace.h>
#include <utils.h>
#include <in_kernel.h>
+#include <bpf_monitor.h>
static int stop_session;
@@ -76,6 +77,7 @@ static void rv_list(int argc, char **argv)
}
ikm_list_monitors(container);
+ bpf_list_monitors(container);
exit(EXIT_SUCCESS);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (8 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 11/18] tools/rv: Rework tracing to support generic events Gabriele Monaco
` (7 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Implement BPF monitor loading, execution, and optional tracing
functionality.
Running rv mon MON loads the MON monitor into the kernel and passing the
-t parameter also attaches to the trace events using the same utilities
shared with in-kernel monitors.
The shared infrastructure still needs refactoring and wiring with new
generic trace events.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/include/bpf_monitor.h | 6 +
tools/verification/rv/include/utils.h | 2 +
tools/verification/rv/src/bpf_monitor.c | 490 ++++++++++++++++++++
tools/verification/rv/src/rv.c | 3 +
tools/verification/rv/src/utils.c | 7 +-
5 files changed, 506 insertions(+), 2 deletions(-)
diff --git a/tools/verification/rv/include/bpf_monitor.h b/tools/verification/rv/include/bpf_monitor.h
index e58bc45c5f75..e650f11afdab 100644
--- a/tools/verification/rv/include/bpf_monitor.h
+++ b/tools/verification/rv/include/bpf_monitor.h
@@ -4,11 +4,17 @@
#ifdef HAVE_LIBBPF
int bpf_list_monitors(char *container);
+int bpf_run_monitor(char *monitor_name, int argc, char **argv);
#else
static inline int bpf_list_monitors(char *container)
{
return 0;
}
+
+static inline int bpf_run_monitor(char *monitor_name, int argc, char **argv)
+{
+ return 0;
+}
#endif /* HAVE_LIBBPF */
#endif
diff --git a/tools/verification/rv/include/utils.h b/tools/verification/rv/include/utils.h
index 61f77a72a1a2..d6b4e60df7ff 100644
--- a/tools/verification/rv/include/utils.h
+++ b/tools/verification/rv/include/utils.h
@@ -10,11 +10,13 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...);
int parse_arguments(char *monitor_name, int argc, char **argv);
void ikm_usage_print_reactors(void);
+void bpf_usage_print_reactors(void);
struct config {
bool debug;
bool is_container;
bool trace;
+ bool is_bpf;
int has_id;
int my_pid;
char *initial_reactor;
diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c
index a5767617c720..5c9c4d9b4835 100644
--- a/tools/verification/rv/src/bpf_monitor.c
+++ b/tools/verification/rv/src/bpf_monitor.c
@@ -16,11 +16,13 @@
#include <dirent.h>
#include <libgen.h>
#include <errno.h>
+#include <inttypes.h>
#include <bpf/libbpf.h>
#include <bpf/bpf.h>
#include <bpf/btf.h>
#include <bpf_monitor.h>
+#include <trace.h>
#include <utils.h>
#include <rv.h>
@@ -36,6 +38,31 @@ static char bpf_base_paths[][MAX_PATH] = {
#define DEVEL_PATH 0
#define RV_LOCK_DIR "/run/rv"
+#define MAX_ENUMS 64
+#define MAX_LINKS 16
+#define PROG_ENABLE_MON "enable_monitor"
+#define PROG_INIT_TASK "init_task"
+#define RV_TRACE_STRUCT "rv_trace_entry"
+#define RV_TRACE_TYPE_ENUM "rv_trace_type"
+
+#define CPU_POSSIBLE "/sys/devices/system/cpu/possible"
+#define CPU_MAX "/sys/devices/system/cpu/kernel_max"
+
+enum trace_type_id {
+ TRACE_TYPE_ERROR,
+ TRACE_TYPE_EVENT,
+ TRACE_TYPE_MAX,
+};
+
+static const char *const trace_type_names[] = {
+ [TRACE_TYPE_ERROR] = "RV_TRACE_ERROR",
+ [TRACE_TYPE_EVENT] = "RV_TRACE_EVENT",
+};
+
+struct bpf_monitor_ctx {
+ char monitor_name[MAX_DA_NAME_LEN];
+ int trace_types[TRACE_TYPE_MAX];
+};
/*
* bpf_lock_acquire - take the ownership lock for a monitor
@@ -238,3 +265,466 @@ int bpf_list_monitors(char *container)
return 0;
}
+
+static int libbpf_print_fn(enum libbpf_print_level level, const char *format,
+ va_list args)
+{
+ if (level == LIBBPF_DEBUG && !config.debug)
+ return 0;
+ return vfprintf(stderr, format, args);
+}
+
+/*
+ * extract_trace_type_metadata - extract trace type enum values from BTF
+ *
+ * Introspect the rv_trace_type enum via BTF and store enum values for
+ * event type dispatch and configuration.
+ *
+ * Returns 0 on success, -1 on error
+ */
+static int extract_trace_type_metadata(const struct btf *btf, struct bpf_monitor_ctx *ctx)
+{
+ const struct btf_type *enum_type;
+ const struct btf_enum *enums;
+ int type_id, vlen, filled = 0;
+
+ for (int i = 0; i < TRACE_TYPE_MAX; i++)
+ ctx->trace_types[i] = -1;
+
+ type_id = btf__find_by_name_kind(btf, RV_TRACE_TYPE_ENUM, BTF_KIND_ENUM);
+ if (type_id <= 0) {
+ debug_msg("bpf: could not find enum '%s' in BTF\n", RV_TRACE_TYPE_ENUM);
+ return -1;
+ }
+
+ enum_type = btf__type_by_id(btf, type_id);
+ if (!enum_type) {
+ debug_msg("bpf: could not get type for '%s'\n", RV_TRACE_TYPE_ENUM);
+ return -1;
+ }
+
+ enums = btf_enum(enum_type);
+ vlen = btf_vlen(enum_type);
+
+ for (int i = 0; i < vlen; i++) {
+ const char *name = btf__name_by_offset(btf, enums[i].name_off);
+
+ if (!name)
+ continue;
+
+ for (int j = 0; j < TRACE_TYPE_MAX; j++) {
+ if (strcmp(name, trace_type_names[j]) == 0) {
+ ctx->trace_types[j] = enums[i].val;
+ ++filled;
+ break;
+ }
+ }
+ }
+
+ if (filled < TRACE_TYPE_MAX) {
+ debug_msg("bpf: could not find all trace types in BTF\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * extract_btf_info - extract BTF types information from the monitor
+ *
+ * Extract state and event names from enums using BTF and extract field
+ * offsets for flexible event parsing.
+ */
+static int extract_btf_info(struct bpf_object *obj, struct bpf_monitor_ctx *ctx)
+{
+ const struct btf *btf;
+
+ btf = bpf_object__btf(obj);
+ if (!btf) {
+ err_msg("bpf: no BTF found in BPF object\n");
+ return -1;
+ }
+
+ if (extract_trace_type_metadata(btf, ctx)) {
+ err_msg("bpf: failed to extract trace type metadata\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * find_bpf_file - search for a BPF object file in a specific subdirectory
+ */
+static int find_bpf_file(const char *subdir, const char *name, char *path_out, size_t path_len)
+{
+ char path[MAX_PATH];
+
+ for (int i = 0; bpf_base_paths[i][0]; i++) {
+ size_t size = snprintf(path, sizeof(path), "%s/%s/%s.o",
+ bpf_base_paths[i], subdir, name);
+
+ if (size < MAX_PATH && access(path, R_OK) == 0) {
+ strncpy(path_out, path, path_len - 1);
+ path_out[path_len - 1] = '\0';
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * find_bpf_monitor - search for BPF monitor object file in all directories
+ */
+static int find_bpf_monitor(const char *monitor_name, char *path_out, size_t path_len)
+{
+ return find_bpf_file("bpf_monitors", monitor_name, path_out, path_len);
+}
+
+/*
+ * bpf_usage_print_reactors - print available BPF reactors
+ */
+void bpf_usage_print_reactors(void)
+{
+ fprintf(stderr, " available BPF reactors: nop\n");
+}
+
+/*
+ * bpf_enable_tracing - set the trace_level variable in .rodata
+ *
+ * Find trace_level in a special section of .rodata and set its value before
+ * loading.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+static int bpf_enable_tracing(struct bpf_object *obj, struct bpf_monitor_ctx *ctx)
+{
+ struct bpf_map *map = bpf_object__find_map_by_name(obj, ".rodata.trace_level");
+ size_t data_size;
+ int *trace_level;
+
+ if (!map)
+ return -1;
+
+ trace_level = bpf_map__initial_value(map, &data_size);
+ if (!trace_level || data_size != sizeof(*trace_level))
+ return -1;
+
+ *trace_level = ctx->trace_types[TRACE_TYPE_EVENT];
+ return 0;
+}
+
+static int readline(char *buf, size_t size, const char *path)
+{
+ FILE *f;
+
+ f = fopen(path, "r");
+ if (!f)
+ return -errno;
+
+ if (!fgets(buf, size, f)) {
+ fclose(f);
+ return -EINVAL;
+ }
+ fclose(f);
+
+ if (!strchr(buf, '\n'))
+ return -E2BIG;
+ return 0;
+}
+
+/*
+ * get_nr_cpu_ids: Find the maximum number of CPUs
+ *
+ * The BPF programs iterate over CPUs during initialisation, the highest id + 1
+ * is a safe value in case of a sparse CPU mask.
+ * Fall back to the maximum number of CPUs.
+ *
+ * Returns nr_cpu_ids or a negative errno.
+ */
+static int get_nr_cpu_ids(void)
+{
+ char buf[4096], *comma, *dash, *sep;
+
+ if (readline(buf, sizeof(buf), CPU_POSSIBLE)) {
+ int res = readline(buf, sizeof(buf), CPU_MAX);
+
+ return res ?: strtol(buf, NULL, 10) + 1;
+ }
+
+ comma = strrchr(buf, ',');
+ dash = strrchr(buf, '-');
+ sep = dash && (!comma || dash > comma) ? dash : comma;
+
+ return strtol(sep ? sep + 1 : buf, NULL, 10) + 1;
+}
+
+/*
+ * open_bpf_monitor - open and load a BPF monitor object from a file path
+ *
+ * Returns loaded BPF object on success, NULL on error.
+ */
+static struct bpf_object *open_bpf_monitor(const char *path, struct bpf_monitor_ctx *ctx)
+{
+ struct bpf_object *obj = NULL;
+ int res, nproc = get_nr_cpu_ids();
+ char kconfig[128];
+
+ if (nproc <= 0) {
+ err_msg("bpf: error getting possible CPUs: %s\n", strerror(-nproc));
+ return NULL;
+ }
+ /* Define statically what is known, Kconfig may not be available. */
+ snprintf(kconfig, sizeof(kconfig), "CONFIG_NR_CPUS=%d\n",
+ nproc);
+
+ LIBBPF_OPTS(bpf_object_open_opts, opts,
+ .object_name = ctx->monitor_name,
+ .kconfig = kconfig,
+ );
+
+ obj = bpf_object__open_file(path, &opts);
+ if (!obj) {
+ err_msg("bpf: error opening object: %s\n", strerror(errno));
+ return NULL;
+ }
+
+ res = extract_btf_info(obj, ctx);
+ if (res || bpf_enable_tracing(obj, ctx)) {
+ err_msg("bpf: failed to enable tracing\n");
+ bpf_object__close(obj);
+ return NULL;
+ }
+
+ res = bpf_object__load(obj);
+ if (res) {
+ err_msg("bpf: error loading object: %s\n", strerror(-res));
+ bpf_object__close(obj);
+ return NULL;
+ }
+
+ return obj;
+}
+
+/*
+ * attach_bpf_handlers - attach all BPF programs
+ *
+ * Attach all handler programs and store links in the provided array. Skip
+ * known non-handler programs.
+ *
+ * Returns fd of enable program on success, -1 on error.
+ */
+static int attach_bpf_handlers(const char *monitor_name, struct bpf_object *obj,
+ struct bpf_link **links, int *link_count)
+{
+ struct bpf_program *prog;
+ int enable_mon_fd = -1;
+
+ bpf_object__for_each_program(prog, obj) {
+ struct bpf_link *link = NULL;
+ const char *prog_name;
+
+ /* Special program to initialise the monitor */
+ if (!strcmp(bpf_program__name(prog), PROG_ENABLE_MON)) {
+ enable_mon_fd = bpf_program__fd(prog);
+ continue;
+ }
+
+ /* Task iterator program to initialise existing tasks */
+ if (!strcmp(bpf_program__name(prog), PROG_INIT_TASK))
+ continue;
+
+ if (*link_count >= MAX_LINKS) {
+ err_msg("bpf: too many programs to attach (%d)\n", *link_count);
+ return -1;
+ }
+
+ prog_name = bpf_program__name(prog);
+ link = bpf_program__attach(prog);
+ if (!link) {
+ err_msg("bpf: error attaching program '%s': %s\n",
+ prog_name, strerror(errno));
+ return -1;
+ }
+ links[(*link_count)++] = link;
+ }
+ if (enable_mon_fd < 0)
+ err_msg("bpf: could not find program %s\n", PROG_ENABLE_MON);
+ return enable_mon_fd;
+}
+
+/*
+ * bpf_init_tasks - initialize storage for existing tasks using task iterator
+ *
+ * Runs the task iterator program if present in the object, initializing
+ * task storage for all currently existing tasks before monitor is enabled.
+ * Silently succeed if the program is not there (not a per-task monitor).
+ *
+ * Returns 0 on success, -errno on error.
+ */
+static int bpf_init_tasks(struct bpf_object *obj)
+{
+ struct bpf_program *prog;
+ struct bpf_link *link;
+ char buf[128];
+ int iter_fd, retval = 0;
+ ssize_t len;
+
+ prog = bpf_object__find_program_by_name(obj, PROG_INIT_TASK);
+ if (!prog)
+ return 0;
+
+ link = bpf_program__attach_iter(prog, NULL);
+ if (!link)
+ return -errno;
+
+ iter_fd = bpf_iter_create(bpf_link__fd(link));
+ if (iter_fd < 0) {
+ bpf_link__destroy(link);
+ return -errno;
+ }
+
+ do {
+ len = read(iter_fd, buf, sizeof(buf));
+ } while (len > 0 || (len < 0 && errno == EINTR));
+
+ retval = (len < 0) ? -errno : 0;
+
+ close(iter_fd);
+ bpf_link__destroy(link);
+
+ return retval;
+}
+
+/*
+ * bpf_validate_name - check that a monitor name is valid
+ *
+ * Avoid path separators, special directories and long names.
+ *
+ * Returns 0 if the name is valid, -1 otherwise.
+ */
+static int bpf_validate_name(const char *monitor_name)
+{
+ if (!monitor_name[0] || strlen(monitor_name) >= MAX_DA_NAME_LEN)
+ return -1;
+
+ if (strchr(monitor_name, '/'))
+ return -1;
+
+ if (!strcmp(monitor_name, ".") || !strcmp(monitor_name, ".."))
+ return -1;
+
+ return 0;
+}
+
+/*
+ * bpf_run_monitor - load and run a BPF monitor
+ *
+ * Returns 1 if monitor was found and executed, 0 if not found, -1 on error
+ */
+int bpf_run_monitor(char *monitor_name, int argc, char **argv)
+{
+ struct bpf_link *links[MAX_LINKS] = {0};
+ struct trace_instance inst = {0};
+ struct bpf_monitor_ctx ctx = {0};
+ struct bpf_object *obj = NULL;
+ int res, link_count = 0, enable_mon_fd, retval = -1, lock_fd = -1;
+ char monitor_path[MAX_PATH];
+
+ libbpf_set_print(libbpf_print_fn);
+ bpf_fill_base_paths();
+
+ if (bpf_validate_name(monitor_name)) {
+ err_msg("bpf: invalid monitor name: %s\n", monitor_name);
+ return -1;
+ }
+
+ if (!find_bpf_monitor(monitor_name, monitor_path, sizeof(monitor_path)))
+ return 0;
+
+ config.is_bpf = true;
+
+ /* we should be good to go */
+ res = parse_arguments(monitor_name, argc, argv);
+ if (res)
+ mon_usage(1, monitor_name, "bpf: failed parsing arguments");
+
+ lock_fd = bpf_lock_acquire(monitor_name);
+ if (lock_fd == -EAGAIN) {
+ err_msg("bpf: monitor %s (BPF) is already enabled\n", monitor_name);
+ return -1;
+ }
+ if (lock_fd < 0) {
+ err_msg("bpf: cannot lock monitor %s: %s\n",
+ monitor_name, strerror(-lock_fd));
+ return -1;
+ }
+
+ strncpy(ctx.monitor_name, monitor_name, sizeof(ctx.monitor_name) - 1);
+
+ if (config.reactor && strcmp(config.reactor, "nop")) {
+ mon_usage(1, monitor_name,
+ "bpf: failed to set %s reactor, is it available?",
+ config.reactor);
+ }
+
+ obj = open_bpf_monitor(monitor_path, &ctx);
+ if (!obj)
+ goto cleanup;
+
+ if (config.trace) {
+ if (trace_instance_setup(&inst, monitor_name))
+ goto cleanup;
+ }
+
+ enable_mon_fd = attach_bpf_handlers(monitor_name, obj, links, &link_count);
+ if (enable_mon_fd < 0)
+ goto cleanup;
+
+ res = bpf_init_tasks(obj);
+ if (res) {
+ err_msg("bpf: error initializing tasks: %s\n", strerror(-res));
+ goto cleanup;
+ }
+
+ res = bpf_prog_test_run_opts(enable_mon_fd, NULL);
+ if (res) {
+ err_msg("bpf: error enabling the monitor: %s\n", strerror(-res));
+ goto cleanup;
+ }
+
+ if (config.trace)
+ trace_print_header(inst.seq);
+
+ while (!should_stop()) {
+ if (config.trace) {
+ res = tracefs_iterate_raw_events(inst.tep,
+ inst.inst,
+ NULL,
+ 0,
+ collect_registered_events,
+ &inst);
+ if (res) {
+ err_msg("bpf: error reading trace buffer\n");
+ break;
+ }
+ }
+
+ sleep(1);
+ }
+
+ retval = 1;
+
+cleanup:
+ for (int i = 0; i < link_count; i++)
+ bpf_link__destroy(links[i]);
+
+ trace_instance_destroy(&inst);
+
+ bpf_object__close(obj);
+
+ close(lock_fd);
+
+ return retval;
+}
diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c
index 7c4a2e49ff9d..571c9a14c1a2 100644
--- a/tools/verification/rv/src/rv.c
+++ b/tools/verification/rv/src/rv.c
@@ -127,6 +127,9 @@ static void rv_mon(int argc, char **argv)
*/
run += ikm_run_monitor(monitor_name, argc-1, &argv[1]);
+ if (!run)
+ run += bpf_run_monitor(monitor_name, argc-1, &argv[1]);
+
if (!run)
err_msg("rv: monitor %s does not exist\n", monitor_name);
exit(run > 0 ? EXIT_SUCCESS : EXIT_FAILURE);
diff --git a/tools/verification/rv/src/utils.c b/tools/verification/rv/src/utils.c
index e19dd65ec789..1b1ad7a3ca32 100644
--- a/tools/verification/rv/src/utils.c
+++ b/tools/verification/rv/src/utils.c
@@ -81,7 +81,10 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...)
for (i = 0; usage[i]; i++)
fprintf(stderr, "%s\n", usage[i]);
- ikm_usage_print_reactors();
+ if (config.is_bpf)
+ bpf_usage_print_reactors();
+ else
+ ikm_usage_print_reactors();
exit(exit_val);
}
@@ -132,7 +135,7 @@ int parse_arguments(char *monitor_name, int argc, char **argv)
}
}
- debug_msg("ikm: my pid is %d\n", config.my_pid);
+ debug_msg("%s: my pid is %d\n", config.is_bpf ? "bpf" : "ikm", config.my_pid);
return 0;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 11/18] tools/rv: Rework tracing to support generic events
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (9 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 12/18] tools/rv: Copy stripped bpf_atomic.h from libarena Gabriele Monaco
` (6 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
The DA event handlers parse the DA events' fields (state, event,
next_state and final_state) to print the state machine transition.
This is DA-specific and wouldn't work with LTL or generic tracepoints
(used in BPF).
Simplify the reporting to print the default representation of events,
this drops the aligned table for DA but transparently add support for
any kind of event.
Transform the my_pid check (used for -s) in an ftrace filter and set it
up for both specific and generic events to further simplify the event
handler.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/include/utils.h | 1 -
tools/verification/rv/src/trace.c | 256 +++++++++-----------------
2 files changed, 92 insertions(+), 165 deletions(-)
diff --git a/tools/verification/rv/include/utils.h b/tools/verification/rv/include/utils.h
index d6b4e60df7ff..397a37981932 100644
--- a/tools/verification/rv/include/utils.h
+++ b/tools/verification/rv/include/utils.h
@@ -17,7 +17,6 @@ struct config {
bool is_container;
bool trace;
bool is_bpf;
- int has_id;
int my_pid;
char *initial_reactor;
char *reactor;
diff --git a/tools/verification/rv/src/trace.c b/tools/verification/rv/src/trace.c
index aa4bb73624ec..6fdbff2c28d4 100644
--- a/tools/verification/rv/src/trace.c
+++ b/tools/verification/rv/src/trace.c
@@ -15,11 +15,13 @@
#include <trace.h>
#include <utils.h>
+#define FILTER_MAX 128
+
/**
- * collect_registered_events - call the existing callback function for the event
+ * collect_registered_events - print an event collected from the trace buffer
*
- * If an event has a registered callback function, call it.
- * Otherwise, ignore the event.
+ * Print the event with a standard prefix for common fields and the
+ * event-specific pretty-print for the event content.
*
* Returns 0 if the event was collected, 1 if the tool should stop collecting trace.
*/
@@ -33,10 +35,12 @@ collect_registered_events(struct tep_event *event, struct tep_record *record,
if (should_stop())
return 1;
- if (!event->handler)
- return 0;
+ tep_print_event(event->tep, s, record, "%16s-%-8d [%.3d] %s: %s\n",
+ TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
+ TEP_PRINT_NAME, TEP_PRINT_INFO);
- event->handler(s, record, event, context);
+ trace_seq_do_printf(s);
+ trace_seq_reset(s);
return 0;
}
@@ -109,176 +113,111 @@ int trace_instance_init(struct trace_instance *trace, char *name)
}
/**
- * trace_instance_start - start tracing a given rv instance
- *
- * Returns 0 on success, -1 otherwise.
+ * trace_print_header - print the header of the monitor events output
*/
-int trace_instance_start(struct trace_instance *trace)
+void trace_print_header(struct trace_seq *s)
{
- return tracefs_trace_on(trace->inst);
+ trace_seq_printf(s, "%16s-%-8s %5s %5s\n", "<TASK>", "PID", "[CPU]", "TYPE");
+ trace_seq_printf(s, "%16s %-8s %5s %5s\n", " | ", " | ", " | ", " | ");
+ trace_seq_do_printf(s);
+ trace_seq_reset(s);
}
-static int monitor_has_id(char *name)
+/*
+ * apply_filter_enable - if a filter is provided, apply it, then enable the event
+ */
+static int apply_filter_enable(struct trace_instance *inst,
+ struct tep_event *tevent, const char *filter)
{
- char path[MAX_PATH];
- char *format;
- int has_id;
-
- snprintf(path, MAX_PATH, "events/rv/event_%s/format", name);
- format = tracefs_instance_file_read(NULL, path, NULL);
- if (!format) {
- err_msg("rv: fail reading monitor's %s format event file\n", name);
- return -1;
+ if (*filter) {
+ if (tracefs_event_filter_apply(inst->inst, tevent, filter) < 0) {
+ char *err = tracefs_error_last(inst->inst);
+
+ err_msg("trace: fail applying filter %s to event %s:\n%s\n",
+ filter, tevent->name, err ?: "(no error)");
+ free(err);
+ return -1;
+ }
}
- /* print fmt: "%d: %s x %s -> %s %s", REC->id, ... */
- has_id = !!strstr(format, "REC->id");
-
- debug_msg("rv: monitor %s has id: %s\n", name, has_id ? "yes" : "no");
+ if (tracefs_event_enable(inst->inst, tevent->system, tevent->name) < 0) {
+ err_msg("trace: fail enabling the rv:%s event: %s\n",
+ tevent->name, strerror(errno));
+ return -1;
+ }
- free(format);
+ return 0;
- return has_id;
-}
-
-/**
- * trace_print_header - print the header of the monitor events output
- *
- * Print the column header of the rv monitor events output: task, pid,
- * cpu and event type, followed by the state machine transition
- * (state x event -> next state and final). The ID column is printed
- * only if the monitor's events have an id field.
- */
-void trace_print_header(struct trace_seq *s)
-{
- trace_seq_printf(s, "%16s-%-8s %5s %5s ", "<TASK>", "PID", "[CPU]", "TYPE");
- if (config.has_id)
- trace_seq_printf(s, "%8s ", "ID");
-
- trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
- "STATE",
- "EVENT",
- "NEXT_STATE",
- "FINAL");
-
- trace_seq_printf(s, "%16s %-8s %5s %5s ", " | ", " | ", " | ", " | ");
-
- if (config.has_id)
- trace_seq_printf(s, "%8s ", " | ");
-
- trace_seq_printf(s, "%24s %-24s %-24s %s\n",
- " | ",
- " | ",
- " | ",
- "|");
}
/*
- * da_event_handler - callback to handle event events
- *
- * Called any time a rv:"monitor"_event events is generated.
- * It parses and prints event.
+ * enable_specific_event - enable a monitor-specific event with filters
*/
-static int da_event_handler(struct trace_seq *s, struct tep_record *record,
- struct tep_event *trace_event, void *context)
+static int enable_specific_event(struct trace_instance *inst, const char *event_name)
{
- char *state, *event, *next_state;
- unsigned long long final_state;
- unsigned long long pid;
- unsigned long long id;
- int val;
- bool missing_id;
-
- if (config.has_id)
- missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
-
- tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
+ struct tep_event *tevent = tep_find_event_by_name(inst->tep, "rv", event_name);
+ char filter[FILTER_MAX] = "";
- if (config.has_id && (config.my_pid == id))
- return 0;
- else if (config.my_pid == pid)
- return 0;
-
- tep_print_event(trace_event->tep, s, record, "%16s-%-8d [%.3d] ",
- TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU);
-
- if (config.is_container)
- tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
- else
- trace_seq_printf(s, "event ");
+ if (!tevent) {
+ err_msg("trace: fail finding the rv:%s event\n", event_name);
+ return -1;
+ }
- if (config.has_id) {
- if (missing_id)
- /* placeholder if we are dealing with a mixed-type container*/
- trace_seq_printf(s, " ");
+ if (config.my_pid > 0) {
+ if (tep_find_field(tevent, "id"))
+ snprintf(filter, sizeof(filter), "common_pid != %d && id != %d",
+ config.my_pid, config.my_pid);
else
- trace_seq_printf(s, "%8llu ", id);
+ snprintf(filter, sizeof(filter), "common_pid != %d",
+ config.my_pid);
}
- state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
- event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
- next_state = tep_get_field_raw(s, trace_event, "next_state", record, &val, 0);
- tep_get_field_val(s, trace_event, "final_state", record, &final_state, 1);
-
- trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n",
- state,
- event,
- next_state,
- final_state ? "Y" : "N");
-
- trace_seq_do_printf(s);
- trace_seq_reset(s);
-
- return 0;
+ return apply_filter_enable(inst, tevent, filter);
}
/*
- * da_error_handler - callback to handle error events
- *
- * Called any time a rv:"monitor"_errors events is generated.
- * It parses and prints event.
+ * enable_generic_event - enable a generic event with filters
*/
-static int da_error_handler(struct trace_seq *s, struct tep_record *record,
- struct tep_event *trace_event, void *context)
+static int enable_generic_event(struct trace_instance *inst, const char *event_name, char *name)
{
- unsigned long long pid, id;
- int cpu = record->cpu;
- char *state, *event;
- int val;
- bool missing_id;
-
- if (config.has_id)
- missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1);
-
- tep_get_common_field_val(s, trace_event, "common_pid", record, &pid, 1);
-
- if (config.has_id && config.my_pid == id)
- return 0;
- else if (config.my_pid == pid)
- return 0;
-
- trace_seq_printf(s, "%8lld [%03d] ", pid, cpu);
+ struct tep_event *tevent = tep_find_event_by_name(inst->tep, "rv", event_name);
+ char filter[FILTER_MAX] = "";
+ size_t len;
- if (config.is_container)
- tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME);
- else
- trace_seq_printf(s, "error ");
+ if (!tevent) {
+ err_msg("trace: fail finding the rv:%s event\n", event_name);
+ return -1;
+ }
- if (config.has_id) {
- if (missing_id)
- /* placeholder if we are dealing with a mixed-type container*/
- trace_seq_printf(s, " ");
- else
- trace_seq_printf(s, "%8llu ", id);
+ len = snprintf(filter, sizeof(filter), "mon == \"%s\"", name);
+ if (len >= sizeof(filter)) {
+ err_msg("trace: monitor name %s too long\n", name);
+ return -1;
}
- state = tep_get_field_raw(s, trace_event, "state", record, &val, 0);
- event = tep_get_field_raw(s, trace_event, "event", record, &val, 0);
+ if (config.my_pid > 0)
+ snprintf(filter + len, sizeof(filter) - len,
+ " && common_pid != %d && !(has_id == 1 && id == %d)",
+ config.my_pid, config.my_pid);
- trace_seq_printf(s, "%24s x %s\n", state, event);
+ return apply_filter_enable(inst, tevent, filter);
+}
- trace_seq_do_printf(s);
- trace_seq_reset(s);
+/*
+ * enable_bpf_events - enable rv:event_monitor and rv:error_monitor for a monitor
+ *
+ * BPF monitors report via generic rv:event_monitor and rv:error_monitor events.
+ * Enable the events and filter them to only collect the messages of the given monitor.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+static int enable_bpf_events(struct trace_instance *inst, char *name)
+{
+ if (enable_generic_event(inst, "event_monitor", name))
+ return -1;
+
+ if (enable_generic_event(inst, "error_monitor", name))
+ return -1;
return 0;
}
@@ -287,35 +226,24 @@ static int da_error_handler(struct trace_seq *s, struct tep_record *record,
* trace_enable_monitor_events - enable a monitor's events in a trace instance
*
* Enable the rv:event_"monitor" and rv:error_"monitor" events in the
- * given trace instance, and register the callbacks that parse and
- * print these events.
+ * given trace instance, and register the filters for these events.
+ * If enabled, the filter for self pid (-s) is applied here.
*
* Returns 0 on success, -1 otherwise.
*/
static int trace_enable_monitor_events(struct trace_instance *inst, char *name)
{
char event[MAX_DA_NAME_LEN + 7]; /* max(error_,event_) + '0' = 7 */
- int retval;
+
+ if (config.is_bpf)
+ return enable_bpf_events(inst, name);
snprintf(event, sizeof(event), "event_%s", name);
- retval = tracefs_event_enable(inst->inst, "rv", event);
- if (retval)
+ if (enable_specific_event(inst, event))
return -1;
- tep_register_event_handler(inst->tep, -1, "rv", event,
- da_event_handler, NULL);
-
snprintf(event, sizeof(event), "error_%s", name);
- retval = tracefs_event_enable(inst->inst, "rv", event);
- if (retval)
- return -1;
-
- tep_register_event_handler(inst->tep, -1, "rv", event,
- da_error_handler, NULL);
-
- /* set if at least 1 monitor has id in case of a container */
- config.has_id = monitor_has_id(name);
- if (config.has_id < 0)
+ if (enable_specific_event(inst, event))
return -1;
return 0;
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 12/18] tools/rv: Copy stripped bpf_atomic.h from libarena
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (10 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 11/18] tools/rv: Rework tracing to support generic events Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 13/18] tools/rv: Add BPF monitors Gabriele Monaco
` (5 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add bpf_atomic.h including atomic read/write macros like READ_ONCE() and
try_cmpxchg(). This version is a stripped down copy of the one currently
present in selftests/bpf/libarena.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
.../verification/rv/bpf_monitors/bpf_atomic.h | 125 ++++++++++++++++++
1 file changed, 125 insertions(+)
create mode 100644 tools/verification/rv/bpf_monitors/bpf_atomic.h
diff --git a/tools/verification/rv/bpf_monitors/bpf_atomic.h b/tools/verification/rv/bpf_monitors/bpf_atomic.h
new file mode 100644
index 000000000000..3cf9a78a15c7
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/bpf_atomic.h
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
+#ifndef BPF_ATOMIC_H
+#define BPF_ATOMIC_H
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+extern bool CONFIG_X86_64 __kconfig __weak;
+
+/*
+ * __unqual_typeof(x) - Declare an unqualified scalar type, leaving
+ * non-scalar types unchanged,
+ *
+ * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
+ * is not type-compatible with 'signed char', and we define a separate case.
+ *
+ * This is copied verbatim from kernel's include/linux/compiler_types.h, but
+ * with default expression (for pointers) changed from (x) to (typeof(x)0).
+ *
+ * This is because LLVM has a bug where for lvalue (x), it does not get rid of
+ * an extra address_space qualifier, but does in case of rvalue (typeof(x)0).
+ * Hence, for pointers, we need to create an rvalue expression to get the
+ * desired type. See https://github.com/llvm/llvm-project/issues/53400.
+ */
+#define __scalar_type_to_expr_cases(type) \
+ unsigned type : (unsigned type)0, signed type : (signed type)0
+
+#define __unqual_typeof(x) \
+ typeof(_Generic((x), \
+ char: (char)0, \
+ __scalar_type_to_expr_cases(char), \
+ __scalar_type_to_expr_cases(short), \
+ __scalar_type_to_expr_cases(int), \
+ __scalar_type_to_expr_cases(long), \
+ __scalar_type_to_expr_cases(long long), \
+ default: (typeof(x))0))
+
+/* No-op for BPF */
+#define cpu_relax() ({})
+
+#define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
+
+#ifndef WRITE_ONCE
+#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *)&(x)) = (val))
+#endif
+
+#define cmpxchg(p, old, new) __sync_val_compare_and_swap((p), old, new)
+
+#define try_cmpxchg(p, pold, new) \
+ ({ \
+ __unqual_typeof(*(pold)) __o = *(pold); \
+ __unqual_typeof(*(p)) __r = cmpxchg(p, __o, new); \
+ if (__r != __o) \
+ *(pold) = __r; \
+ __r == __o; \
+ })
+
+#define try_cmpxchg_relaxed(p, pold, new) try_cmpxchg(p, pold, new)
+
+#define try_cmpxchg_acquire(p, pold, new) try_cmpxchg(p, pold, new)
+
+#define smp_mb() \
+ ({ \
+ volatile unsigned long __val; \
+ __sync_fetch_and_add(&__val, 0); \
+ })
+
+#define smp_rmb() \
+ ({ \
+ if (!CONFIG_X86_64) \
+ smp_mb(); \
+ else \
+ barrier(); \
+ })
+
+#define smp_wmb() \
+ ({ \
+ if (!CONFIG_X86_64) \
+ smp_mb(); \
+ else \
+ barrier(); \
+ })
+
+/* Control dependency provides LOAD->STORE, provide LOAD->LOAD */
+#define smp_acquire__after_ctrl_dep() ({ smp_rmb(); })
+
+#if defined(__BPF_FEATURE_LOAD_ACQ_STORE_REL)
+/*
+ * Clang advertises this feature when it can lower acquire/release atomic
+ * builtins to BPF_LOAD_ACQ/BPF_STORE_REL. Older compilers keep using the
+ * barrier-based fallback below. The generated instructions require kernel
+ * verifier/JIT support added in Linux 6.15; compile for an older BPF CPU to
+ * keep using the fallback when targeting older kernels.
+ */
+#define smp_load_acquire(p) \
+ ({ \
+ __unqual_typeof(*(p)) ___p1 = __atomic_load_n((p), __ATOMIC_ACQUIRE); \
+ (typeof(*(p)))___p1; \
+ })
+
+#define smp_store_release(p, val) \
+ ({ \
+ __atomic_store_n((p), (val), __ATOMIC_RELEASE); \
+ })
+#else
+#define smp_load_acquire(p) \
+ ({ \
+ __unqual_typeof(*(p)) __v = READ_ONCE(*(p)); \
+ if (!CONFIG_X86_64) \
+ smp_mb(); \
+ barrier(); \
+ __v; \
+ })
+
+#define smp_store_release(p, val) \
+ ({ \
+ if (!CONFIG_X86_64) \
+ smp_mb(); \
+ barrier(); \
+ WRITE_ONCE(*(p), val); \
+ })
+#endif
+
+#endif /* BPF_ATOMIC_H */
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 13/18] tools/rv: Add BPF monitors
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (11 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 12/18] tools/rv: Copy stripped bpf_atomic.h from libarena Gabriele Monaco
@ 2026-11-26 12:59 ` Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 14/18] tools/rv: Define CONFIG_X86_64 statically for " Gabriele Monaco
` (4 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 12:59 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add the code for 2 initial BPF monitors, both DA (the only currently
supported type):
* queue: per-task monitor stating tasks alternate enqueue and dequeue.
* nohz: per-cpu monitor stating the scheduler tick don't run when
stopped and can run only after being resumed.
BPF monitors can include the in-kernel da_monitor.h, which is now
adapted to share as much common code and conditionally compile what
needs to be BPF or kernel specific.
Integrate BPF monitor building into main rv Makefile, if all tools are
available on the system.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
include/rv/da_monitor.h | 21 +-
tools/verification/models/nohz.dot | 16 +
tools/verification/models/tqueue.dot | 15 +
tools/verification/rv/Makefile | 41 +-
tools/verification/rv/Makefile.config | 26 ++
tools/verification/rv/Makefile.rv | 5 +
tools/verification/rv/bpf_monitors/.gitignore | 2 +
.../rv/bpf_monitors/da_monitor_bpf.h | 423 ++++++++++++++++++
tools/verification/rv/bpf_monitors/nohz.c | 42 ++
tools/verification/rv/bpf_monitors/nohz.h | 49 ++
tools/verification/rv/bpf_monitors/tqueue.c | 28 ++
tools/verification/rv/bpf_monitors/tqueue.h | 47 ++
12 files changed, 707 insertions(+), 8 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/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
diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h
index fc830c9f5046..4d479d2bb12d 100644
--- a/include/rv/da_monitor.h
+++ b/include/rv/da_monitor.h
@@ -14,14 +14,19 @@
#ifndef _RV_DA_MONITOR_H
#define _RV_DA_MONITOR_H
-#include <rv/automata.h>
-#include <linux/rv.h>
+#ifndef __BPF__
+/* Kernel includes */
#include <rv/kunit.h>
-#include <linux/stringify.h>
#include <linux/bug.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/hashtable.h>
+#endif /* __BPF__ */
+
+#include <linux/args.h>
+#include <rv/automata.h>
+#include <linux/rv.h>
+#include <linux/stringify.h>
/*
* Per-cpu variables require a unique name although static in some
@@ -77,6 +82,9 @@ static struct rv_monitor rv_this;
#define da_id_type int
#endif
+#ifdef __BPF__
+#include "da_monitor_bpf.h"
+#else
static void react(enum states curr_state, enum events event)
{
rv_react(&rv_this,
@@ -85,6 +93,7 @@ static void react(enum states curr_state, enum events event)
model_get_event_name(event),
model_get_state_name(curr_state));
}
+#endif
/*
* da_monitor_reset_state - reset a monitor and setting it to init state
@@ -159,6 +168,7 @@ static inline bool da_monitor_handling_event(struct da_monitor *da_mon)
return 1;
}
+#ifndef __BPF__
#if RV_MON_TYPE == RV_MON_GLOBAL
/*
* Functions to define, init and get a global monitor.
@@ -677,6 +687,7 @@ static inline void da_trace_error(struct da_monitor *da_mon,
CONCATENATE(trace_error_, MONITOR_NAME)(id, curr_state, event);
}
#endif /* RV_MON_TYPE */
+#endif /* __BPF__ */
/*
* da_event - handle an event for the da_mon
@@ -802,7 +813,7 @@ static inline bool da_handle_start_run_event(enum events event)
return __da_handle_start_run_event(da_get_monitor(), event, 0);
}
-#elif RV_MON_TYPE == RV_MON_PER_TASK
+#elif !defined(__BPF__) && RV_MON_TYPE == RV_MON_PER_TASK
/*
* Handle event for per task.
*/
@@ -843,7 +854,7 @@ static inline bool da_handle_start_run_event(struct task_struct *tsk,
return __da_handle_start_run_event(da_get_monitor(tsk), event, tsk->pid);
}
-#elif RV_MON_TYPE == RV_MON_PER_OBJ
+#elif !defined(__BPF__) && RV_MON_TYPE == RV_MON_PER_OBJ
/*
* Handle event for per object.
*/
diff --git a/tools/verification/models/nohz.dot b/tools/verification/models/nohz.dot
new file mode 100644
index 000000000000..49adb25e32d8
--- /dev/null
+++ b/tools/verification/models/nohz.dot
@@ -0,0 +1,16 @@
+digraph state_automaton {
+ {node [shape = circle] "stopped"};
+ {node [shape = plaintext, style=invis, label=""] "__init_running"};
+ {node [shape = doublecircle] "running"};
+ {node [shape = circle] "running"};
+ "__init_running" -> "running";
+ "stopped" [label = "stopped"];
+ "stopped" -> "running" [ label = "tick_restart" ];
+ "running" [label = "running"];
+ "running" -> "running" [ label = "sched_tick" ];
+ "running" -> "stopped" [ label = "tick_stop" ];
+ { rank = min ;
+ "__init_running";
+ "running";
+ }
+}
diff --git a/tools/verification/models/tqueue.dot b/tools/verification/models/tqueue.dot
new file mode 100644
index 000000000000..7aadf99ed29d
--- /dev/null
+++ b/tools/verification/models/tqueue.dot
@@ -0,0 +1,15 @@
+digraph state_automaton {
+ {node [shape = circle] "enqueued"};
+ {node [shape = plaintext, style=invis, label=""] "__init_dequeued"};
+ {node [shape = doublecircle] "dequeued"};
+ {node [shape = circle] "dequeued"};
+ "__init_dequeued" -> "dequeued";
+ "enqueued" [label = "enqueued"];
+ "enqueued" -> "dequeued" [ label = "sched_dequeue" ];
+ "dequeued" [label = "dequeued"];
+ "dequeued" -> "enqueued" [ label = "sched_enqueue" ];
+ { rank = min ;
+ "__init_dequeued";
+ "dequeued";
+ }
+}
diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 0a8c7a656f7f..4bac30324689 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -33,9 +33,13 @@ DOCSRC := ../../../Documentation/tools/rv/
FEATURE_TESTS := libtraceevent
FEATURE_TESTS += libtracefs
FEATURE_TESTS += libbpf
+FEATURE_TESTS += clang-bpf-co-re
+FEATURE_TESTS += bpftool-btf
FEATURE_DISPLAY := libtraceevent
FEATURE_DISPLAY += libtracefs
FEATURE_DISPLAY += libbpf
+FEATURE_DISPLAY += clang-bpf-co-re
+FEATURE_DISPLAY += bpftool-btf
all: $(RV)
@@ -43,7 +47,7 @@ include $(srctree)/tools/build/Makefile.include
include Makefile.rv
# check for dependencies only on required targets
-NON_CONFIG_TARGETS := clean install doc doc_clean doc_install
+NON_CONFIG_TARGETS := clean install doc doc_clean doc_install bpf
config := 1
ifdef MAKECMDGOALS
@@ -68,19 +72,50 @@ static: $(RV_IN)
$(eval LDFLAGS += -static)
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RV)-static $(RV_IN) $(EXTLIBS)
+BPF_DIR := bpf_monitors
+BPF_SOURCES := $(wildcard $(BPF_DIR)/*.c)
+BPF_OBJECTS := $(BPF_SOURCES:.c=.o)
+VMLINUX_H := $(BPF_DIR)/vmlinux.h
+
+BPF_INCLUDES := -I$(srctree)/include/uapi
+BPF_INCLUDES += -I$(srctree)/include
+BPF_INCLUDES += -I$(BPF_DIR)
+
+BPF_CFLAGS := -g -O2 -target bpf -MMD -MP $(BPF_INCLUDES)
+BPF_CFLAGS += -Wall -Wno-unused-function -Wno-missing-declarations
+
+VMLINUX := ../../../vmlinux
+VMLINUX_BTF ?= $(if $(wildcard $(VMLINUX)) , $(VMLINUX), /sys/kernel/btf/vmlinux)
+
+$(VMLINUX_H): $(VMLINUX_BTF)
+ $(QUIET_GEN)$(SYSTEM_BPFTOOL) btf dump file $< format c > $@
+
+$(BPF_DIR)/%.o: $(BPF_DIR)/%.c $(VMLINUX_H)
+ $(QUIET_CLANG)$(CLANG) $(BPF_CFLAGS) -c $< -o $@
+ $(Q)$(LLVM_STRIP) -g $@
+
+-include $(BPF_SOURCES:.c=.d)
+
+bpf: $(BPF_OBJECTS)
+
rv.%: fixdep FORCE
make -f $(srctree)/tools/build/Makefile.build dir=. $@
$(RV_IN): fixdep FORCE
make $(build)=rv
+ifeq ($(BUILD_BPF_OBJS),1)
+all: bpf
+endif
+
clean: doc_clean fixdep-clean
$(call QUIET_CLEAN, rv)
- $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+ $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '*.d' -delete
$(Q)rm -f rv rv-static fixdep FEATURE-DUMP rv-*
+ $(Q)rm -f $(VMLINUX_H)
$(Q)rm -rf feature
check: $(RV)
RV=$(RV) prove -o --directives -f tests/
-.PHONY: FORCE clean check
+.PHONY: FORCE clean check bpf
diff --git a/tools/verification/rv/Makefile.config b/tools/verification/rv/Makefile.config
index 0600170ac217..1caad39ab0c9 100644
--- a/tools/verification/rv/Makefile.config
+++ b/tools/verification/rv/Makefile.config
@@ -66,6 +66,32 @@ ifeq ($(BUILD_BPF),1)
$(call lib_setup,bpf)
endif
+# Building BPF monitors requires clang and bpftool, RV with BPF monitors
+# support can still run without building monitors
+ifndef BUILD_BPF_OBJS
+ BUILD_BPF_OBJS := $(BUILD_BPF)
+endif
+
+ifeq ($(BUILD_BPF_OBJS),1)
+ $(call feature_check,clang-bpf-co-re)
+ ifeq ($(feature-clang-bpf-co-re), 1)
+ $(call detected,CONFIG_CLANG_BPF_CO_RE)
+ else
+ $(info clang is missing or does not support BPF CO-RE, cannot build BPF monitors.)
+ $(info Please install clang)
+ BUILD_BPF_OBJS := 0
+ endif
+
+ $(call feature_check,bpftool-btf)
+ ifeq ($(feature-bpftool-btf), 1)
+ $(call detected,CONFIG_BPFTOOL_BTF)
+ else
+ $(info bpftool is missing or does not support btf, cannot build BPF monitors.)
+ $(info Please install bpftool)
+ BUILD_BPF_OBJS := 0
+ endif
+endif
+
ifeq ($(STOP_ERROR),1)
$(error Please, check the errors above.)
endif
diff --git a/tools/verification/rv/Makefile.rv b/tools/verification/rv/Makefile.rv
index 2497fb96c83d..418748bc3aa1 100644
--- a/tools/verification/rv/Makefile.rv
+++ b/tools/verification/rv/Makefile.rv
@@ -33,12 +33,17 @@ INSTALL := install
MKDIR := mkdir
STRIP := strip
BINDIR := /usr/bin
+BPF_MON_DIR := /usr/share/rv/bpf_monitors
.PHONY: install
install: doc_install
$(Q)$(MKDIR) -p $(DESTDIR)$(BINDIR)
$(call QUIET_INSTALL,rv)$(INSTALL) $(OUTPUT)rv -m 755 $(DESTDIR)$(BINDIR)
$(Q)@$(STRIP) $(DESTDIR)$(BINDIR)/rv
+ifneq ($(wildcard bpf_monitors/*.o),)
+ $(Q)$(MKDIR) -p $(DESTDIR)$(BPF_MON_DIR)
+ $(call QUIET_INSTALL,bpf_monitors)$(INSTALL) bpf_monitors/*.o -m 644 $(DESTDIR)$(BPF_MON_DIR)
+endif
.PHONY: doc doc_clean doc_install
doc:
diff --git a/tools/verification/rv/bpf_monitors/.gitignore b/tools/verification/rv/bpf_monitors/.gitignore
new file mode 100644
index 000000000000..e5add9141ef5
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/.gitignore
@@ -0,0 +1,2 @@
+*.d
+vmlinux.h
diff --git a/tools/verification/rv/bpf_monitors/da_monitor_bpf.h b/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
new file mode 100644
index 000000000000..e9e673c2d1b6
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/da_monitor_bpf.h
@@ -0,0 +1,423 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * BPF support for DA monitors.
+ *
+ * BPF programs can include the in-kernel da_monitor directly, this
+ * header contains all the BPF compatibility layer.
+ *
+ * Copyright (C) 2026 Red Hat Inc, Gabriele Monaco <gmonaco@redhat.com>
+ */
+
+#ifndef _DA_MONITOR_BPF_H
+#define _DA_MONITOR_BPF_H
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+#include "bpf_atomic.h"
+
+/* BPF monitors don't support these */
+#define rv_react(...) do {} while (0)
+#define trace_rv_retries_error(...) do {} while (0)
+#define pr_warn(fmt, ...) bpf_printk(fmt, ##__VA_ARGS__)
+#define rv_monitoring_on() 1
+#define da_implicit_guard()
+#define IS_ENABLED(conf) 0
+
+#define DA_TRACE_MSG_MAX 128
+
+/*
+ * Also used to filter out events higher values imply lower ones.
+ * Userspace will parse this enum but expects EVENT to imply ERROR(s) and ERROR
+ * to imply any other ERROR* type.
+ */
+enum rv_trace_type {
+ RV_TRACE_NONE,
+ RV_TRACE_ERROR,
+ RV_TRACE_EVENT,
+};
+
+/* Configuration set from userspace before loading */
+const volatile SEC(".rodata.trace_level") enum rv_trace_type trace_level = RV_TRACE_NONE;
+
+#define rv_mon_map CONCATENATE(rv_mon_, MONITOR_NAME)
+
+static inline void da_monitor_reset(struct da_monitor *da_mon);
+
+/* BPF monitors do not use reactors */
+static inline void react(enum states curr_state, enum events event) { }
+
+/*
+ * BPF monitor implementations
+ * These use BPF maps instead of kernel data structures
+ */
+
+#if RV_MON_TYPE == RV_MON_GLOBAL
+/*
+ * BPF Global monitor - uses a single-entry BPF array map
+ */
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, __u32);
+ __type(value, union rv_task_monitor);
+} rv_mon_map SEC(".maps");
+
+static inline struct da_monitor *da_get_monitor(void)
+{
+ __u32 key = 0;
+ union rv_task_monitor *mon = bpf_map_lookup_elem(&rv_mon_map, &key);
+
+ return &mon->da_mon;
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_CPU
+/*
+ * BPF Per-CPU monitor - uses BPF per-cpu array map
+ */
+
+struct {
+ __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, __u32);
+ __type(value, union rv_task_monitor);
+} rv_mon_map SEC(".maps");
+
+static inline struct da_monitor *da_get_monitor(void)
+{
+ __u32 key = 0;
+ union rv_task_monitor *mon = bpf_map_lookup_elem(&rv_mon_map, &key);
+
+ return &mon->da_mon;
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_OBJ || RV_MON_TYPE == RV_MON_PER_TASK
+
+/*
+ * Both per-task and per-obj have a target and map lookup may be null, share
+ * the same utility functions.
+ * Types and structs must be different not to collide with vmlinux.h .
+ */
+
+#if RV_MON_TYPE == RV_MON_PER_TASK
+typedef struct task_struct *monitor_target_bpf;
+#endif
+
+struct da_monitor_storage_bpf {
+ da_id_type id;
+ monitor_target_bpf target;
+ union rv_task_monitor rv;
+};
+
+#if RV_MON_TYPE == RV_MON_PER_TASK
+/*
+ * BPF Per-Task monitor - uses BPF task storage map
+ */
+
+#define da_get_monitor(tsk) da_get_monitor_bpf(BPF_CORE_READ(tsk, pid), tsk)
+#define da_handle_event(tsk, event) \
+ da_handle_event_bpf(BPF_CORE_READ(tsk, pid), tsk, event)
+#define da_handle_start_event(tsk, event) \
+ da_handle_start_event_bpf(BPF_CORE_READ(tsk, pid), tsk, event)
+#define da_handle_start_run_event(tsk, event) \
+ da_handle_start_run_event_bpf(BPF_CORE_READ(tsk, pid), tsk, event)
+
+/*
+ * Task storage is created on task creation or monitor initialisation.
+ * Other contexts may not allow allocation.
+ */
+#define da_create_storage(id, t, mon) mon
+
+#define da_extra_init da_create_idle_task_storage
+
+struct {
+ __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
+ __uint(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct da_monitor_storage_bpf);
+} rv_mon_map SEC(".maps");
+
+static inline struct da_monitor *da_get_monitor_bpf(da_id_type id, monitor_target_bpf target)
+{
+ struct da_monitor_storage_bpf *storage;
+
+ storage = bpf_task_storage_get(&rv_mon_map, target, 0, 0);
+ return storage ? &storage->rv.da_mon : NULL;
+}
+
+static inline void da_create_task_storage(struct task_struct *task)
+{
+ struct da_monitor_storage_bpf *storage;
+
+ storage = bpf_task_storage_get(&rv_mon_map, task, 0,
+ BPF_LOCAL_STORAGE_GET_F_CREATE);
+ if (!storage)
+ return;
+
+ storage->target = task;
+ storage->id = BPF_CORE_READ(task, pid);
+
+}
+
+SEC("tp_btf/task_newtask")
+int BPF_PROG(handle_task_init, struct task_struct *task, u64 clone_flags)
+{
+ da_create_task_storage(task);
+ return 0;
+}
+
+SEC("iter/task")
+int init_task(struct bpf_iter__task *ctx)
+{
+ struct task_struct *task = ctx->task;
+
+ if (!task)
+ return 0;
+
+ da_create_task_storage(task);
+ return 0;
+}
+
+extern const struct rq runqueues __ksym;
+extern int CONFIG_NR_CPUS __kconfig __weak;
+
+/*
+ * Iterate over possible CPUs to find idle tasks, those are not present in the
+ * task iterator but some monitors use them.
+ */
+static inline void da_create_idle_task_storage(void)
+{
+ for (int cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) {
+ struct rq *rq = bpf_per_cpu_ptr(&runqueues, cpu);
+
+ if (rq && rq->idle)
+ da_create_task_storage(rq->idle);
+ }
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_OBJ
+/*
+ * BPF Per-Object monitor - uses BPF hash map
+ */
+
+#define da_get_monitor da_get_monitor_bpf
+#define da_handle_event da_handle_event_bpf
+#define da_handle_start_event da_handle_start_event_bpf
+#define da_handle_start_run_event da_handle_start_run_event_bpf
+
+struct {
+ __uint(type, BPF_MAP_TYPE_HASH);
+ __uint(max_entries, 10240);
+ __type(key, da_id_type);
+ __type(value, struct da_monitor_storage_bpf);
+} rv_mon_map SEC(".maps");
+
+static inline struct da_monitor *da_get_monitor_bpf(da_id_type id, monitor_target_bpf target)
+{
+ struct da_monitor_storage_bpf *storage;
+
+ storage = bpf_map_lookup_elem(&rv_mon_map, &id);
+ return storage ? &storage->rv.da_mon : NULL;
+}
+
+static inline struct da_monitor *da_create_storage(da_id_type id,
+ monitor_target_bpf target,
+ struct da_monitor *da_mon)
+{
+ struct da_monitor_storage_bpf new_storage = {
+ .id = id,
+ .target = target,
+ };
+
+ if (da_mon)
+ return da_mon;
+
+ bpf_map_update_elem(&rv_mon_map, &id, &new_storage, BPF_NOEXIST);
+ return da_get_monitor_bpf(id, target);
+}
+
+static inline void da_destroy_storage(da_id_type id)
+{
+ bpf_map_delete_elem(&rv_mon_map, &id);
+}
+
+#endif /* RV_MON_PER_TASK */
+
+static inline da_id_type da_get_id(struct da_monitor *da_mon)
+{
+ return container_of(da_mon, struct da_monitor_storage_bpf, rv.da_mon)->id;
+}
+
+static inline monitor_target_bpf da_get_target(struct da_monitor *da_mon)
+{
+ return container_of(da_mon, struct da_monitor_storage_bpf, rv.da_mon)->target;
+}
+
+/*
+ * Handle event for per object and per task
+ */
+
+static inline void __da_handle_event(struct da_monitor *da_mon,
+ enum events event, da_id_type id);
+static inline bool __da_handle_start_event(struct da_monitor *da_mon,
+ enum events event, da_id_type id);
+static inline bool __da_handle_start_run_event(struct da_monitor *da_mon,
+ enum events event, da_id_type id);
+
+/*
+ * da_handle_event - handle an event
+ */
+static inline void da_handle_event_bpf(da_id_type id, monitor_target_bpf target, enum events event)
+{
+ struct da_monitor *da_mon;
+
+ da_mon = da_get_monitor_bpf(id, target);
+ if (likely(da_mon))
+ __da_handle_event(da_mon, event, id);
+}
+
+/*
+ * da_handle_start_event - start monitoring or handle event
+ *
+ * This function is used to notify the monitor that the system is returning
+ * to the initial state, so the monitor can start monitoring in the next event.
+ * Thus:
+ *
+ * If the monitor already started, handle the event.
+ * If the monitor did not start yet, start the monitor but skip the event.
+ */
+static inline bool da_handle_start_event_bpf(da_id_type id, monitor_target_bpf target,
+ enum events event)
+{
+ struct da_monitor *da_mon;
+
+ da_mon = da_get_monitor_bpf(id, target);
+ da_mon = da_create_storage(id, target, da_mon);
+ if (unlikely(!da_mon))
+ return 0;
+ return __da_handle_start_event(da_mon, event, id);
+}
+
+/*
+ * da_handle_start_run_event - start monitoring and handle event
+ *
+ * This function is used to notify the monitor that the system is in the
+ * initial state, so the monitor can start monitoring and handling event.
+ */
+static inline bool da_handle_start_run_event_bpf(da_id_type id, monitor_target_bpf target,
+ enum events event)
+{
+ struct da_monitor *da_mon;
+
+ da_mon = da_get_monitor_bpf(id, target);
+ da_mon = da_create_storage(id, target, da_mon);
+ if (unlikely(!da_mon))
+ return 0;
+ return __da_handle_start_run_event(da_mon, event, id);
+}
+
+static inline void da_reset_bpf(da_id_type id, monitor_target_bpf target)
+{
+ struct da_monitor *da_mon;
+
+ da_mon = da_get_monitor_bpf(id, target);
+ if (likely(da_mon))
+ da_monitor_reset(da_mon);
+}
+
+#endif /* RV_MON_TYPE */
+
+extern int bpf_rv_event_monitor(const char *mon, const int *id__nullable,
+ const char *msg, u32 msg__sz) __ksym;
+extern int bpf_rv_error_monitor(const char *mon, const int *id__nullable,
+ const char *msg, u32 msg__sz) __ksym;
+
+#if RV_MON_TYPE == RV_MON_GLOBAL || RV_MON_TYPE == RV_MON_PER_CPU
+/*
+ * Trace events for implicit monitors. Implicit monitor is the one which the
+ * handler does not need to specify which da_monitor to manipulate. Examples
+ * of implicit monitor are the per_cpu or the global ones.
+ */
+
+static inline void da_trace_event(struct da_monitor *da_mon,
+ const char *curr_state, const char *event,
+ const char *next_state, bool is_final,
+ da_id_type id)
+{
+ char msg[DA_TRACE_MSG_MAX];
+
+ if (trace_level < RV_TRACE_EVENT)
+ return;
+
+ BPF_SNPRINTF(msg, sizeof(msg), "%s x %s -> %s%s",
+ curr_state, event, next_state, is_final ? " (final)" : "");
+ bpf_rv_event_monitor(__stringify(MONITOR_NAME), NULL, msg, sizeof(msg));
+}
+
+static inline void da_trace_error(struct da_monitor *da_mon,
+ const char *curr_state, const char *event,
+ da_id_type id)
+{
+ char msg[DA_TRACE_MSG_MAX];
+
+ if (trace_level < RV_TRACE_ERROR)
+ return;
+
+ BPF_SNPRINTF(msg, sizeof(msg), "event %s not expected in the state %s",
+ event, curr_state);
+ bpf_rv_error_monitor(__stringify(MONITOR_NAME), NULL, msg, sizeof(msg));
+}
+
+#elif RV_MON_TYPE == RV_MON_PER_TASK || RV_MON_TYPE == RV_MON_PER_OBJ
+/*
+ * Trace events for per_task/per_object monitors, report the target id.
+ */
+
+static inline void da_trace_event(struct da_monitor *da_mon,
+ const char *curr_state, const char *event,
+ const char *next_state, bool is_final,
+ da_id_type id)
+{
+ char msg[DA_TRACE_MSG_MAX];
+
+ if (trace_level < RV_TRACE_EVENT)
+ return;
+
+ BPF_SNPRINTF(msg, sizeof(msg), "%d: %s x %s -> %s%s", id,
+ curr_state, event, next_state, is_final ? " (final)" : "");
+ bpf_rv_event_monitor(__stringify(MONITOR_NAME), &id, msg, sizeof(msg));
+}
+
+static inline void da_trace_error(struct da_monitor *da_mon,
+ const char *curr_state, const char *event,
+ da_id_type id)
+{
+ char msg[DA_TRACE_MSG_MAX];
+
+ if (trace_level < RV_TRACE_ERROR)
+ return;
+
+ BPF_SNPRINTF(msg, sizeof(msg), "%d: event %s not expected in the state %s",
+ id, event, curr_state);
+ bpf_rv_error_monitor(__stringify(MONITOR_NAME), &id, msg, sizeof(msg));
+}
+#endif /* RV_MON_TYPE */
+
+/* Some monitors require extra initialisation. */
+#ifndef da_extra_init
+#define da_extra_init()
+#endif
+
+/*
+ * enable_monitor - BPF program to be called manually after all handlers are attached
+ */
+SEC("syscall")
+int enable_monitor(void *ctx)
+{
+ da_extra_init();
+ rv_this.enabled = 1;
+ return 0;
+}
+
+#endif // _DA_MONITOR_BPF_H
diff --git a/tools/verification/rv/bpf_monitors/nohz.c b/tools/verification/rv/bpf_monitors/nohz.c
new file mode 100644
index 000000000000..cb19944fad77
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/nohz.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#define RV_MON_TYPE RV_MON_PER_CPU
+#include "nohz.h"
+#include <rv/da_monitor.h>
+
+/*
+ * This monitor is broken on purpose to test errors, sched_tick can run with
+ * stopped ticks for one last time (deferred tick reprogram).
+ * A way to fix this monitor is to handle the sched_tick event only when
+ * tick_nohz_handler returns HRTIMER_RESTART (i.e. it isn't stopping the tick).
+ */
+SEC("fentry/sched_tick")
+int BPF_PROG(handle_sched_tick)
+{
+ da_handle_start_event(sched_tick_nohz);
+ return 0;
+}
+
+SEC("fentry/tick_nohz_restart_sched_tick")
+int BPF_PROG(handle_tick_restart)
+{
+ da_handle_start_event(tick_restart_nohz);
+ return 0;
+}
+
+SEC("tp_btf/tick_stop")
+int BPF_PROG(handle_tick_stop, int success, int dependency)
+{
+ if (success)
+ da_handle_event(tick_stop_nohz);
+ return 0;
+}
+
+static struct rv_monitor rv_this = {
+ .enabled = 0,
+};
+
+char LICENSE[] SEC("license") = "GPL";
+char DESCRIPTION[] SEC(".rodata.description") = "tick does not run when stopped.";
diff --git a/tools/verification/rv/bpf_monitors/nohz.h b/tools/verification/rv/bpf_monitors/nohz.h
new file mode 100644
index 000000000000..308d4014cee2
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/nohz.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of nohz automaton
+ * For further information about this format, see kernel documentation:
+ * Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME nohz
+
+enum states_nohz {
+ running_nohz,
+ stopped_nohz,
+ state_max_nohz,
+};
+
+#define INVALID_STATE state_max_nohz
+
+enum events_nohz {
+ sched_tick_nohz,
+ tick_restart_nohz,
+ tick_stop_nohz,
+ event_max_nohz,
+};
+
+struct automaton_nohz {
+ const char state_names[state_max_nohz][32];
+ const char event_names[event_max_nohz][32];
+ unsigned char function[state_max_nohz][event_max_nohz];
+ unsigned char initial_state;
+ bool final_states[state_max_nohz];
+};
+
+static const struct automaton_nohz automaton_nohz = {
+ .state_names = {
+ "running",
+ "stopped",
+ },
+ .event_names = {
+ "sched_tick",
+ "tick_restart",
+ "tick_stop",
+ },
+ .function = {
+ { running_nohz, INVALID_STATE, stopped_nohz },
+ { INVALID_STATE, running_nohz, INVALID_STATE },
+ },
+ .initial_state = running_nohz,
+ .final_states = { 1, 0 },
+};
diff --git a/tools/verification/rv/bpf_monitors/tqueue.c b/tools/verification/rv/bpf_monitors/tqueue.c
new file mode 100644
index 000000000000..0814d559644f
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/tqueue.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#define RV_MON_TYPE RV_MON_PER_TASK
+#include "tqueue.h"
+#include <rv/da_monitor.h>
+
+SEC("tp_btf/sched_dequeue_tp")
+int BPF_PROG(handle_sched_dequeue, struct task_struct *tsk, int cpu)
+{
+ da_handle_start_event(tsk, sched_dequeue_tqueue);
+ return 0;
+}
+
+SEC("tp_btf/sched_enqueue_tp")
+int BPF_PROG(handle_sched_enqueue, struct task_struct *tsk, int cpu)
+{
+ da_handle_event(tsk, sched_enqueue_tqueue);
+ return 0;
+}
+
+static struct rv_monitor rv_this = {
+ .enabled = 0,
+};
+
+char LICENSE[] SEC("license") = "GPL";
+char DESCRIPTION[] SEC(".rodata.description") = "enqueue and dequeue tasks.";
diff --git a/tools/verification/rv/bpf_monitors/tqueue.h b/tools/verification/rv/bpf_monitors/tqueue.h
new file mode 100644
index 000000000000..2e9cde31737b
--- /dev/null
+++ b/tools/verification/rv/bpf_monitors/tqueue.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of tqueue automaton
+ * For further information about this format, see kernel documentation:
+ * Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME tqueue
+
+enum states_tqueue {
+ dequeued_tqueue,
+ enqueued_tqueue,
+ state_max_tqueue,
+};
+
+#define INVALID_STATE state_max_tqueue
+
+enum events_tqueue {
+ sched_dequeue_tqueue,
+ sched_enqueue_tqueue,
+ event_max_tqueue,
+};
+
+struct automaton_tqueue {
+ const char state_names[state_max_tqueue][32];
+ const char event_names[event_max_tqueue][32];
+ unsigned char function[state_max_tqueue][event_max_tqueue];
+ unsigned char initial_state;
+ bool final_states[state_max_tqueue];
+};
+
+static const struct automaton_tqueue automaton_tqueue = {
+ .state_names = {
+ "dequeued",
+ "enqueued",
+ },
+ .event_names = {
+ "sched_dequeue",
+ "sched_enqueue",
+ },
+ .function = {
+ { INVALID_STATE, enqueued_tqueue },
+ { dequeued_tqueue, INVALID_STATE },
+ },
+ .initial_state = dequeued_tqueue,
+ .final_states = { 1, 0 },
+};
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 14/18] tools/rv: Define CONFIG_X86_64 statically for BPF monitors
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (12 preceding siblings ...)
2026-11-26 12:59 ` [PATCH v3 13/18] tools/rv: Add BPF monitors Gabriele Monaco
@ 2026-11-26 13:00 ` Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 15/18] tools/rv: Add -E/--errors-only option Gabriele Monaco
` (3 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 13:00 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
BPF atomic macros require CONFIG_X86_64 to determine barrier
instructions. Reading this from the system Kconfig can fail if the
configuration is missing or in an unexpected location, causing the
loading phase to fail.
Since the rv tool is compiled for the target architecture, the
architecture is known at compile-time. Define the CONFIG_X86_64 value
statically via the libbpf open options to bypass Kconfig dependency and
ensure reliable loading.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/src/bpf_monitor.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c
index 5c9c4d9b4835..1ff76a4ffb68 100644
--- a/tools/verification/rv/src/bpf_monitor.c
+++ b/tools/verification/rv/src/bpf_monitor.c
@@ -460,6 +460,12 @@ static int get_nr_cpu_ids(void)
return strtol(sep ? sep + 1 : buf, NULL, 10) + 1;
}
+#ifdef __x86_64__
+#define X86_64 'y'
+#else
+#define X86_64 'n'
+#endif
+
/*
* open_bpf_monitor - open and load a BPF monitor object from a file path
*
@@ -476,8 +482,8 @@ static struct bpf_object *open_bpf_monitor(const char *path, struct bpf_monitor_
return NULL;
}
/* Define statically what is known, Kconfig may not be available. */
- snprintf(kconfig, sizeof(kconfig), "CONFIG_NR_CPUS=%d\n",
- nproc);
+ snprintf(kconfig, sizeof(kconfig), "CONFIG_NR_CPUS=%d\nCONFIG_X86_64=%c\n",
+ nproc, X86_64);
LIBBPF_OPTS(bpf_object_open_opts, opts,
.object_name = ctx->monitor_name,
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 15/18] tools/rv: Add -E/--errors-only option
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (13 preceding siblings ...)
2026-11-26 13:00 ` [PATCH v3 14/18] tools/rv: Define CONFIG_X86_64 statically for " Gabriele Monaco
@ 2026-11-26 13:00 ` Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors Gabriele Monaco
` (2 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 13:00 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Jonathan Corbet,
Steven Rostedt, Gabriele Monaco, linux-doc
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Currently the rv tool enables tracing when running with -t and that
allows to see tracepoints generated from both in-kernel and BPF
monitors.
In-kernel monitors can be controlled also by other tools but BPF ones
cannot, so if a user is only interested in seeing errors, they need to
bear the performance overhead of other events too.
Add the -E/--errors-only flag. If it's passed with -t, only enable error
tracepoints. On BPF monitors, if -E is passed but -t isn't, still load
the monitor with error tracing enabled, so the user can enable the error
events in other tools.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
Documentation/tools/rv/common_ikm.rst | 6 ++++++
tools/verification/rv/include/utils.h | 1 +
tools/verification/rv/src/bpf_monitor.c | 4 +++-
tools/verification/rv/src/trace.c | 11 +++++++----
tools/verification/rv/src/utils.c | 9 +++++++--
5 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/Documentation/tools/rv/common_ikm.rst b/Documentation/tools/rv/common_ikm.rst
index e50a5f8a7142..b2594f9c35e8 100644
--- a/Documentation/tools/rv/common_ikm.rst
+++ b/Documentation/tools/rv/common_ikm.rst
@@ -19,3 +19,9 @@
**-v**, **--verbose**
Print debug messages.
+
+**-E**, **--errors-only**
+
+ When tracing (**-t**), trace only error events, skipping the monitor's
+ state transitions. Specifying this without tracing is meaningful only
+ for BPF monitors.
diff --git a/tools/verification/rv/include/utils.h b/tools/verification/rv/include/utils.h
index 397a37981932..2fec9ef7c0b3 100644
--- a/tools/verification/rv/include/utils.h
+++ b/tools/verification/rv/include/utils.h
@@ -16,6 +16,7 @@ struct config {
bool debug;
bool is_container;
bool trace;
+ bool trace_errors_only;
bool is_bpf;
int my_pid;
char *initial_reactor;
diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c
index 1ff76a4ffb68..12cb407c55bc 100644
--- a/tools/verification/rv/src/bpf_monitor.c
+++ b/tools/verification/rv/src/bpf_monitor.c
@@ -411,7 +411,9 @@ static int bpf_enable_tracing(struct bpf_object *obj, struct bpf_monitor_ctx *ct
if (!trace_level || data_size != sizeof(*trace_level))
return -1;
- *trace_level = ctx->trace_types[TRACE_TYPE_EVENT];
+ *trace_level = config.trace_errors_only ?
+ ctx->trace_types[TRACE_TYPE_ERROR] :
+ ctx->trace_types[TRACE_TYPE_EVENT];
return 0;
}
diff --git a/tools/verification/rv/src/trace.c b/tools/verification/rv/src/trace.c
index 6fdbff2c28d4..629b4f63e147 100644
--- a/tools/verification/rv/src/trace.c
+++ b/tools/verification/rv/src/trace.c
@@ -213,7 +213,7 @@ static int enable_generic_event(struct trace_instance *inst, const char *event_n
*/
static int enable_bpf_events(struct trace_instance *inst, char *name)
{
- if (enable_generic_event(inst, "event_monitor", name))
+ if (!config.trace_errors_only && enable_generic_event(inst, "event_monitor", name))
return -1;
if (enable_generic_event(inst, "error_monitor", name))
@@ -228,6 +228,7 @@ static int enable_bpf_events(struct trace_instance *inst, char *name)
* Enable the rv:event_"monitor" and rv:error_"monitor" events in the
* given trace instance, and register the filters for these events.
* If enabled, the filter for self pid (-s) is applied here.
+ * Skip the "event" events if errors only (-E) is specified.
*
* Returns 0 on success, -1 otherwise.
*/
@@ -238,9 +239,11 @@ static int trace_enable_monitor_events(struct trace_instance *inst, char *name)
if (config.is_bpf)
return enable_bpf_events(inst, name);
- snprintf(event, sizeof(event), "event_%s", name);
- if (enable_specific_event(inst, event))
- return -1;
+ if (!config.trace_errors_only) {
+ snprintf(event, sizeof(event), "event_%s", name);
+ if (enable_specific_event(inst, event))
+ return -1;
+ }
snprintf(event, sizeof(event), "error_%s", name);
if (enable_specific_event(inst, event))
diff --git a/tools/verification/rv/src/utils.c b/tools/verification/rv/src/utils.c
index 1b1ad7a3ca32..854028324325 100644
--- a/tools/verification/rv/src/utils.c
+++ b/tools/verification/rv/src/utils.c
@@ -65,6 +65,7 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...)
" -r/--reactor 'reactor': enables the 'reactor'",
" -s/--self: when tracing (-t), also trace rv command",
" -t/--trace: trace monitor's event",
+ " -E/--errors-only: when tracing (-t), trace only errors",
" -v/--verbose: print debug messages",
"",
NULL,
@@ -76,7 +77,7 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...)
fprintf(stderr, " %s\n", message);
- fprintf(stderr, "\n usage: rv mon %s [-h] [-q] [-r reactor] [-s] [-v]", monitor_name);
+ fprintf(stderr, "\n usage: rv mon %s [-E] [-h] [-r reactor] [-s] [-t] [-v]", monitor_name);
for (i = 0; usage[i]; i++)
fprintf(stderr, "%s\n", usage[i]);
@@ -103,6 +104,7 @@ int parse_arguments(char *monitor_name, int argc, char **argv)
{"reactor", required_argument, 0, 'r'},
{"self", no_argument, 0, 's'},
{"trace", no_argument, 0, 't'},
+ {"errors-only", no_argument, 0, 'E'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
@@ -110,7 +112,7 @@ int parse_arguments(char *monitor_name, int argc, char **argv)
/* getopt_long stores the option index here. */
int option_index = 0;
- c = getopt_long(argc, argv, "hr:stv", long_options, &option_index);
+ c = getopt_long(argc, argv, "hr:stvE", long_options, &option_index);
/* detect the end of the options. */
if (c == -1)
@@ -132,6 +134,9 @@ int parse_arguments(char *monitor_name, int argc, char **argv)
case 'v':
config.debug = 1;
break;
+ case 'E':
+ config.trace_errors_only = 1;
+ break;
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (14 preceding siblings ...)
2026-11-26 13:00 ` [PATCH v3 15/18] tools/rv: Add -E/--errors-only option Gabriele Monaco
@ 2026-11-26 13:00 ` Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 17/18] tools/rv: Add selftest for rv bpf monitors Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 18/18] verification/rvgen: Add selftest for rvgen -b Gabriele Monaco
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 13:00 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add the -b flag to rvgen monitor to generate a bpf monitor.
By default the code is generated in a folder with the same name as the
model just like in-kernel monitors, although only the source and header
are meaningful here. Passing -a moves the sources to
tools/verification/rv/bpf_monitors/ where they can be built directly.
Currently BPF monitors are only supported for DA.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
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 +++++++++++++++
5 files changed, 80 insertions(+), 19 deletions(-)
create mode 100644 tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c
diff --git a/tools/verification/rvgen/__main__.py b/tools/verification/rvgen/__main__.py
index 246b43fa29f1..16ce9b512fbb 100644
--- a/tools/verification/rvgen/__main__.py
+++ b/tools/verification/rvgen/__main__.py
@@ -39,6 +39,8 @@ if __name__ == '__main__':
help="Monitor specification file")
monitor_parser.add_argument('-t', "--monitor_type", dest="monitor_type", required=True,
help=f"Available options: {', '.join(Monitor.monitor_types.keys())}")
+ monitor_parser.add_argument('-b', "--bpf", dest="bpf", action="store_true",
+ required=False, help="Generate a BPF monitor")
container_parser = subparsers.add_parser("container", parents=[parent_parser])
container_parser.add_argument('-n', "--model_name", dest="model_name", required=True)
@@ -50,6 +52,9 @@ if __name__ == '__main__':
params = parser.parse_args()
+ if params.subcmd == "monitor" and params.bpf and params.monitor_class != "da":
+ parser.error("BPF monitors (-b/--bpf) are only supported for deterministic automaton (-c da)")
+
try:
if params.subcmd == "monitor":
print(f"Opening and parsing the specification file {params.spec}")
@@ -80,7 +85,9 @@ if __name__ == '__main__':
print("Almost done, checklist")
if params.subcmd == "monitor":
print(f" - Edit the {monitor.name}/{monitor.name}.c to add the instrumentation")
- print(monitor.fill_tracepoint_tooltip())
- print(monitor.fill_makefile_tooltip())
- print(monitor.fill_kconfig_tooltip())
- print(monitor.fill_monitor_tooltip())
+ if not params.bpf:
+ print(monitor.fill_tracepoint_tooltip())
+ if not params.subcmd == "monitor" or not params.bpf:
+ print(monitor.fill_makefile_tooltip())
+ print(monitor.fill_kconfig_tooltip())
+ print(monitor.fill_monitor_tooltip())
diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/rvgen/rvgen/dot2c.py
index c6bd4d00d92e..246b76931660 100644
--- a/tools/verification/rvgen/rvgen/dot2c.py
+++ b/tools/verification/rvgen/rvgen/dot2c.py
@@ -111,10 +111,17 @@ class Dot2c(Automata):
min_type = self.get_minimun_type()
buff = []
buff.append(f"struct {self.struct_automaton_def} {{")
- buff.append(f"\tconst char *state_names[state_max{self.enum_suffix}];")
- buff.append(f"\tconst char *event_names[event_max{self.enum_suffix}];")
- if self.is_hybrid_automata():
- buff.append(f"\tconst char *env_names[env_max{self.enum_suffix}];")
+ if self.bpf:
+ # BPF struggles with non-fixed string pointers
+ buff.append(f"\tconst char state_names[state_max{self.enum_suffix}][32];")
+ buff.append(f"\tconst char event_names[event_max{self.enum_suffix}][32];")
+ if self.is_hybrid_automata():
+ buff.append(f"\tconst char env_names[env_max{self.enum_suffix}][32];")
+ else:
+ buff.append(f"\tconst char *state_names[state_max{self.enum_suffix}];")
+ buff.append(f"\tconst char *event_names[event_max{self.enum_suffix}];")
+ if self.is_hybrid_automata():
+ buff.append(f"\tconst char *env_names[env_max{self.enum_suffix}];")
buff.append(f"\t{min_type} function[state_max{self.enum_suffix}][event_max{self.enum_suffix}];")
buff.append(f"\t{min_type} initial_state;")
buff.append(f"\tbool final_states[state_max{self.enum_suffix}];")
diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/rvgen/rvgen/dot2k.py
index b48895b93c8a..d0677da59172 100644
--- a/tools/verification/rvgen/rvgen/dot2k.py
+++ b/tools/verification/rvgen/rvgen/dot2k.py
@@ -30,14 +30,19 @@ class dot2k(Monitor, Dot2c):
buff = [ self.monitor_type.upper() ]
buff += self._fill_timer_type()
if self.monitor_type == "per_obj":
- buff.append("typedef /* XXX: define the target type */ *monitor_target;")
+ pad = "_bpf" if self.bpf else ""
+ buff.append(f"typedef /* XXX: define the target type */ *monitor_target{pad};")
return "\n".join(buff)
def fill_tracepoint_handlers_skel(self) -> str:
buff = []
buff += self._fill_hybrid_definitions()
for event in self.events:
- buff.append(f"static void handle_{event}(void *data, /* XXX: fill header */)")
+ if self.bpf:
+ buff.append("SEC(/* XXX: tracepoint or other probe */)")
+ buff.append(f"int BPF_PROG(handle_{event}, /* XXX: fill header */)")
+ else:
+ buff.append(f"static void handle_{event}(void *data, /* XXX: fill header */)")
buff.append("{")
handle = "handle_event"
if self.is_start_event(event):
@@ -50,19 +55,28 @@ class dot2k(Monitor, Dot2c):
buff.append("\tstruct task_struct *p = /* XXX: how do I get p? */;")
buff.append(f"\tda_{handle}(p, {event}{self.enum_suffix});")
elif self.monitor_type == "per_obj":
+ pad = "_bpf" if self.bpf else ""
buff.append("\tint id = /* XXX: how do I get the id? */;")
- buff.append("\tmonitor_target t = /* XXX: how do I get t? */;")
+ buff.append(f"\tmonitor_target{pad} t = /* XXX: how do I get t? */;")
buff.append(f"\tda_{handle}(id, t, {event}{self.enum_suffix});")
else:
buff.append(f"\tda_{handle}({event}{self.enum_suffix});")
+ if self.bpf:
+ buff.append("\treturn 0;")
buff.append("}")
buff.append("")
if self.monitor_type == "per_obj":
buff.append("/* XXX: obj is being destroyed, remove if not required (e.g. obj is static) */")
- buff.append(f"static void handle_{self.cleanup_marker}(void *data, /* XXX: fill header */)")
+ if self.bpf:
+ buff.append("SEC(/* XXX: tracepoint or other probe */)")
+ buff.append(f"int BPF_PROG(handle_{self.cleanup_marker}, /* XXX: fill header */)")
+ else:
+ buff.append(f"static void handle_{self.cleanup_marker}(void *data, /* XXX: fill header */)")
buff.append("{")
buff.append("\tint id = /* XXX: how do I get the id? */;")
buff.append("\tda_destroy_storage(id);")
+ if self.bpf:
+ buff.append("\treturn 0;")
buff.append("}")
buff.append("")
return '\n'.join(buff)
diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verification/rvgen/rvgen/generator.py
index 626bb7ce90ee..8895a264cf0c 100644
--- a/tools/verification/rvgen/rvgen/generator.py
+++ b/tools/verification/rvgen/rvgen/generator.py
@@ -11,18 +11,22 @@ from pathlib import Path
class RVGenerator:
rv_dir = "kernel/trace/rv"
+ rv_tool_dir = "../../../tools/verification/rv/bpf_monitors/"
def __init__(self, extra_params={}):
self.name = extra_params.get("model_name")
self.parent = extra_params.get("parent")
+ self.bpf = extra_params.get("bpf")
self.abs_template_dir = \
Path(__file__).resolve().parent / "templates" / self.template_dir
- self.main_c = self._read_template_file("main.c")
+ self.main_c = self._read_template_file("main.c" if not self.bpf
+ else "main_bpf.c")
self.kconfig = self._read_template_file("Kconfig")
self.description = extra_params.get("description", self.name) or "auto-generated"
self.auto_patch = extra_params.get("auto_patch")
if self.auto_patch:
self._fill_rv_kernel_dir()
+ self.rv_tool_dir = (Path(self.rv_dir) / self.rv_tool_dir).resolve()
def _fill_rv_kernel_dir(self):
# find the kernel tree root relative to this file's location
@@ -188,6 +192,9 @@ obj-$(CONFIG_RV_MON_{name_up}) += monitors/{name}/{name}.o
def __create_directory(self):
path = Path(self.name)
if self.auto_patch:
+ if self.bpf:
+ # no directory for BPF monitors
+ return
path = Path(self.rv_dir) / "monitors" / path
path.mkdir(exist_ok=True)
@@ -199,6 +206,8 @@ obj-$(CONFIG_RV_MON_{name_up}) += monitors/{name}/{name}.o
path = Path(self.name) / file_name
if self.auto_patch:
path = Path(self.rv_dir) / "monitors" / self.name / file_name
+ if self.bpf:
+ path = Path(self.rv_tool_dir) / file_name
self.__write_file(path, content)
def print_files(self):
@@ -213,8 +222,9 @@ obj-$(CONFIG_RV_MON_{name_up}) += monitors/{name}/{name}.o
path = f"{self.name}.h"
self._create_file(path, model_h)
- kconfig = self.fill_kconfig()
- self._create_file("Kconfig", kconfig)
+ if not self.bpf:
+ kconfig = self.fill_kconfig()
+ self._create_file("Kconfig", kconfig)
class Monitor(RVGenerator):
@@ -222,7 +232,8 @@ class Monitor(RVGenerator):
def __init__(self, extra_params={}):
super().__init__(extra_params)
- self.trace_h = self._read_template_file("trace.h")
+ if not self.bpf:
+ self.trace_h = self._read_template_file("trace.h")
def _is_id_monitor(self):
return False
@@ -241,6 +252,7 @@ class Monitor(RVGenerator):
def print_files(self):
super().print_files()
- trace_h = self.fill_trace_h()
- path = f"{self.name}_trace.h"
- self._create_file(path, trace_h)
+ if not self.bpf:
+ trace_h = self.fill_trace_h()
+ path = f"{self.name}_trace.h"
+ self._create_file(path, trace_h)
diff --git a/tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c b/tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c
new file mode 100644
index 000000000000..1a83f3a2159a
--- /dev/null
+++ b/tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#define RV_MON_TYPE RV_MON_%%MONITOR_TYPE%%
+#include "%%MODEL_NAME%%.h"
+#include <rv/da_monitor.h>
+
+/*
+ * This is the instrumentation part of the monitor.
+ *
+ * This is the section where manual work is required. Here the kernel events
+ * are translated into model's event.
+ */
+%%TRACEPOINT_HANDLERS_SKEL%%
+static struct rv_monitor rv_this = {
+ .enabled = 0,
+};
+
+char LICENSE[] SEC("license") = "GPL";
+char DESCRIPTION[] SEC(".rodata.description") = "%%DESCRIPTION%%";
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 17/18] tools/rv: Add selftest for rv bpf monitors
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (15 preceding siblings ...)
2026-11-26 13:00 ` [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors Gabriele Monaco
@ 2026-11-26 13:00 ` Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 18/18] verification/rvgen: Add selftest for rvgen -b Gabriele Monaco
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 13:00 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add selftest cases for the rv userspace tool BPF monitors, test BPF
monitors listing and functionality, including traces and reactors.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
tools/verification/rv/tests/rv_list.t | 6 +-
tools/verification/rv/tests/rv_mon.t | 80 +++++++++++++++++++++++++--
2 files changed, 79 insertions(+), 7 deletions(-)
diff --git a/tools/verification/rv/tests/rv_list.t b/tools/verification/rv/tests/rv_list.t
index 201af33a52cc..9eae5c3c6eba 100644
--- a/tools/verification/rv/tests/rv_list.t
+++ b/tools/verification/rv/tests/rv_list.t
@@ -6,6 +6,8 @@ test_begin
set_timeout 30s
RVDIR=/sys/kernel/tracing/rv/
+# only works when running in the kernel tree
+RVTOOL=$(dirname "$RV")
# Help and basic tests
check "verify help page" \
@@ -17,13 +19,15 @@ check "verify list subcommand help" \
all_nested=$(grep : $RVDIR/available_monitors | cut -d: -f2 | paste -s | sed 's/\t/\\|/g')
all_non_nested=$(grep -v : $RVDIR/available_monitors | cut -d: -f2 | paste -s | sed 's/\t/\\|/g')
sched_monitors=$(grep sched: $RVDIR/available_monitors | cut -d: -f2 | paste -s | sed 's/\t/\\|/g')
+all_bpf=$(find "$RVTOOL/bpf_monitors" -name "*.o" -exec basename \{\} .o \; | paste -s | sed 's/\t/\\|/g')
description_state="[[:space:]]\+[[:print:]]\+\[\(OFF\|ON\)\]"
line_nested=" - \($all_nested\)${description_state}"
line_non_nested="\($all_non_nested\)${description_state}"
+[ -n "$all_bpf" ] && line_bpf="\($all_bpf\)${description_state}" || line_bpf="<empty>"
# List monitors and containers
check "list all monitors" \
- "$RV list" 0 "" "" "^\($line_nested\|$line_non_nested\)$"
+ "$RV list" 0 "" "" "^\($line_nested\|$line_non_nested\|$line_bpf\)$"
check_if_exists "list container" \
"$RV list sched" "$RVDIR/monitors/sched" \
diff --git a/tools/verification/rv/tests/rv_mon.t b/tools/verification/rv/tests/rv_mon.t
index cbc346c74c71..30d1ddaf0538 100644
--- a/tools/verification/rv/tests/rv_mon.t
+++ b/tools/verification/rv/tests/rv_mon.t
@@ -6,6 +6,7 @@ test_begin
set_timeout 30s
RVDIR=/sys/kernel/tracing/rv/
+RVTOOL=$(dirname "$RV")
# Help and basic tests
check "verify mon subcommand help" \
@@ -29,7 +30,28 @@ check "monitor name is substring of another monitor" \
check "already enabled monitor returns error" \
"echo 1 > $RVDIR/monitors/wwnr/enable; $RV mon wwnr" 1 \
"monitor wwnr (in-kernel) is already enabled"
-echo 0 > $RVDIR/monitors/wwnr/enable
+[ -n "$TEST_COUNT" ] && echo 0 > $RVDIR/monitors/wwnr/enable
+
+fi
+
+if [ -f "$RVTOOL/bpf_monitors/nohz.o" ]; then
+
+check "invalid BPF reactor name" \
+ "$RV mon nohz -r invalid" 1 "failed to set invalid reactor, is it available?"
+
+fi
+
+if [ -f "$RVTOOL/bpf_monitors/tqueue.o" ]; then
+
+[ -n "$TEST_COUNT" ] && { $RV mon tqueue & disown ; tmp=$! ; sleep 1 ; }
+check "already enabled BPF monitor returns error" \
+ "$RV mon tqueue" 1 "monitor tqueue (BPF) is already enabled"
+
+[ -n "$TEST_COUNT" ] && { kill -9 "$tmp" && sleep 1 ; }
+set_expected_timeout 1s
+
+check "crashed BPF monitor does not leak resources" \
+ "$RV mon tqueue" 0 "" "monitor tqueue (BPF) is already enabled"
fi
@@ -40,6 +62,12 @@ set_expected_timeout 2s
check_if_exists "run the monitor without parameters" \
"$RV mon wwnr" "$RVDIR/monitors/wwnr" "" "."
+check_if_exists "run a BPF monitor without parameters" \
+ "$RV mon nohz" "$RVTOOL/bpf_monitors/nohz.o" "" "."
+
+check_if_exists "run a per-task BPF monitor without parameters" \
+ "$RV mon tqueue" "$RVTOOL/bpf_monitors/tqueue.o" "" "."
+
check_if_exists "run the monitor as verbose" \
"$RV mon wwnr -v" "$RVDIR/monitors/wwnr" \
"my pid is \$pid" "\(event\|error\)"
@@ -60,21 +88,32 @@ check_if_exists "run an explicitly nested monitor with a reactor" \
"$RV mon sched:sssw -r printk & sleep .5 && cat $RVDIR/monitors/sched/sssw/reactors && wait" \
"$RVDIR/monitors/sched/sssw/reactors" "\[printk\]"
+TRACE=/sys/kernel/tracing/trace
+
check_if_exists "run container monitor" \
"$RV mon sched & sleep .5 && cat $RVDIR/monitors/sched/{sssw,sco}/enable && wait" \
"$RVDIR/monitors/sched" "1" "0" "^1$"
# Regexes for the trace
header="^[[:space:]]\+\(\([][A-Z_x<>-]\+\||\)[[:space:]]*\)\+$"
-type="\(event\|error\)[[:space:]]\+"
+mon="[a-z_]\+"
+type="\(event\|error\)_$mon"
genpid="[0-9]\+[[:space:]]\+"
selfpid="\$pid[[:space:]]\+"
cpu="\[[0-9]\{3\}\][[:space:]]\+"
state="[a-z_]\+ "
-trace_task="${genpid}${cpu}${type}${genpid}${state}"
-trace_task_self="${genpid}${cpu}${type}${selfpid}${state}"
-trace_cpu="${genpid}${cpu}${type}${state}"
-trace_cpu_self="${selfpid}${cpu}${type}${state}"
+id="[0-9]\+"
+selfid="\$pid"
+# BPF monitors report via the common rv:event_monitor/rv:error_monitor
+# events, which add a "<mon>: " prefix to the message.
+trace_task="${genpid}${cpu}${type}: ${id}: ${state}"
+trace_task_self="${genpid}${cpu}${type}: ${selfid}: ${state}"
+trace_cpu="${genpid}${cpu}${type}: ${state}"
+trace_cpu_self="${selfpid}${cpu}${type}: ${state}"
+trace_task_bpf="${genpid}${cpu}${type}: ${mon}: ${id}: ${state}"
+trace_task_bpf_self="${genpid}${cpu}${type}: ${mon}: ${selfid}: ${state}"
+trace_cpu_bpf="${genpid}${cpu}${type}: ${mon}: ${state}"
+trace_cpu_bpf_self="${selfpid}${cpu}${type}: ${mon}: ${state}"
check_if_exists "run per-task monitor with tracing" \
"$RV mon sssw -t" "$RVDIR/monitors/sched/sssw" \
@@ -92,4 +131,33 @@ check_if_exists "run per-cpu monitor tracing also self" \
"$RV mon sco -t -s" "$RVDIR/monitors/sched/sco" \
"$trace_cpu_self" "" "\($header\|$trace_cpu\)"
+check_if_exists "run per-task BPF monitor with tracing" \
+ "$RV mon tqueue -t" "$RVTOOL/bpf_monitors/tqueue.o" \
+ "$header" "$trace_task_bpf_self" "\($header\|$trace_task_bpf\)"
+
+check_if_exists "run per-task BPF monitor tracing also self" \
+ "$RV mon tqueue -t -s" "$RVTOOL/bpf_monitors/tqueue.o" \
+ "$trace_task_bpf_self" "" "\($header\|$trace_task_bpf\)"
+
+check_if_exists "run per-cpu BPF monitor with tracing" \
+ "$RV mon nohz -t" "$RVTOOL/bpf_monitors/nohz.o" \
+ "$header" "$trace_cpu_bpf_self" "\($header\|$trace_cpu_bpf\)"
+
+# This is unstable, we may never see events from self
+#check_if_exists "run per-cpu BPF monitor tracing also self" \
+# "$RV mon nohz -t -s" "$RVTOOL/bpf_monitors/nohz.o" \
+# "$trace_cpu_bpf_self" "" "\($header\|$trace_cpu_bpf\)"
+
+check_if_exists "run per-task monitor tracing only errors" \
+ "$RV mon sssw -t -E" "$RVDIR/monitors/sched/sssw" \
+ "$header" "event_"
+
+check_if_exists "run per-task BPF monitor tracing only errors" \
+ "$RV mon tqueue -t -E" "$RVTOOL/bpf_monitors/tqueue.o" \
+ "$header" "event_monitor"
+
+check_if_exists "run per-cpu BPF monitor tracing only errors" \
+ "$RV mon nohz -t -E" "$RVTOOL/bpf_monitors/nohz.o" \
+ "error_monitor" "event_monitor"
+
test_end
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 18/18] verification/rvgen: Add selftest for rvgen -b
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
` (16 preceding siblings ...)
2026-11-26 13:00 ` [PATCH v3 17/18] tools/rv: Add selftest for rv bpf monitors Gabriele Monaco
@ 2026-11-26 13:00 ` Gabriele Monaco
17 siblings, 0 replies; 20+ messages in thread
From: Gabriele Monaco @ 2026-11-26 13:00 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, bpf, Steven Rostedt,
Gabriele Monaco
Cc: Alexei Starovoitov, Nam Cao, Wen Yang, Tobias Schaffner,
Viktor Malik, Peter Zijlstra, John Ogness
Add selftest cases for BPF monitors generation.
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
.../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 +++++
5 files changed, 189 insertions(+)
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
diff --git a/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c b/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c
new file mode 100644
index 000000000000..5a652ce9b461
--- /dev/null
+++ b/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#define RV_MON_TYPE RV_MON_PER_CPU
+#include "da_bpf_cpu.h"
+#include <rv/da_monitor.h>
+
+/*
+ * This is the instrumentation part of the monitor.
+ *
+ * This is the section where manual work is required. Here the kernel events
+ * are translated into model's event.
+ */
+SEC(/* XXX: tracepoint or other probe */)
+int BPF_PROG(handle_event_1, /* XXX: fill header */)
+{
+ da_handle_event(event_1_da_bpf_cpu);
+ return 0;
+}
+
+SEC(/* XXX: tracepoint or other probe */)
+int BPF_PROG(handle_event_2, /* XXX: fill header */)
+{
+ /* XXX: validate that this event always leads to the initial state */
+ da_handle_start_event(event_2_da_bpf_cpu);
+ return 0;
+}
+
+static struct rv_monitor rv_this = {
+ .enabled = 0,
+};
+
+char LICENSE[] SEC("license") = "GPL";
+char DESCRIPTION[] SEC(".rodata.description") = "auto-generated";
diff --git a/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h b/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h
new file mode 100644
index 000000000000..715b34a099f6
--- /dev/null
+++ b/tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of da_bpf_cpu automaton
+ * For further information about this format, see kernel documentation:
+ * Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME da_bpf_cpu
+
+enum states_da_bpf_cpu {
+ state_a_da_bpf_cpu,
+ state_b_da_bpf_cpu,
+ state_max_da_bpf_cpu,
+};
+
+#define INVALID_STATE state_max_da_bpf_cpu
+
+enum events_da_bpf_cpu {
+ event_1_da_bpf_cpu,
+ event_2_da_bpf_cpu,
+ event_max_da_bpf_cpu,
+};
+
+struct automaton_da_bpf_cpu {
+ const char state_names[state_max_da_bpf_cpu][32];
+ const char event_names[event_max_da_bpf_cpu][32];
+ unsigned char function[state_max_da_bpf_cpu][event_max_da_bpf_cpu];
+ unsigned char initial_state;
+ bool final_states[state_max_da_bpf_cpu];
+};
+
+static const struct automaton_da_bpf_cpu automaton_da_bpf_cpu = {
+ .state_names = {
+ "state_a",
+ "state_b",
+ },
+ .event_names = {
+ "event_1",
+ "event_2",
+ },
+ .function = {
+ { state_b_da_bpf_cpu, state_a_da_bpf_cpu },
+ { INVALID_STATE, state_a_da_bpf_cpu },
+ },
+ .initial_state = state_a_da_bpf_cpu,
+ .final_states = { 1, 0 },
+};
diff --git a/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c b/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c
new file mode 100644
index 000000000000..a7d465f84f05
--- /dev/null
+++ b/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#define RV_MON_TYPE RV_MON_PER_OBJ
+typedef /* XXX: define the target type */ *monitor_target_bpf;
+#include "da_bpf_obj.h"
+#include <rv/da_monitor.h>
+
+/*
+ * This is the instrumentation part of the monitor.
+ *
+ * This is the section where manual work is required. Here the kernel events
+ * are translated into model's event.
+ */
+SEC(/* XXX: tracepoint or other probe */)
+int BPF_PROG(handle_event_1, /* XXX: fill header */)
+{
+ int id = /* XXX: how do I get the id? */;
+ monitor_target_bpf t = /* XXX: how do I get t? */;
+ da_handle_event(id, t, event_1_da_bpf_obj);
+ return 0;
+}
+
+SEC(/* XXX: tracepoint or other probe */)
+int BPF_PROG(handle_event_2, /* XXX: fill header */)
+{
+ /* XXX: validate that this event always leads to the initial state */
+ int id = /* XXX: how do I get the id? */;
+ monitor_target_bpf t = /* XXX: how do I get t? */;
+ da_handle_start_event(id, t, event_2_da_bpf_obj);
+ return 0;
+}
+
+/* XXX: obj is being destroyed, remove if not required (e.g. obj is static) */
+SEC(/* XXX: tracepoint or other probe */)
+int BPF_PROG(handle_obj_cleanup, /* XXX: fill header */)
+{
+ int id = /* XXX: how do I get the id? */;
+ da_destroy_storage(id);
+ return 0;
+}
+
+static struct rv_monitor rv_this = {
+ .enabled = 0,
+};
+
+char LICENSE[] SEC("license") = "GPL";
+char DESCRIPTION[] SEC(".rodata.description") = "auto-generated";
diff --git a/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h b/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h
new file mode 100644
index 000000000000..f42fa733abee
--- /dev/null
+++ b/tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of da_bpf_obj automaton
+ * For further information about this format, see kernel documentation:
+ * Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME da_bpf_obj
+
+enum states_da_bpf_obj {
+ state_a_da_bpf_obj,
+ state_b_da_bpf_obj,
+ state_max_da_bpf_obj,
+};
+
+#define INVALID_STATE state_max_da_bpf_obj
+
+enum events_da_bpf_obj {
+ event_1_da_bpf_obj,
+ event_2_da_bpf_obj,
+ event_max_da_bpf_obj,
+};
+
+struct automaton_da_bpf_obj {
+ const char state_names[state_max_da_bpf_obj][32];
+ const char event_names[event_max_da_bpf_obj][32];
+ unsigned char function[state_max_da_bpf_obj][event_max_da_bpf_obj];
+ unsigned char initial_state;
+ bool final_states[state_max_da_bpf_obj];
+};
+
+static const struct automaton_da_bpf_obj automaton_da_bpf_obj = {
+ .state_names = {
+ "state_a",
+ "state_b",
+ },
+ .event_names = {
+ "event_1",
+ "event_2",
+ },
+ .function = {
+ { state_b_da_bpf_obj, state_a_da_bpf_obj },
+ { INVALID_STATE, state_a_da_bpf_obj },
+ },
+ .initial_state = state_a_da_bpf_obj,
+ .final_states = { 1, 0 },
+};
diff --git a/tools/verification/rvgen/tests/rvgen_monitor.t b/tools/verification/rvgen/tests/rvgen_monitor.t
index 5f2562600bad..3d71685a7ad5 100644
--- a/tools/verification/rvgen/tests/rvgen_monitor.t
+++ b/tools/verification/rvgen/tests/rvgen_monitor.t
@@ -47,6 +47,17 @@ check_and_compare_folder "LTL per_task with parent and description (default name
"$RVGEN monitor -c ltl -s tests/specs/test_ltl.ltl -t per_task -p ltl_parent -D 'Simple description'" \
"test_ltl" "LTL_MON_EVENTS_ID"
+# BPF monitor test
+check_and_compare_folder "DA BPF per_cpu" \
+ "$RVGEN monitor -b -c da -s tests/specs/test_da.dot -t per_cpu -n da_bpf_cpu" \
+ "da_bpf_cpu" "Edit the da_bpf_cpu/da_bpf_cpu.c to add the instrumentation" \
+ "Edit kernel/trace/rv/Makefile"
+
+check_and_compare_folder "DA BPF per_obj" \
+ "$RVGEN monitor -b -c da -s tests/specs/test_da.dot -t per_obj -n da_bpf_obj" \
+ "da_bpf_obj" "Edit the da_bpf_obj/da_bpf_obj.c to add the instrumentation" \
+ "Edit kernel/trace/rv/Kconfig"
+
# Error handling tests
check "missing required spec argument" \
"$RVGEN monitor -c da -t per_cpu" 2 \
--
2.56.1
^ permalink raw reply related [flat|nested] 20+ messages in thread