Re: [PATCH v10 03/40] sched/deadline: Record the root domain holding a task's bandwidth

From: sashiko-bot

Date: Fri Nov 20 2026 - 16:18:54 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: dl_task_admit_cpu() returns offline CPU in
p->cpus_mask
- [Medium] sched/deadline: dl_task_check_affinity() uses stale CPU when
dl_bw is 0
--

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

sched/deadline: Record the root domain holding a task's bandwidth

This commit records in dl_bw_cpu a CPU of the root domain that accounts for
a deadline task's bandwidth, replacing dl_departed_cpu so that admission,
affinity checks, moves, and releases operate on the root domain where the
bandwidth is counted even when a sleeping task remains on a CPU from
another root domain.

Link: https://lore.kernel.org/all/20261103-b4-sched-dl-bw-fixes-v1-1-dd761fe005b4@xxxxxxxxxx/

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index d1a2ae9ab75fd..dbb5dafff3717 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -3592,14 +3618,52 @@ static void task_woken_dl(struct rq *rq, struct task_struct *p)
[ ... ]
> +static unsigned int dl_task_admit_cpu(struct task_struct *p)
> +{
> + unsigned int cpu;
> +
> + if (task_has_dl_policy(p) && p->dl.dl_bw && p->dl.dl_bw_cpu >= 0 &&
> + p->dl.dl_bw_gen == dl_bw_gen)
> + return p->dl.dl_bw_cpu;
> + cpu = task_cpu(p);
> + if (!cpumask_test_cpu(cpu, &p->cpus_mask)) {
> + unsigned int other = cpumask_first_and(cpu_active_mask, &p->cpus_mask);
> +
> + if (other < nr_cpu_ids)
> + cpu = other;
> + }
> + return cpu;
> +}

[Severity: Medium]
Can dl_task_admit_cpu() return an offline CPU when p is asleep on a CPU
that went offline?

For tasks in top_cpuset (or when CONFIG_CPUSETS is disabled), CPU
hot-unplug does not clear the offline CPU from p->cpus_mask. If p is
asleep on that CPU when sched_setattr() enters SCHED_DEADLINE (or updates
a zero-bandwidth task), cpumask_test_cpu(cpu, &p->cpus_mask) is still
true, so dl_task_admit_cpu() returns the offline CPU whose runqueue is
attached to def_root_domain. __sched_setscheduler() and
sched_dl_overflow() then check and charge def_root_domain instead of the
active root domain where p will run, failing with -EBUSY when
def_root_domain has no active CPUs or accounting the bandwidth in the
wrong root domain.

Should the fallback also trigger when !cpu_active(cpu)?

> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index 96a5f0a7adbc3..95181e5de8da6 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
[ ... ]
> @@ -1204,9 +1213,16 @@ int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
> * if admission test is enabled, we only admit -deadline
> * tasks allowed to run on all the CPUs in the task's
> * root_domain.
> + *
> + * That is the root domain that counts the bandwidth of the task:
> + * the one of the CPU recorded with it. A task moved asleep to
> + * another cpuset is still on a CPU of the root domain it left. A
> + * bandwidth of 0 is counted nowhere, and no move updates its
> + * record: use the CPU the task is on.
> */
> + cpu = READ_ONCE(p->dl.dl_bw) ? dl_task_root_domain_cpu(p) : task_cpu(p);
> guard(rcu)();
> - if (!cpumask_subset(task_rq(p)->rd->span, mask))
> + if (!cpumask_subset(cpu_rq(cpu)->rd->span, mask))
> return -EBUSY;
>
> return 0;

[Severity: Medium]
When p->dl.dl_bw is 0 and p was moved to another cpuset partition while
asleep, doesn't task_cpu(p) still point to the old root domain that p left?

Because dl_task_needs_bw_move() skips zero-bandwidth tasks, p->dl.dl_bw_cpu
is not updated on the move, and while p remains asleep task_cpu(p) is still
a CPU of the old partition outside p->cpus_mask. Calling
sched_setaffinity() before p wakes up intersects the requested mask with
the new cpuset's allowed CPUs and then checks cpumask_subset() against the
old root domain's span, causing sched_setaffinity() to fail with -EBUSY.

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