cgroup/cpuset: Make sure compute_partition_effective_cpumask() is only called for valid partition

With visual inspection to make sure that
compute_partition_effective_cpumask() is only called for valid partition
root, it was found that the function can be called for an invalidated
partition near the end of cpuset_hotplug_update_tasks(). When partcmd is
set, update_parent_effective_cpumask() is called to either invalidate a
valid partition or with partcmd_update to check if an invalid partition
can be switched back to valid. In both cases, cpuset_force_rebuild()
should be invoked. However, compute_partition_effective_cpumask()
should only be called when an invalid partition is switched back to
valid. When a partition is invalidated, compute_effective_cpumask()
should be called instead.

Also add a WARN_ON_ONCE() in compute_partition_effective_cpumask() to
ensure that a valid partition root is passed in.

Fixes: 72c6303acf ("cgroup/cpuset: Take isolated CPUs out of workqueue unbound cpumask")
Signed-off-by: Waiman Long <longman@redhat.com>
Acked-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Waiman Long 2026-10-25 17:44:45 -04:00 committed by Tejun Heo
parent 10a6f00d82
commit 356a3aa740

View File

@ -2163,6 +2163,8 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
struct cpuset *child;
bool populated = partition_is_populated(cs, NULL);
WARN_ON_ONCE(!is_partition_valid(cs));
/*
* Check child partition roots to see if they should be
* invalidated when
@ -4035,9 +4037,12 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp)
if (partcmd >= 0) {
update_parent_effective_cpumask(cs, partcmd, NULL, tmp);
if ((partcmd == partcmd_invalidate) || is_partition_valid(cs)) {
if (is_partition_valid(cs)) {
compute_partition_effective_cpumask(cs, &new_cpus);
cpuset_force_rebuild();
} else if (partcmd == partcmd_invalidate) {
compute_effective_cpumask(&new_cpus, cs, parent);
cpuset_force_rebuild();
}
}