Re: [PATCH v6 26/37] sched/deadline: Keep a task in the root domain that counts its bandwidth
From: sashiko-bot
Date: Mon Nov 16 2026 - 14:50:19 EST
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: dl_task_offline_migration() bypasses
dl_task_bw_span()
- [Medium] sched/deadline: dl_task_bw_span() returns NULL for
deactivating dl_bw_cpu
- [Low] sched/deadline: dead branch and fallback order in
dl_task_rebuild_cpu()
--
commit a54933b747047e1dd4434be5e5299159be0de9fe
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
sched/deadline: Keep a task in the root domain that counts its bandwidth
This commit adds dl_task_bw_span() and updates CPU selection paths and
dl_task_rebuild_cpu() to prefer CPUs in the root domain that counts a
deadline task's bandwidth.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 35f40185953a3..5294546786f12 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -864,13 +864,19 @@ static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p
>
> later_rq = find_lock_later_rq(p, rq);
> if (!later_rq) {
> + const struct cpumask *span = dl_task_bw_span(p);
> int cpu;
>
> /*
> * If we cannot preempt any rq, fall back to pick any
> - * online CPU:
> + * online CPU. Try the root domain that counts @p first.
> */
> - cpu = cpumask_any_and(cpu_active_mask, p->cpus_ptr);
> + cpu = nr_cpu_ids;
> + if (span)
> + cpu = cpumask_first_and_and(cpu_active_mask,
> + p->cpus_ptr, span);
> + if (cpu >= nr_cpu_ids)
> + cpu = cpumask_any_and(cpu_active_mask, p->cpus_ptr);
[Severity: Medium]
Can find_lock_later_rq(p, rq) bypass the dl_task_bw_span(p) check and
migrate p onto an isolated CPU in def_root_domain?
When a housekeeping CPU goes offline, detach_destroy_domains() attaches
its runqueue to def_root_domain while dl_rebuild_rd_accounting() moves a
throttled task's bandwidth to the new housekeeping root domain. When
dl_task_timer() later fires on that offline CPU and calls
dl_task_offline_migration(), find_later_rq() searches
task_rq(p)->rd->cpudl, which is def_root_domain.cpudl:
kernel/sched/deadline.c:find_later_rq() {
...
if (!cpudl_find(&task_rq(task)->rd->cpudl, task, later_mask))
return -1;
...
}
With isolcpus=domain, isolated CPUs also belong to def_root_domain. If
p->cpus_mask includes an isolated CPU that is free or running a later
deadline in def_root_domain.cpudl, find_lock_later_rq() returns that
isolated CPU's runqueue and skips the !later_rq fallback entirely,
moving p and its bandwidth into def_root_domain without admission
control.
[ ... ]
> @@ -3669,6 +3690,29 @@ static unsigned int dl_task_root_domain_cpu(struct task_struct *p)
> return cpu;
> }
>
> +/*
> + * Return the CPUs of the root domain that counts the bandwidth of @p, or
> + * NULL if none does. The mask of @p can hold CPUs of another root domain,
> + * with isolcpus="domain". Where a CPU is picked for @p, a CPU of this
> + * root domain comes first: no other root domain admitted @p.
> + *
> + * The caller holds the pi_lock or the rq lock of @p. With interrupts
> + * off, the root domain is not freed.
> + */
> +const struct cpumask *dl_task_bw_span(struct task_struct *p)
> +{
> + int cpu;
> +
> + if (!task_has_dl_policy(p) || dl_entity_is_special(&p->dl) ||
> + !p->dl.dl_bw)
> + return NULL;
> + cpu = READ_ONCE(p->dl.dl_bw_cpu);
> + if (cpu < 0 || !cpu_active(cpu) ||
> + READ_ONCE(p->dl.dl_bw_gen) != READ_ONCE(dl_bw_gen))
> + return NULL;
> + return cpu_rq(cpu)->rd->span;
> +}
[Severity: Medium]
Does rejecting !cpu_active(cpu) here cause dl_task_bw_span() to return
NULL while a CPU is being deactivated?
In sched_cpu_deactivate(cpu), set_cpu_active(cpu, false) runs before
balance_push_set(), synchronize_rcu(), and cpuset_cpu_inactive(), and
cpuset_handle_hotplug() also calls cpuset_hotplug_update_tasks() before
rebuild_sched_domains_cpuslocked() runs dl_rebuild_rd_accounting().
Throughout that window, cpu_rq(cpu)->rd still points to the root domain
that counts p's bandwidth, but any task whose p->dl.dl_bw_cpu is the
outgoing CPU gets dl_task_bw_span(p) == NULL. Tasks pushed by
balance_push, updated by cpuset_hotplug_update_tasks(), or woken during
deactivation can then be placed on an isolated CPU in def_root_domain
and move their bandwidth there without admission control.
> @@ -3903,6 +3947,27 @@ static unsigned int dl_task_rebuild_cpu(struct task_struct *p)
> */
> cpumask_and(msk, &p->cpus_mask, cpu_active_mask);
> cpu = task_cpu(p);
> + /*
> + * Keep the bandwidth where it was counted: with the housekeeping
> + * CPUs, or with the CPUs that isolcpus="domain" isolates. The root
> + * domains are new, and the CPU recorded can be offline. So prefer a
> + * CPU of the mask of the same kind as the CPU recorded: housekeeping
> + * or not.
> + */
> + if (recorded >= 0) {
> + const struct cpumask *hk = housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT);
> + bool rec_hk = cpumask_test_cpu(recorded, hk);
> + unsigned int same;
> +
> + if (cpumask_test_cpu(cpu, msk) && cpumask_test_cpu(cpu, hk) == rec_hk)
> + return cpu;
> + if (cpumask_test_cpu(recorded, msk))
> + return recorded;
> + for_each_cpu(same, msk) {
> + if (cpumask_test_cpu(same, hk) == rec_hk)
> + return same;
> + }
> + }
> if (cpumask_test_cpu(cpu, msk))
> return cpu;
> if (cpumask_empty(msk)) {
[Severity: Low]
Because the new (recorded >= 0) block returns recorded whenever
cpumask_test_cpu(recorded, msk) is true, the existing else-if branch
right below this hunk is now unreachable:
kernel/sched/deadline.c:dl_task_rebuild_cpu() {
...
if (cpumask_empty(msk)) {
if (recorded >= 0 && cpu_active(recorded))
return recorded;
dl_get_task_effective_cpus(p, msk);
cpumask_and(msk, msk, cpu_active_mask);
} else if (recorded >= 0 && cpumask_test_cpu(recorded, msk)) {
return recorded;
}
...
}
Also, when cpumask_empty(msk) is true and recorded is inactive,
dl_get_task_effective_cpus(p, msk) refills msk after the kind-matching
loop has already run, so the fallback at the end of the function will
pick a housekeeping CPU even when recorded was an isolated CPU.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=26