Re: [PATCH v6 28/37] cgroup/cpuset: Refuse to take a deadline task out of its root domain

From: sashiko-bot

Date: Mon Nov 16 2026 - 15:09:04 EST


Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] cgroup/cpuset: excpus clobbered via tmp->new_cpus in
remote_cpus_update()
- [High] cgroup/cpuset: partition_xcpus_del() called on invalid
partition in update_parent_effective_cpumask()
- [Medium] cgroup/cpuset: wrong descendant effective_cpus in
dl_tasks_keep_without()
- [Medium] sched/deadline: user_cpus_ptr ignored in
dl_task_keeps_root_domain()
- [Medium] cgroup/cpuset: dl_tasks_keep_root_domain() skips invalidated
partitions
--

commit 2c62aa35faa810e650ef3867961558c694f57e4c
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 resulting effective CPUs would move a SCHED_DEADLINE task out of the
root domain accounting its bandwidth without admission control.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index ef5ad8e38f06f..5b4f7d4ef3ae2 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -1126,6 +1127,92 @@ static void update_partition_sd_lb(struct cpuset *cs, int old_prs)
[ ... ]
> +static bool dl_tasks_keep_without(struct cpuset *root, struct cpuset *part,
> + const struct cpumask *xcpus, bool enable,
> + struct cpumask *new_cpus)
> +{
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp, *a;
> + bool keep = true;
> +
> + 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;
> + }
> + if (!cpumask_intersects(cp->effective_cpus, xcpus))
> + continue;
> + for (a = cp; ; a = parent_cs(a)) {
> + if (cpumask_andnot(new_cpus, a->effective_cpus, xcpus) ||
> + a == root)
> + break;
> + }
> + keep = dl_tasks_keep_cpus(cp, new_cpus);
> + 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;
> + }
> + if (cpumask_subset(cp->effective_cpus, xcpus))
> + continue;
> + if (!cpumask_and(new_cpus, cp->effective_cpus, xcpus))
> + cpumask_copy(new_cpus, xcpus);
> + keep = dl_tasks_keep_cpus(cp, new_cpus);
> + if (!keep)
> + break;
> + }
> + }
> + rcu_read_unlock();
> + return keep;
> +}

[Severity: Medium]
Can dl_tasks_keep_without() miscompute new_cpus for descendant cpusets and
let a deadline task move to another root domain without admission control?

In the first loop, when cp loses all of its effective_cpus to xcpus and
inherits from an ancestor a above parent_cs(cp), new_cpus is set to
a->effective_cpus & ~xcpus without filtering top-down through the
cpus_allowed masks of the cpusets between a and cp as
compute_effective_cpumask() does. If root has effective_cpus {0, 1, 2}
(0-1 housekeeping, 2 isolated), child P has cpus_allowed {0}, and grandchild
C has cpus_allowed {2} (so C inherits effective_cpus {0}), a partition taking
xcpus {0} tests C against root's {1, 2} and sees housekeeping CPU 1, whereas
update_cpumasks_hier() gives P {1, 2} and gives C {2}, moving a deadline
task in C into the isolated root domain.

In the second loop (when enable is true), cp's new mask is derived from
cp->effective_cpus & xcpus instead of filtering xcpus & cpu_active_mask
top-down through each descendant's cpus_allowed. Because enabling part
switches its effective CPUs from cpus_allowed to effective_xcpus, a child C
whose cpus_allowed only intersects part->exclusive_cpus previously inherited
part->cpus_allowed, passes the cpumask_subset(cp->effective_cpus, xcpus)
check if part->cpus_allowed is a subset of xcpus, and then switches to
C->cpus_allowed once part is enabled; in addition, xcpus is not masked with
cpu_active_mask, so offline CPUs in xcpus can match def_root_domain->span.

[ ... ]

> @@ -1779,6 +1868,9 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
> else if (prstate_housekeeping_conflict(prs, PRS_ROOT,
> excpus, tmp->delmask))
> WRITE_ONCE(cs->prs_err, PERR_HKEEPING);
> + else if (!dl_tasks_keep_without(&top_cpuset, cs, tmp->addmask,
> + false, tmp->new_cpus))
> + WRITE_ONCE(cs->prs_err, PERR_DLTASK);
> if (cs->prs_err)
> goto invalidate;
> }

[Severity: High]
Does passing tmp->new_cpus to dl_tasks_keep_without() clobber excpus before
it is copied to cs->effective_xcpus?

update_cpumasks_hier() calls remote_cpus_update() with excpus pointing to
tmp->new_cpus:

kernel/cgroup/cpuset.c:update_cpumasks_hier() {
...
compute_excpus(cp, tmp->new_cpus);
...
rcu_read_unlock();
remote_cpus_update(cp, NULL, tmp->new_cpus, tmp);
rcu_read_lock();
...
}

When a descendant remote partition gains exclusive CPUs during
update_cpumasks_hier(), dl_tasks_keep_without() overwrites tmp->new_cpus
with top_cpuset's remaining effective CPUs, and remote_cpus_update() then
copies that clobbered mask from excpus into cs->effective_xcpus.

[ ... ]

> @@ -2013,6 +2109,15 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> deleting = false;
> adding = cpumask_and(tmp->addmask,
> cs->effective_xcpus, parent->effective_xcpus);
> + } else if (deleting &&
> + !dl_tasks_keep_without(parent, cs, tmp->delmask,
> + is_partition_invalid(cs),
> + tmp->new_cpus)) {
> + /* As above: the partition becomes invalid. */
> + part_error = PERR_DLTASK;
> + deleting = false;
> + adding = cpumask_and(tmp->addmask,
> + cs->effective_xcpus, parent->effective_xcpus);
> }
> } else {

[Severity: High]
Can setting adding here when is_partition_invalid(cs) is true call
partition_xcpus_del() on an already-invalid partition?

An invalid local partition root (old_prs < 0) with cpuset.cpus.exclusive set
keeps a non-empty cs->effective_xcpus even though those CPUs were not removed
from parent->effective_cpus. When updating cpuset.cpus or
cpuset.cpus.exclusive on that invalid partition takes the newmask branch and
dl_tasks_keep_without() returns false, adding becomes true while old_prs < 0,
so partition_xcpus_del(old_prs, parent, tmp->addmask) triggers
WARN_ON_ONCE(old_prs < 0) and corrupts subpartitions_cpus, isolated_cpus, and
parent->effective_cpus by releasing CPUs that cs never held. Guarding adding
with is_partition_valid(cs) avoids releasing unowned CPUs.

[ ... ]

> @@ -2496,6 +2604,66 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs,
[ ... ]
> +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);
> + if (cpumask_subset(cp->effective_cpus, new_cpus))
> + continue;
> + keep = dl_tasks_keep_cpus(cp, new_cpus);
> + if (!keep)
> + break;
> + }
> + rcu_read_unlock();
> + return keep;
> +}
> +
> /**
> * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
> * @cs: the cpuset to consider
> @@ -2528,6 +2696,11 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> if (alloc_tmpmasks(&tmp))
> return -ENOMEM;
>
> + if (!dl_tasks_keep_root_domain(cs, trialcs, tmp.new_cpus)) {
> + free_tmpmasks(&tmp);
> + return -EBUSY;
> + }
> +
> /*
> * Check all the descendants in update_cpumasks_hier() if
> * effective_xcpus is to be changed.

[Severity: Medium]
What happens when a write to cpuset.cpus (or cpuset.cpus.exclusive)
invalidates a valid partition root?

dl_tasks_keep_root_domain() runs before partition_cpus_change() and returns
true immediately when is_partition_valid(cs) is true, and
update_exclusive_cpumask() does not check dl_tasks_keep_root_domain() at all.
If cs is a valid root partition on a housekeeping CPU containing a deadline
task and a user writes a boot-isolated CPU to cs/cpuset.cpus,
partition_cpus_change() invalidates cs (PERR_HKEEPING), and
update_cpumasks_hier() recomputes cs->effective_cpus as a non-partition
cpuset on the isolated CPU; dl_rebuild_rd_accounting() then adds the task's
bandwidth to def_root_domain via dl_add_task_root_domain() without admission
control.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 096c0ec55cdc2..61b50266468f9 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -4955,6 +4955,25 @@ 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.
> + */
> +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;
> + guard(raw_spinlock_irqsave)(&p->pi_lock);
> + guard(rcu)();
> + span = dl_task_bw_span(p);
> + return !span || !cpumask_intersects(span, p->cpus_ptr) ||
> + cpumask_intersects(span, new_mask);
> +}

[Severity: Medium]
Should dl_task_keeps_root_domain() account for p->user_cpus_ptr the way
__set_cpus_allowed_ptr() and dl_task_bw_reserve_cpu() do?

When cpuset_update_tasks_cpumask() calls set_cpus_allowed_ptr(task, new_cpus),
__set_cpus_allowed_ptr() restricts new_cpus to new_cpus & p->user_cpus_ptr
whenever their intersection is non-empty. Because dl_task_keeps_root_domain()
tests span against new_mask directly (and dl_tasks_keep_root_domain() and
dl_tasks_keep_without() skip cpusets where cpumask_subset(cp->effective_cpus,
new_cpus) holds), a deadline task counted in housekeeping span {0, 1} whose
p->user_cpus_ptr only intersects new_mask on isolated CPU {2} passes this
check (or the subset check when widening effective_cpus from {0, 1} to
{0, 1, 2}) and has its affinity restricted to {2} in the isolated root domain
without admission control. Intersecting new_mask with p->user_cpus_ptr when
cpumask_intersects(new_mask, p->user_cpus_ptr) is true and checking tasks even
when new_cpus grows would match __set_cpus_allowed_ptr().

--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=28