* [PATCH 0/2] cgroup/cpuset: Fix partition switch after a sibling releases CPUs
@ 2026-12-03 19:58 Hang Zhengyang
2026-12-03 19:58 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Hang Zhengyang
2026-12-03 19:58 ` [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs Hang Zhengyang
0 siblings, 2 replies; 4+ messages in thread
From: Hang Zhengyang @ 2026-12-03 19:58 UTC (permalink / raw)
To: Waiman Long, Ridong Chen, Tejun Heo
Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups,
linux-kselftest, linux-kernel
Since commit 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling
partitions on cpuset.cpus conflict"), a partition without
cpuset.cpus.exclusive whose cpuset.cpus overlap the exclusive CPUs of a
sibling gets only the other CPUs. When the sibling releases them, the
partition keeps its CPUs until they are recomputed. A switch between
root and isolated recomputes them and takes the released CPUs without
taking them from the parent, so the CPUs end up in two partitions.
Patch 1 fixes the switch for local and remote partitions. Patch 2 adds
tests.
CPU hotplug recomputes them the same way, so offlining a CPU after the
sibling released its CPUs also leads to overlapping partitions. Chen
Ridong's v6 "cpuset: rework local partition logic" and Waiman Long's v4
"More fix patches" both change that path, so I left it alone. The switch
problem reproduces with either series applied. Another way to fix both
would be to update valid sibling partitions when a cpuset releases
exclusive CPUs. I can do that instead, or rebase on the rework, if you
prefer.
The series is based on cgroup/for-7.4-fixes and also applies to
cgroup/for-next.
Testing:
- Reproduced on v7.0, v7.4-rc5 and next-20261202, not on v6.18 or on
the parent of 2a3602030d80.
- With the series, test_cpuset_prs.sh passes on cgroup/for-7.4-fixes
and next-20261202 with 8 CPUs, and on next-20261202 with 12 CPUs and
isolcpus=10-11. Without patch 1, the new cases fail.
I used Claude Code to find the issue, write the patches and run the
tests. I reviewed the patches.
Hang Zhengyang (2):
cgroup/cpuset: Update the parent when a partition switch adds CPUs
selftests/cgroup: Test partition switches after a sibling releases
CPUs
kernel/cgroup/cpuset.c | 41 ++++++++++++++-----
.../selftests/cgroup/test_cpuset_prs.sh | 14 +++++++
2 files changed, 45 insertions(+), 10 deletions(-)
base-commit: 05afa0c55015b3c7f3c2136dde7fbcfe5195b21f
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs 2026-12-03 19:58 [PATCH 0/2] cgroup/cpuset: Fix partition switch after a sibling releases CPUs Hang Zhengyang @ 2026-12-03 19:58 ` Hang Zhengyang 2026-12-04 3:35 ` Ridong Chen 2026-12-03 19:58 ` [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs Hang Zhengyang 1 sibling, 1 reply; 4+ messages in thread From: Hang Zhengyang @ 2026-12-03 19:58 UTC (permalink / raw) To: Waiman Long, Ridong Chen, Tejun Heo Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups, linux-kselftest, linux-kernel, stable When a valid partition is switched between "root" and "isolated", update_prstate() updates isolated_cpus with the CPUs the partition has and then calls update_cpumasks_hier(). That recomputes the exclusive CPUs of the partition with compute_excpus(), which leaves out the exclusive CPUs of its siblings. If the partition has no cpuset.cpus.exclusive and a sibling has released exclusive CPUs since the partition was created, the partition gets them, but they are not taken from the parent, or from the top cpuset for a remote partition. update_cpumasks_hier() does that for child partitions, but not for the cpuset it starts from. Example on an 8-CPU system: cd /sys/fs/cgroup echo +cpuset > cgroup.subtree_control mkdir A1 B1 echo 3-4 > A1/cpuset.cpus.exclusive echo 2-5 > B1/cpuset.cpus echo root > B1/cpuset.cpus.partition # B1: 2,5, root: 0-1,3-4,6-7 echo > A1/cpuset.cpus.exclusive # B1 is still 2,5 echo isolated > B1/cpuset.cpus.partition B1 now has CPUs 2-5, the root cpuset still has 0-1,3-4,6-7, and cpuset.cpus.isolated shows only 2,5. Switching from isolated to root instead makes two load balancing partitions overlap: WARNING: kernel/cgroup/cpuset.c:919 at rebuild_sched_domains_locked+0x4f8/0x890 The same happens when the sibling was a partition root that became a member or was removed. A remote partition also triggers a warning in remote_partition_disable() when it becomes a member later. Take the new CPUs after the new state is set, as update_cpumasks_hier() does for child partitions: with update_parent_effective_cpumask() for a local partition and with remote_cpus_update() for a remote one. If the parent can't give them up, for example because it has tasks and no other CPUs, the partition becomes invalid. With this patch, B1 gets CPUs 2-5 in both directions, the root cpuset keeps 0-1,6-7, and cpuset.cpus.isolated shows 2-5 when B1 is isolated. Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict") Cc: stable@vger.kernel.org # v7.0+ Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> --- kernel/cgroup/cpuset.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index aa82080dd1fa..bc5b0fa5199b 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1909,11 +1909,11 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, * update_prstate(). An error code may be returned and the caller will check * for error. * - * The partcmd_update command is used by update_cpumasks_hier() with newmask - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used - * by update_cpumask() with NULL newmask. In both cases, the callers won't - * check for error and so partition_root_state and prs_err will be updated - * directly. + * The partcmd_update command is used by update_cpumasks_hier() and + * update_prstate() with newmask NULL and update_cpumask() with newmask set. + * The partcmd_invalidate is used by update_cpumask() with NULL newmask. In + * both cases, the callers won't check for error and so partition_root_state + * and prs_err will be updated directly. */ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, struct cpumask *newmask, @@ -2081,6 +2081,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, * This can be called from: * 1) update_cpumasks_hier() * 2) cpuset_hotplug_update_tasks() + * 3) update_prstate() * * Check to see if it can be transitioned from valid to * invalid partition or vice versa. @@ -2213,9 +2214,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, } /* - * For partcmd_update without newmask, it is being called from - * cpuset_handle_hotplug(). Update the load balance flag and - * scheduling domain accordingly. + * For partcmd_update without newmask, update the load balance flag + * and scheduling domain accordingly. */ if ((cmd == partcmd_update) && !newmask) update_partition_sd_lb(cs, old_prs); @@ -3008,8 +3008,9 @@ static int update_prstate(struct cpuset *cs, int new_prs) ? PRS_ROOT : parent->partition_root_state; /* - * A change in load balance state only, no change in cpumasks. - * Need to update isolated_cpus. + * A change in load balance state. Need to update isolated_cpus. + * The cpumasks change only if a sibling has released exclusive + * CPUs, see below. */ if (prstate_housekeeping_conflict(new_prs, parent_prs, cs->effective_xcpus, NULL)) @@ -3077,6 +3078,26 @@ static int update_prstate(struct cpuset *cs, int new_prs) isolated_cpus_update(new_prs, tmpmask.new_cpus); spin_unlock_irq(&callback_lock); + /* + * A sibling may have released exclusive CPUs since cs became a + * partition. update_cpumasks_hier() recomputes the effective CPUs of + * cs and would include them, so take them from the parent, or from + * the top cpuset for a remote partition, first. This has to come + * after the new partition state is set so that the new CPUs are + * accounted with it. If the CPUs can't be given, cs becomes invalid. + */ + if (isolcpus_updated) { + if (is_remote_partition(cs)) { + compute_excpus(cs, tmpmask.new_cpus); + if (!cpumask_equal(cs->effective_xcpus, tmpmask.new_cpus)) + remote_cpus_update(cs, NULL, tmpmask.new_cpus, + &tmpmask); + } else { + update_parent_effective_cpumask(cs, partcmd_update, + NULL, &tmpmask); + } + } + /* Force update if partition is disabled & update effective_xcpus */ update_cpumasks_hier(cs, &tmpmask, disable_partition); -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs 2026-12-03 19:58 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Hang Zhengyang @ 2026-12-04 3:35 ` Ridong Chen 0 siblings, 0 replies; 4+ messages in thread From: Ridong Chen @ 2026-12-04 3:35 UTC (permalink / raw) To: Hang Zhengyang, Waiman Long, Tejun Heo Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups, linux-kselftest, linux-kernel, stable On 12/4/2026 3:58 AM, Hang Zhengyang wrote: > When a valid partition is switched between "root" and "isolated", > update_prstate() updates isolated_cpus with the CPUs the partition has > and then calls update_cpumasks_hier(). That recomputes the exclusive > CPUs of the partition with compute_excpus(), which leaves out the > exclusive CPUs of its siblings. If the partition has no > cpuset.cpus.exclusive and a sibling has released exclusive CPUs since > the partition was created, the partition gets them, but they are not > taken from the parent, or from the top cpuset for a remote partition. > update_cpumasks_hier() does that for child partitions, but not for the > cpuset it starts from. > > Example on an 8-CPU system: > > cd /sys/fs/cgroup > echo +cpuset > cgroup.subtree_control > mkdir A1 B1 > echo 3-4 > A1/cpuset.cpus.exclusive > echo 2-5 > B1/cpuset.cpus > echo root > B1/cpuset.cpus.partition # B1: 2,5, root: 0-1,3-4,6-7 > echo > A1/cpuset.cpus.exclusive # B1 is still 2,5 > echo isolated > B1/cpuset.cpus.partition > > B1 now has CPUs 2-5, the root cpuset still has 0-1,3-4,6-7, and > cpuset.cpus.isolated shows only 2,5. Switching from isolated to root > instead makes two load balancing partitions overlap: > > WARNING: kernel/cgroup/cpuset.c:919 at rebuild_sched_domains_locked+0x4f8/0x890 > > The same happens when the sibling was a partition root that became a > member or was removed. A remote partition also triggers a warning in > remote_partition_disable() when it becomes a member later. > > Take the new CPUs after the new state is set, as update_cpumasks_hier() > does for child partitions: with update_parent_effective_cpumask() for a > local partition and with remote_cpus_update() for a remote one. If the > parent can't give them up, for example because it has tasks and no > other CPUs, the partition becomes invalid. > > With this patch, B1 gets CPUs 2-5 in both directions, the root cpuset > keeps 0-1,6-7, and cpuset.cpus.isolated shows 2-5 when B1 is isolated. > > Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict") > Cc: stable@vger.kernel.org # v7.0+ > Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> > --- > kernel/cgroup/cpuset.c | 41 +++++++++++++++++++++++++++++++---------- > 1 file changed, 31 insertions(+), 10 deletions(-) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index aa82080dd1fa..bc5b0fa5199b 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -1909,11 +1909,11 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, > * update_prstate(). An error code may be returned and the caller will check > * for error. > * > - * The partcmd_update command is used by update_cpumasks_hier() with newmask > - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used > - * by update_cpumask() with NULL newmask. In both cases, the callers won't > - * check for error and so partition_root_state and prs_err will be updated > - * directly. > + * The partcmd_update command is used by update_cpumasks_hier() and > + * update_prstate() with newmask NULL and update_cpumask() with newmask set. > + * The partcmd_invalidate is used by update_cpumask() with NULL newmask. In > + * both cases, the callers won't check for error and so partition_root_state > + * and prs_err will be updated directly. > */ > static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > struct cpumask *newmask, > @@ -2081,6 +2081,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > * This can be called from: > * 1) update_cpumasks_hier() > * 2) cpuset_hotplug_update_tasks() > + * 3) update_prstate() > * > * Check to see if it can be transitioned from valid to > * invalid partition or vice versa. > @@ -2213,9 +2214,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > } > > /* > - * For partcmd_update without newmask, it is being called from > - * cpuset_handle_hotplug(). Update the load balance flag and > - * scheduling domain accordingly. > + * For partcmd_update without newmask, update the load balance flag > + * and scheduling domain accordingly. > */ > if ((cmd == partcmd_update) && !newmask) > update_partition_sd_lb(cs, old_prs); > @@ -3008,8 +3008,9 @@ static int update_prstate(struct cpuset *cs, int new_prs) > ? PRS_ROOT : parent->partition_root_state; > > /* > - * A change in load balance state only, no change in cpumasks. > - * Need to update isolated_cpus. > + * A change in load balance state. Need to update isolated_cpus. > + * The cpumasks change only if a sibling has released exclusive > + * CPUs, see below. > */ > if (prstate_housekeeping_conflict(new_prs, parent_prs, > cs->effective_xcpus, NULL)) > @@ -3077,6 +3078,26 @@ static int update_prstate(struct cpuset *cs, int new_prs) > isolated_cpus_update(new_prs, tmpmask.new_cpus); > spin_unlock_irq(&callback_lock); > > + /* > + * A sibling may have released exclusive CPUs since cs became a > + * partition. update_cpumasks_hier() recomputes the effective CPUs of > + * cs and would include them, so take them from the parent, or from > + * the top cpuset for a remote partition, first. This has to come > + * after the new partition state is set so that the new CPUs are > + * accounted with it. If the CPUs can't be given, cs becomes invalid. > + */ > + if (isolcpus_updated) { > + if (is_remote_partition(cs)) { > + compute_excpus(cs, tmpmask.new_cpus); > + if (!cpumask_equal(cs->effective_xcpus, tmpmask.new_cpus)) > + remote_cpus_update(cs, NULL, tmpmask.new_cpus, > + &tmpmask); > + } else { > + update_parent_effective_cpumask(cs, partcmd_update, > + NULL, &tmpmask); > + } > + } > + > /* Force update if partition is disabled & update effective_xcpus */ > update_cpumasks_hier(cs, &tmpmask, disable_partition); > The fix looks correct to me, but it also makes the code more complex. update_prstate() now needs separate local and remote handling for the switch, and update_parent_effective_cpumask() gets one more caller with special cases to document. This would be much simpler to fix on top of my rework series [1]. There the switch is done in partition_switch(), and the fix is just calling local_partition_update(), or remote_cpus_update() for a remote partition, at its beginning. Those helpers already take the new CPUs from the parent and invalidate the partition on failure. [1] https://lore.kernel.org/cgroups/20261101114206.2434398-1-ridong.chen@linux.dev/ -- Best regards Ridong ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs 2026-12-03 19:58 [PATCH 0/2] cgroup/cpuset: Fix partition switch after a sibling releases CPUs Hang Zhengyang 2026-12-03 19:58 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Hang Zhengyang @ 2026-12-03 19:58 ` Hang Zhengyang 1 sibling, 0 replies; 4+ messages in thread From: Hang Zhengyang @ 2026-12-03 19:58 UTC (permalink / raw) To: Waiman Long, Ridong Chen, Tejun Heo Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups, linux-kselftest, linux-kernel Add two cases each to TEST_MATRIX and REMOTE_TEST_MATRIX. A sibling releases its exclusive CPUs 3-4, then a partition with cpuset.cpus 2-5 is switched from root to isolated or back. It should take CPUs 3-4 from its parent, which leaves CPU 1 to the member cpusets next to it. Without the previous patch, the parent keeps CPUs 3-4 and the new cases fail. Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> --- tools/testing/selftests/cgroup/test_cpuset_prs.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index 1397ec428c46..fb3d1440d1e8 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -440,6 +440,11 @@ TEST_MATRIX=( " CX2-3:P1 . . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XB1:3 A1:P-1" " CX2-3:P1 X3 . C3 T:O2=0:O3=0:X . . X3 0 XA1:|XA2:|XB1:3 A1:P-1" + # Switching a partition between root and isolated after a sibling + # released its exclusive CPUs takes those CPUs from the parent. + " C1-4:X3-4 . . C2-5:P1 X . . P2 0 A1:1|B1:2-5 B1:P2 2-5" + " C1-4:X3-4 . . C2-5:P2 X . . P1 0 A1:1|B1:2-5 B1:P1 ." + # A child cannot recover until its exclusive CPUs are available again. " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1" @@ -712,6 +717,15 @@ REMOTE_TEST_MATRIX=( " CX2-3:T . C2-3:X2:P1 . . . \ . . X2-3 . . . p1:1,4-7|c11:2-3 \ p1:P0|c11:P1" + # Switching a remote partition between root and isolated after a + # sibling released its exclusive CPUs takes those CPUs from the top + # cpuset. + " CX1-5 . X3-4 C2-5:P1 . . \ + . . X P2 . . p1:1|c11:1|c12:2-5 \ + p1:P0|c11:P0|c12:P2 2-5" + " CX1-5 . X3-4 C2-5:P2 . . \ + . . X P1 . . p1:1|c11:1|c12:2-5 \ + p1:P0|c11:P0|c12:P1 ." ) # -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 3:35 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 19:58 [PATCH 0/2] cgroup/cpuset: Fix partition switch after a sibling releases CPUs Hang Zhengyang 2026-12-03 19:58 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Hang Zhengyang 2026-12-04 3:35 ` Ridong Chen 2026-12-03 19:58 ` [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs Hang Zhengyang
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.