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 09/39] sched/deadline: Keep departing bandwidth across a root domain rebuild
Date: Thu, 03 Dec 2026 15:49:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-248147@kernel.org> (raw)
In-Reply-To: <9ab68e7bb2bf0a109ac26f8976820f96354193f1.1796296313.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: global raw spinlock held across all root
domains in dl_clear_root_domains()
- [Medium] sched/deadline: global dl_departed_lock wraps dl_b->lock and
__dl_update()
- [Medium] sched/deadline: departed bw misattributed in
dl_clear_root_domains()
--
commit a0e3318afb889030b52c3d3e246d5783369fcb93
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 exit before their
0-lag time on a global dl_departed_list with their departing CPU and a
rebuild generation counter, so root domain accounting rebuilds and
inactive_task_timer() account their bandwidth against the right root domain.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 422a8120454a3..7d1e305049c25 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> +static void dl_task_release_bw(struct task_struct *p, int cpu)
> +{
> + struct sched_dl_entity *dl_se = &p->dl;
> + struct dl_bw *dl_b;
> +
> + lockdep_assert_irqs_disabled();
> + guard(raw_spinlock)(&dl_departed_lock);
> + if (dl_se->dl_departed_cpu >= 0) {
> + cpu = dl_se->dl_departed_cpu;
> + dl_se->dl_departed_cpu = -1;
> + list_del_init(&dl_se->dl_departed_node);
> + }
> + if (dl_se->dl_bw_gen == dl_bw_gen) {
> + dl_b = dl_bw_of(cpu);
> + raw_spin_lock(&dl_b->lock);
> + __dl_sub(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 holding the global raw spinlock dl_departed_lock across dl_b->lock and
__dl_sub() -> __dl_update() stall unrelated root domains?
Previously, bandwidth accounting was isolated per root domain via
rd->dl_bw.lock. Now dl_task_release_bw() holds dl_departed_lock while
__dl_update() loops over every active CPU in rd->span touching remote
rq->dl.extra_bw cachelines.
sched_dl_overflow() also acquires dl_departed_lock unconditionally on every
entry into SCHED_DEADLINE (even when dl_departed_cpu < 0) and holds it
across dl_b->lock, dl_bw_capacity(), and __dl_update().
When a large housekeeping root domain runs sched_dl_overflow() or releases
departed bandwidth, inactive_task_timer() hardirqs in an unrelated isolated
RT partition spin on dl_departed_lock with rq->__lock held and IRQs
disabled.
[ ... ]
> @@ -3670,9 +3805,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);
> + }
[Severity: Medium]
Does holding dl_departed_lock with IRQs disabled across all root domains
here introduce long IRQ-off stalls on large SMP systems?
Previously, dl_rebuild_rd_accounting() walked root domains with IRQs
enabled and locked each rd->dl_bw.lock separately. Now one
raw_spinlock_irqsave section spans every root domain's O(|rd->span|^2)
dl_server_add_bw() -> __dl_update() loop plus the dl_departed_list walk.
During a cpuset partition change or CPU hotplug, this creates a long
non-preemptible IRQ-off stall (even on PREEMPT_RT) and stalls unrelated
isolated RT partitions whenever their CPUs hit dl_departed_lock from
inactive_task_timer() or switched_from_dl() while holding rq->__lock.
> + 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]
Will splitting a CPU into a child cpuset partition root misattribute
departed bandwidth and wrap rq->dl.extra_bw below zero?
dl_task_depart() records only task_cpu(p) in dl_departed_cpu, and
dl_clear_root_domains() charges dl_se->dl_bw to dl_bw_of(dl_departed_cpu)
whenever that CPU is active.
If two 60% deadline tasks on CPUs 0-2 leave SCHED_DEADLINE or exit on
CPU 2, and CPU 2 is split into a 1-CPU child partition root before their
0-lag timers fire, both tasks' bandwidth is charged to the child partition
instead of the original root domain.
Until inactive_task_timer() fires, the original root domain can over-admit
deadline tasks while the child partition rejects valid admissions. Worse,
__dl_add() -> __dl_update() subtracts the misattributed bandwidth from the
unsigned u64 rq->dl.extra_bw, wrapping it near U64_MAX.
While rq->dl.extra_bw is wrapped, grub_reclaim() sees
u_inact + rq->dl.extra_bw > rq->dl.max_bw - dl_se->dl_bw as true and
grants maximum GRUB reclamation to SCHED_FLAG_RECLAIM tasks in the
overcommitted partition.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@efficios.com?part=9
next prev parent reply other threads:[~2026-12-03 15:49 UTC|newest]
Thread overview: 45+ 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 [this message]
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 14:58 ` [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
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 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 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 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 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 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 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 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
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 14:58 ` [PATCH v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
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-248147@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