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 33/36] sched/deadline: Keep a reaped deadline task in a rebuild
Date: Tue, 01 Dec 2026 19:57:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-244136@kernel.org> (raw)
In-Reply-To: <3edb25262589e32cd881312999f521f9bab9d910.1796146461.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: stale dl_bw_cpu when dl_task_depart() skips
queued task
- [Medium] sched/deadline: rebuild drops bandwidth of active task on
dl_departed_list
- [Medium] sched/deadline: lockless dl_bw check in dl_task_unhash()
races with setattr
--
commit 4c28f4a343df6c19b2f8f610ef54bf2893d243f4
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Keep a reaped deadline task in a rebuild
This commit adds dl_task_unhash() to place a deadline task on
dl_departed_list in release_task() before unhashing it, and keeps exited
tasks on dl_departed_list in dl_task_undepart().
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index d84a459e7a640..e759e4f27cc7a 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -442,6 +443,27 @@ static void dl_task_depart(struct task_struct *p)
> list_add(&dl_se->dl_departed_node, &dl_departed_list);
> }
>
> +/*
> + * Put @p on dl_departed_list if it is a deadline task with a bandwidth.
> + * release_task() calls this before it takes @p off the task list, so
> + * that a rebuild still counts @p until its last schedule. That schedule,
> + * or the inactive timer after it, takes @p off the list. The caller holds
> + * tasklist_lock for writing: no walk of the task list runs meanwhile.
> + */
> +void dl_task_unhash(struct task_struct *p)
> +{
> + struct rq_flags rf;
> + struct rq *rq;
> +
> + lockdep_assert_held_write(&tasklist_lock);
> + if (!READ_ONCE(p->dl.dl_bw))
> + return;
[Severity: Medium]
Can the lockless check of p->dl.dl_bw race with __sched_setscheduler()
admitting p to SCHED_DEADLINE?
__sched_setscheduler() checks p->exit_state under task_rq_lock() without
holding tasklist_lock, and only assigns p->dl.dl_bw later in
__setparam_dl():
CPU0 CPU1
__sched_setscheduler(p)
task_rq_lock(p)
if (p->exit_state) // 0
sched_dl_overflow()
do_exit()
exit_notify()
write_lock_irq(&tasklist_lock)
p->exit_state = EXIT_DEAD
release_task(p)
dl_task_unhash(p)
!READ_ONCE(p->dl.dl_bw)
--> returns early
__exit_signal()
__unhash_process()
__setparam_dl()
dl_se->dl_bw = ...
task_rq_unlock(p)
p is then off the task list and not on dl_departed_list while holding
deadline bandwidth, so a root domain rebuild before p's final schedule
drops its bandwidth from total_bw.
> + rq = task_rq_lock(p, &rf);
> + if (dl_task(p) && dl_task_holds_bw(p))
> + dl_task_depart(p);
> + task_rq_unlock(rq, p, &rf);
> +}
[Severity: Medium]
If p migrates to another active CPU in the same root domain between
release_task() and its final schedule in do_task_dead(), does
dl_task_depart() leave a stale p->dl.dl_bw_cpu?
Because the migration stays within the same root domain,
dl_task_bw_elsewhere() is false and dl_task_move_bw() does not update
dl_bw_cpu. When p later reaches do_task_dead() and task_non_contending()
calls dl_task_depart(p), p is already on dl_departed_list from
dl_task_unhash(), so dl_task_depart() returns early before reaching
dl_record_bw_cpu():
kernel/sched/deadline.c:dl_task_depart() {
...
if (!list_empty(&dl_se->dl_departed_node) || dl_se->dl_bw_cpu < 0)
return;
...
if (dl_se->dl_bw_gen == dl_bw_gen && !dl_bw_rebuilding() && cpu_active(cpu) &&
cpu_rq(cpu)->rd == cpu_rq(dl_se->dl_bw_cpu)->rd)
dl_record_bw_cpu(dl_se, cpu);
If the old dl_bw_cpu goes offline before p's 0-lag time while the CPU p
actually departed from remains active, dl_clear_root_domains() sees an
inactive dl_bw_cpu and drops p's bandwidth.
> @@ -462,7 +484,12 @@ static void dl_task_undepart(struct task_struct *p, int cpu)
> if (list_empty(&dl_se->dl_departed_node))
> return;
> guard(raw_spinlock)(&dl_departed_lock);
> - list_del_init(&dl_se->dl_departed_node);
> + /*
> + * Keep a task that has exited on the list. It may be off the task list
> + * already (dl_task_unhash()), and a rebuild must still count it.
> + */
> + if (!p->exit_state)
> + list_del_init(&dl_se->dl_departed_node);
> if (dl_se->dl_bw_gen != dl_bw_gen && !dl_bw_move_blocked(p) &&
> cpu_active(cpu))
> dl_task_count_bw(p, cpu);
[Severity: Medium]
Can keeping an active exited task on dl_departed_list cause a rebuild to
drop its bandwidth while it is still running in SCHED_DEADLINE?
Both dl_clear_root_domains() and dl_add_task_root_domain() treat any task
with !list_empty(&dl_se->dl_departed_node) as a departed task: they
require dl_se->dl_bw_gen == dl_bw_gen - 1 and cpu_active(dl_se->dl_bw_cpu)
instead of picking an active CPU via dl_task_rebuild_cpu(p).
This drops the bandwidth of an in-class task in two cases:
1. If an earlier rebuild dropped an exited task's departed bandwidth
(dl_se->dl_bw_gen != dl_bw_gen) and the task is PI-boosted back into
SCHED_DEADLINE while dl_bw_rebuilding() is true, dl_bw_move_blocked(p)
prevents dl_task_undepart() from calling dl_task_count_bw(). When
dl_clear_root_domains() and dl_add_task_root_domain() run next, both
see !list_empty(&dl_se->dl_departed_node) with
dl_se->dl_bw_gen != dl_bw_gen - 1 and skip the task.
2. If an exited task on dl_departed_list (via dl_task_unhash() or kept
there by dl_task_undepart()) is running on an active CPU when its
recorded dl_bw_cpu goes offline, dl_clear_root_domains() and
dl_add_task_root_domain() check !cpu_active(dl_se->dl_bw_cpu) and drop
its bandwidth even though the task is still running in the root domain.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796146461.git.mathieu.desnoyers@efficios.com?part=33
next prev parent reply other threads:[~2026-12-01 19:57 UTC|newest]
Thread overview: 47+ 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
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 19:11 ` sashiko-bot
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 19:02 ` sashiko-bot
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 19:29 ` sashiko-bot
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 19:34 ` sashiko-bot
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 19:41 ` sashiko-bot
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 19:47 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-01 19:57 ` sashiko-bot [this message]
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 19:51 ` sashiko-bot
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-244136@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.