[PATCH] rv: opid: Allow self-wakeups with interrupts enabled
From: Karl Mehltretter
Date: Tue Dec 01 2026 - 21:11:30 EST
On non-PREEMPT_RT kernels without threadirqs, the opid monitor reports
a false positive when a task wakes itself from an inline softirq:
rv: monitor opid does not allow event sched_waking on state any with env irq_off=0,preempt_off=1
For example, schedule_timeout() arms a non-TIMER_IRQSAFE timer for
current and calls schedule(). If the timer expires inline on IRQ exit
before the task switches out, expire_timers() enables interrupts and
calls process_timeout() -> wake_up_process(current). The p == current
fast path in try_to_wake_up() skips pi_lock and only disables
preemption, so trace_sched_waking() runs with interrupts enabled.
Commit 2b406fdb3338 ("rv: Convert the opid monitor to a hybrid
automaton") enabled opid by default on non-PREEMPT_RT kernels but kept
the irq_off == 1 guard for all wakeups.
Split self-wakeups into a separate sched_waking_current event that only
requires preemption to be disabled, leaving the existing guards for
other wakeups and sched_need_resched unchanged. Update the model,
documentation, and KUnit test.
Fixes: 2b406fdb3338 ("rv: Convert the opid monitor to a hybrid automaton")
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
Tested on x86_64 v7.4-rc3 with an AF_UNIX SO_RCVTIMEO workload (6/6
unpatched vs 0/6 patched, 0/3 with threadirqs) and rv_test_opid on
non-RT and PREEMPT_RT. Accepted IRQs-enabled sched_waking_current
events were observed in the trace on patched runs.
Restricting opid back to PREEMPT_RT would be an alternative, though the
p == current fast path does not require IRQs disabled regardless.
Assisted by an LLM.
Documentation/trace/rv/monitor_sched.rst | 11 +++++--
kernel/trace/rv/monitors/opid/opid.c | 11 ++++++-
kernel/trace/rv/monitors/opid/opid.h | 4 ++-
kernel/trace/rv/monitors/opid/opid_kunit.c | 37 ++++++++++++++++++++++
tools/verification/models/sched/opid.dot | 2 +-
5 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace/rv/monitor_sched.rst
index d3ba7ed..aa50efa 100644
--- a/Documentation/trace/rv/monitor_sched.rst
+++ b/Documentation/trace/rv/monitor_sched.rst
@@ -344,9 +344,13 @@ can be triggered also by preemption, but cannot occur after the task got to
Monitor opid
------------
-The operations with preemption and irq disabled (opid) monitor ensures
-operations like ``wakeup`` and ``need_resched`` occur with interrupts and
-preemption disabled.
+The operations with preemption and irq disabled (opid) monitor checks
+the interrupt and preemption state during ``wakeup`` and ``need_resched``
+operations.
+Wakeups of tasks other than ``current`` require both interrupts and
+preemption to be disabled. Self-wakeups do not take ``pi_lock`` and only
+require preemption to be disabled, for instance when a timer expires in a
+softirq running on interrupt exit. This is the ``sched_waking_current`` event.
``need_resched`` can be set by some RCU internals functions, in which case it
doesn't match a task wakeup and might occur with only interrupts disabled.
The interrupt and preemption status are validated by the hybrid automaton
@@ -357,6 +361,7 @@ constraints when processing the events::
v
#=========# sched_need_resched;irq_off == 1
H H sched_waking;irq_off == 1 && preempt_off == 1
+ H H sched_waking_current;preempt_off == 1
H any H ------------------------------------------------+
H H |
H H <-----------------------------------------------+
diff --git a/kernel/trace/rv/monitors/opid/opid.c b/kernel/trace/rv/monitors/opid/opid.c
index 9ae619f..cd450eb 100644
--- a/kernel/trace/rv/monitors/opid/opid.c
+++ b/kernel/trace/rv/monitors/opid/opid.c
@@ -40,6 +40,8 @@ static inline bool ha_verify_guards(struct ha_monitor *ha_mon,
else if (curr_state == any_opid && event == sched_waking_opid)
res = ha_get_env(ha_mon, irq_off_opid, time_ns) == 1ull &&
ha_get_env(ha_mon, preempt_off_opid, time_ns) == 1ull;
+ else if (curr_state == any_opid && event == sched_waking_current_opid)
+ res = ha_get_env(ha_mon, preempt_off_opid, time_ns) == 1ull;
return res;
}
@@ -60,7 +62,14 @@ static void handle_sched_need_resched(void *data, struct task_struct *tsk, int c
static void handle_sched_waking(void *data, struct task_struct *p)
{
- da_handle_start_run_event(sched_waking_opid);
+ /*
+ * try_to_wake_up() wakes current without taking pi_lock, so interrupts
+ * can be enabled, e.g. when a timer expires in a softirq on irq exit.
+ */
+ if (p == current)
+ da_handle_start_run_event(sched_waking_current_opid);
+ else
+ da_handle_start_run_event(sched_waking_opid);
}
static int enable_opid(void)
diff --git a/kernel/trace/rv/monitors/opid/opid.h b/kernel/trace/rv/monitors/opid/opid.h
index fb0aa4c..b8e9704 100644
--- a/kernel/trace/rv/monitors/opid/opid.h
+++ b/kernel/trace/rv/monitors/opid/opid.h
@@ -17,6 +17,7 @@ enum states_opid {
enum events_opid {
sched_need_resched_opid,
sched_waking_opid,
+ sched_waking_current_opid,
event_max_opid,
};
@@ -45,13 +46,14 @@ static const struct automaton_opid automaton_opid = {
.event_names = {
"sched_need_resched",
"sched_waking",
+ "sched_waking_current",
},
.env_names = {
"irq_off",
"preempt_off",
},
.function = {
- { any_opid, any_opid },
+ { any_opid, any_opid, any_opid },
},
.initial_state = any_opid,
.final_states = { 1 },
diff --git a/kernel/trace/rv/monitors/opid/opid_kunit.c b/kernel/trace/rv/monitors/opid/opid_kunit.c
index 3cb087a..dcaea97 100644
--- a/kernel/trace/rv/monitors/opid/opid_kunit.c
+++ b/kernel/trace/rv/monitors/opid/opid_kunit.c
@@ -21,6 +21,43 @@ static void rv_test_opid(struct kunit *test)
RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
rv_opid_ops.handle_sched_waking(NULL, NULL);
+ /* Wakeup of another task with only preemption disabled */
+ RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) {
+ scoped_guard(preempt)
+ rv_opid_ops.handle_sched_waking(NULL, NULL);
+ }
+
+ /* Preemption is only checked with CONFIG_PREEMPTION */
+ if (IS_ENABLED(CONFIG_PREEMPTION)) {
+ /* Wakeup of another task with only interrupts disabled */
+ RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) {
+ scoped_guard(irq)
+ rv_opid_ops.handle_sched_waking(NULL, NULL);
+ }
+
+ /* Wakeup of current with only interrupts disabled */
+ RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) {
+ scoped_guard(irq)
+ rv_opid_ops.handle_sched_waking(NULL, current);
+ }
+
+ /* Wakeup of current with preemption and interrupts enabled */
+ RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
+ rv_opid_ops.handle_sched_waking(NULL, current);
+ }
+
+ /* Wakeup of current with only preemption disabled */
+ scoped_guard(preempt)
+ rv_opid_ops.handle_sched_waking(NULL, current);
+ RV_KUNIT_EXPECT_NO_REACTION(test, ctx);
+
+ /* Wakeup of current with preemption and interrupts disabled */
+ scoped_guard(preempt) {
+ scoped_guard(irq)
+ rv_opid_ops.handle_sched_waking(NULL, current);
+ }
+ RV_KUNIT_EXPECT_NO_REACTION(test, ctx);
+
/* Need resched with interrupts enabled */
RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) {
scoped_guard(preempt)
diff --git a/tools/verification/models/sched/opid.dot b/tools/verification/models/sched/opid.dot
index 511051f..35fbd6c 100644
--- a/tools/verification/models/sched/opid.dot
+++ b/tools/verification/models/sched/opid.dot
@@ -5,7 +5,7 @@ digraph state_automaton {
{node [shape = doublecircle] "any"};
"__init_any" -> "any";
"any" [label = "any", color = green3];
- "any" -> "any" [ label = "sched_need_resched;irq_off == 1\nsched_waking;irq_off == 1 && preempt_off == 1" ];
+ "any" -> "any" [ label = "sched_need_resched;irq_off == 1\nsched_waking;irq_off == 1 && preempt_off == 1\nsched_waking_current;preempt_off == 1" ];
{ rank = min ;
"__init_any";
"any";
--
2.39.5 (Apple Git-154)