From: Ridong Chen <ridong.chen@linux.dev>
To: "Waiman Long" <longman@redhat.com>, "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>
Subject: Re: [PATCH-next v2 5/5] cgroup/cpuset: Correctly set isolated_cpus when switching partition state
Date: Tue, 10 Nov 2026 21:02:34 +0800 [thread overview]
Message-ID: <2e28d0a0-e0bc-422b-857c-226bcea62ffe@linux.dev> (raw)
In-Reply-To: <aedd01b8-3f49-4916-b891-38e9c4ff3b06@linux.dev>
On 11/10/2026 7:40 PM, Ridong Chen wrote:
>
>
> On 11/10/2026 3:09 AM, Waiman Long wrote:
>> When update_prstate() is called to switch the partition state from
>> root to isolated or vice versa, the whole effective_xcpus is passed to
>> isolated_cpus_update(). However, if there are child partitions present,
>> some of the effective_xcpus are dedicated to those child partitions
>> and their partition states will remain the same or get invalidated in
>> the case of child root partition with isolated parent in the latter
>> update_cpumasks_heir() call. In the latter case, their exclusive CPUs
>
> update_cpumasks_heir
Sorry, it should be update_cpumasks_hier.
>
>> will be returned to their parent.
>>
>> Therefore isolated_cpus may be set incorrectly with child partitions
>> underneath. Fix that by excluding their exclusive CPUs in computing
>> the correct cpumask of exclusive CPUs used by that partition alone.
>>
>> Add new test cases into test_cpuset_prs.sh to test for such cases.
>>
>> Fixes: 11e5f407b64a ("cgroup/cpuset: Keep track of CPUs in isolated partitions")
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>> kernel/cgroup/cpuset.c | 30 +++++++++++++++----
>> .../selftests/cgroup/test_cpuset_prs.sh | 7 +++++
>> 2 files changed, 32 insertions(+), 5 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 7aa614c6ac4d..41048997a955 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -3054,12 +3054,32 @@ static int update_prstate(struct cpuset *cs, int new_prs)
>> cs->effective_xcpus, NULL))
>> err = PERR_HKEEPING;
>> else if (parent_prs == PRS_ISOLATED)
>> - err = PERR_ISOPARENT;
>> + err = PERR_ISOPARENT; /* old_prs should be isolated */
>> - if (!err)
>> - isolcpus_updated = true;
>> - else
>> + if (err) {
>> disable_partition = true;
>> + } else {
>> + struct cgroup_subsys_state *css;
>> + struct cpuset *child;
>> +
>> + /*
>> + * Need to scan child partitions, if present, and
>> + * exclude their effective_xcpus from cs. In the case
>> + * of switching to isolated partition with child root
>> + * partitions, those child partitions will be
>> + * invalidated in update_cpumasks_hier().
>> + */
>> + isolcpus_updated = true;
>> + cpumask_copy(tmpmask.new_cpus, cs->effective_xcpus);
>> + rcu_read_lock();
>> + cpuset_for_each_child(child, css, cs) {
>> + if (!is_partition_valid(child))
>> + continue;
>> + cpumask_andnot(tmpmask.new_cpus, tmpmask.new_cpus,
>> + child->effective_xcpus);
>> + }
>> + rcu_read_unlock();
>> + }
>> } else {
>> /*
>> * Switching back to member is always allowed even if it
>> @@ -3093,7 +3113,7 @@ static int update_prstate(struct cpuset *cs, int new_prs)
>> if (!is_partition_valid(cs))
>> reset_partition_data(cs);
>> else if (isolcpus_updated)
>> - isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus);
>> + isolated_cpus_update(old_prs, new_prs, tmpmask.new_cpus);
>> spin_unlock_irq(&callback_lock);
>> /* Force update if partition is disabled & update effective_xcpus */
>> diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/
>> testing/selftests/cgroup/test_cpuset_prs.sh
>> index 2d4744f2d6ac..741a13bbeda7 100755
>> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
>> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
>> @@ -556,6 +556,13 @@ TEST_MATRIX=(
>> " C2-6:X2-5:P1 CX3-6:P2 \
>> . . T:X4-6 . . . 0 A1:4-6|
>> A2:4-6 A1:P1|A2:P-2 ."
>> + # Switch PRS state (root <=> isolated) will properly update
>> cpuset.cpus.isolated
>> + # even if child partitions are present.
>> + " C1-6:P1 C3-6:P1 C5-6:P2 . . P2 . . 0
>> A1:1-2:A2:3-4:A3:5-6
>> + A1:P1|A2:P2:A3:P2 3-6"
>> + " C1-6:P1 C3-6:P2 C5-6:P2 . . P1 . . 0
>> A1:1-2:A2:3-4:A3:5-6
>> + A1:P1|A2:P1:A3:P2 5-6"
>> +
>> #
>> # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs
>> Pstate ISOLCPUS
>> # ------ ------ ------ ------ ------ ------ ------ ------ ---- -----
>> ------ --------
>
> We hit the same issue in our testing earlier (an isolated child partition
> loses its isolation when the parent is switched from isolated to root),
> and this is the same fix I had in mind. I also ran a few 3-level nested
> cases (root/isolated combinations, switching the parent and the middle
> level) on top of this series and cpuset.cpus.isolated is correct in all
> of them.
>
> Nits: The first line of the two new test cases lacks
> the trailing "\" used by the other multi-line entries. It still works
> as the newline is just treated as a field separator, though.
>
> Reviewed-by: Ridong Chen <ridong.chen@linux.dev>
> Tested-by: Ridong Chen <ridong.chen@linux.dev>
>
--
Best regards
Ridong
prev parent reply other threads:[~2026-11-10 13:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 19:09 [PATCH-next v2 0/5] More fix patches Waiman Long
2026-11-09 19:09 ` [PATCH-next v2 1/5] selftests/cgroup: Fix "test_cpuset_prs.sh -v" failures Waiman Long
2026-11-10 7:56 ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 2/5] cgroup/cpuset: Correctly set cpus_updated in cpuset_hotplug_update_tasks() Waiman Long
2026-11-10 8:40 ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 3/5] cgroup/cpuset: Fix incorrect partition invalidation logic " Waiman Long
2026-11-10 8:51 ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 4/5] cgroup/cpuset: Protect current->mems_allowed read in cpuset_fork() Waiman Long
2026-11-10 11:24 ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 5/5] cgroup/cpuset: Correctly set isolated_cpus when switching partition state Waiman Long
2026-11-10 2:23 ` Waiman Long
2026-11-10 2:24 ` [PATCH-next v2.1 " Waiman Long
2026-11-10 11:40 ` [PATCH-next v2 " Ridong Chen
2026-11-10 13:02 ` Ridong Chen [this message]
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=2e28d0a0-e0bc-422b-857c-226bcea62ffe@linux.dev \
--to=ridong.chen@linux.dev \
--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=longman@redhat.com \
--cc=mkoutny@suse.com \
--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®