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

From: sashiko-bot

Date: Tue Nov 17 2026 - 10:14:50 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: __sched_setscheduler() checks task_rq(p) root
domain
--

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

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

This commit replaces dl_departed_cpu with dl_bw_cpu in struct sched_dl_entity
to record a CPU of the root domain that accounts for a deadline task's
bandwidth across admissions, moves, rebuilds, and releases.

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 8e8c62c574d55..01fbbd02cf8d0 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -4213,6 +4280,23 @@ int sched_dl_overflow(struct task_struct *p, int policy,
> if (new_bw == p->dl.dl_bw && task_has_dl_policy(p))
> return 0;
>
> + /*
> + * Change the bandwidth of a deadline task where it is counted: in
> + * the root domain of the CPU recorded with it. A task moved asleep
> + * has not run there yet, so the CPU it is on can be elsewhere. No
> + * bandwidth is counted if a rebuild dropped it, or if the task
> + * enters the class. A runtime below about a millionth of the period
> + * gives a bandwidth of 0. It counts for nothing, and no move updates
> + * its record. In these three cases, the root domain of the CPU the
> + * task is on takes the new bandwidth. The caller holds cpuset_mutex,
> + * or dl_accounting_mutex without cpusets, so no rebuild runs
> + * meanwhile.
> + */
> + counted = task_has_dl_policy(p) && p->dl.dl_bw_cpu >= 0 &&
> + p->dl.dl_bw_gen == dl_bw_gen;
> + cpu = counted && p->dl.dl_bw ? p->dl.dl_bw_cpu : task_cpu(p);
> + dl_b = dl_bw_of(cpu);
[ ... ]
> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
> index 4c013caa24713..306cd8d32173b 100644
> --- a/kernel/sched/syscalls.c
> +++ b/kernel/sched/syscalls.c
> @@ -1185,6 +1185,8 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
>
> int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
> {
> + unsigned int cpu;
> +
> /*
> * If the task isn't a deadline task or admission control is
> * disabled then we don't care about affinity changes.
> @@ -1204,9 +1206,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]
Should __sched_setscheduler() also use the root domain recorded in
p->dl.dl_bw_cpu rather than rq->rd when validating a deadline task's
root domain span and dl_bw.bw?

kernel/sched/syscalls.c:__sched_setscheduler() {
...
if (dl_bandwidth_enabled() && dl_policy(policy) &&
!(attr->sched_flags & SCHED_FLAG_SUGOV)) {
cpumask_t *span = rq->rd->span;

if (!cpumask_subset(span, &p->cpus_mask) ||
rq->rd->dl_bw.bw == 0) {
retval = -EPERM;
goto unlock;
}
}
...
}

When a sleeping SCHED_DEADLINE task is moved to another exclusive cpuset
partition (or its CPU goes offline into the default root domain),
p->cpus_mask and p->dl.dl_bw_cpu reflect the root domain holding its
bandwidth, while rq (task_rq(p)) remains in the old root domain. Because
rq->rd->span is not a subset of p->cpus_mask, __sched_setscheduler()
rejects sched_setattr() parameter updates on that task with -EPERM before
reaching the moved-sleeper handling in sched_dl_overflow().

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