[PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock
From: Mathieu Desnoyers
Date: Thu Dec 03 2026 - 09:59:48 EST
check_dl_overrun() clears dl_overrun without the rq lock. dl_overrun is
a bit field. It shares a word with other flags of the deadline entity,
such as dl_throttled, dl_non_contending and dl_bw_oncpu. These change
under the rq lock. The clear loads the whole word and stores it back.
If another CPU changes one of these flags in between, the store undoes
that change, and leaves the state of the task wrong.
check_dl_overrun() runs under the siglock. Without PREEMPT_RT, the
siglock disables interrupts, so the window is a few instructions. With
PREEMPT_RT, the siglock is a sleeping lock and interrupts stay on. The
task can be preempted between the load and the store, so the window
can be long. This was found by reading.
Fix this by clearing dl_overrun under task_rq_lock(), in a new helper,
dl_task_clear_overrun(). The caller holds the siglock.
signal_wake_up_state() takes the same lock order: the siglock, then
pi_lock and the rq lock.
Fixes: 34be39305a77 ("sched/deadline: Implement "runtime overrun signal" support")
Reported-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
include/linux/sched/deadline.h | 2 ++
kernel/sched/deadline.c | 20 ++++++++++++++++++++
kernel/time/posix-cpu-timers.c | 4 +---
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h
index 273538200a44..47c8be0ca14a 100644
--- a/include/linux/sched/deadline.h
+++ b/include/linux/sched/deadline.h
@@ -43,6 +43,8 @@ extern void dl_clear_root_domain_cpu(int cpu);
extern bool dl_task_needs_bw_move(struct task_struct *p,
const struct cpumask *new_mask);
+extern bool dl_task_clear_overrun(struct task_struct *p);
+
extern u64 dl_cookie;
extern bool dl_bw_visited(int cpu, u64 cookie);
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index a02975eb91f6..0afcb7b53bc4 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -4154,6 +4154,26 @@ void init_dl_entity(struct sched_dl_entity *dl_se)
#endif
}
+/*
+ * Clear the runtime overrun flag of @p. Return true if it was set.
+ *
+ * dl_overrun shares a word with other flags, such as dl_throttled,
+ * which change under the rq lock. Clear it under that lock too, or the
+ * store could undo a change to another flag.
+ *
+ * The caller holds the siglock of @p. signal_wake_up_state() takes the
+ * same lock order: siglock, then pi_lock and the rq lock.
+ */
+bool dl_task_clear_overrun(struct task_struct *p)
+{
+ guard(task_rq_lock)(p);
+
+ if (!p->dl.dl_overrun)
+ return false;
+ p->dl.dl_overrun = 0;
+ return true;
+}
+
bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr)
{
struct sched_dl_entity *dl_se = &p->dl;
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 2f23d62ad446..b37a38041170 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -976,10 +976,8 @@ static void collect_posix_cputimers(struct posix_cputimers *pct, u64 *samples,
static inline void check_dl_overrun(struct task_struct *tsk)
{
- if (tsk->dl.dl_overrun) {
- tsk->dl.dl_overrun = 0;
+ if (tsk->dl.dl_overrun && dl_task_clear_overrun(tsk))
send_signal_locked(SIGXCPU, SEND_SIG_PRIV, tsk, PIDTYPE_TGID);
- }
}
static bool check_rlimit(u64 time, u64 limit, int signo, bool rt, bool hard)
--
2.47.3