Re: [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks

From: sashiko-bot

Date: Tue Dec 01 2026 - 14:41:23 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: dl_task_depart() ignores cpus_mask and
dl_bw_def during walk
--

commit 7998428425c31015887f4856ff0afd652b3061f2
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

sched/deadline: Count a task that departs while a rebuild walks the tasks

This commit counts the bandwidth of a task in dl_task_depart() when it
leaves SCHED_DEADLINE during a root domain accounting rebuild after
dl_clear_root_domains() has run and before the task-list walk reaches it.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 7aa6c3f7e99d2..ef97b07c0aa21 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -400,6 +419,24 @@ static void dl_task_depart(struct task_struct *p)
> 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);
> + /*
> + * dl_clear_root_domains() counted the departed tasks, and the walk
> + * of the task list counts the deadline tasks. A task that departs
> + * after the clear, before the walk reaches it, would be counted by
> + * neither. Count it here, as the walk would have. Use the CPU it
> + * departs from, or else the CPU recorded, or else an active CPU of
> + * its mask. If none is active, leave it out. While the sched domains
> + * are rebuilt, the clear is still ahead, and finds the task on the
> + * list.
> + */
> + if (dl_bw_move_blocked(p) && !dl_bw_rebuilding()) {
> + if (!cpu_active(cpu))
> + cpu = dl_se->dl_bw_cpu;
> + if (!cpu_active(cpu))
> + cpu = cpumask_first_and(cpu_active_mask, &p->cpus_mask);
> + if (cpu < nr_cpu_ids)
> + dl_task_count_bw(p, cpu);
> + }
> list_add(&dl_se->dl_departed_node, &dl_departed_list);
> }

[Severity: Medium]
Can dl_task_depart() charge the departing task's bandwidth to the wrong
root domain when task_cpu(p) or dl_se->dl_bw_cpu is still active but no
longer in p->cpus_mask?

When p is sleeping while holding an rt_mutex, a cpuset partition change
updates p->cpus_mask without migrating p off task_cpu(p). Unlike
dl_task_rebuild_cpu(), which intersects candidate CPUs for a non-queued
task with p->cpus_mask and matches dl_se->dl_bw_def, dl_task_depart() only
checks cpu_active(cpu):

kernel/sched/deadline.c:dl_task_rebuild_cpu() {
...
cpumask_and(msk, &p->cpus_mask, cpu_active_mask);
cpu = task_cpu(p);
if (cpu_active(cpu) && task_on_rq_queued(p) &&
(cpu == recorded || !cpumask_test_cpu(cpu, &p->cpus_mask)))
return cpu;
...
if (recorded >= 0) {
bool def = READ_ONCE(p->dl.dl_bw_def);
unsigned int same;

if (cpumask_test_cpu(cpu, msk) && dl_cpu_in_def(cpu) == def)
return cpu;
if (cpumask_test_cpu(recorded, msk) && dl_cpu_in_def(recorded) == def)
return recorded;
...
}

If the partition update that triggered dl_rebuild_rd_accounting() moved
task_cpu(p) into another partition and removed it from p->cpus_mask,
task_cpu(p) remains active in that other root domain. If p is deboosted
before the task-list walk reaches it, dl_task_depart() picks task_cpu(p)
and adds p->dl.dl_bw to the old CPU's new root domain instead of p's root
domain until the 0-lag timer fires, leaving p's root domain under-counted
for sched_setattr() admission and the other root domain over-counted.

When no active CPU is found (cpu >= nr_cpu_ids), this hunk also leaves
dl_se->dl_bw_skip_gen unset, though commit "sched/deadline: Count again a
departed task that a boost brings back" later in this series updates that
case.

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796146461.git.mathieu.desnoyers@xxxxxxxxxxxx?part=31