Re: [PATCH v9 17/33] cgroup/cpuset: Refuse to take a deadline task out of its root domain

From: sashiko-bot

Date: Fri Nov 20 2026 - 09:33:18 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: dl_task_keeps_root_domain() checks cpus_ptr
instead of cpus_mask
- [Medium] cgroup/cpuset: stale root domain check in
update_parent_effective_cpumask()
--

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

cgroup/cpuset: Refuse to take a deadline task out of its root domain

This commit rejects cpuset.cpus updates with -EBUSY and invalidates
partitions with PERR_DLTASK when a cpumask change would remove all CPUs
of the root domain accounting a deadline task's bandwidth.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index ef95c730853e0..421e0bfc1c81e 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -2106,10 +2232,13 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> }
> rcu_read_unlock();
> }
> - if (exclusive)
> - deleting = !cpumask_empty(tmp->delmask);
> - else
> + if (!exclusive)
> part_error = PERR_NOTEXCL;
> + else if (!dl_tasks_keep_without(parent, cs, tmp->delmask,
> + NULL, true))
> + part_error = PERR_DLTASK;
> + else
> + deleting = !cpumask_empty(tmp->delmask);
> }
> /*
> * When both cs and parent remain valid, parent's

[Severity: Medium]
Can this dl_tasks_keep_without() check fail with PERR_DLTASK against a
stale root domain span before the sched domains are rebuilt?

This branch (partcmd_update with newmask == NULL) runs from
update_cpumasks_hier() and cpuset_hotplug_update_tasks() after
parent->effective_cpus grows, but before rebuild_sched_domains_locked() or
rebuild_sched_domains_cpuslocked() updates rd->span to include the newly
added or onlined CPUs.

If a valid non-top partition parent holding CPU 0, a deadline task on CPU
0, and an invalid child partition requesting CPU 0 (previously PERR_NOCPUS)
is expanded to CPUs 0-1, dl_tasks_keep_without() checks parent's remaining
CPU 1 against the task's pre-rebuild dl_task_bw_span() of CPU 0 and keeps
the child invalid with PERR_DLTASK. Similarly, when a CPU comes online for
an invalid partition holding a deadline task on a fallback CPU,
dl_tasks_keep_without() tests the newly onlined CPU against the fallback
root domain span and sets PERR_DLTASK before hotplug_update_tasks() moves
the task onto the onlined CPU anyway.

[ ... ]

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 2ed99b55d8a60..a21b504d467f3 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -5268,6 +5268,31 @@ int dl_bw_deactivate(int cpu)
> return ret;
> }
>
> +/*
> + * Return false if @p has CPUs in the root domain that counts its
> + * bandwidth and @new_mask holds none of them. A cpuset refuses such a
> + * mask: only a move to another cpuset makes room in another root domain.
> + * Like __set_cpus_allowed_ptr(), keep @new_mask within the affinity set by
> + * the user, if they intersect.
> + */
> +bool dl_task_keeps_root_domain(struct task_struct *p,
> + const struct cpumask *new_mask)
> +{
> + const struct cpumask *span;
> +
> + if (!dl_bandwidth_enabled() || !task_has_dl_policy(p))
> + return true;
> + /* pi_lock also protects p->user_cpus_ptr. */
> + guard(raw_spinlock_irqsave)(&p->pi_lock);
> + guard(rcu)();
> + span = dl_task_bw_span(p);
> + if (!span || !cpumask_intersects(span, p->cpus_ptr))
> + return true;
> + if (p->user_cpus_ptr && cpumask_intersects(new_mask, p->user_cpus_ptr))
> + return cpumask_intersects_and(span, new_mask, p->user_cpus_ptr);
> + return cpumask_intersects(span, new_mask);
> +}

[Severity: Medium]
Should dl_task_keeps_root_domain() check &p->cpus_mask instead of
p->cpus_ptr, as dl_task_leaves_span() and dl_task_rebuild_cpu() do?

When p is scheduled out inside a migrate_disable() section,
migrate_disable_switch() sets p->cpus_ptr to cpumask_of(rq->cpu) while
p->cpus_mask retains the task's allowed mask. If a domain rebuild (such
as switching an isolated partition covering housekeeping and isolated CPUs
back to a member cpuset) happens while p is scheduled out in
migrate_disable() on a housekeeping CPU, dl_task_rebuild_cpu() inspects
&p->cpus_mask and keeps p's bandwidth in def_root_domain. At that point
span intersects &p->cpus_mask but not p->cpus_ptr, so
cpumask_intersects(span, p->cpus_ptr) is false and a subsequent
cpuset.cpus write can strip all def_root_domain CPUs from p, moving its
bandwidth into the housekeeping root domain without admission control when
p wakes.

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