* [PATCH] rv: Adapt handle racing preemptions in nrp
@ 2026-12-04 8:09 Gabriele Monaco
2026-12-04 8:31 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Gabriele Monaco @ 2026-12-04 8:09 UTC (permalink / raw)
To: linux-kernel, Steven Rostedt, Gabriele Monaco, Jonathan Corbet,
Masami Hiramatsu, linux-trace-kernel, linux-doc
Cc: K Prateek Nayak, Andrea Righi, Nam Cao
As Prateek pointed out and Andrea validated, the schedule_entry event
may be seen before the set_need_resched event that caused the
preemption. This rare race can occur because the schedule_entry is
emitted before taking the rq lock.
The nrp model expects a strict order and catches this as a violation.
Add a branch to handle this inverted order. Essentially allowing a
preemption provided the set_need_resched is visible before being done
scheduling (switch out or sched_exit if there was no switch).
This weakens the model because it allows a preemption without
need_resched where the flag is simply set later in an event unrelated to
the preemption.
Guard this by transforming nrp in a hybrid automaton and also mandate
the TIF is set when preemption occurs.
This applies in all preemption cases besides a nested preemption,
where the flag is cleared by a racing scheduler call.
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Andrea Righi <arighi@nvidia.com>
Cc: Nam Cao <namcao@linutronix.de>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
Documentation/trace/rv/monitor_sched.rst | 45 +++++++++++++++++--
kernel/trace/rv/monitors/nrp/Kconfig | 2 +-
kernel/trace/rv/monitors/nrp/nrp.c | 57 ++++++++++++++++++++++--
kernel/trace/rv/monitors/nrp/nrp.h | 48 +++++++++++++++++++-
kernel/trace/rv/monitors/nrp/nrp_trace.h | 4 ++
kernel/trace/rv/rv_trace.h | 2 +-
tools/verification/models/sched/nrp.dot | 21 ++++++---
7 files changed, 163 insertions(+), 16 deletions(-)
diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace/rv/monitor_sched.rst
index d3ba7edc202f..c2cc8f25ac18 100644
--- a/Documentation/trace/rv/monitor_sched.rst
+++ b/Documentation/trace/rv/monitor_sched.rst
@@ -225,8 +225,8 @@ occurred, as the situation above is hard to pinpoint::
| #===========================================#
| schedule_entry | ^
| schedule_entry_preempt | sched_need_resched | schedule_entry
- | | schedule_entry_preempt
- | v |
+ | | schedule_entry_preempt;
+ | v | need_resched == 1
| +----------------------+ |
| +--- | | |
| sched_need_resched | | rescheduling | -+
@@ -242,7 +242,8 @@ occurred, as the situation above is hard to pinpoint::
| | | <--+
| +----------------------+ |
| | schedule_entry | sched_need_resched
- | | schedule_entry_preempt |
+ | | schedule_entry_preempt; |
+ | | need_resched == 1 |
| v |
| +-----------------------+ |
+-------------------------- | nested_preempt | --+
@@ -250,6 +251,44 @@ occurred, as the situation above is hard to pinpoint::
^ irq_entry |
+-------------------+
+The ``schedule_entry`` events are emitted before taking the rq lock, this means
+that they can race with the ``need_resched`` event. In practice this mean that,
+although the ``need_resched`` event is what caused the reschedule to happen,
+the monitor might see it *after* the ``schedule_entry_preempt`` event.
+For this purpose, the model allows another branch, for simplicity represented
+separately here, that allows a racing preemption provided it is followed by a
+``need_resched`` before being done scheduling::
+
+ schedule_entry #=========================#
+ schedule_exit H H
+ irq_entry H H
+ +----------------- H any_thread_running H
+ | H H
+ +----------------> H H <+
+ #=========================# |
+ | |
+ | schedule_entry_preempt; |
+ | need_resched == 1 |
+ v |
+ irq_entry +-------------------------+ |
+ +----------------- | | |
+ | | racing_preempt | | schedule_exit_vain
+ +----------------> | | | sched_switch_preempt
+ +-------------------------+ |
+ | |
+ | sched_need_resched |
+ sched_need_resched v |
+ irq_entry +-------------------------+ |
+ +----------------- | | |
+ | | racing_resched | |
+ +----------------> | | -+
+ +-------------------------+
+
+Excluding coming from ``nested_preempt``, all ``schedule_entry_preempt`` also
+contain a guard for ``need_resched == 1``, which is especially necessary to
+avoid false negatives in the backup branch where scheduling must be visible
+before ``need_resched``.
+
Due to how the ``need_resched`` flag on the preemption count works on arm64,
this monitor is unstable on that architecture, as it often records preemption
when the flag is not set, even in presence of the workaround above.
diff --git a/kernel/trace/rv/monitors/nrp/Kconfig b/kernel/trace/rv/monitors/nrp/Kconfig
index f5ec08f65535..61a5846aa0f5 100644
--- a/kernel/trace/rv/monitors/nrp/Kconfig
+++ b/kernel/trace/rv/monitors/nrp/Kconfig
@@ -4,7 +4,7 @@ config RV_MON_NRP
depends on RV
depends on RV_MON_SCHED
default y if !ARM64
- select DA_MON_EVENTS_ID
+ select HA_MON_EVENTS_ID
bool "nrp monitor"
help
Monitor to ensure preemption requires need resched.
diff --git a/kernel/trace/rv/monitors/nrp/nrp.c b/kernel/trace/rv/monitors/nrp/nrp.c
index 4b5646a70094..be6f4a036079 100644
--- a/kernel/trace/rv/monitors/nrp/nrp.c
+++ b/kernel/trace/rv/monitors/nrp/nrp.c
@@ -16,7 +16,39 @@
#define RV_MON_TYPE RV_MON_PER_TASK
#include "nrp.h"
-#include <rv/da_monitor.h>
+#include <rv/ha_monitor.h>
+
+static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_nrp env, u64 time_ns)
+{
+ if (env == need_resched_nrp)
+ return test_tsk_need_resched(ha_get_target(ha_mon));
+ return ENV_INVALID_VALUE;
+}
+
+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 == any_thread_running_nrp && event == schedule_entry_preempt_nrp)
+ res = ha_get_env(ha_mon, need_resched_nrp, time_ns) == 1ull;
+ else if (curr_state == preempt_irq_nrp && event == schedule_entry_preempt_nrp)
+ res = ha_get_env(ha_mon, need_resched_nrp, time_ns) == 1ull;
+ else if (curr_state == rescheduling_nrp && event == schedule_entry_preempt_nrp)
+ res = ha_get_env(ha_mon, need_resched_nrp, 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)
+{
+ if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns))
+ return false;
+
+ return true;
+}
#ifdef CONFIG_X86_LOCAL_APIC
#include <asm/trace/irq_vectors.h>
@@ -73,6 +105,15 @@ static void handle_sched_need_resched(void *data, struct task_struct *tsk,
da_handle_start_event(tsk, sched_need_resched_nrp);
}
+static void handle_sched_switch(void *data, bool preempt,
+ struct task_struct *prev,
+ struct task_struct *next,
+ unsigned int prev_state)
+{
+ if (preempt)
+ da_handle_event(prev, sched_switch_preempt_nrp);
+}
+
static void handle_schedule_entry(void *data, bool preempt)
{
if (preempt)
@@ -81,17 +122,25 @@ static void handle_schedule_entry(void *data, bool preempt)
da_handle_event(current, schedule_entry_nrp);
}
+static void handle_schedule_exit(void *data, bool is_switch)
+{
+ if (!is_switch)
+ da_handle_event(current, schedule_exit_vain_nrp);
+}
+
static int enable_nrp(void)
{
int retval;
- retval = da_monitor_init();
+ retval = ha_monitor_init();
if (retval)
return retval;
rv_attach_trace_probe("nrp", irq_handler_entry, handle_irq_entry);
rv_attach_trace_probe("nrp", sched_set_need_resched_tp, handle_sched_need_resched);
+ rv_attach_trace_probe("nrp", sched_switch, handle_sched_switch);
rv_attach_trace_probe("nrp", sched_entry_tp, handle_schedule_entry);
+ rv_attach_trace_probe("nrp", sched_exit_tp, handle_schedule_exit);
attach_vector_irq();
return 0;
@@ -103,10 +152,12 @@ static void disable_nrp(void)
rv_detach_trace_probe("nrp", irq_handler_entry, handle_irq_entry);
rv_detach_trace_probe("nrp", sched_set_need_resched_tp, handle_sched_need_resched);
+ rv_detach_trace_probe("nrp", sched_switch, handle_sched_switch);
rv_detach_trace_probe("nrp", sched_entry_tp, handle_schedule_entry);
+ rv_detach_trace_probe("nrp", sched_exit_tp, handle_schedule_exit);
detach_vector_irq();
- da_monitor_destroy();
+ ha_monitor_destroy();
}
static struct rv_monitor rv_this = {
diff --git a/kernel/trace/rv/monitors/nrp/nrp.h b/kernel/trace/rv/monitors/nrp/nrp.h
index 3270d4c0139f..e2e71a940d32 100644
--- a/kernel/trace/rv/monitors/nrp/nrp.h
+++ b/kernel/trace/rv/monitors/nrp/nrp.h
@@ -11,6 +11,8 @@ enum states_nrp {
preempt_irq_nrp,
any_thread_running_nrp,
nested_preempt_nrp,
+ racing_preempt_nrp,
+ racing_resched_nrp,
rescheduling_nrp,
state_max_nrp,
};
@@ -20,14 +22,25 @@ enum states_nrp {
enum events_nrp {
irq_entry_nrp,
sched_need_resched_nrp,
+ sched_switch_preempt_nrp,
schedule_entry_nrp,
schedule_entry_preempt_nrp,
+ schedule_exit_vain_nrp,
event_max_nrp,
};
+enum envs_nrp {
+ need_resched_nrp,
+ env_max_nrp,
+ env_max_stored_nrp = need_resched_nrp,
+};
+
+_Static_assert(env_max_stored_nrp <= MAX_HA_ENV_LEN, "Not enough slots");
+
struct automaton_nrp {
char *state_names[state_max_nrp];
char *event_names[event_max_nrp];
+ char *env_names[env_max_nrp];
unsigned char function[state_max_nrp][event_max_nrp];
unsigned char initial_state;
bool final_states[state_max_nrp];
@@ -38,40 +51,71 @@ static const struct automaton_nrp automaton_nrp = {
"preempt_irq",
"any_thread_running",
"nested_preempt",
+ "racing_preempt",
+ "racing_resched",
"rescheduling",
},
.event_names = {
"irq_entry",
"sched_need_resched",
+ "sched_switch_preempt",
"schedule_entry",
"schedule_entry_preempt",
+ "schedule_exit_vain",
+ },
+ .env_names = {
+ "need_resched",
},
.function = {
{
+ preempt_irq_nrp,
preempt_irq_nrp,
preempt_irq_nrp,
nested_preempt_nrp,
nested_preempt_nrp,
+ preempt_irq_nrp,
},
{
any_thread_running_nrp,
rescheduling_nrp,
any_thread_running_nrp,
- INVALID_STATE,
+ any_thread_running_nrp,
+ racing_preempt_nrp,
+ any_thread_running_nrp,
},
{
nested_preempt_nrp,
preempt_irq_nrp,
+ nested_preempt_nrp,
any_thread_running_nrp,
any_thread_running_nrp,
+ nested_preempt_nrp,
+ },
+ {
+ racing_preempt_nrp,
+ racing_resched_nrp,
+ INVALID_STATE,
+ INVALID_STATE,
+ INVALID_STATE,
+ INVALID_STATE,
+ },
+ {
+ racing_resched_nrp,
+ racing_resched_nrp,
+ any_thread_running_nrp,
+ INVALID_STATE,
+ INVALID_STATE,
+ any_thread_running_nrp,
},
{
preempt_irq_nrp,
rescheduling_nrp,
+ rescheduling_nrp,
any_thread_running_nrp,
any_thread_running_nrp,
+ rescheduling_nrp,
},
},
.initial_state = preempt_irq_nrp,
- .final_states = { 0, 1, 0, 0 },
+ .final_states = { 0, 1, 0, 0, 0, 0 },
};
diff --git a/kernel/trace/rv/monitors/nrp/nrp_trace.h b/kernel/trace/rv/monitors/nrp/nrp_trace.h
index 2e13497de3b6..70682a53261a 100644
--- a/kernel/trace/rv/monitors/nrp/nrp_trace.h
+++ b/kernel/trace/rv/monitors/nrp/nrp_trace.h
@@ -12,4 +12,8 @@ DEFINE_EVENT(event_da_monitor_id, event_nrp,
DEFINE_EVENT(error_da_monitor_id, error_nrp,
TP_PROTO(int id, char *state, char *event),
TP_ARGS(id, state, event));
+
+DEFINE_EVENT(error_env_da_monitor_id, error_env_nrp,
+ TP_PROTO(int id, char *state, char *event, char *env),
+ TP_ARGS(id, state, event, env));
#endif /* CONFIG_RV_MON_NRP */
diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h
index 2f8a932432c9..373e939d8b3c 100644
--- a/kernel/trace/rv/rv_trace.h
+++ b/kernel/trace/rv/rv_trace.h
@@ -154,7 +154,6 @@ DECLARE_EVENT_CLASS(error_da_monitor_id,
#include <monitors/wwnr/wwnr_trace.h>
#include <monitors/snroc/snroc_trace.h>
-#include <monitors/nrp/nrp_trace.h>
#include <monitors/sssw/sssw_trace.h>
// Add new monitors based on CONFIG_DA_MON_EVENTS_ID here
@@ -189,6 +188,7 @@ DECLARE_EVENT_CLASS(error_env_da_monitor_id,
#include <monitors/stall/stall_trace.h>
#include <monitors/nomiss/nomiss_trace.h>
+#include <monitors/nrp/nrp_trace.h>
// Add new monitors based on CONFIG_HA_MON_EVENTS_ID here
#endif
diff --git a/tools/verification/models/sched/nrp.dot b/tools/verification/models/sched/nrp.dot
index 77bb64669416..cbab8fec6c57 100644
--- a/tools/verification/models/sched/nrp.dot
+++ b/tools/verification/models/sched/nrp.dot
@@ -6,22 +6,31 @@ digraph state_automaton {
{node [shape = circle] "nested_preempt"};
{node [shape = plaintext, style=invis, label=""] "__init_preempt_irq"};
{node [shape = circle] "preempt_irq"};
+ {node [shape = circle] "racing_preempt"};
+ {node [shape = circle] "racing_resched"};
{node [shape = circle] "rescheduling"};
"__init_preempt_irq" -> "preempt_irq";
"any_thread_running" [label = "any_thread_running", color = green3];
- "any_thread_running" -> "any_thread_running" [ label = "schedule_entry\nirq_entry" ];
+ "any_thread_running" -> "any_thread_running" [ label = "schedule_entry\nschedule_exit_vain\nsched_switch_preempt\nirq_entry" ];
+ "any_thread_running" -> "racing_preempt" [ label = "schedule_entry_preempt;need_resched == 1" ];
"any_thread_running" -> "rescheduling" [ label = "sched_need_resched" ];
"nested_preempt" [label = "nested_preempt"];
"nested_preempt" -> "any_thread_running" [ label = "schedule_entry_preempt\nschedule_entry" ];
- "nested_preempt" -> "nested_preempt" [ label = "irq_entry" ];
+ "nested_preempt" -> "nested_preempt" [ label = "irq_entry\nsched_switch_preempt\nschedule_exit_vain" ];
"nested_preempt" -> "preempt_irq" [ label = "sched_need_resched" ];
"preempt_irq" [label = "preempt_irq"];
- "preempt_irq" -> "nested_preempt" [ label = "schedule_entry_preempt\nschedule_entry" ];
- "preempt_irq" -> "preempt_irq" [ label = "irq_entry\nsched_need_resched" ];
+ "preempt_irq" -> "nested_preempt" [ label = "schedule_entry_preempt;need_resched == 1\nschedule_entry" ];
+ "preempt_irq" -> "preempt_irq" [ label = "irq_entry\nsched_switch_preempt\nschedule_exit_vain\nsched_need_resched" ];
+ "racing_preempt" [label = "racing_preempt"];
+ "racing_preempt" -> "racing_preempt" [ label = "irq_entry" ];
+ "racing_preempt" -> "racing_resched" [ label = "sched_need_resched" ];
+ "racing_resched" [label = "racing_resched"];
+ "racing_resched" -> "any_thread_running" [ label = "sched_switch_preempt\nschedule_exit_vain" ];
+ "racing_resched" -> "racing_resched" [ label = "irq_entry\nsched_need_resched" ];
"rescheduling" [label = "rescheduling"];
- "rescheduling" -> "any_thread_running" [ label = "schedule_entry_preempt\nschedule_entry" ];
+ "rescheduling" -> "any_thread_running" [ label = "schedule_entry_preempt;need_resched == 1\nschedule_entry" ];
"rescheduling" -> "preempt_irq" [ label = "irq_entry" ];
- "rescheduling" -> "rescheduling" [ label = "sched_need_resched" ];
+ "rescheduling" -> "rescheduling" [ label = "sched_need_resched\nsched_switch_preempt\nschedule_exit_vain" ];
{ rank = min ;
"__init_preempt_irq";
"preempt_irq";
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] rv: Adapt handle racing preemptions in nrp
2026-12-04 8:09 [PATCH] rv: Adapt handle racing preemptions in nrp Gabriele Monaco
@ 2026-12-04 8:31 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 8:31 UTC (permalink / raw)
To: Gabriele Monaco, linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] rv: racing_resched self-loop in nrp drops new reschedule on
vain schedule
- [Medium] rv: nested preemption during racing preemption fails nrp
guard check
- [Low] rv: incorrect any_thread_running self-loop labels in nrp
documentation
- [Low] rv: need_resched guard on preempt_irq causes false positive at
startup
- [Low] rv: nrp attaches unused sched_process_exit probe and extra
synchronize_rcu()
- [Low] rv: missing Fixes trailer for nrp monitor introducing commit
--
commit a94703095d16688d6cf8c217dc6265f8e208b268
Author: Gabriele Monaco <gmonaco@redhat.com>
> rv: Adapt handle racing preemptions in nrp
>
> As Prateek pointed out and Andrea validated, the schedule_entry event
> may be seen before the set_need_resched event that caused the
> preemption. This rare race can occur because the schedule_entry is
> emitted before taking the rq lock.
> The nrp model expects a strict order and catches this as a violation.
>
> Add a branch to handle this inverted order. Essentially allowing a
> preemption provided the set_need_resched is visible before being done
> scheduling (switch out or sched_exit if there was no switch).
>
> This weakens the model because it allows a preemption without
> need_resched where the flag is simply set later in an event unrelated to
> the preemption.
>
> Guard this by transforming nrp in a hybrid automaton and also mandate
> the TIF is set when preemption occurs.
> This applies in all preemption cases besides a nested preemption,
> where the flag is cleared by a racing scheduler call.
>
> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
> Cc: Andrea Righi <arighi@nvidia.com>
> Cc: Nam Cao <namcao@linutronix.de>
> Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
[Severity: Low]
This fixes false-positive violations in the nrp monitor introduced with
the monitor itself. Should this include:
Fixes: e8440a88e56b ("rv: Add nrp and sssw per-task monitors")
> diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace/rv/monitor_sched.rst
> index d3ba7edc202f6..c2cc8f25ac18c 100644
> --- a/Documentation/trace/rv/monitor_sched.rst
> +++ b/Documentation/trace/rv/monitor_sched.rst
[ ... ]
> + schedule_entry #=========================#
> + schedule_exit H H
> + irq_entry H H
> + +----------------- H any_thread_running H
[Severity: Low]
Should this self-loop label use schedule_exit_vain instead of
schedule_exit and also list sched_switch_preempt? Both nrp.dot and
automaton_nrp in nrp.h use schedule_exit_vain (there is no schedule_exit
event) and include sched_switch_preempt on that self-loop.
> diff --git a/kernel/trace/rv/monitors/nrp/nrp.c b/kernel/trace/rv/monitors/nrp/nrp.c
> index 4b5646a700946..be6f4a036079c 100644
> --- a/kernel/trace/rv/monitors/nrp/nrp.c
> +++ b/kernel/trace/rv/monitors/nrp/nrp.c
[ ... ]
> +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 == any_thread_running_nrp && event == schedule_entry_preempt_nrp)
> + res = ha_get_env(ha_mon, need_resched_nrp, time_ns) == 1ull;
[Severity: Medium]
Can this guard trigger a false-positive error_env_nrp violation when an
IRQ nests inside preempt_schedule_common() during a racing preemption?
Because irq_entry self-loops in any_thread_running and racing_resched
always returns to any_thread_running on completion, the monitor loses
track of the nested preemption:
CPU0 (task T) CPU1
[state: any_thread_running]
__resched_curr(rq0, TIF_NEED_RESCHED)
set_nr_and_not_polling()
preempt_schedule_common()
<hardirq> (before preempt_disable_notrace())
irq_entry -> any_thread_running
preempt_schedule_irq()
__schedule(SM_PREEMPT)
schedule_entry_preempt -> racing_preempt
trace_sched_set_need_resched_tp()
sched_need_resched -> racing_resched
clear_tsk_need_resched(T)
schedule_exit_vain -> any_thread_running
__schedule(SM_PREEMPT)
schedule_entry_preempt <-- need_resched == 0, error_env_nrp
When the outer __schedule(SM_PREEMPT) runs after the IRQ returns,
TIF_NEED_RESCHED is already cleared, so the guard fails and triggers a
spurious monitor reaction and reset.
> + else if (curr_state == preempt_irq_nrp && event == schedule_entry_preempt_nrp)
> + res = ha_get_env(ha_mon, need_resched_nrp, time_ns) == 1ull;
[Severity: Low]
Can this guard on the initial state preempt_irq cause a false-positive
error_env_nrp right after enabling or resetting the monitor?
handle_sched_need_resched() starts an untracked task in preempt_irq. If
that happens while a nested preempt_schedule_irq() is already running on
another CPU, the inner schedule clears TIF_NEED_RESCHED before the outer
__schedule(SM_PREEMPT) runs:
CPU0 (task T) CPU1
[monitoring == 0]
__resched_curr(rq0, TIF_NEED_RESCHED)
set_nr_and_not_polling()
preempt_schedule_common()
<hardirq>
preempt_schedule_irq()
__schedule(SM_PREEMPT)
schedule_entry_preempt (ignored)
trace_sched_set_need_resched_tp()
-> starts in preempt_irq
clear_tsk_need_resched(T)
schedule_exit_vain -> preempt_irq
__schedule(SM_PREEMPT)
schedule_entry_preempt <-- need_resched == 0, error_env_nrp
Because preempt_irq -> nested_preempt was previously unguarded, this
startup race did not trigger a spurious violation before.
[ ... ]
> static int enable_nrp(void)
> {
> int retval;
>
> - retval = da_monitor_init();
> + retval = ha_monitor_init();
[Severity: Low]
Does switching to ha_monitor_init() without HA_SKIP_AUTO_CLEANUP attach an
unused sched_process_exit probe and add an extra synchronize_rcu()?
nrp leaves HA_TIMER_TYPE at HA_TIMER_NONE, so ha_cancel_timer_sync() is a
no-op, yet ha_monitor_enable_hook() still hooks sched_process_exit to run
memory barriers and reset task_struct->rv on every exiting task.
In addition, da_monitor_sync_hook() runs a redundant synchronize_rcu() in
disable_nrp() right after tracepoint_synchronize_unregister(). Defining
HA_SKIP_AUTO_CLEANUP here, or gating those hooks in ha_monitor.h on
HA_TIMER_TYPE != HA_TIMER_NONE, would avoid both costs.
> diff --git a/kernel/trace/rv/monitors/nrp/nrp.h b/kernel/trace/rv/monitors/nrp/nrp.h
> index 3270d4c0139fd..e2e71a940d326 100644
> --- a/kernel/trace/rv/monitors/nrp/nrp.h
> +++ b/kernel/trace/rv/monitors/nrp/nrp.h
[ ... ]
> + {
> + racing_preempt_nrp,
> + racing_resched_nrp,
> + INVALID_STATE,
> + INVALID_STATE,
> + INVALID_STATE,
> + INVALID_STATE,
> + },
> + {
> + racing_resched_nrp,
> + racing_resched_nrp,
> + any_thread_running_nrp,
> + INVALID_STATE,
> + INVALID_STATE,
> + any_thread_running_nrp,
> + },
[Severity: Medium]
Does self-looping racing_resched_nrp on sched_need_resched_nrp drop a new
reschedule arriving before schedule_exit_vain_nrp and cause a spurious
violation on the next preemption loop iteration?
In __schedule(), when prev == next, clear_tsk_need_resched() and
raw_spin_rq_unlock_irq() run before trace_sched_exit_tp(false):
CPU0 (task T) CPU1
[state: racing_resched]
__schedule(SM_PREEMPT) [next == prev]
clear_tsk_need_resched(T)
raw_spin_rq_unlock_irq(rq)
resched_curr(rq)
set TIF_NEED_RESCHED
sched_need_resched -> racing_resched
trace_sched_exit_tp(false)
schedule_exit_vain -> any_thread_running
preempt_schedule_common() loops (need_resched() is true)
__schedule(SM_PREEMPT)
schedule_entry_preempt -> racing_preempt
sched_switch_preempt <-- INVALID_STATE, error_nrp
Because TIF_NEED_RESCHED is already set, no further sched_need_resched
event is emitted for the second __schedule(SM_PREEMPT), leaving the
monitor in racing_preempt where completion hits INVALID_STATE.
Transitioning racing_resched_nrp -> rescheduling_nrp on
sched_need_resched_nrp (and updating nrp.dot to match) would preserve the
pending reschedule across schedule_exit_vain_nrp.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204080908.129943-1-gmonaco@redhat.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 8:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 8:09 [PATCH] rv: Adapt handle racing preemptions in nrp Gabriele Monaco
2026-12-04 8:31 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox