From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters
Date: Thu, 03 Dec 2026 17:39:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-248271@kernel.org> (raw)
In-Reply-To: <a964d363f461144804e77eacf4f137ef295041fc.1796296313.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] sched/deadline: double dl_release_params() wipes constrained
task deadline
- [Medium] sched/deadline: switched_from_dl() zeroes preserved
constrained deadline
- [Medium] sched/deadline: dl_task_timer() leaves phantom deadline on
departed task
- [Medium] sched/deadline: dl_task_timer() misses stale callback check
when boosted
--
commit 3ee57a6bbb822d45131cce62988fa9cdd9ab1948
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Cancel the replenishment timer with the parameters
This commit cancels the replenishment timer alongside parameter release
in task_non_contending() and inactive_task_timer() so a task re-entering
SCHED_DEADLINE does not inherit a stale timer from its previous
reservation.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 081c5812a063b..82066b2402a95 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -781,6 +781,7 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task)
> if (dl_task && READ_ONCE(p->__state) == TASK_DEAD)
> sub_rq_bw(dl_se, &rq->dl);
> dl_task_release_bw(p);
> + cancel_replenish_timer(dl_se);
> dl_release_params(dl_se);
> }
> }
[Severity: Medium]
Can switched_from_dl() wipe the deadline that dl_release_params() just
preserved for a constrained-deadline task?
When a queued constrained-deadline task (such as one that called
sched_yield()) leaves SCHED_DEADLINE past its 0-lag time,
switched_from_dl() calls task_non_contending(&p->dl, false). That
cancels the replenishment timer and calls dl_release_params(), which
clears p->dl.dl_runtime to 0 while keeping p->dl.deadline. On return,
switched_from_dl() then executes the boosted-task cleanup:
kernel/sched/deadline.c:switched_from_dl() {
...
if (task_on_rq_queued(p) && p->dl.dl_runtime)
task_non_contending(&p->dl, false);
...
if (!p->dl.dl_runtime) {
p->dl.deadline = 0;
p->dl.runtime = 0;
}
}
With dl_throttled cleared, the replenishment timer cancelled, and
deadline zeroed, re-entering SCHED_DEADLINE before the next period
bypasses dl_check_constrained_dl() and grants a fresh period, exceeding
the task's admitted bandwidth. Checking !p->dl.dl_runtime before
calling task_non_contending() (or using else if) would preserve the
deadline.
> @@ -2630,6 +2631,7 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer)
> }
>
> dl_task_release_bw(p);
> + cancel_replenish_timer(dl_se);
> dl_release_params(dl_se);
>
> goto unlock;
[Severity: Medium]
Can a racing inactive_task_timer() call dl_release_params() a second
time and wipe a constrained task's preserved deadline?
dl_release_params() is not idempotent: the first call clears dl_deadline
and dl_period to 0 while keeping dl_se->deadline, so a second call sees
dl_is_implicit(dl_se) as true (0 == 0) and overwrites deadline with 0.
This can happen when inactive_task_timer() is waiting on task_rq_lock()
as the task wakes and leaves SCHED_DEADLINE:
CPU0 CPU1
---- ----
__run_hrtimer(inactive_timer)
inactive_task_timer()
task_rq_lock(p) [waits]
task_contending()
dl_non_contending = 0
cancel_inactive_timer() == -1
switched_from_dl()
task_non_contending(..., false)
hrtimer_active() == true
dl_task_release_bw(p)
cancel_replenish_timer(dl_se)
dl_release_params(dl_se)
dl_deadline = dl_period = 0
rq_unlock()
[acquires rq lock]
!dl_task(p) is true
dl_release_params(dl_se)
deadline = 0 <-- wipes deadline
Clearing the preserved deadline lets the task bypass
dl_check_constrained_dl() if it re-enters SCHED_DEADLINE before its next
period, exceeding its admitted bandwidth. In addition, when
zerolag_time >= 0 while inactive_task_timer() is running,
task_non_contending() releases bandwidth and cancels dl_timer before the
new 0-lag time. Guarding dl_release_params() with an early return when
!dl_se->dl_runtime would prevent the second call from wiping deadline.
[Severity: Medium]
What happens if dl_task_timer() fires before inactive_task_timer() on a
departed constrained-deadline task?
Suppose a constrained-deadline task overruns its runtime (runtime < 0)
in period [0, P] and leaves SCHED_DEADLINE before P. Its 0-lag time
falls after P, so dl_task_timer() fires first at P; seeing !dl_task(p)
and dl_throttled, it calls replenish_dl_entity(dl_se) and advances
dl_se->deadline to P + dl_deadline. When inactive_task_timer() later
runs at the 0-lag time, cancel_replenish_timer() is a no-op and
dl_release_params() clears runtime to 0 while keeping that advanced
deadline.
If the task re-enters SCHED_DEADLINE during (0-lag, 2*P) without ever
having run in [P, 2*P], it is given zero runtime and throttled for an
extra period until 2*P.
[Severity: Medium]
Does cancel_replenish_timer() handle a dl_task_timer() callback that is
already running on another CPU?
cancel_replenish_timer() calls hrtimer_try_to_cancel(), which returns -1
if dl_task_timer() is already executing and waiting on task_rq_lock(p).
Because __run_hrtimer() already cleared is_queued, a subsequent
start_dl_timer() for a new reservation R2 re-arms dl_timer while the
stale callback is still pending:
CPU0 CPU1
---- ----
__run_hrtimer(dl_timer)
timer->is_queued = false
dl_task_timer()
task_rq_lock(p) [waits]
inactive_task_timer()
cancel_replenish_timer() == -1
dl_release_params(dl_se)
rq_unlock()
p re-enters SCHED_DEADLINE (R2)
throttles while blocking ->
start_dl_timer() [queues for T2]
PI-boosted while asleep
[acquires rq lock]
!task_on_rq_queued(p) is true
replenish_dl_entity(dl_se) <-- premature replenish
If the PI donor then deboosts the task before T2 and the task wakes up,
it runs with unearned runtime while the newer dl_timer remains queued,
violating CBS bandwidth guarantees. A later patch in this series,
commit "sched/deadline: Keep the debt of a task across a change of
parameters", guards the non-boosted case with a dl_next_period(dl_se)
check, but skips it when is_dl_boosted(dl_se) is true, leaving this
sleeping PI-boosted case exposed. Checking hrtimer_is_queued(timer)
under task_rq_lock(p) in dl_task_timer() would reject any stale callback
once dl_timer has been re-armed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@efficios.com?part=28
next prev parent reply other threads:[~2026-12-03 17:39 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:58 [PATCH v14 00/39] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-03 15:44 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 02/39] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-03 15:29 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 03/39] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 04/39] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 06/39] sched/deadline: Admit a returning task without the bandwidth it holds Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 07/39] sched/deadline: Leave an active task alone in the inactive timer Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task Mathieu Desnoyers
2026-12-03 15:45 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 09/39] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 15:49 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 10/39] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-03 15:57 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 11/39] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 12/39] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-03 16:20 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 16:10 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 14/39] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-03 16:10 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 15/39] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 16/39] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-03 16:22 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 17/39] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 18/39] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 19/39] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 20/39] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 21/39] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 22/39] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 23/39] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 24/39] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 25/39] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 26/39] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:25 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 27/39] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-03 17:39 ` sashiko-bot [this message]
2026-12-03 14:58 ` [PATCH v14 29/39] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 30/39] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 31/39] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-03 17:42 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 32/39] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 33/39] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:56 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 34/39] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 35/39] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-03 18:01 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-03 18:14 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 37/39] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-03 18:05 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-03 18:07 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 39/39] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248271@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox