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 v13 06/36] sched/deadline: Keep departing bandwidth across a root domain rebuild
Date: Tue, 01 Dec 2026 18:20:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-243962@kernel.org> (raw)
In-Reply-To: <6b669993ed9589032ec88900ad05418673030fc5.1796146461.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: departed bw misattributed in
dl_clear_root_domains()
- [Medium] sched/deadline: departed bw not discounted under lock in
sched_dl_overflow()
--
commit 61bc675abcdc6b82b59f9a092043cd6f4e528bc5
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Keep departing bandwidth across a root domain rebuild
This commit tracks tasks that leave SCHED_DEADLINE or die before their
0-lag time on dl_departed_list so that root domain accounting rebuilds
preserve their bandwidth until their inactive timer fires.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index cd7f2ada8cdf3..f345216deb77b 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -3744,9 +3881,51 @@ void dl_clear_root_domain(struct root_domain *rd)
> dl_server_add_bw(rd, i);
> }
>
> -void dl_clear_root_domain_cpu(int cpu)
> +/*
> + * Clear every root domain before a rebuild of their accounting, and count
> + * the rebuild in dl_bw_gen. Put back the bandwidth of their servers. Put
> + * back the bandwidth of the tasks on dl_departed_list, which no cpuset
> + * holds as deadline tasks. Put each in the root domain of the CPU
> + * recorded for it, or drop it if that CPU is not active.
> + * dl_add_task_root_domain() then adds the deadline tasks of the cpusets.
> + */
> +void dl_clear_root_domains(void)
> {
> - dl_clear_root_domain(cpu_rq(cpu)->rd);
> + struct sched_dl_entity *dl_se;
> + u64 cookie = ++dl_cookie;
> + struct dl_bw *dl_b;
> + int cpu;
> +
> + guard(raw_spinlock_irqsave)(&dl_departed_lock);
> + dl_bw_gen++;
> + for_each_possible_cpu(cpu) {
> + if (!dl_bw_visited(cpu, cookie))
> + dl_clear_root_domain(cpu_rq(cpu)->rd);
> + }
> + list_for_each_entry(dl_se, &dl_departed_list, dl_departed_node) {
> + cpu = dl_se->dl_departed_cpu;
> + /*
> + * Skip bandwidth that an earlier rebuild dropped. It is not
> + * counted now, and its release removes nothing
> + * (dl_task_release_bw()).
> + */
> + if (dl_se->dl_bw_gen != dl_bw_gen - 1)
> + continue;
> + /*
> + * Drop the bandwidth of a task whose CPU is inactive. A CPU
> + * that goes offline is in the default root domain by then.
> + * The root domain that counted the task cannot be found
> + * from the recorded number. The release then removes
> + * nothing, and no later rebuild restores it.
> + */
> + if (!cpu_active(cpu))
> + continue;
> + dl_b = dl_bw_of(cpu);
> + raw_spin_lock(&dl_b->lock);
> + __dl_add(dl_b, dl_se->dl_bw, dl_bw_cpus(cpu));
> + raw_spin_unlock(&dl_b->lock);
> + dl_se->dl_bw_gen = dl_bw_gen;
> + }
> }
[Severity: Medium]
Can dl_clear_root_domains() (and the dl_departed_cpu branch in
dl_add_task_root_domain()) charge departed bandwidth to the wrong root
domain when dl_se->dl_departed_cpu is split into a new child cpuset
partition before the 0-lag timer fires?
If tasks in a multi-CPU root domain leave SCHED_DEADLINE on CPU N and a
new partition root is created on CPU N before their inactive timers
expire, dl_bw_of(dl_se->dl_departed_cpu) resolves to the new partition's
root domain. The original root domain loses that departing bandwidth and
can over-admit deadline tasks, while the new partition is charged for
bandwidth that never belonged to it (rejecting admissions with -EBUSY and
underflowing cpu_rq(cpu)->dl.extra_bw via __dl_add() -> __dl_update() if
the departed bandwidth on CPU N exceeds the new partition's max_bw).
[ ... ]
> @@ -4065,8 +4261,6 @@ int sched_dl_overflow(struct task_struct *p, int policy,
>
> if (dl_policy(policy) && !task_has_dl_policy(p) &&
> !__dl_overflow(dl_b, cap, 0, new_bw)) {
> - if (hrtimer_active(&p->dl.inactive_timer))
> - __dl_sub(dl_b, p->dl.dl_bw, cpus);
> __dl_add(dl_b, new_bw, cpus);
> err = 0;
> } else if (dl_policy(policy) && task_has_dl_policy(p) &&
> @@ -4092,6 +4286,19 @@ int sched_dl_overflow(struct task_struct *p, int policy,
> }
> raw_spin_unlock(&dl_b->lock);
>
> + /*
> + * A task that comes back before its 0-lag time still has the
> + * bandwidth it left with. The new bandwidth replaces it, so remove the
> + * old one from the root domain that keeps it (dl_task_release_bw()).
> + * No rebuild can run meanwhile: the caller holds cpuset_mutex.
> + */
> + if (!err && dl_policy(policy) && !task_has_dl_policy(p)) {
> + lockdep_assert_cpuset_lock_held();
> + if (p->dl.dl_departed_cpu >= 0)
> + dl_task_release_bw(p, -1);
> + p->dl.dl_bw_gen = dl_bw_gen;
> + }
> +
> return err;
> }
[Severity: Medium]
When a departed task returns to SCHED_DEADLINE in the same root domain
before its 0-lag time, does deferring the old p->dl.dl_bw subtraction to
dl_task_release_bw() after raw_spin_unlock(&dl_b->lock) double-count the
task's bandwidth?
__dl_overflow(dl_b, cap, 0, new_bw) checks admission with old_bw = 0 even
though p->dl.dl_bw is still in dl_b->total_bw, so sched_setattr() fails
with -EBUSY whenever dl_b->total_bw + new_bw exceeds capacity while
dl_b->total_bw - p->dl.dl_bw + new_bw would fit. In addition, between
raw_spin_unlock(&dl_b->lock) and dl_task_release_bw() reacquiring
dl_b->lock, both p->dl.dl_bw and new_bw are present in dl_b->total_bw and
subtracted from rq->dl.extra_bw, which can cause concurrent
sched_dl_global_validate() or dl_server_apply_params() calls to fail with
-EBUSY and transiently skews (or underflows when admission control is
disabled) rq->dl.extra_bw in grub_reclaim().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796146461.git.mathieu.desnoyers@efficios.com?part=6
next prev parent reply other threads:[~2026-12-01 18:20 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:43 [PATCH v13 00/36] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 02/36] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 03/36] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 04/36] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-12-01 18:17 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 06/36] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 18:20 ` sashiko-bot [this message]
2026-12-01 17:44 ` [PATCH v13 07/36] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 08/36] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 09/36] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 10/36] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 11/36] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 12/36] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 13/36] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 14/36] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 15/36] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 16/36] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 17/36] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 18/36] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 19/36] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 20/36] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 21/36] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 23/36] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 24/36] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 25/36] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 26/36] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 27/36] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 28/36] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 29/36] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 30/36] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 34/36] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 35/36] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 36/36] 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-243962@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