Skip to contentSkip to conversation

Add support for BPF monitors

PATCH New Gabriele Monaco 3 participants 27 messages Nov 26

Subsystems (5)
Documentation BPF Tracing Scheduler +1 more subsystems
lore
Share & tools
lore

Gabriele Monaco

author maintainer
#0 lore raw

v3 cover Add support for BPF monitors

Extend the rv userspace tool to load BPF monitors, those can be found in specific locations (e.g. /usr/share/rv/bpf_monitors/) and are plain object files including BTF data.

This type of BPF monitors can be generated from rvgen using the -b flag just like in-kernel monitors and, after manual adaptation, can be built and run transparently by the rv userspace tool.

Only DA monitors are supported (as they are the only class the rv tool currenly supports) and the tool aims to work in the same way for both in-kernel and BPF monitors.

The da_monitor header is adapted to be included directly in BPF programs and share as much logic as possible.

BPF monitors are implemented purely in BPF and as such require the rv userspace tool for any operation:
* listing: find properly formatted objects in specific locations
* running: load trace handlers for events
* tracing: read event/errors from the ring buffer

Selftests (make -C tools/verification/rv check) are present to validate and demonstrate the usage, which is mostly equivalent to the standard rv tool usage.

Patch 1 adds tracepoints required in a later monitor example. Patch 2 improves the rv tool selftest reporting.
Patches 3-5 prepare the kernel headers for BPF support. Patch 6 adds a feature check for tools/build.
Patch 7-11 prepare and add support for BPF monitors in the rv tool. Patch 12-15 prepare and include BPF monitors examples.
Patch 16 adds support for generating BPF monitors in rvgen. Patch 17-18 adds BPF selftests (make check) for the rv and rvgen tools.

Changes since V2 [1]:
* Use BPF_MAP_TYPE_TASK_STORAGE for per-task monitors.
* Drop useless relocation removal in Makefile.
* Avoid cast and propagate const to all tracepoints.
* Validate monitor names before running.
* Drop reactors for BPF monitors.
* Use new generic tracepoints for BPF monitors and drop ringbuf.
* Add -E/--errors-only option in the userspace tool.
* Use an OFD lock to determine if monitors are enabled.

Changes since RFC [2]:
* Drop struct_ops integration to favour a BPF-only implementation.
* Implement BPF reactors with a dynamic linker.
* Don't pin programs and maps.
* Improve handler performance when not tracing.

[1] - https://lore.kernel.org/lkml/[email protected]
[2] - https://lore.kernel.org/lkml/[email protected]

To: [email protected]
To: [email protected]
Cc: Steven Rostedt <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Nam Cao <[email protected]>
Cc: Wen Yang <[email protected]>
Cc: Tobias Schaffner <[email protected]>
Cc: Viktor Malik <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: John Ogness <[email protected]>

Gabriele Monaco (17):
tools/rv: Skip empty pid error in selftest if command failed
rv: Add wrapper macros for monitor tracepoint definitions
rv: Propagate const to model strings and tracepoints
rv: Add generic monitor event tracepoints and BPF kfuncs tools/build: Add a feature test for bpftool-btf tools/rv: Move argument parsing from in_kernel to utils tools/rv: Move monitor trace handling to trace.c tools/rv: Implement BPF monitor discovery and listing tools/rv: Implement BPF monitor loading and tracing tools/rv: Rework tracing to support generic events tools/rv: Copy stripped bpf_atomic.h from libarena tools/rv: Add BPF monitors
tools/rv: Define CONFIG_X86_64 statically for BPF monitors tools/rv: Add -E/--errors-only option verification/rvgen: Add support for BPF monitors tools/rv: Add selftest for rv bpf monitors verification/rvgen: Add selftest for rvgen -b

Nam Cao (1):
sched: Add task enqueue/dequeue trace points

 Documentation/tools/rv/common_ikm.rst         |   6 +
 include/rv/automata.h                         |   4 +-
 include/rv/da_monitor.h                       |  33 +-
 include/rv/ha_monitor.h                       |  10 +-
 include/trace/events/sched.h                  |   8 +
 kernel/sched/core.c                           |  12 +-
 kernel/sched/sched.h                          |   2 +
 kernel/trace/rv/Makefile                      |   1 +
 kernel/trace/rv/monitors/nomiss/nomiss.h      |   6 +-
 .../trace/rv/monitors/nomiss/nomiss_trace.h   |  14 +-
 kernel/trace/rv/monitors/nrp/nrp.h            |   4 +-
 kernel/trace/rv/monitors/nrp/nrp_trace.h      |   9 +-
 kernel/trace/rv/monitors/opid/opid.h          |   6 +-
 kernel/trace/rv/monitors/opid/opid_trace.h    |  14 +-
 .../rv/monitors/pagefault/pagefault_trace.h   |   8 +-
 kernel/trace/rv/monitors/sco/sco.h            |   4 +-
 kernel/trace/rv/monitors/sco/sco_trace.h      |   9 +-
 kernel/trace/rv/monitors/scpd/scpd.h          |   4 +-
 kernel/trace/rv/monitors/scpd/scpd_trace.h    |   9 +-
 kernel/trace/rv/monitors/sleep/sleep_trace.h  |   8 +-
 kernel/trace/rv/monitors/snep/snep.h          |   4 +-
 kernel/trace/rv/monitors/snep/snep_trace.h    |   9 +-
 kernel/trace/rv/monitors/snroc/snroc.h        |   4 +-
 kernel/trace/rv/monitors/snroc/snroc_trace.h  |   9 +-
 kernel/trace/rv/monitors/sssw/sssw.h          |   4 +-
 kernel/trace/rv/monitors/sssw/sssw_trace.h    |   9 +-
 kernel/trace/rv/monitors/stall/stall.h        |   6 +-
 kernel/trace/rv/monitors/stall/stall_trace.h  |  14 +-
 kernel/trace/rv/monitors/sts/sts.h            |   4 +-
 kernel/trace/rv/monitors/sts/sts_trace.h      |   9 +-
 .../trace/rv/monitors/wakeup/wakeup_trace.h   |   8 +-
 kernel/trace/rv/monitors/wip/wip.h            |   4 +-
 kernel/trace/rv/monitors/wip/wip_trace.h      |   9 +-
 kernel/trace/rv/monitors/wwnr/wwnr.h          |   4 +-
 kernel/trace/rv/monitors/wwnr/wwnr_trace.h    |   9 +-
 kernel/trace/rv/rv_bpf.c                      |  76 ++
 kernel/trace/rv/rv_reactors.c                 |   2 +-
 kernel/trace/rv/rv_trace.h                    | 100 ++-
 tools/build/Makefile.feature                  |   1 +
 tools/build/feature/Makefile                  |   7 +-
 tools/verification/models/nohz.dot            |  16 +
 tools/verification/models/tqueue.dot          |  15 +
 tools/verification/rv/Makefile                |  45 +-
 tools/verification/rv/Makefile.config         |  49 ++
 tools/verification/rv/Makefile.rv             |   5 +
 tools/verification/rv/bpf_monitors/.gitignore |   2 +
 .../verification/rv/bpf_monitors/bpf_atomic.h | 125 +++
 .../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 ++
 tools/verification/rv/include/bpf_monitor.h   |  20 +
 tools/verification/rv/include/trace.h         |   4 +-
 tools/verification/rv/include/utils.h         |  19 +-
 tools/verification/rv/src/Build               |   5 +
 tools/verification/rv/src/bpf_monitor.c       | 738 ++++++++++++++++++
 tools/verification/rv/src/in_kernel.c         | 439 +----------
 tools/verification/rv/src/rv.c                |   5 +
 tools/verification/rv/src/trace.c             | 237 +++++-
 tools/verification/rv/src/utils.c             | 103 ++-
 tools/verification/rv/tests/rv_list.t         |   6 +-
 tools/verification/rv/tests/rv_mon.t          |  80 +-
 tools/verification/rvgen/__main__.py          |  15 +-
 tools/verification/rvgen/rvgen/dot2c.py       |  15 +-
 tools/verification/rvgen/rvgen/dot2k.py       |  50 +-
 tools/verification/rvgen/rvgen/generator.py   |  40 +-
 .../rvgen/rvgen/templates/dot2k/main_bpf.c    |  21 +
 .../rvgen/rvgen/templates/dot2k/trace.h       |   7 +-
 .../rvgen/templates/dot2k/trace_hybrid.h      |  11 +-
 .../rvgen/rvgen/templates/ltl2k/trace.h       |   8 +-
 .../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 ++
 .../rvgen/tests/golden/da_global/da_global.h  |   4 +-
 .../tests/golden/da_global/da_global_trace.h  |   9 +-
 .../da_perobj_parent/da_perobj_parent.h       |   4 +-
 .../da_perobj_parent/da_perobj_parent_trace.h |   9 +-
 .../golden/da_pertask_desc/da_pertask_desc.h  |   4 +-
 .../da_pertask_desc/da_pertask_desc_trace.h   |   9 +-
 .../rvgen/tests/golden/ha_percpu/ha_percpu.h  |   6 +-
 .../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 +-
 .../rvgen/tests/golden/test_da/test_da.h      |   4 +-
 .../tests/golden/test_da/test_da_trace.h      |   9 +-
 .../golden/test_da_kunit/test_da_kunit.h      |   4 +-
 .../test_da_kunit/test_da_kunit_trace.h       |   9 +-
 .../rvgen/tests/golden/test_ha/test_ha.h      |   6 +-
 .../tests/golden/test_ha/test_ha_trace.h      |  14 +-
 .../golden/test_ha_kunit/test_ha_kunit.h      |   6 +-
 .../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 +-
 .../verification/rvgen/tests/rvgen_monitor.t  |  11 +
 tools/verification/tests/engine.sh            |   5 +-
 97 files changed, 2674 insertions(+), 809 deletions(-)
 create mode 100644 kernel/trace/rv/rv_bpf.c
 create mode 100644 tools/verification/models/nohz.dot
 create mode 100644 tools/verification/models/tqueue.dot
 create mode 100644 tools/verification/rv/bpf_monitors/.gitignore
 create mode 100644 tools/verification/rv/bpf_monitors/bpf_atomic.h
 create mode 100644 tools/verification/rv/bpf_monitors/da_monitor_bpf.h
 create mode 100644 tools/verification/rv/bpf_monitors/nohz.c
 create mode 100644 tools/verification/rv/bpf_monitors/nohz.h
 create mode 100644 tools/verification/rv/bpf_monitors/tqueue.c
 create mode 100644 tools/verification/rv/bpf_monitors/tqueue.h
 create mode 100644 tools/verification/rv/include/bpf_monitor.h
 create mode 100644 tools/verification/rv/src/bpf_monitor.c
 create mode 100644 tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c
 create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c
 create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h
 create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c
 create mode 100644 tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Signature · 1 line
2.56.1
author maintainer
#1 lore raw

PATCH v3 1/18 sched: Add task enqueue/dequeue trace points

From: Nam Cao <[email protected]>

Add trace points into enqueue_task() and dequeue_task().

---
 include/trace/events/sched.h |  8 ++++++++
 kernel/sched/core.c          | 12 +++++++++++-
 kernel/sched/sched.h         |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)
include/trace/events/sched.h +8 -0
index 535860581f15..d6e41edc25d2 100644
@@ -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
kernel/sched/core.c +11 -1
index 515b9d0353ce..69800a8dec05 100644
@@ -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)
kernel/sched/sched.h +2 -0
index a4e6696e3a51..d22e6c6d1b2d 100644
@@ -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++;
 
Signature · 1 line
2.56.1
author maintainer
#3 lore raw

PATCH v3 2/18 tools/rv: Skip empty pid error in selftest if command failed

In reply to Gabriele Monaco

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")
---
 tools/verification/tests/engine.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/verification/tests/engine.sh +3 -2
index cfdf2180aad8..4dad43b0b822 100644
@@ -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
Signature · 1 line
2.56.1
author maintainer
#4 lore raw

PATCH v3 3/18 Add wrapper macros for monitor tracepoint definitions

In reply to Gabriele Monaco

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.

---
 .../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(-)
kernel/trace/rv/monitors/nomiss/nomiss_trace.h +3 -11
index 42e7efaca4e7..2863b905e0db 100644
@@ -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 */
kernel/trace/rv/monitors/nrp/nrp_trace.h +2 -7
index 2e13497de3b6..3d85bdcbcd90 100644
@@ -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 */
kernel/trace/rv/monitors/opid/opid_trace.h +3 -11
index b04005b64208..914763d5dbf4 100644
@@ -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 */
kernel/trace/rv/monitors/pagefault/pagefault_trace.h +2 -6
index fe1f82597b1a..4b49ddbbb244 100644
@@ -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 */
kernel/trace/rv/monitors/sco/sco_trace.h +2 -7
index b711cd9024ec..36ec9b876df5 100644
@@ -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 */
kernel/trace/rv/monitors/scpd/scpd_trace.h +2 -7
index 6b0f4aa4732e..ad330701eb2d 100644
@@ -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 */
kernel/trace/rv/monitors/sleep/sleep_trace.h +2 -6
index 22eaf31da987..44a22828a810 100644
@@ -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 */
kernel/trace/rv/monitors/snep/snep_trace.h +2 -7
index 01aad49a949a..94edc47b30b9 100644
@@ -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 */
kernel/trace/rv/monitors/snroc/snroc_trace.h +2 -7
index 50114cef5122..20462159988a 100644
@@ -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 */
kernel/trace/rv/monitors/sssw/sssw_trace.h +2 -7
index 6c03cfc6960b..26cffbf9ed62 100644
@@ -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 */
kernel/trace/rv/monitors/stall/stall_trace.h +3 -11
index 6a7cc1b1d040..9da0aedf01c1 100644
@@ -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 */
kernel/trace/rv/monitors/sts/sts_trace.h +2 -7
index d78beb58d5b3..5b7d5e359290 100644
@@ -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 */
kernel/trace/rv/monitors/wakeup/wakeup_trace.h +2 -6
index 7e056183f920..817826d77341 100644
@@ -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 */
kernel/trace/rv/monitors/wip/wip_trace.h +2 -7
index aa2162f47a4c..454333ea51e3 100644
@@ -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 */
kernel/trace/rv/monitors/wwnr/wwnr_trace.h +2 -7
index fc97ec7476ad..c395bb01542b 100644
@@ -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 */
kernel/trace/rv/rv_trace.h +44 -0

74 lines not on this page · raw message

tools/verification/rvgen/rvgen/dot2k.py +0 -28
index fd3254ea5b4d..b48895b93c8a 100644
@@ -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 []
tools/verification/rvgen/rvgen/generator.py +5 -9
index 45e2bab26cb5..626bb7ce90ee 100644
@@ -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):
tools/verification/rvgen/rvgen/templates/dot2k/trace.h +2 -5
index 87d3a1308926..44ef49457bbe 100644
@@ -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%% */
tools/verification/rvgen/rvgen/templates/dot2k/trace_hybrid.h +3 -8
index c8290e9ba2f4..6b49529bc0e5 100644
@@ -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%% */
tools/verification/rvgen/rvgen/templates/ltl2k/trace.h +2 -6
index 49394c4b0f1c..47266a383ac9 100644
@@ -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%% */
tools/verification/rvgen/tests/golden/da_global/da_global_trace.h +2 -7
index 4d2730b71dd0..4be02dfaed97 100644
@@ -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 */
tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent_trace.h +2 -7
index 59bfca8f73d2..6e99897f51d1 100644
@@ -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 */
tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc_trace.h +2 -7
index 4e6086c4d86e..2198f0626fb5 100644
@@ -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 */
tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h +3 -11
index 074ddff6a60d..374c5daa9c30 100644
@@ -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 */
tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h +2 -6
index ebd53621a5b1..34eb6cda2026 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_trace.h +2 -6
index b984208838c4..580de388f415 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_da/test_da_trace.h +2 -7
index 8bd67115d244..77107e1033ac 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_trace.h +2 -7
index 16804a79e834..8ef5c32e9224 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h +3 -11
index 381bafcb3322..77623246b4b6 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_trace.h +3 -11
index 6c13ee0068d3..9de08745e46e 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h +2 -6
index 3571b004c114..72609d3d5570 100644
@@ -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 */
tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_trace.h +2 -6
index a054d5b2c0ea..039fd38dde9f 100644
@@ -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 */
Signature · 1 line
2.56.1
author maintainer
#5 lore raw

PATCH v3 4/18 Propagate const to model strings and tracepoints

In reply to Gabriele Monaco

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.

---
 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(-)
include/rv/automata.h +2 -2
index 4a4eb40cf09a..e4afd5ba1d06 100644
@@ -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";
include/rv/da_monitor.h +6 -6
index 6fc5ef8142ac..fc830c9f5046 100644
@@ -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);
include/rv/ha_monitor.h +5 -5
index 6e1c7fe5449a..0952a3f161c3 100644
@@ -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);
kernel/trace/rv/monitors/nomiss/nomiss.h +3 -3
index 3d1b436194d7..0e74a27bc38c 100644
@@ -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];
kernel/trace/rv/monitors/nrp/nrp.h +2 -2
index 3270d4c0139f..f6c1ec62233d 100644
@@ -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];
kernel/trace/rv/monitors/opid/opid.h +3 -3
index fb0aa4c28aa6..42680aa81f33 100644
@@ -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];
kernel/trace/rv/monitors/sco/sco.h +2 -2
index bac3beb51e72..65bcfcb136b7 100644
@@ -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];
kernel/trace/rv/monitors/scpd/scpd.h +2 -2
index d6329da2671b..e9742c2789f7 100644
@@ -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];
kernel/trace/rv/monitors/snep/snep.h +2 -2
index 357520a5b3d1..fabc363684d2 100644
@@ -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];
kernel/trace/rv/monitors/snroc/snroc.h +2 -2
index 88b7328ad31a..12aa743e4f19 100644
@@ -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];
kernel/trace/rv/monitors/sssw/sssw.h +2 -2
index 1a4b806061c3..ad8d7a18c52d 100644
@@ -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];
kernel/trace/rv/monitors/stall/stall.h +3 -3
index 638520cb1082..ce38b6b2311e 100644
@@ -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];
kernel/trace/rv/monitors/sts/sts.h +2 -2
index 6f7b2d9d72e6..74397c37cb0e 100644
@@ -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];
kernel/trace/rv/monitors/wip/wip.h +2 -2
index b4c3eea94c86..b65baeae5419 100644
@@ -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];
kernel/trace/rv/monitors/wwnr/wwnr.h +2 -2
index a28006512c9b..06d724ac1182 100644
@@ -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];
kernel/trace/rv/rv_reactors.c +1 -1
index 8e57a95d446b..8988b9ab2a40 100644
@@ -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;
 
kernel/trace/rv/rv_trace.h +21 -18
index 36e7c78c046e..24d4b94a54a5 100644
@@ -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),
 
tools/verification/rvgen/rvgen/dot2c.py +3 -3
index 22938ce1bf6c..c6bd4d00d92e 100644
@@ -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}];")
tools/verification/rvgen/tests/golden/da_global/da_global.h +2 -2
index 40b1f1c0c681..3faf0c92b8b0 100644
@@ -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];
tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_parent.h +2 -2
index 3c8dc3b22443..8027c4eec979 100644
@@ -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];
tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc.h +2 -2
index 837b238754b0..3e4501795f4a 100644
@@ -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];
tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h +3 -3
index 2538db4f6a26..ee8aa72d6d5a 100644
@@ -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];
tools/verification/rvgen/tests/golden/test_da/test_da.h +2 -2
index d55795efbb61..d4a230a1173d 100644
@@ -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];
tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h +2 -2
index 290a9454caa4..ef98895fac1b 100644
@@ -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];
tools/verification/rvgen/tests/golden/test_ha/test_ha.h +3 -3
index 949fa4453403..eb90c0600a69 100644
@@ -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];
tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h +3 -3
index 5c428f818bdf..153533e5d47a 100644
@@ -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];
Signature · 1 line
2.56.1
author maintainer
#6 lore raw

PATCH v3 5/18 Add generic monitor event tracepoints and BPF kfuncs

In reply to Gabriele Monaco

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).

---
 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
kernel/trace/rv/Makefile +1 -0
index c895d81dfdad..588250ce3fa9 100644
@@ -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
kernel/trace/rv/rv_bpf.c new file +76 -0

76 lines not on this page · raw message

kernel/trace/rv/rv_trace.h +37 -0
index 24d4b94a54a5..9fa9e1230e84 100644
@@ -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,
Signature · 1 line
2.56.1
author maintainer
#9 lore raw

PATCH v3 6/18 tools/build: Add a feature test for bpftool-btf

In reply to Gabriele Monaco

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.

---
 tools/build/Makefile.feature | 1 +
 tools/build/feature/Makefile | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/build/Makefile.feature +1 -0
index c010049d9720..79e08fc62bb5 100644
@@ -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))
tools/build/feature/Makefile +6 -1
index 359da8b98bc5..e021846fb662 100644
@@ -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,
Signature · 1 line
2.56.1
author maintainer
#10 lore raw

PATCH v3 7/18 tools/rv: Move argument parsing from in_kernel to utils

In reply to Gabriele Monaco

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.

---
 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(-)
tools/verification/rv/include/utils.h +16 -1
index f24ae8282bd2..61f77a72a1a2 100644
@@ -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;
tools/verification/rv/src/in_kernel.c +40 -136

307 lines not on this page · raw message

tools/verification/rv/src/utils.c +93 -2

114 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#11 lore raw

PATCH v3 8/18 tools/rv: Move monitor trace handling to trace.c

In reply to Gabriele Monaco

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

---
 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(-)
tools/verification/rv/include/trace.h +3 -1
index 8d89e8c303fa..e3d65ff3d544 100644
@@ -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);
tools/verification/rv/src/in_kernel.c +8 -287

349 lines not on this page · raw message

tools/verification/rv/src/trace.c +269 -21

321 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#12 lore raw

PATCH v3 9/18 tools/rv: Implement BPF monitor discovery and listing

In reply to Gabriele Monaco

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).

---
 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
tools/verification/rv/Makefile +3 -1
index 8ae5fc0d1d17..0a8c7a656f7f 100644
@@ -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)
tools/verification/rv/Makefile.config +23 -0
index 066302230eb2..0600170ac217 100644
@@ -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
tools/verification/rv/include/bpf_monitor.h new file +14 -0
new file mode 100644
index 000000000000..e58bc45c5f75
@@ -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
tools/verification/rv/src/Build +5 -0
index d781983c1a79..326503c22915 100644
@@ -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
tools/verification/rv/src/bpf_monitor.c new file +240 -0

240 lines not on this page · raw message

tools/verification/rv/src/rv.c +2 -0
index 09e0d8598619..7c4a2e49ff9d 100644
@@ -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);
 }
Signature · 1 line
2.56.1
author maintainer
#14 lore raw

PATCH v3 10/18 tools/rv: Implement BPF monitor loading and tracing

In reply to Gabriele Monaco

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.

---
 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(-)
tools/verification/rv/include/bpf_monitor.h +6 -0
index e58bc45c5f75..e650f11afdab 100644
@@ -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
tools/verification/rv/include/utils.h +2 -0
index 61f77a72a1a2..d6b4e60df7ff 100644
@@ -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;
tools/verification/rv/src/bpf_monitor.c +490 -0

510 lines not on this page · raw message

tools/verification/rv/src/rv.c +3 -0
index 7c4a2e49ff9d..571c9a14c1a2 100644
@@ -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);
tools/verification/rv/src/utils.c +5 -2
index e19dd65ec789..1b1ad7a3ca32 100644
@@ -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;
 }
Signature · 1 line
2.56.1
author maintainer
#16 lore raw

PATCH v3 11/18 tools/rv: Rework tracing to support generic events

In reply to Gabriele Monaco

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.

---
 tools/verification/rv/include/utils.h |   1 -
 tools/verification/rv/src/trace.c     | 256 +++++++++-----------------
 2 files changed, 92 insertions(+), 165 deletions(-)
tools/verification/rv/include/utils.h +0 -1
index d6b4e60df7ff..397a37981932 100644
@@ -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;
tools/verification/rv/src/trace.c +92 -164

324 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#18 lore raw

PATCH v3 12/18 tools/rv: Copy stripped bpf_atomic.h from libarena

In reply to Gabriele Monaco

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.

---
 .../verification/rv/bpf_monitors/bpf_atomic.h | 125 ++++++++++++++++++
 1 file changed, 125 insertions(+)
 create mode 100644 tools/verification/rv/bpf_monitors/bpf_atomic.h
tools/verification/rv/bpf_monitors/bpf_atomic.h new file +125 -0
new file mode 100644
index 000000000000..3cf9a78a15c7
@@ -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 */
Signature · 1 line
2.56.1
author maintainer
#19 lore raw

PATCH v3 13/18 tools/rv: Add BPF monitors

In reply to Gabriele Monaco

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.

---
 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
include/rv/da_monitor.h +16 -5
index fc830c9f5046..4d479d2bb12d 100644
@@ -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.
  */
tools/verification/models/nohz.dot new file +16 -0
new file mode 100644
index 000000000000..49adb25e32d8
@@ -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";
+	}
+}
tools/verification/models/tqueue.dot new file +15 -0
new file mode 100644
index 000000000000..7aadf99ed29d
@@ -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";
+	}
+}
tools/verification/rv/Makefile +38 -3

73 lines not on this page · raw message

tools/verification/rv/Makefile.config +26 -0
index 0600170ac217..1caad39ab0c9 100644
@@ -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
tools/verification/rv/Makefile.rv +5 -0
index 2497fb96c83d..418748bc3aa1 100644
@@ -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:
tools/verification/rv/bpf_monitors/.gitignore new file +2 -0
new file mode 100644
index 000000000000..e5add9141ef5
@@ -0,0 +1,2 @@
+*.d
+vmlinux.h
tools/verification/rv/bpf_monitors/da_monitor_bpf.h new file +423 -0

423 lines not on this page · raw message

tools/verification/rv/bpf_monitors/nohz.c new file +42 -0

42 lines not on this page · raw message

tools/verification/rv/bpf_monitors/nohz.h new file +49 -0

49 lines not on this page · raw message

tools/verification/rv/bpf_monitors/tqueue.c new file +28 -0
new file mode 100644
index 000000000000..0814d559644f
@@ -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.";
tools/verification/rv/bpf_monitors/tqueue.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#21 lore raw

PATCH v3 14/18 tools/rv: Define CONFIG_X86_64 statically for BPF monitors

In reply to Gabriele Monaco

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.

---
 tools/verification/rv/src/bpf_monitor.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/verification/rv/src/bpf_monitor.c +8 -2
index 5c9c4d9b4835..1ff76a4ffb68 100644
@@ -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,
Signature · 1 line
2.56.1
author maintainer
#22 lore raw

PATCH v3 15/18 tools/rv: Add -E/--errors-only option

In reply to Gabriele Monaco

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.

---
 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(-)
Documentation/tools/rv/common_ikm.rst +6 -0
index e50a5f8a7142..b2594f9c35e8 100644
@@ -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.
tools/verification/rv/include/utils.h +1 -0
index 397a37981932..2fec9ef7c0b3 100644
@@ -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;
tools/verification/rv/src/bpf_monitor.c +3 -1
index 1ff76a4ffb68..12cb407c55bc 100644
@@ -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;
 }
 
tools/verification/rv/src/trace.c +7 -4
index 6fdbff2c28d4..629b4f63e147 100644
@@ -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))
tools/verification/rv/src/utils.c +7 -2
index 1b1ad7a3ca32..854028324325 100644
@@ -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;
 		}
 	}
 
Signature · 1 line
2.56.1
author maintainer
#23 lore raw

PATCH v3 16/18 verification/rvgen: Add support for BPF monitors

In reply to Gabriele Monaco

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.

---
 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
tools/verification/rvgen/__main__.py +11 -4
index 246b43fa29f1..16ce9b512fbb 100644
@@ -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())
tools/verification/rvgen/rvgen/dot2c.py +11 -4
index c6bd4d00d92e..246b76931660 100644
@@ -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}];")
tools/verification/rvgen/rvgen/dot2k.py +18 -4
index b48895b93c8a..d0677da59172 100644
@@ -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)
tools/verification/rvgen/rvgen/generator.py +19 -7
index 626bb7ce90ee..8895a264cf0c 100644
@@ -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)
tools/verification/rvgen/rvgen/templates/dot2k/main_bpf.c new file +21 -0
new file mode 100644
index 000000000000..1a83f3a2159a
@@ -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%%";
Signature · 1 line
2.56.1
author maintainer
#25 lore raw

PATCH v3 17/18 tools/rv: Add selftest for rv bpf monitors

In reply to Gabriele Monaco

Add selftest cases for the rv userspace tool BPF monitors, test BPF monitors listing and functionality, including traces and reactors.

---
 tools/verification/rv/tests/rv_list.t |  6 +-
 tools/verification/rv/tests/rv_mon.t  | 80 +++++++++++++++++++++++++--
 2 files changed, 79 insertions(+), 7 deletions(-)
tools/verification/rv/tests/rv_list.t +5 -1
index 201af33a52cc..9eae5c3c6eba 100644
@@ -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" \
tools/verification/rv/tests/rv_mon.t +74 -6

118 lines not on this page · raw message

Signature · 1 line
2.56.1
author maintainer
#26 lore raw

PATCH v3 18/18 verification/rvgen: Add selftest for rvgen -b

In reply to Gabriele Monaco

Add selftest cases for BPF monitors generation.

---
 .../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
tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.c new file +35 -0
new file mode 100644
index 000000000000..5a652ce9b461
@@ -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";
tools/verification/rvgen/tests/golden/da_bpf_cpu/da_bpf_cpu.h new file +47 -0

47 lines not on this page · raw message

tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.c new file +49 -0

49 lines not on this page · raw message

tools/verification/rvgen/tests/golden/da_bpf_obj/da_bpf_obj.h new file +47 -0

47 lines not on this page · raw message

tools/verification/rvgen/tests/rvgen_monitor.t +11 -0
index 5f2562600bad..3d71685a7ad5 100644
@@ -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 \
Signature · 1 line
2.56.1
#2 lore raw

Re: [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] sched: commit message lacks rationale for enqueue and dequeue tracepoints --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] sched: commit message lacks rationale for enqueue and dequeue tracepoints
--

commit 9e126d48d20c6a32f27d4f37320ca4e103557c73
Author: Nam Cao <[email protected]>

Quoted 9 lines

sched: Add task enqueue/dequeue trace points

Add trace points into enqueue_task() and dequeue_task().

[Severity: Low]
As reported by Peter Zijlstra on v2 [1], could the commit message explain why sched_enqueue and sched_dequeue are needed, and how delayed dequeues are handled across enqueue_task(), dequeue_task(), and __block_task()?

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#17 lore raw

Re: [PATCH v3 11/18] tools/rv: Rework tracing to support generic events

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] tools/rv: missing pid field check in enable_specific_event() self filter --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] tools/rv: missing pid field check in enable_specific_event() self filter
--

commit 6b11a8a850e9f9fbce2a029fa1ab5858e9dcc9dc
Author: Gabriele Monaco <[email protected]>

tools/rv: Rework tracing to support generic events

This commit replaces the DA-specific trace event formatting callbacks with default tep_print_event() formatting and moves self-PID filtering into ftrace event filters to support LTL and generic BPF monitor events.

Quoted 4 lines
tools/verification/rv/src/trace.c +0 -0
index aa4bb73624ecd..6fdbff2c28d45 100644

[ ... ]

Quoted 41 lines
tools/verification/rv/src/trace.c +9 -28
+/*
+ * 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*/

tools/verification/rv/src/trace.c int trace_instance_init(struct trace_instance *trace, char *name) · line 173

Quoted 10 lines
tools/verification/rv/src/trace.c +6 -2
-			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);
 	}

[Severity: Low]
Does enable_specific_event() miss filtering the target task PID for LTL monitors?

While per-task DA monitor tracepoints name their target task PID field "id", LTL monitor tracepoints (event_ltl_monitor_id and error_ltl_monitor_id in kernel/trace/rv/rv_trace.h) define that field as "pid". Because tep_find_field(tevent, "id") returns NULL for LTL events, the filter falls back to "common_pid != %d" and will not filter out events targeting the rv process when emitted from another task or interrupt context (such as sched_waking waking the rv process).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#15 lore raw

Re: [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] tools/rv: undefined reference to bpf_usage_print_reactors() when BUILD_BPF=0 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] tools/rv: undefined reference to bpf_usage_print_reactors() when BUILD_BPF=0
--

commit 32e1d389b743671fba97d9526fde476a03a6fc44
Author: Gabriele Monaco <[email protected]>

tools/rv: Implement BPF monitor loading and tracing

This commit implements BPF monitor loading, execution, and optional trace event attachment for the rv tool.

Quoted 23 lines
tools/verification/rv/include/utils.h +2 -0
index 61f77a72a1a23..d6b4e60df7ffa 100644
@@ -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;
tools/verification/rv/src/utils.c +0 -0
index e19dd65ec789e..1b1ad7a3ca32e 100644

tools/verification/rv/src/utils.c void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...) · line 89

Quoted 10 lines
tools/verification/rv/src/utils.c +4 -1
@@ -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);
 }

[Severity: Medium]
Does building rv with BUILD_BPF=0 (or without libbpf installed) fail at link time with an undefined reference to bpf_usage_print_reactors()?

utils.o is built unconditionally, while bpf_monitor.o is only linked when BUILD_BPF is enabled. Should bpf_usage_print_reactors() be declared in include/bpf_monitor.h with a static inline stub under #ifndef HAVE_LIBBPF, like bpf_list_monitors() and bpf_run_monitor()?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#24 lore raw

Re: [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] verification/rvgen: missing self.bpf in Dot2c.format_automaton_definition() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] verification/rvgen: missing self.bpf in Dot2c.format_automaton_definition()
--

commit f6c387dbb1dd7cab260bf2fa7f3c9e7a20021e5e
Author: Gabriele Monaco <[email protected]>

verification/rvgen: Add support for BPF monitors

This commit adds the -b/--bpf option to rvgen to generate BPF-based deterministic automaton monitors.

Quoted 13 lines
tools/verification/rvgen/rvgen/dot2c.py +1 -4
index c6bd4d00d92e1..246b769316609 100644
@@ -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:

tools/verification/rvgen/rvgen/dot2c.py class Dot2c(Automata): · line 124

Quoted 10 lines
tools/verification/rvgen/rvgen/dot2c.py +10 -0
+            # 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}];")

[Severity: Medium]
Does checking self.bpf here raise an AttributeError when Dot2c is instantiated directly?

self.bpf is only initialized in RVGenerator.__init__(), which Dot2c does not inherit from. Running the standalone tools/verification/rvgen/dot2c utility instantiates Dot2c directly and calls print_model_classic() -> format_model() -> format_automaton_definition(), crashing with "AttributeError: 'Dot2c' object has no attribute 'bpf'". Setting self.bpf = False in Dot2c.__init__() (or as a class attribute on Dot2c) would avoid this regression.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
#13 lore raw

Re: [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] tools/rv: path truncation checked after open in bpf_object_iterate_path() - [Low] tools/rv…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] tools/rv: path truncation checked after open in bpf_object_iterate_path()
- [Low] tools/rv: uncoordinated monitor listing in rv_list() and ikm_list_monitors()
--

commit 4abb124d92aede7d5ee4cdd253273b42ad6b0fdc
Author: Gabriele Monaco <[email protected]>

tools/rv: Implement BPF monitor discovery and listing

This commit adds libbpf detection to the rv build configuration and implements discovery and listing of compiled BPF monitor object files for rv list.

Quoted 5 lines
tools/verification/rv/src/bpf_monitor.c new file +0 -0
new file mode 100644
index 0000000000000..a5767617c7200

[ ... ]

Quoted 34 lines
tools/verification/rv/src/bpf_monitor.c new file +34 -0
+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);

tools/verification/rv/src/bpf_monitor.c line 193

Quoted 10 lines
tools/verification/rv/src/bpf_monitor.c new file +10 -0
+		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;
+		}

[Severity: Low]
Should size >= MAX_PATH be checked before calling bpf_object__open_file()?

When the formatted path reaches MAX_PATH, bpf_object__open_file() is invoked on a truncated obj_path. If opening the truncated path succeeds, the size >= MAX_PATH branch logs a stale errno and continues without calling bpf_object__close(obj), leaking obj. Also, the earlier snprintf(path, sizeof(path), "%s/%s", base_path, subdir) does not check for truncation when formatting base_path (which is itself sized MAX_PATH).

[ ... ]

Quoted 13 lines
tools/verification/rv/src/rv.c +1 -0
index 09e0d85986196..7c4a2e49ff9d1 100644
@@ -13,6 +13,7 @@
 #include <trace.h>
 #include <utils.h>
 #include <in_kernel.h>
+#include <bpf_monitor.h>
 
 static int stop_session;
 

tools/verification/rv/src/rv.c static void rv_list(int argc, char **argv) · line 83

Quoted 7 lines
tools/verification/rv/src/rv.c +1 -0
@@ -76,6 +77,7 @@ static void rv_list(int argc, char **argv)
 	}
 
 	ikm_list_monitors(container);
+	bpf_list_monitors(container);
 
 	exit(EXIT_SUCCESS);
 }

[Severity: Low]
Does calling ikm_list_monitors() and bpf_list_monitors() independently produce broken output when no in-kernel monitors are registered or listed?

tools/verification/rv/src/in_kernel.c:ikm_list_monitors() {
	available_monitors = tracefs_instance_file_read(NULL, "rv/available_monitors", NULL);

	if (!available_monitors) {
		err_msg("ikm: available monitors is not available, is CONFIG_RV enabled?\n");
		return -1;
	}

	curr = available_monitors;
	do {
		next = strstr(curr, "\n");
		*next = '\0';

		retval = ikm_fill_monitor_definition(curr, &ikm, container);
		if (retval < 0)
			err_msg("ikm: error reading %d in kernel monitor, skipping\n", curr);
    ...
	if (!list_monitor) {
		if (container)
			printf("-- No monitor found in container %s --\n", container);
		else
			printf("-- No monitor found --\n");
	}
}

When CONFIG_RV is enabled without any in-kernel CONFIG_RV_MON_* monitors, rv/available_monitors is 0 bytes and tracefs_instance_file_read() returns NULL, so ikm_list_monitors() prints the error asking if CONFIG_RV is enabled before bpf_list_monitors() lists the BPF monitors (and if an empty string were returned, strstr(curr, "\n") would return NULL and *next = '\0' would dereference NULL). Even when in-kernel monitors exist, if none are printed, ikm_list_monitors() prints "-- No monitor found --" right before bpf_list_monitors() prints the available BPF monitors. In addition, the error message in ikm_list_monitors() formats curr (char *) with %d instead of %s.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#7 lore raw

Re: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] rv: undefined tracepoint symbols when CONFIG_RV_MON_EVENTS is unset - [Medium] rv: TOCTOU…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] rv: undefined tracepoint symbols when CONFIG_RV_MON_EVENTS is unset
- [Medium] rv: TOCTOU unbounded strlen() after strnlen() in bpf_rv_*_monitor()
- [Low] rv: missing @id__nullable kernel-doc description in rv_bpf.c --

commit 12ad0d7960250beaac1afe9380fabf830419122f
Author: Gabriele Monaco <[email protected]>

rv: Add generic monitor event tracepoints and BPF kfuncs

This commit adds generic event_monitor and error_monitor tracepoints along with bpf_rv_event_monitor() and bpf_rv_error_monitor() BPF kfuncs so BPF monitors can emit RV events and errors.

kernel/trace/rv/Makefile line 9

Quoted 12 lines
kernel/trace/rv/Makefile +1 -0
index c895d81dfdad9..588250ce3fa93 100644
@@ -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

[Severity: Medium]
Does this fail to link when CONFIG_RV=y is enabled without any in-kernel C monitor?

rv_bpf.o is built whenever CONFIG_RV is set and calls trace_event_monitor() and trace_error_monitor(), but CREATE_TRACE_POINTS in kernel/trace/rv/rv.c is only defined under CONFIG_RV_MON_EVENTS:

kernel/trace/rv/rv.c:

    #ifdef CONFIG_RV_MON_EVENTS
    #define CREATE_TRACE_POINTS
    #include <rv_trace.h>
    #endif

CONFIG_RV_MON_EVENTS is only selected by the in-kernel C monitor options (all of which default to n), so a BPF-only RV build leaves __tracepoint_event_monitor, __tracepoint_error_monitor, and their static call symbols undefined at link time.

Quoted 6 lines
kernel/trace/rv/rv_bpf.c new file +0 -0
new file mode 100644
index 0000000000000..f39f33335c71b
@@ -0,0 +1,76 @@

[ ... ]

Quoted 5 lines
kernel/trace/rv/rv_bpf.c new file +5 -0
+/**
+ * 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

kernel/trace/rv/rv_bpf.c line 28

Quoted 10 lines
kernel/trace/rv/rv_bpf.c new file +10 -0
+ * 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)

[Severity: Low]
Both bpf_rv_event_monitor() and bpf_rv_error_monitor() use kernel-doc comments but omit @id__nullable, which triggers kernel-doc warnings under W=1 builds.

Quoted 20 lines
kernel/trace/rv/rv_bpf.c new file +20 -0
+{
+	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.

kernel/trace/rv/rv_bpf.c line 58

Quoted 10 lines
kernel/trace/rv/rv_bpf.c new file +10 -0
+ */
+__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;
+}

[Severity: Medium]
Can a concurrent update to msg after strnlen() cause trace_event_monitor() or trace_error_monitor() to read past msg + msg__sz?

For the (const char *msg, u32 msg__sz) kfunc argument pair, the BPF verifier accepts any writable BPF memory region of size msg__sz, including shared BPF map values. event_template_monitor uses __string(msg, msg), which runs an unbounded strlen(msg) and memcpy() after strnlen() has already returned:

CPU0 CPU1
bpf_rv_event_monitor(mon, id,

                     msg, msg__sz)
  strnlen(msg, msg__sz) < msg__sz
                                      /* overwrites NUL byte in shared
                                       * BPF map value backing msg
                                       */

trace_event_monitor(mon, id, msg)
strlen(msg)
memcpy(..., msg, ...) <-- out-of-bounds read past msg__sz

Reading past the end of a BPF map allocation can fault on an unmapped vmalloc guard page or copy adjacent kernel memory into the trace ring buffer. Passing the length returned by strnlen() into the tracepoint and using __string_len() in event_template_monitor would bound the copy without re-scanning msg.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#20 lore raw

Re: [PATCH v3 13/18] tools/rv: Add BPF monitors

In reply to Gabriele Monaco
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] tools/rv: BPF monitor build fails when BTF source lacks CONFIG_RV types - [Medium] tools/rv: BPF…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] tools/rv: BPF monitor build fails when BTF source lacks CONFIG_RV types
- [Medium] tools/rv: BPF monitor build lacks -mcpu=v3, likely() fallback, and O= support
- [Low] tools/rv: bpftool failure leaves empty bpf_monitors/vmlinux.h on disk
- [Low] tools/rv: missing da_reset() macro mappings in da_monitor_bpf.h --

commit e722072977f9f930cda140d2eaa94a39a1ea1809
Author: Gabriele Monaco <[email protected]>

tools/rv: Add BPF monitors

This commit adds two initial DA BPF monitors (tqueue and nohz), adapts include/rv/da_monitor.h for BPF compilation via da_monitor_bpf.h, and integrates BPF monitor building and installation into the tools/rv Makefiles.

Quoted 4 lines
tools/verification/rv/Makefile +0 -0
index 0a8c7a656f7f3..4bac303246892 100644

[ ... ]

Quoted 5 lines
tools/verification/rv/Makefile +1 -0
@@ -68,19 +72,50 @@ static: $(RV_IN)
 	$(eval LDFLAGS += -static)
 	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RV)-static $(RV_IN) $(EXTLIBS)
 
+BPF_DIR		:= bpf_monitors

tools/verification/rv/Makefile static: $(RV_IN) · line 85

Quoted 10 lines
tools/verification/rv/Makefile +10 -0
+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

[Severity: Medium]
As reported by [email protected] on v2 [1], does building the BPF monitors fail on Clang older than 20, system libbpf headers older than 1.6, or out-of-tree O= builds?

Clang versions before 20 default to -mcpu=v1, which rejects the 32-bit cmpxchg and fetch-and-add instructions in da_event() and smp_mb() unless -mcpu=v3 is passed in BPF_CFLAGS. Without -I$(srctree)/tools/lib or a fallback definition in da_monitor_bpf.h, <bpf/bpf_helpers.h> resolves to the system libbpf header, which lacks likely() and unlikely() prior to libbpf 1.6. Finally, BPF_DIR is not prefixed with $(OUTPUT), so O= builds write artifacts into the source tree instead of $(OUTPUT), where the rv binary looks for bpf_monitors.

tools/verification/rv/Makefile static: $(RV_IN) · line 91

Quoted 6 lines
tools/verification/rv/Makefile +6 -0
+
+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 > $@

[Severity: Medium]
As reported by [email protected] on v2 [2], does the default build fail with incomplete type errors when $(VMLINUX_BTF) comes from a kernel built without CONFIG_RV=y?

BUILD_BPF_OBJS defaults to 1 whenever libbpf, clang, and bpftool are installed, adding the bpf target to all. Because include/linux/rv.h guards struct rv_monitor, struct da_monitor, and union rv_task_monitor under #ifdef CONFIG_RV, compiling the BPF monitors relies on vmlinux.h providing those types from kernel BTF. When the host or in-tree kernel has CONFIG_RV disabled, those definitions are absent from vmlinux.h and compiling da_monitor.h and da_monitor_bpf.h fails.

[Severity: Low]
As reported by [email protected] on v2 [3], if bpftool fails while generating $(VMLINUX_H), does shell redirection leave an empty bpf_monitors/vmlinux.h on disk? Without .DELETE_ON_ERROR or writing via a temporary file, subsequent make runs see an up-to-date header and fail with compiler errors until make clean.

Quoted 9 lines
tools/verification/rv/Makefile.rv +1 -0
index 2497fb96c83d2..418748bc3aa12 100644
@@ -33,12 +33,17 @@ INSTALL		:= install
 MKDIR		:= mkdir
 STRIP		:= strip
 BINDIR		:= /usr/bin
+BPF_MON_DIR	:= /usr/share/rv/bpf_monitors

tools/verification/rv/Makefile.rv INSTALL := install · line 46

Quoted 10 lines
tools/verification/rv/Makefile.rv +4 -0
 
 .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

[Severity: Medium]
As reported by [email protected] on v2 [4], does a single-invocation "make all install" on a clean tree skip installing bpf_monitors/*.o? $(wildcard bpf_monitors/*.o) is evaluated when the Makefile is parsed, before the bpf target builds the object files, and it also looks in the source directory rather than $(OUTPUT)bpf_monitors/*.o.

Quoted 5 lines
tools/verification/rv/bpf_monitors/da_monitor_bpf.h new file +0 -0
new file mode 100644
index 0000000000000..e9e673c2d1b68

[ ... ]

Quoted 11 lines
tools/verification/rv/bpf_monitors/da_monitor_bpf.h new file +11 -0
+/*
+ * 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)

[ ... ]

Quoted 9 lines
tools/verification/rv/bpf_monitors/da_monitor_bpf.h new file +9 -0
+#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

[ ... ]

tools/verification/rv/bpf_monitors/da_monitor_bpf.h line 327

Quoted 8 lines
tools/verification/rv/bpf_monitors/da_monitor_bpf.h new file +8 -0
+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);
+}

[Severity: Low]
Should RV_MON_PER_TASK and RV_MON_PER_OBJ also map da_reset to da_reset_bpf()? da_reset_bpf() is defined here, but without the corresponding #define da_reset macros it is unused and any per-task or per-object BPF monitor calling da_reset() will fail to compile.

[1] https://lore.kernel.org/r/1081b7a0f143f29745409a1356f223fd8b196c827e18d46cde7f41716def72c0@mail.kernel.org
[2] https://lore.kernel.org/r/1081b7a0f143f29745409a1356f223fd8b196c827e18d46cde7f41716def72c0@mail.kernel.org
[3] https://lore.kernel.org/r/1081b7a0f143f29745409a1356f223fd8b196c827e18d46cde7f41716def72c0@mail.kernel.org
[4] https://lore.kernel.org/r/1081b7a0f143f29745409a1356f223fd8b196c827e18d46cde7f41716def72c0@mail.kernel.org

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#8 lore raw

Re: [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs

In reply to Gabriele Monaco
kernel test robot noticed the following build warnings:

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/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261127/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki