[PATCH v7 34/40] sched/deadline: Cap the runtime left of a constrained task at dl_runtime
From: Mathieu Desnoyers
Date: Tue Nov 17 2026 - 09:18:04 EST
sched_setattr() can change the parameters of a SCHED_DEADLINE task. The
task keeps its runtime and its absolute deadline: the new parameters
take effect at the next period. At the next wakeup, update_dl_entity()
checks the runtime left against the new parameters.
For a constrained task, that check uses the density, dl_runtime /
dl_deadline. Commit 2317d5f1c349 ("sched/deadline: Use deadline instead
of period when calculating overflow") made dl_entity_overflow() compare
with it: "We care about if the runtime can make its deadline, not its
period." Commit 3effcb4247e7 ("sched/deadline: Use the revised wakeup
rule for suspending constrained dl tasks") then cut the runtime of a
constrained task that overflows to density * laxity. Both bound the
runtime by dl_runtime only while the deadline is at most dl_deadline
ahead.
A change to a shorter dl_deadline breaks that. The old deadline can be
farther ahead. The check then keeps more runtime than the new
dl_runtime, or computes more. For example, take a task of 50ms every
100ms with 49ms left. Changed to 8ms in 20ms every 100ms, it would wake
with 39.6ms. It would then run far more than its new runtime in this
period. Admission control already counts the new, smaller bandwidth. So
other deadline tasks could miss their deadlines.
An implicit task is not affected. Its check compares with its
bandwidth, which bounds the runtime for any deadline.
Fix this by keeping no more than dl_runtime before the check, for a
constrained task. A boosted task runs on the parameters of its donor,
and is left alone. The runtime is signed and can be negative there, so
compare it as signed.
The cases change_constrained_new_params and wake_constrained_new_params
of deadline_bw_test, added later in this series, test this. The first
changes a running task, the second a sleeping one. Both fail without
this patch.
The Sashiko AI review of the sixth posting of this series found this.
Fixes: 2317d5f1c349 ("sched/deadline: Use deadline instead of period when calculating overflow")
Fixes: 3effcb4247e7 ("sched/deadline: Use the revised wakeup rule for suspending constrained dl tasks")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 90b17969554b..1a07f4109cc5 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1389,6 +1389,25 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)
{
struct rq *rq = rq_of_dl_se(dl_se);
+ /*
+ * The checks below compare the runtime left with the density,
+ * dl_runtime / dl_deadline. That bounds the runtime by dl_runtime
+ * only while the deadline is at most dl_deadline ahead. After a
+ * change to a shorter dl_deadline, the deadline can be farther
+ * ahead, and the runtime left larger than dl_runtime. A constrained
+ * task would then run more than dl_runtime in a period. Keep no
+ * more than dl_runtime.
+ *
+ * An implicit task is checked against its bandwidth, which holds
+ * for any deadline. A boosted task runs on the parameters of its
+ * donor. Leave both alone.
+ *
+ * The runtime is signed, and can be negative here.
+ */
+ if (!dl_is_implicit(dl_se) && !is_dl_boosted(dl_se) &&
+ dl_se->runtime > (s64)dl_se->dl_runtime)
+ dl_se->runtime = dl_se->dl_runtime;
+
if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
dl_entity_overflow(dl_se, rq_clock(rq))) {
--
2.47.3