From: Waiman Long <longman@redhat.com>
To: "Ridong Chen" <ridong.chen@linux.dev>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Guopeng Zhang <guopeng.zhang@linux.dev>,
Waiman Long <longman@redhat.com>
Subject: [PATCH-next v2 08/10] cgroup/cpuset: Update isolated_cpus if necessary in compute_partition_effective_cpumask()
Date: Fri, 23 Oct 2026 16:00:34 -0400 [thread overview]
Message-ID: <20261023200036.60560-9-longman@redhat.com> (raw)
In-Reply-To: <20261023200036.60560-1-longman@redhat.com>
It is found by sashiko that when a child isolated partition with parent
root partition is invalidated in compute_partition_effective_cpumask(),
the switching of the isolated exclusive CPUs from child to parent will
not be reflected in isolated_cpus leading to CPU leakage. Fix that by
calling isolated_cpus_update() when that happens.
Also simplify compute_partition_effective_cpumask() by doing
child partition invalidation only for the special case of no more
effective_cpus left in a populated parent. The other case doesn't
actually warrant invalidation at this stage and subsequent iteration
in update_cpumasks_hier() will handle that child later on anyway.
Also drop the make_partition_invalid() helper by inlining it into
compute_partition_effective_cpumask() as it is the only caller.
A new test case is add to test_cpuset_prs.sh to verify this.
Fixes: 11e5f407b64a ("cgroup/cpuset: Keep track of CPUs in isolated partitions")
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/cgroup/cpuset.c | 46 +++++++------------
.../selftests/cgroup/test_cpuset_prs.sh | 4 ++
2 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 2c3a148fa40b..03c666f658e4 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -254,15 +254,6 @@ static inline bool cs_is_member(const struct cpuset *cs)
return cs->partition_root_state == PRS_MEMBER;
}
-/*
- * Callers should hold callback_lock to modify partition_root_state.
- */
-static inline void make_partition_invalid(struct cpuset *cs)
-{
- if (cs->partition_root_state > 0)
- cs->partition_root_state = -cs->partition_root_state;
-}
-
/*
* Send notification event of whenever partition_root_state changes.
*/
@@ -2106,8 +2097,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
* or update_cpumasks_hier() where parent and children are modified
* successively, we don't need to call update_parent_effective_cpumask()
* and the child's effective_cpus will be updated in later iterations.
- *
- * Note that rcu_read_lock() is assumed to be held.
*/
static void compute_partition_effective_cpumask(struct cpuset *cs,
struct cpumask *new_ecpus)
@@ -2119,15 +2108,16 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
WARN_ON_ONCE(!is_partition_valid(cs));
/*
- * Check child partition roots to see if they should be
- * invalidated when
- * 1) child effective_xcpus not a subset of new
- * excluisve_cpus
- * 2) All the effective_cpus will be used up and cp
- * has tasks
+ * Check child partition roots to see if they should be invalidated
+ * when all the effective_cpus will be used up and cs is populated.
+ * It is better to sacrifice a child partition root than invalidating
+ * the whole subtree.
+ *
+ * Return early if the effective_cpus is already empty.
*/
compute_excpus(cs, new_ecpus);
- cpumask_and(new_ecpus, new_ecpus, cpu_active_mask);
+ if (!cpumask_and(new_ecpus, new_ecpus, cpu_active_mask))
+ return;
rcu_read_lock();
cpuset_for_each_child(child, css, cs) {
@@ -2139,22 +2129,20 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
* partition root.
*/
WARN_ON_ONCE(is_remote_partition(child));
- WRITE_ONCE(child->prs_err, 0);
- if (!cpumask_subset(child->effective_xcpus,
- cs->effective_xcpus))
- WRITE_ONCE(child->prs_err, PERR_INVCPUS);
- else if (populated &&
- cpumask_subset(new_ecpus, child->effective_xcpus))
- WRITE_ONCE(child->prs_err, PERR_NOCPUS);
-
- if (child->prs_err) {
+ if (populated && cpumask_subset(new_ecpus, child->effective_xcpus)) {
int old_prs = child->partition_root_state;
+ int parent_prs = cs->partition_root_state;
/*
- * Invalidate child partition
+ * Invalidate child partition and update isolated_cpus
+ * if necessary.
*/
spin_lock_irq(&callback_lock);
- make_partition_invalid(child);
+ WRITE_ONCE(child->prs_err, PERR_NOCPUS);
+ if ((old_prs == PRS_ISOLATED) && (parent_prs == PRS_ROOT))
+ isolated_cpus_update(old_prs, parent_prs,
+ child->effective_xcpus);
+ child->partition_root_state = -old_prs;
spin_unlock_irq(&callback_lock);
notify_partition_change(child, old_prs);
continue;
diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
index f0d98da3cfd8..d7d0bef0a17a 100755
--- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
+++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
@@ -518,6 +518,10 @@ TEST_MATRIX=(
" CX0-4:P2 CX2-4:P2 CX3-4:P2 . . X2 . . 0 A1:0-1,3-4|A2:2|A3:2 \
A1:P2|A2:P2|A3:P-2 0-4"
+ # When an isolated partition child with root partition parent is invalidated,
+ # its effective xcpus will be removed from isolated_cpus.
+ " C1-4:P1 C3-4:P2 . . T:C3-4 . . . 0 A1:3-4|A2:3-4 A1:P1|A2:P-2 ."
+
#
# old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS
# ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------
--
2.56.0
next prev parent reply other threads:[~2026-10-23 20:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 20:00 [PATCH-next v2 00/10] cgroup/cpuset: Miscellaneous bug fixes & cleanup Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 01/10] cgroup/cpuset: Find furthest isolated ancestor for invalidated isolated partition Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 02/10] cgroup/cpuset: Properly compute effective xcpus in update_parent_effective_cpumask() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 03/10] cgroup/cpuset: Fix incorrect effective_cpus bug in update_cpumasks_hier() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 04/10] cgroup/cpuset: Minor fixes to prstate_housekeeping_conflict() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 05/10] selftests/cgroup: Check for a single range nohz_full CPUs before running test matrix Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 06/10] cgroup/cpuset: Prevent recursive call of remote_cpus_update() via update_cpumasks_hier() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 07/10] cgroup/cpuset: Make sure compute_partition_effective_cpumask() is only called for valid partition Waiman Long
2026-10-23 20:00 ` Waiman Long [this message]
2026-10-23 20:00 ` [PATCH-next v2 09/10] cgroup/cpuset: Relocate compute_*effective_cpumask() and compute_effective_nodemask() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 10/10] cgroup/cpuset: Integrate compute_partition_effective_cpumask() into compute_effective_cpumask() Waiman Long
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=20261023200036.60560-9-longman@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=guopeng.zhang@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=shuah@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®