[PATCH v4 7/7] cgroup/cpuset: Publish exclusive_cpus before partition updates
From: Guopeng Zhang
Date: Thu Sep 10 2026 - 05:55:13 EST
From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
update_exclusive_cpumask() calls partition_cpus_change() before publishing
the new exclusive_cpus mask. When an invalid partition is recovered,
update_parent_effective_cpumask() therefore gets the old mask from
user_xcpus(). If that mask contains only offline CPUs and the partition is
populated, the valid replacement is rejected with PERR_NOCPUS.
This can be reproduced on a cgroup v2 system with CPUs 1-4 online:
cd /sys/fs/cgroup
echo +cpuset > cgroup.subtree_control
mkdir exclusive-repro
echo 1-4 > exclusive-repro/cpuset.cpus
echo isolated > exclusive-repro/cpuset.cpus.partition
echo +cpuset > exclusive-repro/cgroup.subtree_control
mkdir exclusive-repro/child
echo 4 > exclusive-repro/child/cpuset.cpus.exclusive
echo isolated > exclusive-repro/child/cpuset.cpus.partition
sleep 1000 & task=$!
echo $task > exclusive-repro/child/cgroup.procs
echo 0 > /sys/devices/system/cpu/cpu4/online
echo 3 > exclusive-repro/child/cpuset.cpus.exclusive
cat exclusive-repro/child/cpuset.cpus.partition
echo 1 > /sys/devices/system/cpu/cpu4/online
kill $task
Without this fix, the child remains invalid after CPU 3 is written because
the recovery path still validates the old CPU 4 mask.
Publish exclusive_cpus after all fallible preparation and before
partition_cpus_change(), as update_cpumask() already does for cpus_allowed.
Keep effective_xcpus unchanged until the partition update has computed the
old-to-new difference.
Fixes: c49b5e89c45f ("cpuset: use partition_cpus_change for setting exclusive cpus")
Signed-off-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
---
kernel/cgroup/cpuset.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 80a709bfa4b7..94c56ec8d4f8 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2690,10 +2690,18 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
return -ENOMEM;
trialcs->prs_err = PERR_NONE;
- partition_cpus_change(cs, trialcs, &tmp);
+ /*
+ * partition_cpus_change() may inspect user_xcpus(cs). Publish the
+ * configured mask that was used to compute trialcs->effective_xcpus.
+ */
spin_lock_irq(&callback_lock);
cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus);
+ spin_unlock_irq(&callback_lock);
+
+ partition_cpus_change(cs, trialcs, &tmp);
+
+ spin_lock_irq(&callback_lock);
cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus);
if ((old_prs > 0) && !is_partition_valid(cs))
reset_partition_data(cs);
--
2.43.0