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

From: sashiko-bot

Date: Thu Nov 19 2026 - 15:43:36 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] cgroup/cpuset: stale root domain check in
update_parent_effective_cpumask()
- [Medium] cgroup/cpuset: offline CPU mismatch in
dl_tasks_keep_without() for top_cpuset
--

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

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

This commit refuses cpuset cpumask updates and invalidates partitions that
would remove all CPUs of the root domain accounting a SCHED_DEADLINE task's
bandwidth.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 5299652d47b6e..4350977601eb1 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 dl_tasks_keep_without() here reject a valid partition recovery with
PERR_DLTASK because the root domains have not been rebuilt yet?

This partcmd_update branch with newmask == NULL runs from
cpuset_hotplug_update_tasks() and update_cpumasks_hier() after
parent->effective_cpus has grown, but before rebuild_sched_domains_locked()
or rebuild_sched_domains_cpuslocked() updates rd->span.

For example, when 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}, update_cpumasks_hier() updates
parent->effective_cpus to {0, 1} and calls
update_parent_effective_cpumask(cp, partcmd_update, NULL, tmp) before
rebuilding sched domains. At that point dl_task_bw_span() for parent's
deadline task is still {0}, so dl_tasks_keep_without(parent, cp, {0}, NULL,
true) sees that parent's remaining CPU {1} does not intersect {0} and leaves
the child partition invalid with PERR_DLTASK. The same stale span check also
runs when a CPU comes online in cpuset_hotplug_update_tasks(), which then
migrates the task onto the newly onlined CPU anyway while leaving the
partition invalid.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index eead45a0c1191..641674f65931f 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -5141,6 +5141,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]
Does dl_task_keeps_root_domain() mismatch cpuset_update_tasks_cpumask() when
offline CPUs are present in top_cpuset?

For top_cpuset, dl_tasks_keep_without() builds new_mask from
top_cpuset.effective_cpus, which only contains active CPUs, whereas
cpuset_update_tasks_cpumask() passes possible_mask & ~subpartitions_cpus
(including offline CPUs) to set_cpus_allowed_ptr():

kernel/cgroup/cpuset.c:cpuset_update_tasks_cpumask() {
...
if (top_cs) {
if (task->flags & (PF_KTHREAD | PF_NO_SETAFFINITY))
continue;
cpumask_andnot(new_cpus, possible_mask, subpartitions_cpus);
} else {
cpumask_and(new_cpus, possible_mask, cs->effective_cpus);
}
set_cpus_allowed_ptr(task, new_cpus);
}

If a deadline task in top_cpuset has user_cpus_ptr set to {offline CPU,
online CPU X} and a partition takes CPU X, cpumask_intersects(new_mask,
p->user_cpus_ptr) is false because new_mask excludes the offline CPU, so
dl_task_keeps_root_domain() assumes user_cpus_ptr will be ignored and allows
the partition change. When cpuset_update_tasks_cpumask() then calls
set_cpus_allowed_ptr() with the offline CPU included in new_cpus,
__set_cpus_allowed_ptr() intersects with user_cpus_ptr down to the offline
CPU alone and fails with -EINVAL, leaving the top_cpuset deadline task bound
to CPU X inside the new partition.

In addition, cpumask_intersects(span, p->cpus_ptr) does not mask with
cpu_active_mask; because def_root_domain.span and top_cpuset tasks' cpus_ptr
both include all offline possible CPUs, that test stays true whenever any
possible CPU is offline even if p has no active CPUs in def_root_domain.

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