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

From: sashiko-bot

Date: Wed Nov 25 2026 - 20:42:01 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] cgroup/cpuset: unnecessary hierarchy and task walks in
dl_tasks_keep_*()
- [Medium] cgroup/cpuset: dl_tasks_keep_without() omits pending CPUs for
PRS_ISOLATED
--

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

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

This commit refuses cpuset CPU mask updates and invalidates partitions that
would move a deadline task out of the root domain accounting its bandwidth.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 37d04b08996ec..67b2429c0e22f 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
[ ... ]
> @@ -1148,6 +1181,91 @@ 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.
> + */
> + if (root->partition_root_state == PRS_ROOT) {
> + pending = dl_pending_cpus;
> + cpumask_copy(pending, root->effective_cpus);
> + if (root == &top_cpuset)
> + cpumask_and(pending, pending,
> + housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
> + }

[Severity: Medium]
Should pending also be populated when root->partition_root_state is
PRS_ISOLATED (or via is_partition_valid(root))?

An isolated partition root can have an invalid child isolated partition and
hold deadline tasks counted in def_root_domain. When that isolated parent
grows to include a new CPU before rebuild_sched_domains_locked() runs at
the end of the change, def_root_domain.span does not include the new CPU
yet. Because pending is left NULL here, re-evaluating the child during
update_cpumasks_hier() -> update_parent_effective_cpumask() rejects the
child with PERR_DLTASK even though the rebuild will attach the parent's new
CPU to def_root_domain.

> + 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);
> + if (!keep)
> + break;
> + }

[Severity: Medium]
Does dl_tasks_keep_without() (and dl_tasks_keep_root_domain() below) walk
the cpuset hierarchy and iterate every task in affected cpusets even when
no deadline tasks hold bandwidth or admission control is disabled?

Commit "sched/deadline: Keep the last CPU a task has in its root domain"
earlier in this series guards dl_cpu_last_of_task() with
!dl_bandwidth_enabled() || !atomic_read(&dl_nr_bw_tasks), whereas here
dl_bandwidth_enabled() is only checked per task inside
dl_task_keeps_root_domain() after css_task_iter has already locked
css_set_lock and pinned each task, and dl_nr_bw_tasks is not checked.

In addition, when cpumask_equal(cp->effective_cpus, new_cpus) is true in
either function, continuing without advancing pos_css =
css_rightmost_descendant(pos_css) visits all descendants of an unchanged
subtree even though their effective_cpus cannot change either.

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