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 v10 38/40] sched/deadline: Boost an owner that cannot run on its own reservation
Date: Fri, 20 Nov 2026 21:33:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-226195@kernel.org> (raw)
In-Reply-To: <297755d1d8dde37f65e12a4cd502c6332011f44c.1795207233.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] sched/deadline: missing throttle restoration in dl_deboost()
- [High] sched/deadline: donor period added to own_deadline in
replenish_dl_entity()
- [Medium] sched/deadline: missing dl_boost_held check in
switched_from_dl()
- [Medium] sched/deadline: expired own_deadline restored in dl_deboost()
- [Medium] sched/deadline: stale deadline on PI chain in
dl_boost_blocked()
- [Medium] sched/deadline: missing refill on boosted wakeup in
enqueue_task_dl()
--
commit 59eba5619dd87ca592a528ffc0286ed100abcecc
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Boost an owner that cannot run on its own reservation
This commit updates deadline priority inheritance so that a deadline
waiter boosts a lock owner that is throttled or past its deadline, saving
and restoring the owner's parameters across the boost when it could not
run on its own reservation.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 0dce129b41468..cbe0dfe26de3d 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7974,10 +7974,13 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
> if (!dl_prio(p->normal_prio) ||
> (pi_task && dl_prio(pi_task->prio) &&
> !(p->dl.dl_new_params && p->dl.pi_se != &p->dl) &&
> - dl_entity_preempt(&pi_task->dl, &p->dl))) {
> + dl_waiter_boosts(p, pi_task))) {
> struct sched_dl_entity *old_donor = p->dl.pi_se;
>
> dl_set_donor(&p->dl, pi_task);
> + if (dl_prio(p->normal_prio) && old_donor == &p->dl &&
> + p->dl.pi_se != &p->dl)
> + dl_boost_start(&p->dl);
> scope->flags |= ENQUEUE_REPLENISH;
> if (!scope->queued && p->dl.pi_se != old_donor)
> dl_boost_blocked(p);
[Severity: Medium]
When p is a deadline task blocked on another rt_mutex (!scope->queued),
does dl_boost_blocked(p) leave p->dl.deadline stale for the rest of the PI
chain walk?
sched_change_end() skips enqueue_task_dl() when !scope->queued, and
dl_boost_blocked() only replenishes tasks with !dl_se->dl_deadline &&
!dl_se->dl_throttled:
kernel/sched/deadline.c:dl_boost_blocked() {
struct sched_dl_entity *dl_se = &p->dl;
if (!dl_se->dl_deadline && !dl_se->dl_throttled &&
dl_task_pi_blocked(p))
replenish_dl_new_period(dl_se, task_rq(p));
}
When p has its own deadline parameters or is throttled, p->dl.deadline is
not updated to the donor's deadline before rt_mutex_adjust_prio_chain()
calls waiter_update_prio() and dl_waiter_boosts() on the next lock in the
chain, so the boost fails to propagate across nested rt_mutexes.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index e9b3d3ec71d77..ff1c104f6afd8 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -161,21 +165,32 @@ static inline bool dl_task_pi_blocked(struct task_struct *p)
> void dl_deboost(struct sched_dl_entity *dl_se)
> {
> struct task_struct *p = dl_task_of(dl_se);
> -
> + bool own = false;
> +
> + /* Put back what dl_boost_start() saved. */
> + if (dl_se->dl_boost_held) {
> + dl_se->deadline = dl_se->own_deadline;
> + dl_se->runtime = dl_se->own_runtime;
> + dl_se->period_start = dl_se->own_period_start;
> + dl_se->dl_donor_refill = 0;
> + own = true;
> + }
[Severity: High]
When a task that was boosted while throttled (own_runtime <= 0) is
deboosted before own_deadline, does restoring own_runtime without restoring
dl_throttled leave the task runnable on dl_rq with exhausted runtime?
When the boost started, enqueue_task_dl() canceled dl_timer and cleared
dl_se->dl_throttled = 0. If the boost ends before own_deadline,
dl_deboost() restores own_deadline and own_runtime <= 0 with dl_throttled
still 0, and enqueue_dl_entity() only checks dl_check_constrained_dl() for
past deadlines before calling __enqueue_dl_entity(dl_se). The exhausted
owner is then enqueued as runnable with its earlier own_deadline,
preventing the woken waiter from preempting it and running beyond its CBS
budget until the next tick. If dl_new_params was set during the boost,
the subsequent dl_waiter_boosts() and dl_boost_start() check in
rt_mutex_setprio() also sees dl_throttled == 0 and misses that the owner
cannot run on its own reservation.
[Severity: Medium]
Should switched_from_dl() also restore own_deadline, own_runtime and
own_period_start when dl_boost_held is set?
If a task boosted with dl_boost_held changes policy to a non-deadline
class while boosted and leaves dl_sched_class at deboost,
rt_mutex_setprio() runs switched_from_dl() and dl_drop_boost() instead of
dl_deboost():
kernel/sched/deadline.c:switched_from_dl() {
bool own_period = p->dl.dl_runtime && p->dl.dl_donor_refill;
...
if (own_period)
dl_start_own_period(&p->dl);
if (task_on_rq_queued(p) && p->dl.dl_runtime)
task_non_contending(&p->dl, false);
}
Because dl_donor_refill was set when the boosted task replenished from its
donor, switched_from_dl() calls dl_start_own_period() and resets runtime
to full dl_runtime instead of restoring the exhausted own_* reservation.
task_non_contending() then sees a 0-lag time of now and releases the
task's root-domain bandwidth immediately instead of waiting until the true
0-lag time of the saved period.
[ ... ]
> @@ -214,6 +229,62 @@ void dl_check_blocked_params(struct task_struct *p)
> update_dl_entity(dl_se);
> }
> }
> +
> +/*
> + * Return true if the deadline waiter @pi_task must boost the owner @p,
> + * which has a deadline policy of its own. Compare @pi_task with the
> + * deadline that @p would run on:
> + * - @p is throttled, or past its deadline and before its next period:
> + * it cannot run on its own reservation. Boost it.
> + * - @p was boosted for that reason: keep the boost until its own next
> + * period. After that period starts, compare with now + dl_deadline.
> + * - @p is past its deadline otherwise: its next enqueue starts a new
> + * period. Compare with now + dl_deadline.
> + * - Else, compare with the deadline of @p.
> + * A special entity, such as a sugov kthread, always boosts @p.
> + *
> + * The caller holds the rq lock of @p and has updated the rq clock.
> + */
> +bool dl_waiter_boosts(struct task_struct *p, struct task_struct *pi_task)
> +{
> + struct sched_dl_entity *dl_se = &p->dl;
> + u64 now = rq_clock(task_rq(p));
> +
> + if (dl_entity_is_special(&pi_task->dl))
> + return true;
> + if (dl_se->dl_boost_held) {
> + if (dl_time_before(now, dl_se->own_period_start + dl_se->dl_period))
> + return true;
> + return dl_time_before(pi_task->dl.deadline, now + dl_se->dl_deadline);
> + }
[Severity: Medium]
Once now reaches own_period_start + dl_period, dl_waiter_boosts() compares
pi_task against now + dl_se->dl_deadline, but if it returns false and
triggers a deboost while p is pi-blocked on another rt_mutex, does
dl_deboost() restore the expired own_deadline instead of starting a new
period?
In dl_deboost(), the dl_boost_held branch unconditionally restores
dl_se->deadline = dl_se->own_deadline (which is now in the past) and
clears dl_se->dl_donor_refill = 0 so dl_start_own_period() is skipped.
When p is blocked on a second rt_mutex (!scope->queued), enqueue_task_dl()
does not run in sched_change_end(), so rt_mutex_adjust_prio_chain() copies
that expired past deadline into p's waiter node on the outer lock and
orders p ahead of waiters with valid future deadlines. The same expired
own_deadline is also exposed on the outer lock if p is deboosted while
still in the constrained gap and pi-blocked.
> + if (!is_dl_boosted(dl_se)) {
> + if (dl_se->dl_throttled || dl_in_constrained_gap(dl_se))
> + return true;
> + if (dl_time_before(dl_se->deadline, now))
> + return dl_time_before(pi_task->dl.deadline,
> + now + dl_se->dl_deadline);
> + }
> + return dl_entity_preempt(&pi_task->dl, dl_se);
> +}
> +
> +/*
> + * Call this when @dl_se gets its first donor, after dl_set_donor()
> + * installed it. If @dl_se cannot run on its own reservation, save its
> + * deadline, runtime and period start in own_*. Then set dl_boost_held.
> + * dl_deboost() puts them back. A task with no parameters of its own has
> + * nothing to save. The caller holds the rq lock and has updated the rq
> + * clock.
> + */
> +void dl_boost_start(struct sched_dl_entity *dl_se)
> +{
> + if (!dl_se->dl_runtime ||
> + (!dl_se->dl_throttled && !dl_in_constrained_gap(dl_se)))
> + return;
> + dl_se->own_deadline = dl_se->deadline;
> + dl_se->own_runtime = dl_se->runtime;
> + dl_se->own_period_start = dl_se->period_start;
> + dl_se->dl_boost_held = 1;
> +}
[Severity: Medium]
If an owner is throttled while going to sleep, boosted while asleep, and
then wakes up before own_deadline while still boosted, does
enqueue_task_dl() fail to replenish it from the donor?
When the boost happens while !scope->queued, ENQUEUE_REPLENISH is not
consumed by sched_change_end(). On the subsequent wakeup,
enqueue_task_dl(rq, p, ENQUEUE_WAKEUP) cancels dl_timer and clears
dl_se->dl_throttled = 0 without setting ENQUEUE_REPLENISH, so
enqueue_dl_entity() calls update_dl_entity(dl_se):
kernel/sched/deadline.c:update_dl_entity() {
...
if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
dl_entity_overflow(dl_se, rq_clock(rq))) {
...
replenish_dl_new_period(dl_se, rq);
}
}
Because rq_clock(rq) < own_deadline and dl_se->runtime <= 0 makes left <= 0
while right > 0 in dl_entity_overflow(), both checks are false and
replenish_dl_new_period() is skipped, enqueuing the boosted owner with
runtime <= 0 and its old own_deadline instead of the donor's parameters.
[ ... ]
> @@ -1443,7 +1514,13 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> * entity.
> */
> if (dl_time_before(dl_se->deadline, rq_clock(rq))) {
> - printk_deferred_once("sched: DL replenish lagged too much\n");
> + /*
> + * dl_waiter_boosts() boosts an owner past its deadline. Its
> + * deadline is then expected to be in the past: do not warn.
> + * The new period takes the donor's parameters.
> + */
> + if (!is_dl_boosted(dl_se))
> + printk_deferred_once("sched: DL replenish lagged too much\n");
> replenish_dl_new_period(dl_se, rq);
> }
[Severity: High]
When a runnable throttled owner (runtime <= 0) is boosted, does the
while (dl_se->runtime <= 0) loop right above this check advance
dl_se->deadline from own_deadline by the donor's period instead of
starting a donor period at rq_clock(rq)?
kernel/sched/deadline.c:replenish_dl_entity() {
...
while (dl_se->runtime <= 0) {
dl_se->deadline += period;
dl_se->period_start += period;
dl_se->runtime += runtime;
}
if (dl_time_before(dl_se->deadline, rq_clock(rq))) {
if (!is_dl_boosted(dl_se))
printk_deferred_once("sched: DL replenish lagged too much\n");
replenish_dl_new_period(dl_se, rq);
}
}
For any throttled owner whose own_deadline has not passed yet (or is
within one donor period of rq_clock(rq)), adding the donor's period to
own_deadline keeps dl_se->deadline >= rq_clock(rq), so
replenish_dl_new_period() is never reached. The boosted owner runs with a
deadline of own_deadline + pi_se->dl_period (later than its unboosted
own_deadline) instead of rq_clock(rq) + pi_se->dl_deadline, and its own
pre-boost overrun is deducted from the donor's runtime while also being
restored from own_runtime at dl_deboost().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795207232.git.mathieu.desnoyers@efficios.com?part=38
next prev parent reply other threads:[~2026-11-20 21:33 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 20:41 [PATCH v10 00/40] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 01/40] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 02/40] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 03/40] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-20 21:18 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 04/40] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 05/40] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 21:12 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 06/40] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 07/40] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 08/40] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 09/40] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 10/40] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 11/40] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 12/40] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 13/40] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-20 21:11 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 14/40] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 15/40] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 16/40] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-20 21:19 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 17/40] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-20 21:22 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 18/40] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:54 ` sashiko-bot
2026-11-20 20:41 ` [PATCH v10 19/40] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 20/40] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 21/40] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-20 20:41 ` [PATCH v10 22/40] rtmutex: Do not stop the chain walk at an owner whose top waiter changed Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 23/40] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 24/40] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-20 21:06 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 25/40] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-20 21:26 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 26/40] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-20 21:22 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 27/40] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 28/40] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-20 21:21 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 29/40] sched/deadline: Start a period at a deboost out of the class Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 30/40] sched/deadline: Start a period for a task requeued onto an rt_mutex Mathieu Desnoyers
2026-11-20 21:24 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 31/40] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-20 21:08 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 32/40] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 33/40] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 34/40] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 35/40] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-20 21:38 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 36/40] sched/deadline: Reschedule a running task throttled at its enqueue Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 37/40] sched/deadline: Keep the start of the period across a change of dl_deadline Mathieu Desnoyers
2026-11-20 21:21 ` sashiko-bot
2026-11-20 20:42 ` [PATCH v10 38/40] sched/deadline: Boost an owner that cannot run on its own reservation Mathieu Desnoyers
2026-11-20 21:33 ` sashiko-bot [this message]
2026-11-20 20:42 ` [PATCH v10 39/40] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-11-20 20:42 ` [PATCH v10 40/40] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers
2026-11-20 21:15 ` sashiko-bot
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-226195@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