Re: [PATCH v6 16/37] sched/deadline: Record the root domain holding a task's bandwidth
From: sashiko-bot
Date: Mon Nov 16 2026 - 14:45:26 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 685fb9b4f51b7675ac0c8a518174590afd51eb14
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, and updates bandwidth moves, releases,
parameter changes, and affinity checks to consult that recorded root domain
instead of task_rq(p)->rd.
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 ccd6426811b9e..44db625bffc32 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -4193,6 +4260,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 check the root domain of the recorded
dl_bw_cpu instead of rq->rd?
While sched_dl_overflow() and dl_task_check_affinity() are updated to look
up the root domain via dl_bw_cpu for a task moved while asleep,
__sched_setscheduler() still checks rq = task_rq(p) before calling
sched_dl_overflow():
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,
p->cpus_mask is updated to the destination cpuset while task_rq(p) stays in
the old root domain. Because the old rq->rd->span is disjoint from
p->cpus_mask, sched_setattr() fails here with -EPERM before reaching
sched_dl_overflow().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=16