]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cgroup/cpuset: Consistently compute effective_xcpus in update_cpumasks_hier()
authorWaiman Long <longman@redhat.com>
Mon, 12 Jan 2026 16:00:18 +0000 (11:00 -0500)
committerTejun Heo <tj@kernel.org>
Mon, 12 Jan 2026 19:01:44 +0000 (09:01 -1000)
Since commit f62a5d39368e ("cgroup/cpuset: Remove remote_partition_check()
& make update_cpumasks_hier() handle remote partition"), the
compute_effective_exclusive_cpumask() helper was extended to
strip exclusive CPUs from siblings when computing effective_xcpus
(cpuset.cpus.exclusive.effective). This helper was later renamed to
compute_excpus() in commit 86bbbd1f33ab ("cpuset: Refactor exclusive
CPU mask computation logic").

This helper is supposed to be used consistently to compute
effective_xcpus. However, there is an exception within the callback
critical section in update_cpumasks_hier() when exclusive_cpus of a
valid partition root is empty. This can cause effective_xcpus value to
differ depending on where exactly it is last computed. Fix this by using
compute_excpus() in this case to give a consistent result.

Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Chen Ridong <chenridong@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c

index da2b3b51630e4eb4bc547906a8e1e5506e2239b4..894131f47f78aa891bbe44445d6f86aed9b4faea 100644 (file)
@@ -2168,17 +2168,13 @@ get_css:
                spin_lock_irq(&callback_lock);
                cpumask_copy(cp->effective_cpus, tmp->new_cpus);
                cp->partition_root_state = new_prs;
-               if (!cpumask_empty(cp->exclusive_cpus) && (cp != cs))
-                       compute_excpus(cp, cp->effective_xcpus);
-
                /*
-                * Make sure effective_xcpus is properly set for a valid
-                * partition root.
+                * Need to compute effective_xcpus if either exclusive_cpus
+                * is non-empty or it is a valid partition root.
                 */
-               if ((new_prs > 0) && cpumask_empty(cp->exclusive_cpus))
-                       cpumask_and(cp->effective_xcpus,
-                                   cp->cpus_allowed, parent->effective_xcpus);
-               else if (new_prs < 0)
+               if ((new_prs > 0) || !cpumask_empty(cp->exclusive_cpus))
+                       compute_excpus(cp, cp->effective_xcpus);
+               if (new_prs <= 0)
                        reset_partition_data(cp);
                spin_unlock_irq(&callback_lock);