All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail
@ 2026-11-10 18:08 Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 1/7] dovetail: factor out the mayday check on return to user mode Tobias Schaffner
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Hi all,

with this RFC I would like to propose using the Linux kernel Runtime
Verification (RV) system [1] for runtime verification of Dovetail based
cokernels.

Running a system with RV monitors active should ensure that the system
behaves as described in the model. As this is checked at runtime we can
verify if the system is even behaving as inteded when it is running the
real workload.

My ultimate goal is not only to use it for verification but also for wakeup
latency tracing and decomposition in EVL by describing the whole wakeup
path. I am working on upstreaming dwell time measurements in the RV system
in parallel for that [2].

This would allow us not only to get a worst case latency and decomposition
for a latency evaluation tool like latmus but to get a worst case latency
for any load applied to the system (e.g. the real application of the user).

This patch set proposes three Dovetail monitors bundled in one container:

 * offstage checks that Linux leaves a task alone while it runs out-of-band. It
must neither schedule the task nor let it raise a signal on itself.

 * oob_trap checks that every out-of-band trap notification is unwound for the
same trap before the task goes out-of-band again.

 * oob_signal checks that a task receiving a signal out-of-band is kicked
in-band. Once the cokernel handled the notification, the task must not return
to user mode out-of-band without a mayday pending. I think his monitor found
a present bug in EVL: since "evl/sched: get rid of this_evl_rq_thread()"
evl_kick_thread() skips the mayday for a thread running out-of-band on a
remote CPU, so the thread ignores all signals, even SIGKILL.

For the monitors the series adds a few bare tracepoints to Dovetail. They are
not exposed in tracefs.

The monitors can be built by setting CONFIG_RV_DOVETAIL, which enables RV,
the monitors and the printk reactor. oob_signal is not available on 32-bit
arm yet, as the out-of-band syscall fast path there is written in assembly.

To execute them:

  # cd /sys/kernel/tracing/rv
  # echo printk > monitors/dovetail/reactors
  # echo 1 > monitors/dovetail/enable

Looking forward to your feedback, input and ideas on how to use and improve
this further.

Best,
Tobias

[1] https://docs.kernel.org/trace/rv/runtime-verification.html
[2] https://lore.kernel.org/linux-trace-kernel/20260827072400.45734-1-tobias.schaffner@siemens.com

Tobias Schaffner (7):
  dovetail: factor out the mayday check on return to user mode
  dovetail: trace stage switches
  rv: add dovetail container and offstage monitor
  dovetail: trace out-of-band trap notifications
  rv: add oob_trap monitor
  dovetail: trace signal notifications and out-of-band returns
  rv: add oob_signal monitor

 Documentation/trace/rv/index.rst              |   1 +
 Documentation/trace/rv/monitor_dovetail.rst   | 124 +++++++++++++++
 include/linux/dovetail.h                      |  19 ++-
 include/trace/events/dovetail.h               |  40 +++++
 kernel/Kconfig.dovetail                       |  14 ++
 kernel/dovetail.c                             |  35 ++++-
 kernel/irq/pipeline.c                         |   4 +-
 kernel/sched/core.c                           |   2 +
 kernel/trace/rv/Kconfig                       |   5 +
 kernel/trace/rv/Makefile                      |   4 +
 kernel/trace/rv/monitors/dovetail/Kconfig     |  13 ++
 kernel/trace/rv/monitors/dovetail/dovetail.c  |  41 +++++
 kernel/trace/rv/monitors/dovetail/dovetail.h  |   3 +
 kernel/trace/rv/monitors/offstage/Kconfig     |  15 ++
 kernel/trace/rv/monitors/offstage/offstage.c  | 114 ++++++++++++++
 kernel/trace/rv/monitors/offstage/offstage.h  |  61 ++++++++
 .../rv/monitors/offstage/offstage_trace.h     |  15 ++
 kernel/trace/rv/monitors/oob_signal/Kconfig   |  16 ++
 .../trace/rv/monitors/oob_signal/oob_signal.c | 114 ++++++++++++++
 .../trace/rv/monitors/oob_signal/oob_signal.h |  74 +++++++++
 .../rv/monitors/oob_signal/oob_signal_trace.h |  15 ++
 kernel/trace/rv/monitors/oob_trap/Kconfig     |  14 ++
 kernel/trace/rv/monitors/oob_trap/oob_trap.c  | 144 ++++++++++++++++++
 kernel/trace/rv/monitors/oob_trap/oob_trap.h  |  61 ++++++++
 .../rv/monitors/oob_trap/oob_trap_trace.h     |  19 +++
 kernel/trace/rv/rv_trace.h                    |   3 +
 tools/verification/models/offstage.dot        |  14 ++
 tools/verification/models/oob_signal.dot      |  23 +++
 tools/verification/models/oob_trap.dot        |  14 ++
 29 files changed, 1013 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/trace/rv/monitor_dovetail.rst
 create mode 100644 include/trace/events/dovetail.h
 create mode 100644 kernel/trace/rv/monitors/dovetail/Kconfig
 create mode 100644 kernel/trace/rv/monitors/dovetail/dovetail.c
 create mode 100644 kernel/trace/rv/monitors/dovetail/dovetail.h
 create mode 100644 kernel/trace/rv/monitors/offstage/Kconfig
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage.c
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage.h
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage_trace.h
 create mode 100644 kernel/trace/rv/monitors/oob_signal/Kconfig
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal.c
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal.h
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal_trace.h
 create mode 100644 kernel/trace/rv/monitors/oob_trap/Kconfig
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap.c
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap.h
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap_trace.h
 create mode 100644 tools/verification/models/offstage.dot
 create mode 100644 tools/verification/models/oob_signal.dot
 create mode 100644 tools/verification/models/oob_trap.dot


base-commit: a3ad77d7ba3eac8a73f64026272747c01dd84fc6
-- 
2.53.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 1/7] dovetail: factor out the mayday check on return to user mode
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 2/7] dovetail: trace stage switches Tobias Schaffner
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Dovetail checks for a pending mayday at three places before returning to
user mode out-of-band. Move the check into dovetail_oob_exit_to_user().
On the IRQ path it now runs only when returning out-of-band, as an
in-band task has no mayday pending.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 include/linux/dovetail.h |  2 ++
 kernel/dovetail.c        | 14 +++++++++-----
 kernel/irq/pipeline.c    |  4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/linux/dovetail.h b/include/linux/dovetail.h
index 1140c5b7c99f..b41ea0f8fc4e 100644
--- a/include/linux/dovetail.h
+++ b/include/linux/dovetail.h
@@ -198,6 +198,8 @@ struct oob_mm_state *dovetail_mm_state(void)
 
 void dovetail_call_mayday(struct pt_regs *regs);
 
+void dovetail_oob_exit_to_user(struct pt_regs *regs);
+
 static inline void dovetail_send_mayday(struct task_struct *castaway)
 {
 	struct thread_info *ti = task_thread_info(castaway);
diff --git a/kernel/dovetail.c b/kernel/dovetail.c
index d2ea78913fb6..da4016697b67 100644
--- a/kernel/dovetail.c
+++ b/kernel/dovetail.c
@@ -99,6 +99,13 @@ void dovetail_call_mayday(struct pt_regs *regs)
 	hard_local_irq_restore(flags);
 }
 
+/* Returning to user mode on the out-of-band stage. */
+void dovetail_oob_exit_to_user(struct pt_regs *regs)
+{
+	if (test_thread_flag(TIF_MAYDAY))
+		dovetail_call_mayday(regs);
+}
+
 void inband_retuser_notify(void)
 {
 	clear_thread_flag(TIF_RETUSER);
@@ -137,7 +144,6 @@ bool in_oob_syscall(struct pt_regs *regs)
 
 int __pipeline_syscall(struct pt_regs *regs)
 {
-	struct thread_info *ti = current_thread_info();
 	struct irq_stage *caller_stage, *target_stage;
 	struct irq_stage_data *p, *this_context;
 	unsigned long flags;
@@ -189,8 +195,7 @@ int __pipeline_syscall(struct pt_regs *regs)
 		if (stage_irqs_pending(p))
 			sync_current_irq_stage();
 	} else {
-		if (test_ti_thread_flag(ti, TIF_MAYDAY))
-			call_mayday(ti, regs);
+		dovetail_oob_exit_to_user(regs);
 	}
 
 	hard_local_irq_restore(flags);
@@ -244,8 +249,7 @@ int pipeline_syscall(unsigned int nr, struct pt_regs *regs)
 		local_flags = READ_ONCE(ti_local_flags(ti));
 		if (likely(ret)) {
 			if (local_flags & _TLF_OOB) {
-				if (test_ti_thread_flag(ti, TIF_MAYDAY))
-					dovetail_call_mayday(regs);
+				dovetail_oob_exit_to_user(regs);
 				return 1; /* don't pass down, no tail work. */
 			} else {
 				WARN_ON_ONCE(dovetail_debug() && irqs_disabled());
diff --git a/kernel/irq/pipeline.c b/kernel/irq/pipeline.c
index 88911489aeb6..f9c9c13d7137 100644
--- a/kernel/irq/pipeline.c
+++ b/kernel/irq/pipeline.c
@@ -1244,8 +1244,8 @@ int handle_irq_pipelined_finish(struct irq_stage_data *prevd,
 	 * Sending MAYDAY is in essence a rare case, so prefer test
 	 * then maybe clear over test_and_clear.
 	 */
-	if (user_mode(regs) && test_thread_flag(TIF_MAYDAY))
-		dovetail_call_mayday(regs);
+	if (user_mode(regs) && running_oob())
+		dovetail_oob_exit_to_user(regs);
 #endif
 
 	return running_inband() && !irqs_disabled();
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 2/7] dovetail: trace stage switches
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 1/7] dovetail: factor out the mayday check on return to user mode Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-11  7:40   ` Jan Kiszka
  2026-11-10 18:08 ` [RFC PATCH dovetail 3/7] rv: add dovetail container and offstage monitor Tobias Schaffner
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Add tracepoints for a task leaving the in-band and the out-of-band stage,
for use by the Dovetail RV monitors.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 include/linux/dovetail.h        |  9 +++++++++
 include/trace/events/dovetail.h | 23 +++++++++++++++++++++++
 kernel/dovetail.c               | 13 +++++++++++++
 kernel/sched/core.c             |  2 ++
 4 files changed, 47 insertions(+)
 create mode 100644 include/trace/events/dovetail.h

diff --git a/include/linux/dovetail.h b/include/linux/dovetail.h
index b41ea0f8fc4e..5ab07e69152a 100644
--- a/include/linux/dovetail.h
+++ b/include/linux/dovetail.h
@@ -18,6 +18,7 @@ struct files_struct;
 #include <linux/mm.h>
 #include <linux/thread_info.h>
 #include <linux/irqstage.h>
+#include <linux/tracepoint-defs.h>
 #include <uapi/asm-generic/dovetail.h>
 #include <asm/dovetail.h>
 
@@ -163,8 +164,16 @@ void dovetail_stop_altsched(void);
 
 __must_check int dovetail_leave_inband(void);
 
+DECLARE_TRACEPOINT(dovetail_leave_inband_tp);
+void __trace_dovetail_leave_inband(struct task_struct *p);
+
+DECLARE_TRACEPOINT(dovetail_leave_oob_tp);
+void __trace_dovetail_leave_oob(void);
+
 static inline void dovetail_leave_oob(void)
 {
+	if (tracepoint_enabled(dovetail_leave_oob_tp))
+		__trace_dovetail_leave_oob();
 	clear_thread_local_flags(_TLF_OOB|_TLF_OFFSTAGE);
 	clear_thread_flag(TIF_MAYDAY);
 }
diff --git a/include/trace/events/dovetail.h b/include/trace/events/dovetail.h
new file mode 100644
index 000000000000..785a653252d3
--- /dev/null
+++ b/include/trace/events/dovetail.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM dovetail
+
+#if !defined(_TRACE_DOVETAIL_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_DOVETAIL_H
+
+#include <linux/tracepoint.h>
+
+struct task_struct;
+
+DECLARE_TRACE(dovetail_leave_inband,
+	TP_PROTO(struct task_struct *p),
+	TP_ARGS(p));
+
+DECLARE_TRACE(dovetail_leave_oob,
+	TP_PROTO(struct task_struct *p),
+	TP_ARGS(p));
+
+#endif /* _TRACE_DOVETAIL_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/kernel/dovetail.c b/kernel/dovetail.c
index da4016697b67..98892f0a63da 100644
--- a/kernel/dovetail.c
+++ b/kernel/dovetail.c
@@ -12,6 +12,19 @@
 #include <asm/syscall.h>
 #include <uapi/asm-generic/dovetail.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dovetail.h>
+
+void __trace_dovetail_leave_inband(struct task_struct *p)
+{
+	trace_dovetail_leave_inband_tp(p);
+}
+
+void __trace_dovetail_leave_oob(void)
+{
+	trace_dovetail_leave_oob_tp(current);
+}
+
 static bool dovetail_enabled;
 
 void __weak arch_inband_task_init(struct task_struct *p)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3ec77a682c4a..b2ad0ab0626c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -10689,6 +10689,8 @@ int dovetail_leave_inband(void)
 	 */
 	if (likely(__schedule(SM_NONE))) {
 		arch_dovetail_switch_finish(false);
+		if (tracepoint_enabled(dovetail_leave_inband_tp))
+			__trace_dovetail_leave_inband(p);
 		return 0;
 	}
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 3/7] rv: add dovetail container and offstage monitor
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 1/7] dovetail: factor out the mayday check on return to user mode Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 2/7] dovetail: trace stage switches Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 4/7] dovetail: trace out-of-band trap notifications Tobias Schaffner
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Add a container for monitors verifying the interaction between Dovetail
and the companion core, and CONFIG_RV_DOVETAIL to enable it with RV.

Add the offstage monitor checking that Linux neither schedules a task
nor lets it signal itself while it runs out-of-band.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 Documentation/trace/rv/index.rst              |   1 +
 Documentation/trace/rv/monitor_dovetail.rst   |  64 ++++++++++
 kernel/Kconfig.dovetail                       |  14 +++
 kernel/trace/rv/Kconfig                       |   3 +
 kernel/trace/rv/Makefile                      |   2 +
 kernel/trace/rv/monitors/dovetail/Kconfig     |  13 ++
 kernel/trace/rv/monitors/dovetail/dovetail.c  |  41 +++++++
 kernel/trace/rv/monitors/dovetail/dovetail.h  |   3 +
 kernel/trace/rv/monitors/offstage/Kconfig     |  15 +++
 kernel/trace/rv/monitors/offstage/offstage.c  | 114 ++++++++++++++++++
 kernel/trace/rv/monitors/offstage/offstage.h  |  61 ++++++++++
 .../rv/monitors/offstage/offstage_trace.h     |  15 +++
 kernel/trace/rv/rv_trace.h                    |   1 +
 tools/verification/models/offstage.dot        |  14 +++
 14 files changed, 361 insertions(+)
 create mode 100644 Documentation/trace/rv/monitor_dovetail.rst
 create mode 100644 kernel/trace/rv/monitors/dovetail/Kconfig
 create mode 100644 kernel/trace/rv/monitors/dovetail/dovetail.c
 create mode 100644 kernel/trace/rv/monitors/dovetail/dovetail.h
 create mode 100644 kernel/trace/rv/monitors/offstage/Kconfig
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage.c
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage.h
 create mode 100644 kernel/trace/rv/monitors/offstage/offstage_trace.h
 create mode 100644 tools/verification/models/offstage.dot

diff --git a/Documentation/trace/rv/index.rst b/Documentation/trace/rv/index.rst
index 29769f06bb0f..8e2b4a270670 100644
--- a/Documentation/trace/rv/index.rst
+++ b/Documentation/trace/rv/index.rst
@@ -14,6 +14,7 @@ Runtime Verification
    da_monitor_instrumentation.rst
    monitor_wip.rst
    monitor_wwnr.rst
+   monitor_dovetail.rst
    monitor_sched.rst
    monitor_rtapp.rst
    monitor_stall.rst
diff --git a/Documentation/trace/rv/monitor_dovetail.rst b/Documentation/trace/rv/monitor_dovetail.rst
new file mode 100644
index 000000000000..e46cd0ab0b8d
--- /dev/null
+++ b/Documentation/trace/rv/monitor_dovetail.rst
@@ -0,0 +1,64 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Dovetail monitors
+=================
+
+- Name: dovetail
+- Type: container for multiple monitors
+- Author: Tobias Schaffner <tobias.schaffner@siemens.com>
+
+Description
+-----------
+
+Dovetail runs a task either on the in-band stage, scheduled by Linux, or on
+the out-of-band stage, scheduled by a companion core. The monitors in this
+container check the contract between Dovetail and the companion core. They
+are per-task monitors fed by Dovetail and generic tracepoints only, meant for
+validation: while enabled, they add work to out-of-band hot paths.
+``CONFIG_RV_DOVETAIL`` enables them with RV and the printk reactor.
+
+The Dovetail tracepoints fire in the context given here, so their probes must
+be safe there:
+
+==========================  ======  ============================================
+Tracepoint                  Stage   Context
+==========================  ======  ============================================
+dovetail_leave_inband_tp    oob     after a successful switch; oob stage
+                                    stalled, hard IRQs off, the core may hold
+                                    its runqueue lock
+dovetail_leave_oob_tp       oob     before the switch to in-band, in the core
+==========================  ======  ============================================
+
+Monitor offstage
+++++++++++++++++
+
+Linux leaves a task alone while it runs out-of-band: it neither schedules
+it nor runs signal code for it, as a trap handler raising a signal before
+the companion core demoted the task would::
+
+                 sched_in
+                 signal_self    leave_inband
+                  +--+  ----------------> +-----+
+                  |  v                    |     |
+                 +--------+               | oob |
+                 | inband |               |     |
+                 +--------+ <------------ +-----+
+                              leave_oob
+
+``sched_in`` is a ``sched_switch`` to the task, ``signal_self`` a
+``signal_generate`` by the task for itself.
+
+Usage
+-----
+
+::
+
+  # cd /sys/kernel/tracing/rv
+  # echo printk > monitors/dovetail/reactors
+  # echo 1 > monitors/dovetail/enable
+  # cat enabled_monitors
+  dovetail
+  dovetail:offstage
+
+Violations are reported by the selected reactor and as ``error_*`` events in
+``events/rv``. The models are in ``tools/verification/models/``.
diff --git a/kernel/Kconfig.dovetail b/kernel/Kconfig.dovetail
index 29c46e06e435..26478d9112d9 100644
--- a/kernel/Kconfig.dovetail
+++ b/kernel/Kconfig.dovetail
@@ -18,6 +18,20 @@ config DOVETAIL
 	  running a high-priority software core on the out-of-band
 	  pipeline stage (aka "dual kernel" configuration).
 
+config RV_DOVETAIL
+	bool "Runtime verification of the Dovetail interface"
+	depends on DOVETAIL
+	select RV
+	select RV_REACTORS
+	select RV_REACT_PRINTK
+	select RV_MON_DOVETAIL
+	help
+	  Enable the runtime verification monitors checking the contract
+	  between Dovetail and the companion core, with the printk reactor.
+
+	  For further information, see:
+	    Documentation/trace/rv/monitor_dovetail.rst
+
 config DOVETAIL_LEGACY_SYSCALL_RANGE
        depends on DOVETAIL
        def_bool y
diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig
index 3884b14df375..3f43cdfcbb32 100644
--- a/kernel/trace/rv/Kconfig
+++ b/kernel/trace/rv/Kconfig
@@ -54,6 +54,7 @@ config RV_PER_TASK_MONITORS
 	int "Maximum number of per-task monitor"
 	depends on RV
 	range 1 8
+	default 3 if RV_DOVETAIL
 	default 2
 	help
 	  This option configures the maximum number of per-task RV monitors that can run
@@ -83,6 +84,8 @@ source "kernel/trace/rv/monitors/deadline/Kconfig"
 source "kernel/trace/rv/monitors/nomiss/Kconfig"
 # Add new deadline monitors here
 
+source "kernel/trace/rv/monitors/dovetail/Kconfig"
+source "kernel/trace/rv/monitors/offstage/Kconfig"
 # Add new monitors here
 
 config RV_REACTORS
diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
index 94498da35b37..a684b0c9af2f 100644
--- a/kernel/trace/rv/Makefile
+++ b/kernel/trace/rv/Makefile
@@ -20,6 +20,8 @@ obj-$(CONFIG_RV_MON_OPID) += monitors/opid/opid.o
 obj-$(CONFIG_RV_MON_STALL) += monitors/stall/stall.o
 obj-$(CONFIG_RV_MON_DEADLINE) += monitors/deadline/deadline.o
 obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o
+obj-$(CONFIG_RV_MON_DOVETAIL) += monitors/dovetail/dovetail.o
+obj-$(CONFIG_RV_MON_OFFSTAGE) += monitors/offstage/offstage.o
 # Add new monitors here
 obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
 obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
diff --git a/kernel/trace/rv/monitors/dovetail/Kconfig b/kernel/trace/rv/monitors/dovetail/Kconfig
new file mode 100644
index 000000000000..59faf165d0ec
--- /dev/null
+++ b/kernel/trace/rv/monitors/dovetail/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+config RV_MON_DOVETAIL
+	depends on RV
+	depends on DOVETAIL
+	bool "dovetail monitor"
+	help
+	  Collection of per-task monitors checking that Dovetail and its
+	  companion core keep their contract: stage switches, out-of-band
+	  traps and signals. Enable this to enable all of them.
+
+	  For further information, see:
+	    Documentation/trace/rv/monitor_dovetail.rst
diff --git a/kernel/trace/rv/monitors/dovetail/dovetail.c b/kernel/trace/rv/monitors/dovetail/dovetail.c
new file mode 100644
index 000000000000..c14e37d0ff17
--- /dev/null
+++ b/kernel/trace/rv/monitors/dovetail/dovetail.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * dovetail: container for the Dovetail monitors.
+ *
+ * Copyright (C) 2026 Siemens AG
+ * Author: Tobias Schaffner <tobias.schaffner@siemens.com>
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/rv.h>
+
+#define MODULE_NAME "dovetail"
+
+#include "dovetail.h"
+
+struct rv_monitor rv_dovetail = {
+	.name = "dovetail",
+	.description = "container for the Dovetail monitors",
+	.enable = NULL,
+	.disable = NULL,
+	.reset = NULL,
+	.enabled = 0,
+};
+
+static int __init register_dovetail(void)
+{
+	return rv_register_monitor(&rv_dovetail, NULL);
+}
+
+static void __exit unregister_dovetail(void)
+{
+	rv_unregister_monitor(&rv_dovetail);
+}
+
+module_init(register_dovetail);
+module_exit(unregister_dovetail);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Tobias Schaffner <tobias.schaffner@siemens.com>");
+MODULE_DESCRIPTION("dovetail: container for the Dovetail monitors");
diff --git a/kernel/trace/rv/monitors/dovetail/dovetail.h b/kernel/trace/rv/monitors/dovetail/dovetail.h
new file mode 100644
index 000000000000..279806cd8e00
--- /dev/null
+++ b/kernel/trace/rv/monitors/dovetail/dovetail.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+extern struct rv_monitor rv_dovetail;
diff --git a/kernel/trace/rv/monitors/offstage/Kconfig b/kernel/trace/rv/monitors/offstage/Kconfig
new file mode 100644
index 000000000000..2b9c6869b315
--- /dev/null
+++ b/kernel/trace/rv/monitors/offstage/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+config RV_MON_OFFSTAGE
+	depends on RV
+	depends on RV_MON_DOVETAIL
+	default y
+	select DA_MON_EVENTS_ID
+	bool "offstage monitor"
+	help
+	  Per-task monitor following which stage a dovetailed task runs on,
+	  in-band or out-of-band. It reports a task that Linux schedules, or
+	  that raises a signal on itself, while Dovetail has it out-of-band.
+
+	  For further information, see:
+	    Documentation/trace/rv/monitor_dovetail.rst
diff --git a/kernel/trace/rv/monitors/offstage/offstage.c b/kernel/trace/rv/monitors/offstage/offstage.c
new file mode 100644
index 000000000000..940c5175e46d
--- /dev/null
+++ b/kernel/trace/rv/monitors/offstage/offstage.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * offstage: Linux leaves a task alone while it is out-of-band.
+ *
+ * Copyright (C) 2026 Siemens AG
+ * Author: Tobias Schaffner <tobias.schaffner@siemens.com>
+ */
+#include <linux/ftrace.h>
+#include <linux/tracepoint.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/rv.h>
+#include <linux/dovetail.h>
+#include <rv/instrumentation.h>
+
+#define MODULE_NAME "offstage"
+
+#include <trace/events/dovetail.h>
+#include <trace/events/sched.h>
+#include <trace/events/signal.h>
+#include <rv_trace.h>
+#include <monitors/dovetail/dovetail.h>
+
+#define RV_MON_TYPE RV_MON_PER_TASK
+#include "offstage.h"
+#include <rv/da_monitor.h>
+
+static bool offstage_monitors_task(struct task_struct *p)
+{
+	return test_ti_local_flags(task_thread_info(p), _TLF_DOVETAIL);
+}
+
+static void handle_leave_inband(void *data, struct task_struct *p)
+{
+	da_handle_start_run_event(p, leave_inband_offstage);
+}
+
+static void handle_leave_oob(void *data, struct task_struct *p)
+{
+	da_handle_event(p, leave_oob_offstage);
+}
+
+static void handle_sched_switch(void *data, bool preempt,
+				struct task_struct *prev,
+				struct task_struct *next,
+				unsigned int prev_state)
+{
+	if (offstage_monitors_task(next))
+		da_handle_event(next, sched_in_offstage);
+}
+
+static void handle_signal_generate(void *data, int sig,
+				   struct kernel_siginfo *info,
+				   struct task_struct *task, int group,
+				   int result)
+{
+	if (task == current && offstage_monitors_task(task))
+		da_handle_event(task, signal_self_offstage);
+}
+
+static int enable_offstage(void)
+{
+	int retval;
+
+	retval = da_monitor_init();
+	if (retval)
+		return retval;
+
+	rv_attach_trace_probe("offstage", dovetail_leave_inband_tp, handle_leave_inband);
+	rv_attach_trace_probe("offstage", dovetail_leave_oob_tp, handle_leave_oob);
+	rv_attach_trace_probe("offstage", sched_switch, handle_sched_switch);
+	rv_attach_trace_probe("offstage", signal_generate, handle_signal_generate);
+
+	return 0;
+}
+
+static void disable_offstage(void)
+{
+	rv_this.enabled = 0;
+
+	rv_detach_trace_probe("offstage", dovetail_leave_inband_tp, handle_leave_inband);
+	rv_detach_trace_probe("offstage", dovetail_leave_oob_tp, handle_leave_oob);
+	rv_detach_trace_probe("offstage", sched_switch, handle_sched_switch);
+	rv_detach_trace_probe("offstage", signal_generate, handle_signal_generate);
+
+	da_monitor_destroy();
+}
+
+static struct rv_monitor rv_this = {
+	.name = "offstage",
+	.description = "Linux leaves a task alone while it is out-of-band",
+	.enable = enable_offstage,
+	.disable = disable_offstage,
+	.reset = da_monitor_reset_all,
+	.enabled = 0,
+};
+
+static int __init register_offstage(void)
+{
+	return rv_register_monitor(&rv_this, &rv_dovetail);
+}
+
+static void __exit unregister_offstage(void)
+{
+	rv_unregister_monitor(&rv_this);
+}
+
+module_init(register_offstage);
+module_exit(unregister_offstage);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Tobias Schaffner <tobias.schaffner@siemens.com>");
+MODULE_DESCRIPTION("offstage: Linux leaves a task alone while it is out-of-band");
diff --git a/kernel/trace/rv/monitors/offstage/offstage.h b/kernel/trace/rv/monitors/offstage/offstage.h
new file mode 100644
index 000000000000..2b8070ae6d5c
--- /dev/null
+++ b/kernel/trace/rv/monitors/offstage/offstage.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of offstage automaton
+ * For further information about this format, see kernel documentation:
+ *   Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME offstage
+
+enum states_offstage {
+	inband_offstage,
+	oob_offstage,
+	state_max_offstage,
+};
+
+#define INVALID_STATE state_max_offstage
+
+enum events_offstage {
+	leave_inband_offstage,
+	leave_oob_offstage,
+	sched_in_offstage,
+	signal_self_offstage,
+	event_max_offstage,
+};
+
+struct automaton_offstage {
+	char *state_names[state_max_offstage];
+	char *event_names[event_max_offstage];
+	unsigned char function[state_max_offstage][event_max_offstage];
+	unsigned char initial_state;
+	bool final_states[state_max_offstage];
+};
+
+static const struct automaton_offstage automaton_offstage = {
+	.state_names = {
+		"inband",
+		"oob",
+	},
+	.event_names = {
+		"leave_inband",
+		"leave_oob",
+		"sched_in",
+		"signal_self",
+	},
+	.function = {
+		{
+			oob_offstage,
+			INVALID_STATE,
+			inband_offstage,
+			inband_offstage,
+		},
+		{
+			INVALID_STATE,
+			inband_offstage,
+			INVALID_STATE,
+			INVALID_STATE,
+		},
+	},
+	.initial_state = inband_offstage,
+	.final_states = { 1, 0 },
+};
diff --git a/kernel/trace/rv/monitors/offstage/offstage_trace.h b/kernel/trace/rv/monitors/offstage/offstage_trace.h
new file mode 100644
index 000000000000..275ba7c78914
--- /dev/null
+++ b/kernel/trace/rv/monitors/offstage/offstage_trace.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Snippet to be included in rv_trace.h
+ */
+
+#ifdef CONFIG_RV_MON_OFFSTAGE
+DEFINE_EVENT(event_da_monitor_id, event_offstage,
+	     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_offstage,
+	     TP_PROTO(int id, char *state, char *event),
+	     TP_ARGS(id, state, event));
+#endif /* CONFIG_RV_MON_OFFSTAGE */
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 9622c269789c..9bda8ef3b96f 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -156,6 +156,7 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
 #include <monitors/snroc/snroc_trace.h>
 #include <monitors/nrp/nrp_trace.h>
 #include <monitors/sssw/sssw_trace.h>
+#include <monitors/offstage/offstage_trace.h>
 // Add new monitors based on CONFIG_DA_MON_EVENTS_ID here
 
 #ifdef CONFIG_HA_MON_EVENTS_ID
diff --git a/tools/verification/models/offstage.dot b/tools/verification/models/offstage.dot
new file mode 100644
index 000000000000..79f36efd430f
--- /dev/null
+++ b/tools/verification/models/offstage.dot
@@ -0,0 +1,14 @@
+digraph state_automaton {
+	{node [shape = plaintext, style=invis, label=""] "__init_inband"};
+	{node [shape = ellipse] "inband"};
+	{node [shape = plaintext] "oob"};
+	"__init_inband" -> "inband";
+	"inband" [label = "inband", color = green3];
+	"inband" -> "inband" [ label = "sched_in\nsignal_self" ];
+	"inband" -> "oob" [ label = "leave_inband" ];
+	"oob" -> "inband" [ label = "leave_oob" ];
+	{ rank = min ;
+		"__init_inband";
+		"inband";
+	}
+}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 4/7] dovetail: trace out-of-band trap notifications
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
                   ` (2 preceding siblings ...)
  2026-11-10 18:08 ` [RFC PATCH dovetail 3/7] rv: add dovetail container and offstage monitor Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 5/7] rv: add oob_trap monitor Tobias Schaffner
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Add tracepoints to oob_trap_notify() and oob_trap_unwind(), passing the
trap number and its register frame, for use by the oob_trap RV monitor.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 include/trace/events/dovetail.h | 9 +++++++++
 kernel/dovetail.c               | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/include/trace/events/dovetail.h b/include/trace/events/dovetail.h
index 785a653252d3..86d6405e84f5 100644
--- a/include/trace/events/dovetail.h
+++ b/include/trace/events/dovetail.h
@@ -7,6 +7,7 @@
 
 #include <linux/tracepoint.h>
 
+struct pt_regs;
 struct task_struct;
 
 DECLARE_TRACE(dovetail_leave_inband,
@@ -17,6 +18,14 @@ DECLARE_TRACE(dovetail_leave_oob,
 	TP_PROTO(struct task_struct *p),
 	TP_ARGS(p));
 
+DECLARE_TRACE(dovetail_trap_notify,
+	TP_PROTO(unsigned int trapnr, struct pt_regs *regs),
+	TP_ARGS(trapnr, regs));
+
+DECLARE_TRACE(dovetail_trap_unwind,
+	TP_PROTO(unsigned int trapnr, struct pt_regs *regs),
+	TP_ARGS(trapnr, regs));
+
 #endif /* _TRACE_DOVETAIL_H */
 
 /* This part must be outside protection */
diff --git a/kernel/dovetail.c b/kernel/dovetail.c
index 98892f0a63da..191fb651e396 100644
--- a/kernel/dovetail.c
+++ b/kernel/dovetail.c
@@ -304,6 +304,7 @@ noinstr void __oob_trap_notify(unsigned int exception,
 		set_thread_local_flags(_TLF_OOBTRAP);
 		flags = hard_local_irq_save();
 		instrumentation_begin();
+		trace_dovetail_trap_notify_tp(exception, regs);
 		handle_oob_trap_entry(exception, regs);
 		instrumentation_end();
 		hard_local_irq_restore(flags);
@@ -325,6 +326,7 @@ noinstr void __oob_trap_unwind(unsigned int exception, struct pt_regs *regs)
 	hard_local_irq_disable();
 	clear_thread_local_flags(_TLF_OOBTRAP);
 	instrumentation_begin();
+	trace_dovetail_trap_unwind_tp(exception, regs);
 	handle_oob_trap_exit(exception, regs);
 	instrumentation_end();
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 5/7] rv: add oob_trap monitor
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
                   ` (3 preceding siblings ...)
  2026-11-10 18:08 ` [RFC PATCH dovetail 4/7] dovetail: trace out-of-band trap notifications Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 6/7] dovetail: trace signal notifications and out-of-band returns Tobias Schaffner
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

A trap handler missing oob_trap_unwind() leaves _TLF_OOBTRAP set and the
companion core is no longer notified about traps of that task.

Add a monitor checking that every out-of-band trap is unwound for the same
trap, by number and frame, before the task resumes out-of-band.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 Documentation/trace/rv/monitor_dovetail.rst   |  26 ++++
 kernel/trace/rv/Kconfig                       |   1 +
 kernel/trace/rv/Makefile                      |   1 +
 kernel/trace/rv/monitors/oob_trap/Kconfig     |  14 ++
 kernel/trace/rv/monitors/oob_trap/oob_trap.c  | 144 ++++++++++++++++++
 kernel/trace/rv/monitors/oob_trap/oob_trap.h  |  61 ++++++++
 .../rv/monitors/oob_trap/oob_trap_trace.h     |  19 +++
 kernel/trace/rv/rv_trace.h                    |   1 +
 tools/verification/models/oob_trap.dot        |  14 ++
 9 files changed, 281 insertions(+)
 create mode 100644 kernel/trace/rv/monitors/oob_trap/Kconfig
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap.c
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap.h
 create mode 100644 kernel/trace/rv/monitors/oob_trap/oob_trap_trace.h
 create mode 100644 tools/verification/models/oob_trap.dot

diff --git a/Documentation/trace/rv/monitor_dovetail.rst b/Documentation/trace/rv/monitor_dovetail.rst
index e46cd0ab0b8d..e660b5c9a1ea 100644
--- a/Documentation/trace/rv/monitor_dovetail.rst
+++ b/Documentation/trace/rv/monitor_dovetail.rst
@@ -27,6 +27,8 @@ dovetail_leave_inband_tp    oob     after a successful switch; oob stage
                                     stalled, hard IRQs off, the core may hold
                                     its runqueue lock
 dovetail_leave_oob_tp       oob     before the switch to in-band, in the core
+dovetail_trap_notify_tp     oob     hard IRQs off, before the core is notified
+dovetail_trap_unwind_tp     either  hard IRQs off, before the core is notified
 ==========================  ======  ============================================
 
 Monitor offstage
@@ -48,6 +50,29 @@ the companion core demoted the task would::
 ``sched_in`` is a ``sched_switch`` to the task, ``signal_self`` a
 ``signal_generate`` by the task for itself.
 
+Monitor oob_trap
+++++++++++++++++
+
+Every out-of-band trap notification is unwound for the same trap before the
+task goes out-of-band again. A handler missing the unwind leaves
+``_TLF_OOBTRAP`` set, and the companion core is no longer told about the
+traps of that task::
+
+                  trap_notify; reset(same_trap)
+          +-------+   ------------------------>   +---------+
+          | idle  |                               | trapped |
+          +-------+   <------------------------   +---------+
+           |     ^    trap_unwind; same_trap == 1
+           +-----+
+         leave_inband
+
+A trap is identified by its number and register frame, so an unwind with the
+wrong number, and the unwind of a trap nested in the in-band handling of
+another one, are reported too. A leak is only seen once the task goes
+out-of-band again. Traps taken in NMI context are ignored. The model uses no
+clock, so the hybrid automaton core arms no timer and is safe on the
+out-of-band stage.
+
 Usage
 -----
 
@@ -59,6 +84,7 @@ Usage
   # cat enabled_monitors
   dovetail
   dovetail:offstage
+  dovetail:oob_trap
 
 Violations are reported by the selected reactor and as ``error_*`` events in
 ``events/rv``. The models are in ``tools/verification/models/``.
diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig
index 3f43cdfcbb32..d7207d7e9892 100644
--- a/kernel/trace/rv/Kconfig
+++ b/kernel/trace/rv/Kconfig
@@ -86,6 +86,7 @@ source "kernel/trace/rv/monitors/nomiss/Kconfig"
 
 source "kernel/trace/rv/monitors/dovetail/Kconfig"
 source "kernel/trace/rv/monitors/offstage/Kconfig"
+source "kernel/trace/rv/monitors/oob_trap/Kconfig"
 # Add new monitors here
 
 config RV_REACTORS
diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
index a684b0c9af2f..c5848be60f5b 100644
--- a/kernel/trace/rv/Makefile
+++ b/kernel/trace/rv/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_RV_MON_DEADLINE) += monitors/deadline/deadline.o
 obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o
 obj-$(CONFIG_RV_MON_DOVETAIL) += monitors/dovetail/dovetail.o
 obj-$(CONFIG_RV_MON_OFFSTAGE) += monitors/offstage/offstage.o
+obj-$(CONFIG_RV_MON_OOB_TRAP) += monitors/oob_trap/oob_trap.o
 # Add new monitors here
 obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
 obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
diff --git a/kernel/trace/rv/monitors/oob_trap/Kconfig b/kernel/trace/rv/monitors/oob_trap/Kconfig
new file mode 100644
index 000000000000..7a1709d3a8f3
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_trap/Kconfig
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+config RV_MON_OOB_TRAP
+	depends on RV
+	depends on RV_MON_DOVETAIL
+	default y
+	select HA_MON_EVENTS_ID
+	bool "oob_trap monitor"
+	help
+	  Per-task monitor checking that every out-of-band trap notification
+	  is unwound for the same trap before the task goes out-of-band again.
+
+	  For further information, see:
+	    Documentation/trace/rv/monitor_dovetail.rst
diff --git a/kernel/trace/rv/monitors/oob_trap/oob_trap.c b/kernel/trace/rv/monitors/oob_trap/oob_trap.c
new file mode 100644
index 000000000000..47e7ddd95aa1
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_trap/oob_trap.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * oob_trap: out-of-band trap notifications are balanced.
+ *
+ * Copyright (C) 2026 Siemens AG
+ * Author: Tobias Schaffner <tobias.schaffner@siemens.com>
+ */
+#include <linux/ftrace.h>
+#include <linux/tracepoint.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/rv.h>
+#include <rv/instrumentation.h>
+
+#define MODULE_NAME "oob_trap"
+
+#include <trace/events/dovetail.h>
+#include <trace/events/sched.h>
+#include <rv_trace.h>
+#include <monitors/dovetail/dovetail.h>
+
+#define RV_MON_TYPE RV_MON_PER_TASK
+#include "oob_trap.h"
+#include <rv/ha_monitor.h>
+
+/*
+ * Both trap tracepoints fire with hard IRQs off, and NMIs are ignored. A trap
+ * is identified by its number and frame; on 64-bit, kernel addresses share
+ * their top byte.
+ */
+static DEFINE_PER_CPU(u64, oob_trap_key);
+
+static u64 oob_trap_key_of(unsigned int trapnr, struct pt_regs *regs)
+{
+	return ((u64)trapnr << 56) ^ (unsigned long)regs;
+}
+
+static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_oob_trap env, u64 time_ns)
+{
+	if (env == same_trap_oob_trap)
+		return READ_ONCE(ha_mon->env_store[env]) == __this_cpu_read(oob_trap_key);
+	return ENV_INVALID_VALUE;
+}
+
+static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_oob_trap env, u64 time_ns)
+{
+	if (env == same_trap_oob_trap)
+		WRITE_ONCE(ha_mon->env_store[env], __this_cpu_read(oob_trap_key));
+}
+
+static inline bool ha_verify_guards(struct ha_monitor *ha_mon,
+				    enum states curr_state, enum events event,
+				    enum states next_state, u64 time_ns)
+{
+	bool res = true;
+
+	if (curr_state == idle_oob_trap && event == trap_notify_oob_trap)
+		ha_reset_env(ha_mon, same_trap_oob_trap, time_ns);
+	else if (curr_state == trapped_oob_trap && event == trap_unwind_oob_trap)
+		res = ha_monitor_env_invalid(ha_mon, same_trap_oob_trap) ||
+		      ha_get_env(ha_mon, same_trap_oob_trap, time_ns) == 1ull;
+	return res;
+}
+
+static bool ha_verify_constraint(struct ha_monitor *ha_mon,
+				 enum states curr_state, enum events event,
+				 enum states next_state, u64 time_ns)
+{
+	return ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns);
+}
+
+static void handle_trap_notify(void *data, unsigned int trapnr, struct pt_regs *regs)
+{
+	if (in_nmi())
+		return;
+	__this_cpu_write(oob_trap_key, oob_trap_key_of(trapnr, regs));
+	da_handle_start_run_event(current, trap_notify_oob_trap);
+}
+
+static void handle_trap_unwind(void *data, unsigned int trapnr, struct pt_regs *regs)
+{
+	if (in_nmi())
+		return;
+	__this_cpu_write(oob_trap_key, oob_trap_key_of(trapnr, regs));
+	da_handle_event(current, trap_unwind_oob_trap);
+}
+
+static void handle_leave_inband(void *data, struct task_struct *p)
+{
+	da_handle_start_run_event(p, leave_inband_oob_trap);
+}
+
+static int enable_oob_trap(void)
+{
+	int retval;
+
+	retval = ha_monitor_init();
+	if (retval)
+		return retval;
+
+	rv_attach_trace_probe("oob_trap", dovetail_trap_notify_tp, handle_trap_notify);
+	rv_attach_trace_probe("oob_trap", dovetail_trap_unwind_tp, handle_trap_unwind);
+	rv_attach_trace_probe("oob_trap", dovetail_leave_inband_tp, handle_leave_inband);
+
+	return 0;
+}
+
+static void disable_oob_trap(void)
+{
+	rv_this.enabled = 0;
+
+	rv_detach_trace_probe("oob_trap", dovetail_trap_notify_tp, handle_trap_notify);
+	rv_detach_trace_probe("oob_trap", dovetail_trap_unwind_tp, handle_trap_unwind);
+	rv_detach_trace_probe("oob_trap", dovetail_leave_inband_tp, handle_leave_inband);
+
+	ha_monitor_destroy();
+}
+
+static struct rv_monitor rv_this = {
+	.name = "oob_trap",
+	.description = "out-of-band trap notifications are balanced",
+	.enable = enable_oob_trap,
+	.disable = disable_oob_trap,
+	.reset = da_monitor_reset_all,
+	.enabled = 0,
+};
+
+static int __init register_oob_trap(void)
+{
+	return rv_register_monitor(&rv_this, &rv_dovetail);
+}
+
+static void __exit unregister_oob_trap(void)
+{
+	rv_unregister_monitor(&rv_this);
+}
+
+module_init(register_oob_trap);
+module_exit(unregister_oob_trap);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Tobias Schaffner <tobias.schaffner@siemens.com>");
+MODULE_DESCRIPTION("oob_trap: out-of-band trap notifications are balanced");
diff --git a/kernel/trace/rv/monitors/oob_trap/oob_trap.h b/kernel/trace/rv/monitors/oob_trap/oob_trap.h
new file mode 100644
index 000000000000..7d73dc10560f
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_trap/oob_trap.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of oob_trap automaton
+ * For further information about this format, see kernel documentation:
+ *   Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME oob_trap
+
+enum states_oob_trap {
+	idle_oob_trap,
+	trapped_oob_trap,
+	state_max_oob_trap,
+};
+
+#define INVALID_STATE state_max_oob_trap
+
+enum events_oob_trap {
+	leave_inband_oob_trap,
+	trap_notify_oob_trap,
+	trap_unwind_oob_trap,
+	event_max_oob_trap,
+};
+
+enum envs_oob_trap {
+	same_trap_oob_trap,
+	env_max_oob_trap,
+	env_max_stored_oob_trap = env_max_oob_trap,
+};
+
+_Static_assert(env_max_stored_oob_trap <= MAX_HA_ENV_LEN, "Not enough slots");
+
+struct automaton_oob_trap {
+	char *state_names[state_max_oob_trap];
+	char *event_names[event_max_oob_trap];
+	char *env_names[env_max_oob_trap];
+	unsigned char function[state_max_oob_trap][event_max_oob_trap];
+	unsigned char initial_state;
+	bool final_states[state_max_oob_trap];
+};
+
+static const struct automaton_oob_trap automaton_oob_trap = {
+	.state_names = {
+		"idle",
+		"trapped",
+	},
+	.event_names = {
+		"leave_inband",
+		"trap_notify",
+		"trap_unwind",
+	},
+	.env_names = {
+		"same_trap",
+	},
+	.function = {
+		{          idle_oob_trap,       trapped_oob_trap,          INVALID_STATE },
+		{          INVALID_STATE,          INVALID_STATE,          idle_oob_trap },
+	},
+	.initial_state = idle_oob_trap,
+	.final_states = { 1, 0 },
+};
diff --git a/kernel/trace/rv/monitors/oob_trap/oob_trap_trace.h b/kernel/trace/rv/monitors/oob_trap/oob_trap_trace.h
new file mode 100644
index 000000000000..fcb2f5bc6965
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_trap/oob_trap_trace.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Snippet to be included in rv_trace.h
+ */
+
+#ifdef CONFIG_RV_MON_OOB_TRAP
+DEFINE_EVENT(event_da_monitor_id, event_oob_trap,
+	     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_oob_trap,
+	     TP_PROTO(int id, char *state, char *event),
+	     TP_ARGS(id, state, event));
+
+DEFINE_EVENT(error_env_da_monitor_id, error_env_oob_trap,
+	     TP_PROTO(int id, char *state, char *event, char *env),
+	     TP_ARGS(id, state, event, env));
+#endif /* CONFIG_RV_MON_OOB_TRAP */
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 9bda8ef3b96f..bcd7ee424e89 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -190,6 +190,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,
 
 #include <monitors/stall/stall_trace.h>
 #include <monitors/nomiss/nomiss_trace.h>
+#include <monitors/oob_trap/oob_trap_trace.h>
 // Add new monitors based on CONFIG_HA_MON_EVENTS_ID here
 
 #endif
diff --git a/tools/verification/models/oob_trap.dot b/tools/verification/models/oob_trap.dot
new file mode 100644
index 000000000000..97ef5c3b9431
--- /dev/null
+++ b/tools/verification/models/oob_trap.dot
@@ -0,0 +1,14 @@
+digraph state_automaton {
+	{node [shape = plaintext, style=invis, label=""] "__init_idle"};
+	{node [shape = ellipse] "idle"};
+	{node [shape = plaintext] "trapped"};
+	"__init_idle" -> "idle";
+	"idle" [label = "idle", color = green3];
+	"idle" -> "trapped" [ label = "trap_notify;reset(same_trap)" ];
+	"trapped" -> "idle" [ label = "trap_unwind;same_trap == 1" ];
+	"idle" -> "idle" [ label = "leave_inband" ];
+	{ rank = min ;
+		"__init_idle";
+		"idle";
+	}
+}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 6/7] dovetail: trace signal notifications and out-of-band returns
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
                   ` (4 preceding siblings ...)
  2026-11-10 18:08 ` [RFC PATCH dovetail 5/7] rv: add oob_trap monitor Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-10 18:08 ` [RFC PATCH dovetail 7/7] rv: add oob_signal monitor Tobias Schaffner
  2026-11-19 19:14 ` [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Philippe Gerum
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Add a tracepoint for the signal notification to the companion core, fired
once the core handled it, and one in dovetail_oob_exit_to_user(), for use
by the oob_signal RV monitor.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 include/linux/dovetail.h        | 8 +++++++-
 include/trace/events/dovetail.h | 8 ++++++++
 kernel/dovetail.c               | 6 ++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/linux/dovetail.h b/include/linux/dovetail.h
index 5ab07e69152a..a25a4ccfbded 100644
--- a/include/linux/dovetail.h
+++ b/include/linux/dovetail.h
@@ -85,10 +85,16 @@ void inband_event_notify(enum inband_event_type,
 
 void inband_clock_was_set(void);
 
+DECLARE_TRACEPOINT(dovetail_signal_notify_tp);
+void __trace_dovetail_signal_notify(struct task_struct *p);
+
 static inline void inband_signal_notify(struct task_struct *p)
 {
-	if (test_ti_local_flags(task_thread_info(p), _TLF_DOVETAIL))
+	if (test_ti_local_flags(task_thread_info(p), _TLF_DOVETAIL)) {
 		inband_event_notify(INBAND_TASK_SIGNAL, p);
+		if (tracepoint_enabled(dovetail_signal_notify_tp))
+			__trace_dovetail_signal_notify(p);
+	}
 }
 
 static inline void inband_migration_notify(struct task_struct *p, int cpu)
diff --git a/include/trace/events/dovetail.h b/include/trace/events/dovetail.h
index 86d6405e84f5..6ac5a7fed420 100644
--- a/include/trace/events/dovetail.h
+++ b/include/trace/events/dovetail.h
@@ -26,6 +26,14 @@ DECLARE_TRACE(dovetail_trap_unwind,
 	TP_PROTO(unsigned int trapnr, struct pt_regs *regs),
 	TP_ARGS(trapnr, regs));
 
+DECLARE_TRACE(dovetail_oob_return,
+	TP_PROTO(struct task_struct *p),
+	TP_ARGS(p));
+
+DECLARE_TRACE(dovetail_signal_notify,
+	TP_PROTO(struct task_struct *p),
+	TP_ARGS(p));
+
 #endif /* _TRACE_DOVETAIL_H */
 
 /* This part must be outside protection */
diff --git a/kernel/dovetail.c b/kernel/dovetail.c
index 191fb651e396..c25ad3ee8e02 100644
--- a/kernel/dovetail.c
+++ b/kernel/dovetail.c
@@ -25,6 +25,11 @@ void __trace_dovetail_leave_oob(void)
 	trace_dovetail_leave_oob_tp(current);
 }
 
+void __trace_dovetail_signal_notify(struct task_struct *p)
+{
+	trace_dovetail_signal_notify_tp(p);
+}
+
 static bool dovetail_enabled;
 
 void __weak arch_inband_task_init(struct task_struct *p)
@@ -115,6 +120,7 @@ void dovetail_call_mayday(struct pt_regs *regs)
 /* Returning to user mode on the out-of-band stage. */
 void dovetail_oob_exit_to_user(struct pt_regs *regs)
 {
+	trace_dovetail_oob_return_tp(current);
 	if (test_thread_flag(TIF_MAYDAY))
 		dovetail_call_mayday(regs);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH dovetail 7/7] rv: add oob_signal monitor
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
                   ` (5 preceding siblings ...)
  2026-11-10 18:08 ` [RFC PATCH dovetail 6/7] dovetail: trace signal notifications and out-of-band returns Tobias Schaffner
@ 2026-11-10 18:08 ` Tobias Schaffner
  2026-11-19 19:14 ` [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Philippe Gerum
  7 siblings, 0 replies; 11+ messages in thread
From: Tobias Schaffner @ 2026-11-10 18:08 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, jan.kiszka, Tobias Schaffner

Signals are delivered in-band only, so the companion core has to kick a
task receiving a signal out-of-band, usually with a mayday.

Add a monitor checking that such a task does not return to user mode
out-of-band without a mayday pending.

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
 Documentation/trace/rv/monitor_dovetail.rst   |  34 ++++++
 kernel/trace/rv/Kconfig                       |   1 +
 kernel/trace/rv/Makefile                      |   1 +
 kernel/trace/rv/monitors/oob_signal/Kconfig   |  16 +++
 .../trace/rv/monitors/oob_signal/oob_signal.c | 114 ++++++++++++++++++
 .../trace/rv/monitors/oob_signal/oob_signal.h |  74 ++++++++++++
 .../rv/monitors/oob_signal/oob_signal_trace.h |  15 +++
 kernel/trace/rv/rv_trace.h                    |   1 +
 tools/verification/models/oob_signal.dot      |  23 ++++
 9 files changed, 279 insertions(+)
 create mode 100644 kernel/trace/rv/monitors/oob_signal/Kconfig
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal.c
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal.h
 create mode 100644 kernel/trace/rv/monitors/oob_signal/oob_signal_trace.h
 create mode 100644 tools/verification/models/oob_signal.dot

diff --git a/Documentation/trace/rv/monitor_dovetail.rst b/Documentation/trace/rv/monitor_dovetail.rst
index e660b5c9a1ea..de9f6f05db24 100644
--- a/Documentation/trace/rv/monitor_dovetail.rst
+++ b/Documentation/trace/rv/monitor_dovetail.rst
@@ -17,6 +17,10 @@ are per-task monitors fed by Dovetail and generic tracepoints only, meant for
 validation: while enabled, they add work to out-of-band hot paths.
 ``CONFIG_RV_DOVETAIL`` enables them with RV and the printk reactor.
 
+Each monitor takes one of ``CONFIG_RV_PER_TASK_MONITORS`` slots while
+enabled, so the container needs at least three, the default with
+``CONFIG_RV_DOVETAIL``.
+
 The Dovetail tracepoints fire in the context given here, so their probes must
 be safe there:
 
@@ -29,6 +33,11 @@ dovetail_leave_inband_tp    oob     after a successful switch; oob stage
 dovetail_leave_oob_tp       oob     before the switch to in-band, in the core
 dovetail_trap_notify_tp     oob     hard IRQs off, before the core is notified
 dovetail_trap_unwind_tp     either  hard IRQs off, before the core is notified
+dovetail_oob_return_tp      oob     on return to user mode from an interrupt
+                                    or an oob syscall; hard IRQs on at the oob
+                                    syscall return
+dovetail_signal_notify_tp   inband  after the core handled the notification,
+                                    siglock held
 ==========================  ======  ============================================
 
 Monitor offstage
@@ -73,6 +82,30 @@ out-of-band again. Traps taken in NMI context are ignored. The model uses no
 clock, so the hybrid automaton core arms no timer and is safe on the
 out-of-band stage.
 
+Monitor oob_signal
+++++++++++++++++++
+
+Signals are delivered in-band, so the companion core has to kick a task
+signaled out-of-band, with a mayday if the task may return to user mode
+there. Once the core handled the notification, the task must not return to
+user mode out-of-band without a mayday pending. A task reaching the
+out-of-band stage with a signal pending is held to the same rule::
+
+    state     leave_   leave_  oob_    oob_return_  signal
+              inband   oob     return  mayday
+    inband    oob      -       -       -            inband
+    oob       -        inband  oob     oob          signaled
+    signaled  -        inband  -       signaled     signaled
+
+The monitor takes no lock. The core sets ``TIF_MAYDAY`` in its
+``INBAND_TASK_SIGNAL`` handler, before the notification moves the task to
+signaled, and a return reads ``TIF_MAYDAY`` only once it sees signaled. As the
+notifier holds ``siglock``, the task cannot consume the signal and come back
+out-of-band before the notification is seen. A return from a trap the core
+does not demote, or after a RETUSER switch, is not seen. The monitor is not
+available on 32-bit arm, whose out-of-band syscall fast path is not
+instrumented.
+
 Usage
 -----
 
@@ -85,6 +118,7 @@ Usage
   dovetail
   dovetail:offstage
   dovetail:oob_trap
+  dovetail:oob_signal
 
 Violations are reported by the selected reactor and as ``error_*`` events in
 ``events/rv``. The models are in ``tools/verification/models/``.
diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig
index d7207d7e9892..cf1c81e3df3f 100644
--- a/kernel/trace/rv/Kconfig
+++ b/kernel/trace/rv/Kconfig
@@ -87,6 +87,7 @@ source "kernel/trace/rv/monitors/nomiss/Kconfig"
 source "kernel/trace/rv/monitors/dovetail/Kconfig"
 source "kernel/trace/rv/monitors/offstage/Kconfig"
 source "kernel/trace/rv/monitors/oob_trap/Kconfig"
+source "kernel/trace/rv/monitors/oob_signal/Kconfig"
 # Add new monitors here
 
 config RV_REACTORS
diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
index c5848be60f5b..46bc8bf33e33 100644
--- a/kernel/trace/rv/Makefile
+++ b/kernel/trace/rv/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_RV_MON_NOMISS) += monitors/nomiss/nomiss.o
 obj-$(CONFIG_RV_MON_DOVETAIL) += monitors/dovetail/dovetail.o
 obj-$(CONFIG_RV_MON_OFFSTAGE) += monitors/offstage/offstage.o
 obj-$(CONFIG_RV_MON_OOB_TRAP) += monitors/oob_trap/oob_trap.o
+obj-$(CONFIG_RV_MON_OOB_SIGNAL) += monitors/oob_signal/oob_signal.o
 # Add new monitors here
 obj-$(CONFIG_RV_REACTORS) += rv_reactors.o
 obj-$(CONFIG_RV_REACT_PRINTK) += reactor_printk.o
diff --git a/kernel/trace/rv/monitors/oob_signal/Kconfig b/kernel/trace/rv/monitors/oob_signal/Kconfig
new file mode 100644
index 000000000000..82d3ca1dbed7
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_signal/Kconfig
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+config RV_MON_OOB_SIGNAL
+	depends on RV
+	depends on RV_MON_DOVETAIL
+	depends on !ARM
+	default y
+	select DA_MON_EVENTS_ID
+	bool "oob_signal monitor"
+	help
+	  Per-task monitor checking that a dovetailed task which receives a
+	  signal while out-of-band does not return to user mode out-of-band
+	  without a mayday pending, since signals are delivered in-band only.
+
+	  For further information, see:
+	    Documentation/trace/rv/monitor_dovetail.rst
diff --git a/kernel/trace/rv/monitors/oob_signal/oob_signal.c b/kernel/trace/rv/monitors/oob_signal/oob_signal.c
new file mode 100644
index 000000000000..44c3d53d9366
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_signal/oob_signal.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * oob_signal: a signaled task does not return to user mode out-of-band.
+ *
+ * Copyright (C) 2026 Siemens AG
+ * Author: Tobias Schaffner <tobias.schaffner@siemens.com>
+ */
+#include <linux/ftrace.h>
+#include <linux/tracepoint.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/rv.h>
+#include <linux/dovetail.h>
+#include <rv/instrumentation.h>
+
+#define MODULE_NAME "oob_signal"
+
+#include <trace/events/dovetail.h>
+#include <rv_trace.h>
+#include <monitors/dovetail/dovetail.h>
+
+#define RV_MON_TYPE RV_MON_PER_TASK
+#include "oob_signal.h"
+#include <rv/da_monitor.h>
+
+/*
+ * No locking: the core sets TIF_MAYDAY before the notification moves the task
+ * to signaled, and a return reads TIF_MAYDAY only after seeing signaled.
+ */
+static void handle_leave_inband(void *data, struct task_struct *p)
+{
+	da_handle_start_run_event(p, leave_inband_oob_signal);
+	/* A signal notified before the switch is seen here, a later one finds oob. */
+	if (task_sigpending(p))
+		da_handle_event(p, signal_oob_signal);
+}
+
+static void handle_leave_oob(void *data, struct task_struct *p)
+{
+	da_handle_event(p, leave_oob_oob_signal);
+}
+
+static void handle_oob_return(void *data, struct task_struct *p)
+{
+	struct da_monitor *da_mon = da_get_monitor(p);
+
+	if (!da_monitoring(da_mon))
+		return;
+	/* Pairs with the cmpxchg of the notification moving to signaled. */
+	if (smp_load_acquire(&da_mon->curr_state) != signaled_oob_signal)
+		return;
+	da_handle_event(p, test_ti_thread_flag(task_thread_info(p), TIF_MAYDAY) ?
+			oob_return_mayday_oob_signal : oob_return_oob_signal);
+}
+
+static void handle_signal_notify(void *data, struct task_struct *p)
+{
+	da_handle_event(p, signal_oob_signal);
+}
+
+static int enable_oob_signal(void)
+{
+	int retval;
+
+	retval = da_monitor_init();
+	if (retval)
+		return retval;
+
+	rv_attach_trace_probe("oob_signal", dovetail_leave_inband_tp, handle_leave_inband);
+	rv_attach_trace_probe("oob_signal", dovetail_leave_oob_tp, handle_leave_oob);
+	rv_attach_trace_probe("oob_signal", dovetail_oob_return_tp, handle_oob_return);
+	rv_attach_trace_probe("oob_signal", dovetail_signal_notify_tp, handle_signal_notify);
+
+	return 0;
+}
+
+static void disable_oob_signal(void)
+{
+	rv_this.enabled = 0;
+
+	rv_detach_trace_probe("oob_signal", dovetail_leave_inband_tp, handle_leave_inband);
+	rv_detach_trace_probe("oob_signal", dovetail_leave_oob_tp, handle_leave_oob);
+	rv_detach_trace_probe("oob_signal", dovetail_oob_return_tp, handle_oob_return);
+	rv_detach_trace_probe("oob_signal", dovetail_signal_notify_tp, handle_signal_notify);
+
+	da_monitor_destroy();
+}
+
+static struct rv_monitor rv_this = {
+	.name = "oob_signal",
+	.description = "a signaled task does not return to user mode out-of-band",
+	.enable = enable_oob_signal,
+	.disable = disable_oob_signal,
+	.reset = da_monitor_reset_all,
+	.enabled = 0,
+};
+
+static int __init register_oob_signal(void)
+{
+	return rv_register_monitor(&rv_this, &rv_dovetail);
+}
+
+static void __exit unregister_oob_signal(void)
+{
+	rv_unregister_monitor(&rv_this);
+}
+
+module_init(register_oob_signal);
+module_exit(unregister_oob_signal);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Tobias Schaffner <tobias.schaffner@siemens.com>");
+MODULE_DESCRIPTION("oob_signal: a signaled task does not return to user mode out-of-band");
diff --git a/kernel/trace/rv/monitors/oob_signal/oob_signal.h b/kernel/trace/rv/monitors/oob_signal/oob_signal.h
new file mode 100644
index 000000000000..655636a0cdef
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_signal/oob_signal.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Automatically generated C representation of oob_signal automaton
+ * For further information about this format, see kernel documentation:
+ *   Documentation/trace/rv/deterministic_automata.rst
+ */
+
+#define MONITOR_NAME oob_signal
+
+enum states_oob_signal {
+	inband_oob_signal,
+	oob_oob_signal,
+	signaled_oob_signal,
+	state_max_oob_signal,
+};
+
+#define INVALID_STATE state_max_oob_signal
+
+enum events_oob_signal {
+	leave_inband_oob_signal,
+	leave_oob_oob_signal,
+	oob_return_oob_signal,
+	oob_return_mayday_oob_signal,
+	signal_oob_signal,
+	event_max_oob_signal,
+};
+
+struct automaton_oob_signal {
+	char *state_names[state_max_oob_signal];
+	char *event_names[event_max_oob_signal];
+	unsigned char function[state_max_oob_signal][event_max_oob_signal];
+	unsigned char initial_state;
+	bool final_states[state_max_oob_signal];
+};
+
+static const struct automaton_oob_signal automaton_oob_signal = {
+	.state_names = {
+		"inband",
+		"oob",
+		"signaled",
+	},
+	.event_names = {
+		"leave_inband",
+		"leave_oob",
+		"oob_return",
+		"oob_return_mayday",
+		"signal",
+	},
+	.function = {
+		{
+			oob_oob_signal,
+			INVALID_STATE,
+			INVALID_STATE,
+			INVALID_STATE,
+			inband_oob_signal,
+		},
+		{
+			INVALID_STATE,
+			inband_oob_signal,
+			oob_oob_signal,
+			oob_oob_signal,
+			signaled_oob_signal,
+		},
+		{
+			INVALID_STATE,
+			inband_oob_signal,
+			INVALID_STATE,
+			signaled_oob_signal,
+			signaled_oob_signal,
+		},
+	},
+	.initial_state = inband_oob_signal,
+	.final_states = { 1, 0, 0 },
+};
diff --git a/kernel/trace/rv/monitors/oob_signal/oob_signal_trace.h b/kernel/trace/rv/monitors/oob_signal/oob_signal_trace.h
new file mode 100644
index 000000000000..63842f32effb
--- /dev/null
+++ b/kernel/trace/rv/monitors/oob_signal/oob_signal_trace.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Snippet to be included in rv_trace.h
+ */
+
+#ifdef CONFIG_RV_MON_OOB_SIGNAL
+DEFINE_EVENT(event_da_monitor_id, event_oob_signal,
+	     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_oob_signal,
+	     TP_PROTO(int id, char *state, char *event),
+	     TP_ARGS(id, state, event));
+#endif /* CONFIG_RV_MON_OOB_SIGNAL */
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index bcd7ee424e89..e590b753beab 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -157,6 +157,7 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
 #include <monitors/nrp/nrp_trace.h>
 #include <monitors/sssw/sssw_trace.h>
 #include <monitors/offstage/offstage_trace.h>
+#include <monitors/oob_signal/oob_signal_trace.h>
 // Add new monitors based on CONFIG_DA_MON_EVENTS_ID here
 
 #ifdef CONFIG_HA_MON_EVENTS_ID
diff --git a/tools/verification/models/oob_signal.dot b/tools/verification/models/oob_signal.dot
new file mode 100644
index 000000000000..1a9e9b5c9e17
--- /dev/null
+++ b/tools/verification/models/oob_signal.dot
@@ -0,0 +1,23 @@
+digraph state_automaton {
+	center = true;
+	size = "7,11";
+	{node [shape = plaintext, style=invis, label=""] "__init_inband"};
+	{node [shape = doublecircle] "inband"};
+	{node [shape = circle] "oob"};
+	{node [shape = circle] "signaled"};
+	"__init_inband" -> "inband";
+	"inband" [label = "inband", color = green3];
+	"oob" [label = "oob"];
+	"signaled" [label = "signaled"];
+	"inband" -> "inband" [ label = "signal" ];
+	"inband" -> "oob" [ label = "leave_inband" ];
+	"oob" -> "inband" [ label = "leave_oob" ];
+	"oob" -> "oob" [ label = "oob_return\noob_return_mayday" ];
+	"oob" -> "signaled" [ label = "signal" ];
+	"signaled" -> "inband" [ label = "leave_oob" ];
+	"signaled" -> "signaled" [ label = "signal\noob_return_mayday" ];
+	{ rank = min ;
+		"__init_inband";
+		"inband";
+	}
+}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH dovetail 2/7] dovetail: trace stage switches
  2026-11-10 18:08 ` [RFC PATCH dovetail 2/7] dovetail: trace stage switches Tobias Schaffner
@ 2026-11-11  7:40   ` Jan Kiszka
  2026-11-19 19:07     ` Philippe Gerum
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Kiszka @ 2026-11-11  7:40 UTC (permalink / raw)
  To: Tobias Schaffner, xenomai; +Cc: rpm

On 10.11.26 19:08, Tobias Schaffner wrote:
> Add tracepoints for a task leaving the in-band and the out-of-band stage,
> for use by the Dovetail RV monitors.
> 
> Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
> ---
>  include/linux/dovetail.h        |  9 +++++++++
>  include/trace/events/dovetail.h | 23 +++++++++++++++++++++++
>  kernel/dovetail.c               | 13 +++++++++++++
>  kernel/sched/core.c             |  2 ++
>  4 files changed, 47 insertions(+)
>  create mode 100644 include/trace/events/dovetail.h
> 
> diff --git a/include/linux/dovetail.h b/include/linux/dovetail.h
> index b41ea0f8fc4e..5ab07e69152a 100644
> --- a/include/linux/dovetail.h
> +++ b/include/linux/dovetail.h
> @@ -18,6 +18,7 @@ struct files_struct;
>  #include <linux/mm.h>
>  #include <linux/thread_info.h>
>  #include <linux/irqstage.h>
> +#include <linux/tracepoint-defs.h>
>  #include <uapi/asm-generic/dovetail.h>
>  #include <asm/dovetail.h>
>  
> @@ -163,8 +164,16 @@ void dovetail_stop_altsched(void);
>  
>  __must_check int dovetail_leave_inband(void);
>  
> +DECLARE_TRACEPOINT(dovetail_leave_inband_tp);
> +void __trace_dovetail_leave_inband(struct task_struct *p);
> +
> +DECLARE_TRACEPOINT(dovetail_leave_oob_tp);
> +void __trace_dovetail_leave_oob(void);
> +
>  static inline void dovetail_leave_oob(void)
>  {
> +	if (tracepoint_enabled(dovetail_leave_oob_tp))
> +		__trace_dovetail_leave_oob();
>  	clear_thread_local_flags(_TLF_OOB|_TLF_OFFSTAGE);
>  	clear_thread_flag(TIF_MAYDAY);
>  }
> diff --git a/include/trace/events/dovetail.h b/include/trace/events/dovetail.h
> new file mode 100644
> index 000000000000..785a653252d3
> --- /dev/null
> +++ b/include/trace/events/dovetail.h
> @@ -0,0 +1,23 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM dovetail
> +
> +#if !defined(_TRACE_DOVETAIL_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_DOVETAIL_H
> +
> +#include <linux/tracepoint.h>
> +
> +struct task_struct;
> +
> +DECLARE_TRACE(dovetail_leave_inband,
> +	TP_PROTO(struct task_struct *p),
> +	TP_ARGS(p));
> +
> +DECLARE_TRACE(dovetail_leave_oob,
> +	TP_PROTO(struct task_struct *p),
> +	TP_ARGS(p));
> +
> +#endif /* _TRACE_DOVETAIL_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> diff --git a/kernel/dovetail.c b/kernel/dovetail.c
> index da4016697b67..98892f0a63da 100644
> --- a/kernel/dovetail.c
> +++ b/kernel/dovetail.c
> @@ -12,6 +12,19 @@
>  #include <asm/syscall.h>
>  #include <uapi/asm-generic/dovetail.h>
>  
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/dovetail.h>
> +
> +void __trace_dovetail_leave_inband(struct task_struct *p)
> +{
> +	trace_dovetail_leave_inband_tp(p);
> +}
> +
> +void __trace_dovetail_leave_oob(void)
> +{
> +	trace_dovetail_leave_oob_tp(current);
> +}
> +
>  static bool dovetail_enabled;
>  
>  void __weak arch_inband_task_init(struct task_struct *p)
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 3ec77a682c4a..b2ad0ab0626c 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -10689,6 +10689,8 @@ int dovetail_leave_inband(void)
>  	 */
>  	if (likely(__schedule(SM_NONE))) {
>  		arch_dovetail_switch_finish(false);
> +		if (tracepoint_enabled(dovetail_leave_inband_tp))
> +			__trace_dovetail_leave_inband(p);

Why does trace point have to be conditional? Rather unusual.

Jan

>  		return 0;
>  	}
>  


-- 
Siemens AG, Foundational Technologies
Linux Expert Center

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH dovetail 2/7] dovetail: trace stage switches
  2026-11-11  7:40   ` Jan Kiszka
@ 2026-11-19 19:07     ` Philippe Gerum
  0 siblings, 0 replies; 11+ messages in thread
From: Philippe Gerum @ 2026-11-19 19:07 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Tobias Schaffner, xenomai

Jan Kiszka <jan.kiszka@siemens.com> writes:

> On 10.11.26 19:08, Tobias Schaffner wrote:
>> Add tracepoints for a task leaving the in-band and the out-of-band stage,
>> for use by the Dovetail RV monitors.
>> 
>> Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
>> ---
>>  include/linux/dovetail.h        |  9 +++++++++
>>  include/trace/events/dovetail.h | 23 +++++++++++++++++++++++
>>  kernel/dovetail.c               | 13 +++++++++++++
>>  kernel/sched/core.c             |  2 ++
>>  4 files changed, 47 insertions(+)
>>  create mode 100644 include/trace/events/dovetail.h
>> 
>> diff --git a/include/linux/dovetail.h b/include/linux/dovetail.h
>> index b41ea0f8fc4e..5ab07e69152a 100644
>> --- a/include/linux/dovetail.h
>> +++ b/include/linux/dovetail.h
>> @@ -18,6 +18,7 @@ struct files_struct;
>>  #include <linux/mm.h>
>>  #include <linux/thread_info.h>
>>  #include <linux/irqstage.h>
>> +#include <linux/tracepoint-defs.h>
>>  #include <uapi/asm-generic/dovetail.h>
>>  #include <asm/dovetail.h>
>>  
>> @@ -163,8 +164,16 @@ void dovetail_stop_altsched(void);
>>  
>>  __must_check int dovetail_leave_inband(void);
>>  
>> +DECLARE_TRACEPOINT(dovetail_leave_inband_tp);
>> +void __trace_dovetail_leave_inband(struct task_struct *p);
>> +
>> +DECLARE_TRACEPOINT(dovetail_leave_oob_tp);
>> +void __trace_dovetail_leave_oob(void);
>> +
>>  static inline void dovetail_leave_oob(void)
>>  {
>> +	if (tracepoint_enabled(dovetail_leave_oob_tp))
>> +		__trace_dovetail_leave_oob();
>>  	clear_thread_local_flags(_TLF_OOB|_TLF_OFFSTAGE);
>>  	clear_thread_flag(TIF_MAYDAY);
>>  }
>> diff --git a/include/trace/events/dovetail.h b/include/trace/events/dovetail.h
>> new file mode 100644
>> index 000000000000..785a653252d3
>> --- /dev/null
>> +++ b/include/trace/events/dovetail.h
>> @@ -0,0 +1,23 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +#undef TRACE_SYSTEM
>> +#define TRACE_SYSTEM dovetail
>> +
>> +#if !defined(_TRACE_DOVETAIL_H) || defined(TRACE_HEADER_MULTI_READ)
>> +#define _TRACE_DOVETAIL_H
>> +
>> +#include <linux/tracepoint.h>
>> +
>> +struct task_struct;
>> +
>> +DECLARE_TRACE(dovetail_leave_inband,
>> +	TP_PROTO(struct task_struct *p),
>> +	TP_ARGS(p));
>> +
>> +DECLARE_TRACE(dovetail_leave_oob,
>> +	TP_PROTO(struct task_struct *p),
>> +	TP_ARGS(p));
>> +
>> +#endif /* _TRACE_DOVETAIL_H */
>> +
>> +/* This part must be outside protection */
>> +#include <trace/define_trace.h>
>> diff --git a/kernel/dovetail.c b/kernel/dovetail.c
>> index da4016697b67..98892f0a63da 100644
>> --- a/kernel/dovetail.c
>> +++ b/kernel/dovetail.c
>> @@ -12,6 +12,19 @@
>>  #include <asm/syscall.h>
>>  #include <uapi/asm-generic/dovetail.h>
>>  
>> +#define CREATE_TRACE_POINTS
>> +#include <trace/events/dovetail.h>
>> +
>> +void __trace_dovetail_leave_inband(struct task_struct *p)
>> +{
>> +	trace_dovetail_leave_inband_tp(p);
>> +}
>> +
>> +void __trace_dovetail_leave_oob(void)
>> +{
>> +	trace_dovetail_leave_oob_tp(current);
>> +}
>> +
>>  static bool dovetail_enabled;
>>  
>>  void __weak arch_inband_task_init(struct task_struct *p)
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 3ec77a682c4a..b2ad0ab0626c 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -10689,6 +10689,8 @@ int dovetail_leave_inband(void)
>>  	 */
>>  	if (likely(__schedule(SM_NONE))) {
>>  		arch_dovetail_switch_finish(false);
>> +		if (tracepoint_enabled(dovetail_leave_inband_tp))
>> +			__trace_dovetail_leave_inband(p);
>
> Why does trace point have to be conditional? Rather unusual.
>

I guess that the upside of having a static key to fully skip the
tracepoint prep dynamically may be wanted here. Granted,
dovetail_leave_inband() should not be on the hot path, but we are
nevertheless on the switch tail path to oob.

-- 
Philippe.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail
  2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
                   ` (6 preceding siblings ...)
  2026-11-10 18:08 ` [RFC PATCH dovetail 7/7] rv: add oob_signal monitor Tobias Schaffner
@ 2026-11-19 19:14 ` Philippe Gerum
  7 siblings, 0 replies; 11+ messages in thread
From: Philippe Gerum @ 2026-11-19 19:14 UTC (permalink / raw)
  To: Tobias Schaffner; +Cc: xenomai, jan.kiszka

Tobias Schaffner <tobias.schaffner@siemens.com> writes:

> Hi all,
>
> with this RFC I would like to propose using the Linux kernel Runtime
> Verification (RV) system [1] for runtime verification of Dovetail based
> cokernels.
>
> Running a system with RV monitors active should ensure that the system
> behaves as described in the model. As this is checked at runtime we can
> verify if the system is even behaving as inteded when it is running the
> real workload.
>
> My ultimate goal is not only to use it for verification but also for wakeup
> latency tracing and decomposition in EVL by describing the whole wakeup
> path. I am working on upstreaming dwell time measurements in the RV system
> in parallel for that [2].
>
> This would allow us not only to get a worst case latency and decomposition
> for a latency evaluation tool like latmus but to get a worst case latency
> for any load applied to the system (e.g. the real application of the user).
>
> This patch set proposes three Dovetail monitors bundled in one container:
>
>  * offstage checks that Linux leaves a task alone while it runs out-of-band. It
> must neither schedule the task nor let it raise a signal on itself.
>
>  * oob_trap checks that every out-of-band trap notification is unwound for the
> same trap before the task goes out-of-band again.
>
>  * oob_signal checks that a task receiving a signal out-of-band is kicked
> in-band. Once the cokernel handled the notification, the task must not return
> to user mode out-of-band without a mayday pending. I think his monitor found
> a present bug in EVL: since "evl/sched: get rid of this_evl_rq_thread()"
> evl_kick_thread() skips the mayday for a thread running out-of-band on a
> remote CPU, so the thread ignores all signals, even SIGKILL.
>

That one was bad indeed.

> For the monitors the series adds a few bare tracepoints to Dovetail. They are
> not exposed in tracefs.
>
> The monitors can be built by setting CONFIG_RV_DOVETAIL, which enables RV,
> the monitors and the printk reactor. oob_signal is not available on 32-bit
> arm yet, as the out-of-band syscall fast path there is written in assembly.
>
> To execute them:
>
>   # cd /sys/kernel/tracing/rv
>   # echo printk > monitors/dovetail/reactors
>   # echo 1 > monitors/dovetail/enable
>
> Looking forward to your feedback, input and ideas on how to use and improve
> this further.
>

Did I already say this is insanely nice and useful work? Hopefully, I
did. I'm looking forward to merge RV support into the EVL core and
libevl.

-- 
Philippe.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-19 19:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 18:08 [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 1/7] dovetail: factor out the mayday check on return to user mode Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 2/7] dovetail: trace stage switches Tobias Schaffner
2026-11-11  7:40   ` Jan Kiszka
2026-11-19 19:07     ` Philippe Gerum
2026-11-10 18:08 ` [RFC PATCH dovetail 3/7] rv: add dovetail container and offstage monitor Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 4/7] dovetail: trace out-of-band trap notifications Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 5/7] rv: add oob_trap monitor Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 6/7] dovetail: trace signal notifications and out-of-band returns Tobias Schaffner
2026-11-10 18:08 ` [RFC PATCH dovetail 7/7] rv: add oob_signal monitor Tobias Schaffner
2026-11-19 19:14 ` [RFC PATCH dovetail 0/7] rv: runtime verification monitors for Dovetail Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.