From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To: Waiman Long <longman@redhat.com>,
Ridong Chen <ridong.chen@linux.dev>, Tejun Heo <tj@kernel.org>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs
Date: Thu, 3 Dec 2026 19:58:42 +0000 [thread overview]
Message-ID: <20261203195843.187930-2-hang.zhengyang1010@gmail.com> (raw)
In-Reply-To: <20261203195843.187930-1-hang.zhengyang1010@gmail.com>
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
next prev parent reply other threads:[~2026-12-03 19:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-04 3:35 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Ridong Chen
2026-12-03 19:58 ` [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs Hang Zhengyang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203195843.187930-2-hang.zhengyang1010@gmail.com \
--to=hang.zhengyang1010@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®