* 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; 2+ 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] 2+ messages in thread