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

From: sashiko-bot

Date: Fri Nov 27 2026 - 11:30:47 EST


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] cgroup/cpuset: stale def_root_domain span in
dl_task_keeps_root_domain()
- [Medium] cgroup/cpuset: update_sibling_cpumasks() bypasses
dl_tasks_keep_without()
- [Medium] cgroup/cpuset: missing dl_tasks_hold_bw() guard and subtree
pruning in walks
--

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

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

This commit rejects cpuset CPU mask updates and invalidates partition roots
when the change would move a SCHED_DEADLINE task out of the root domain
that accounts for its bandwidth without performing admission control.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 9461277ed0fa3..62f0c7e6a97b0 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -1148,6 +1181,96 @@ static void effective_cpus_below(struct cpuset *cp, struct cpuset *from,
> }
> }
>
> +/*
> + * A scratch mask for dl_tasks_keep_without(). Its callers still need each
> + * mask of their struct tmpmasks after the call. Protected by
> + * cpuset_mutex.
> + */
> +static cpumask_var_t dl_keep_cpus, dl_pending_cpus;
> +
> +/*
> + * Return false if a partition that takes the CPUs of @xcpus makes a
> + * deadline task leave the root domain that counts its bandwidth. A cpuset
> + * can hold CPUs of two root domains: with isolcpus="domain", or on cgroup
> + * v1 with sched_load_balance off. Such a task would run in a root domain
> + * that did not admit it.
> + *
> + * @root is the partition root that gives the CPUs. @part is the cpuset
> + * that takes them. In the same change, @part can give the CPUs of @gives
> + * back to @root. @gives is NULL if it gives none back.
> + *
> + * Work out the new CPUs of each cpuset of @root from the top down, as
> + * update_cpumasks_hier() does, down to the next partition roots. If
> + * @enable, @part becomes a partition root. Then do the same for its own
> + * cpusets, starting from the active CPUs of @xcpus.
> + */
> +static bool dl_tasks_keep_without(struct cpuset *root, struct cpuset *part,
> + const struct cpumask *xcpus,
> + const struct cpumask *gives, bool enable)
> +{
> + struct cpumask *new_cpus = dl_keep_cpus, *pending = NULL;
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp;
> + bool keep = true;
> +
> + lockdep_assert_cpuset_lock_held();
> + /*
> + * The CPUs of @root can have changed before the rebuild of the
> + * sched domains, which ends the change. Then the root domain of a
> + * task of @root does not span them yet. The rebuild gives the CPUs
> + * of a root partition to one root domain. It gives those of an
> + * isolated partition, and of its valid children, to the default
> + * root domain.
> + */
> + if (root->partition_root_state == PRS_ROOT ||
> + root->partition_root_state == PRS_ISOLATED) {
> + pending = dl_pending_cpus;
> + cpumask_copy(pending, root->effective_cpus);
> + if (root == &top_cpuset)
> + cpumask_and(pending, pending,
> + housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
> + }
> + rcu_read_lock();
> + cpuset_for_each_descendant_pre(cp, pos_css, root) {
> + if (cp == part || (cp != root && is_partition_valid(cp))) {
> + pos_css = css_rightmost_descendant(pos_css);
> + continue;
> + }
> + /* The CPUs that @root has after the change. */
> + cpumask_copy(new_cpus, root->effective_cpus);
> + if (gives) {
> + cpumask_or(new_cpus, new_cpus, gives);
> + cpumask_and(new_cpus, new_cpus, cpu_active_mask);
> + }
> + cpumask_andnot(new_cpus, new_cpus, xcpus);
> + effective_cpus_below(cp, root, new_cpus);
> + if (cpumask_equal(cp->effective_cpus, new_cpus))
> + continue;
> + keep = dl_tasks_keep_cpus(cp, new_cpus, pending);

[Severity: Medium]
With isolcpus=domain, can a deadline task counted in def_root_domain bypass
this check when a PRS_ISOLATED partition returns a housekeeping CPU to
top_cpuset while taking a boot-isolated CPU?

Suppose an isolated partition holding housekeeping CPU 0 swaps its CPUs in
one write to take boot-isolated CPU 1 (xcpus = {1}, gives = {0}), and a
deadline task in top_cpuset is counted in def_root_domain on CPU 1. Before
rebuild_sched_domains_locked() runs at the end of the write,
dl_task_bw_span(p) returns def_root_domain.span, which still contains CPU
0. Because new_cpus includes gives ({0}), cpumask_intersects_and(span,
new_mask, user) in dl_task_keeps_root_domain() matches on CPU 0 and returns
true. The rebuild then moves CPU 0 back to top_cpuset's housekeeping root
domain while CPU 1 remains in def_root_domain under the isolated partition,
migrating the deadline task and its bandwidth into the housekeeping root
domain without admission control.

> + if (!keep)
> + break;
> + }
> + if (keep && enable) {
> + cpuset_for_each_descendant_pre(cp, pos_css, part) {
> + if (cp != part && is_partition_valid(cp)) {
> + pos_css = css_rightmost_descendant(pos_css);
> + continue;
> + }
> + cpumask_and(new_cpus, xcpus, cpu_active_mask);
> + effective_cpus_below(cp, part, new_cpus);
> + if (cpumask_equal(cp->effective_cpus, new_cpus))
> + continue;
> + keep = dl_tasks_keep_cpus(cp, new_cpus,
> + root->partition_root_state == PRS_ISOLATED ?
> + pending : NULL);
> + if (!keep)
> + break;
> + }
> + }
> + rcu_read_unlock();
> + return keep;
> +}

[Severity: Medium]
Can update_sibling_cpumasks() cause dl_tasks_keep_without() to skip its
check when a growing parent partition has two invalid child partitions?

Suppose parent PRS_ROOT partition P has CPUs 0,2 and two PRS_INVALID_ROOT
children: C1 (cpus 0,2) and C2 (cpus 1, currently falling back to P's
effective_cpus 0,2 and holding 160% total deadline bandwidth admitted in
P's root domain). When P grows to 0-3, update_cpumasks_hier() visits C1
first. update_parent_effective_cpumask() validates C1 on 0,2 (while C2 is
still an invalid member of P, which passes via pending = {0-3}) and calls
update_sibling_cpumasks(P, C1, tmp). That call runs
update_cpumasks_hier(C2, tmp, false), which treats C2 as a member because
cp == cs, setting C2->effective_cpus and its tasks' cpus_mask to {1}:

kernel/cgroup/cpuset.c:update_cpumasks_hier() {
...
if ((cp != cs) && old_prs) {
switch (parent->partition_root_state) {
case PRS_ROOT:
case PRS_ISOLATED:
update_parent = true;
break;
...
spin_lock_irq(&callback_lock);
cpumask_copy(cp->effective_cpus, tmp->new_cpus);
...
cpuset_update_tasks_cpumask(cp, tmp->new_cpus);
...
}

When the outer update_cpumasks_hier(P, ...) loop then reaches C2 and calls
update_parent_effective_cpumask() -> dl_tasks_keep_without(P, C2, {1},
NULL, true), cpumask_equal(cp->effective_cpus, new_cpus) is already true
(and even inside dl_task_keeps_root_domain(), p->cpus_mask is already {1},
which no longer intersects P's pre-rebuild root domain span {0, 2}). C2 is
then promoted to a valid 1-CPU PRS_ROOT partition holding 160% deadline
bandwidth.

[ ... ]

> @@ -2518,6 +2667,62 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs,
> }
> }
>
> +/*
> + * Set @new_cpus to the effective CPUs that @cp gets if @cs takes the CPUs
> + * of @trialcs. @cp is @cs or one of its descendants.
> + */
> +static void trial_effective_cpus(struct cpuset *cp, struct cpuset *cs,
> + struct cpuset *trialcs, struct cpumask *new_cpus)
> +{
> + struct cpuset *parent = parent_cs(cs);
> +
> + if (!cpumask_and(new_cpus, trialcs->cpus_allowed, parent->effective_cpus) &&
> + is_in_v2_mode())
> + cpumask_copy(new_cpus, parent->effective_cpus);
> + effective_cpus_below(cp, cs, new_cpus);
> +}
> +
> +/*
> + * Return false if the CPUs of @trialcs make a deadline task of @cs, or of
> + * a descendant, leave the root domain that counts its bandwidth. A cpuset
> + * can hold CPUs of two root domains: with isolcpus="domain", or on cgroup
> + * v1 with sched_load_balance off. The task would run in a root domain that
> + * did not admit it. Only a move to another cpuset can take the task
> + * there. The move asks the other root domain for room.
> + *
> + * A partition root takes its CPUs from its parent, which checks the same
> + * for its own tasks: see dl_tasks_keep_without().
> + */
> +static bool dl_tasks_keep_root_domain(struct cpuset *cs, struct cpuset *trialcs,
> + struct cpumask *new_cpus)
> +{
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp;
> + bool keep = true;
> +
> + if (is_partition_valid(cs))
> + return true;
> + rcu_read_lock();
> + cpuset_for_each_descendant_pre(cp, pos_css, cs) {
> + if (is_partition_valid(cp)) {
> + pos_css = css_rightmost_descendant(pos_css);
> + continue;
> + }
> + trial_effective_cpus(cp, cs, trialcs, new_cpus);
> + /*
> + * Test a mask that grows too. A task whose user affinity
> + * holds none of the old CPUs gets only the new ones.
> + */
> + if (cpumask_equal(cp->effective_cpus, new_cpus))
> + continue;
> + keep = dl_tasks_keep_cpus(cp, new_cpus, NULL);
> + if (!keep)
> + break;
> + }
> + rcu_read_unlock();
> + return keep;
> +}

[Severity: Medium]
Should dl_tasks_keep_root_domain() and dl_tasks_keep_without() check
!dl_tasks_hold_bw() before walking the hierarchy, and skip unchanged
subtrees with css_rightmost_descendant(pos_css)?

Because dl_tasks_hold_bw() is only checked inside dl_tasks_keep_cpus(),
every cpuset.cpus write and partition update walks the entire non-partition
subtree and runs effective_cpus_below() on every descendant even when no
deadline tasks exist or admission control is disabled. In addition, when
cpumask_equal(cp->effective_cpus, new_cpus) is true in either function, a
plain continue still visits all of cp's descendants even though their
effective_cpus cannot change either.

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