Re: [PATCH v9 16/33] sched/deadline: Keep the last CPU a task has in its root domain

From: sashiko-bot

Date: Fri Nov 20 2026 - 09:31:52 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] cgroup/cpuset: cpuset_offline_moves_dl() misses empty parent
partition
--

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

sched/deadline: Keep the last CPU a task has in its root domain

This commit refuses to take a CPU offline when doing so would leave a
deadline task with no runnable CPU in its admitting root domain, or when
invalidating a cpuset partition would move a deadline task into another
root domain.

> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 7bdb9e21a7edb..ef95c730853e0 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c

[ ... ]

> @@ -4312,6 +4334,233 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
> spin_unlock_irqrestore(&callback_lock, flags);
> }
>
> +/*
> + * Return true if @cs holds a task, or one of its cpusets that is not a
> + * valid partition root does. This is partition_is_populated() for the
> + * offline path, which holds the CPU hotplug lock for writing instead of
> + * cpuset_mutex. That lock keeps tasks from moving to another cgroup:
> + * cgroup_attach_lock() takes it. The caller holds rcu_read_lock().
> + */
> +static bool partition_populated_offline(struct cpuset *cs)
> +{
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp;
> +
> + if (cgroup_has_tasks(cs->css.cgroup))
> + return true;
> + cpuset_for_each_descendant_pre(cp, pos_css, cs) {
> + if (cp == cs)
> + continue;
> + if (is_partition_valid(cp)) {
> + pos_css = css_rightmost_descendant(pos_css);
> + continue;
> + }
> + if (cgroup_is_populated(cp->css.cgroup))
> + return true;
> + }
> + return false;
> +}

[ ... ]

> +bool cpuset_cpus_allowed_without(struct task_struct *tsk, int cpu,
> + struct cpumask *pmask)
> +{
> + const struct cpumask *possible = task_cpu_possible_mask(tsk);
> + struct cpuset *cs = task_cs(tsk), *from;
> +
> + guard(rcu)();
> + if (!is_in_v2_mode()) {

[ ... ]

> + } else {
> + /*
> + * cgroup v2 works out the CPUs of each cpuset from the top
> + * down. A cpuset keeps those of its parent that cpuset.cpus
> + * holds, or takes all of them if there are none. Start from
> + * the nearest partition root that keeps an active CPU, or from
> + * the top cpuset. A partition root left with no CPU of its own
> + * can take those of a child partition.
> + */
> + for (from = cs; ; from = parent_cs(from)) {
> + if (from != &top_cpuset && !is_partition_valid(from))
> + continue;
> + cpumask_and(pmask, from->effective_cpus, cpu_active_mask);
> + cpumask_clear_cpu(cpu, pmask);
> + if (cpumask_empty(pmask) && from != &top_cpuset &&
> + !partition_child_lost(from, cpu, pmask))
> + cpumask_clear(pmask);
> + if (!cpumask_empty(pmask) || from == &top_cpuset)
> + break;
> + }
> + effective_cpus_below(cs, from, pmask);
> + }

[ ... ]

> +bool cpuset_offline_moves_dl(int cpu)
> +{
> + struct cgroup_subsys_state *pos_css;
> + struct cpuset *cp, *a, *p = &top_cpuset, *lost = NULL;
> + bool found = false;
> +
> + if (!is_in_v2_mode())
> + return false;
> + rcu_read_lock();
> + cpuset_for_each_descendant_pre(cp, pos_css, &top_cpuset) {
> + if (cp != &top_cpuset && is_partition_valid(cp) &&
> + cpumask_test_cpu(cpu, cp->effective_cpus)) {
> + p = cp;
> + break;
> + }
> + }
> + if (p != &top_cpuset) {
> + lost = partition_child_lost(p, cpu, &dl_offline_cpus);
> + } else {

[Severity: Medium]
Can cpuset_offline_moves_dl() and cpuset_cpus_allowed_without() miss the
invalidation of a sibling partition when an unpopulated parent partition
delegates all of its active CPUs to child partitions?

Suppose an unpopulated partition parent_p with effective_xcpus {1, 2}
delegates CPU 1 to a populated child partition c1 and CPU 2 to a sibling
partition c2 created after c1, leaving parent_p->effective_cpus empty.
When CPU 1 goes offline, the pre-order walk in cpuset_handle_hotplug()
first invalidates c1 because it has no active CPUs left; c1 then counts
as populating parent_p, so visiting c2 next triggers
tasks_nocpu_error(parent_p, c2, &new_cpus) in
cpuset_hotplug_update_tasks() and invalidates c2 as well, giving CPU 2 to
parent_p and c1.

Before hotplug runs, cpuset_offline_moves_dl(1) finds p = c1, sees
partition_child_lost(c1, 1, &dl_offline_cpus) == NULL, and returns false
without checking whether invalidating c1 causes parent_p to invalidate c2.
Similarly, in cpuset_cpus_allowed_without() for a task in c1, walking up
to from = parent_p calls partition_populated_offline(parent_p), which
skips c1 because is_partition_valid(c1) is still true, causing
partition_child_lost(parent_p, 1, pmask) to return NULL and the loop to
walk past parent_p to top_cpuset. As a result, dl_bw_deactivate() can
accept an offline that moves deadline tasks in c1 or c2 into parent_p's
root domain without admission control.

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