From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Waiman Long <longman@redhat.com>,
cgroups@vger.kernel.org, ridong.chen@linux.dev
Cc: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com,
shuah@kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Guopeng Zhang <zhangguopeng@kylinos.cn>
Subject: Re: [PATCH v2 1/6] cgroup/cpuset: Respect child CPU ownership in type changes
Date: Thu, 3 Sep 2026 09:55:23 +0800 [thread overview]
Message-ID: <12386c03-e7a1-4d7f-b829-1402d74a11fe@linux.dev> (raw)
In-Reply-To: <3c6f43e3-ca8f-4525-a147-68c35d856d35@redhat.com>
在 2026/8/31 23:37, Waiman Long 写道:
> On 8/28/26 5:56 AM, Guopeng Zhang wrote:
>> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>
>> effective_xcpus includes CPUs granted to valid child partitions. Changing
>> a parent between root and isolated must not apply its new isolation state
>> or housekeeping constraints to those CPUs.
...
>> +/*
>> + * Invalidate the highest isolated partition that contains @cs.
>> + *
>> + * A root partition returning CPUs to an isolated parent can consume the last
>> + * housekeeping CPU. Invalidating the whole chain returns the CPUs to a root
>> + * partition instead.
>> + */
>> +static struct cpuset *invalidate_isolated_ancestor(struct cpuset *cs,
>> + struct tmpmasks *tmp)
>> +{
>> + struct cpuset *ancestor = parent_cs(cs);
>> + int err;
>> +
>> + lockdep_assert_held(&cpuset_mutex);
>> + while (!is_remote_partition(ancestor) &&
>> + (parent_cs(ancestor)->partition_root_state == PRS_ISOLATED))
>> + ancestor = parent_cs(ancestor);
> That can be dangerous & may cause NULL pointer dereference. parent_cs(cs) returns NULL if cs is top_cpuset. So you should always check if ancestor is NULL or parent_cs(ancestor) is NULL. Assuming that the given cs is never the top_cpuset so the initial ancestor will not be NULL. Each ancestor reassignment can become NULL. So don't mix ancestor and parent_cs(ancestor) testing in the same compound if statement.
>> +
...
>> @@ -2998,6 +3061,13 @@ static int update_prstate(struct cpuset *cs, int new_prs)
>> * Switching back to member is always allowed even if it
>> * disables child partitions.
>> */
>> + if (old_prs == PRS_ROOT &&
>> + parent->partition_root_state == PRS_ISOLATED &&
>> + !isolated_cpus_can_update(cs->effective_xcpus, NULL))
>> + invalidated = invalidate_isolated_ancestor(cs, &tmpmask);
>> + if (invalidated)
>> + goto out;
>> +
> You are adding a new exception here. You should update the comment above to talk about the exception.
>> if (is_remote_partition(cs))
>> remote_partition_disable(cs, &tmpmask);
>> else
>> @@ -3025,11 +3095,17 @@ 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);
> As I have mentioned in my comment to your v1 series, this code can be reached from multiple places beside switching from root to isolated and vice versa. So tmpmask.new_cpus may not be the "owned xcpus". So additional guard should be needed to decide if effective_xcpus or tmpmask.new_cpus should be used.
>> spin_unlock_irq(&callback_lock);
Hi Longman,
Thanks for the review.
I have addressed your comments in v3:
- rewrote the isolated-ancestor walk so that it stops safely before
dereferencing the parent of the top cpuset;
- expanded the member-transition comment to describe the housekeeping
exception;
- kept cs->effective_xcpus as the default isolation-accounting mask.
The mask pointer is changed to the directly owned CPU mask only after
that mask has been computed and validation has succeeded for a
root-to-isolated or isolated-to-root transition.
I also reworked the trial ownership calculation after additional
feedback from Sashiko.
For example, suppose the kernel is booted with:
isolcpus=domain,15
and the hierarchy is:
parent root partition: cpuset.cpus=13-15
child isolated partition: cpuset.cpus=14-15
The parent directly owns only CPU13, while CPUs 14-15 are owned by the
child.
If the parent's CPU mask is then changed to CPU15, the child is still a
valid partition when validate_partition() examines the trial
configuration. The previous code therefore subtracts the child's current
effective_xcpus from the proposed parent mask. This removes CPU15 and
leaves the parent's trial owned mask empty, so CPU15 is not included in
the parent's housekeeping check.
After the new parent mask is applied, however, the child's {14,15} mask
is no longer a subset of the parent's {15} mask. The child is invalidated
with PERR_INVCPUS and CPU15 returns to the parent. The result is a valid
root partition directly owning a boot-isolated CPU which was hidden from
its housekeeping validation.
In v3, trial ownership no longer depends only on whether a child is
currently valid. It uses the common child-partition validation rules to
predict whether each child will remain valid under the proposed parent
mask. CPUs are subtracted from the parent's trial owned mask only for
children which will remain valid. This handles both PERR_INVCPUS and
PERR_NOCPUS consistently.
v3:
https://lore.kernel.org/all/20260902102615.79189-1-guopeng.zhang@linux.dev/
Thanks,
Guopeng
next prev parent reply other threads:[~2026-09-03 1:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 9:56 [PATCH v2 0/6] cgroup/cpuset: Fix partition type transitions Guopeng Zhang
2026-08-28 9:56 ` [PATCH v2 1/6] cgroup/cpuset: Respect child CPU ownership in type changes Guopeng Zhang
2026-08-31 3:04 ` Ridong Chen
2026-08-31 10:50 ` Guopeng Zhang
2026-08-31 15:37 ` Waiman Long
2026-09-03 1:55 ` Guopeng Zhang [this message]
2026-08-28 9:56 ` [PATCH v2 2/6] selftests/cgroup: Add tests for type-change isolation accounting Guopeng Zhang
2026-08-28 9:56 ` [PATCH v2 3/6] selftests/cgroup: Add tests for type changes with child-owned CPUs Guopeng Zhang
2026-08-28 9:56 ` [PATCH v2 4/6] selftests/cgroup: Add tests for housekeeping CPU return to isolated parents Guopeng Zhang
2026-08-28 9:56 ` [PATCH v2 5/6] cgroup/cpuset: Release CPUs when type-change validation fails Guopeng Zhang
2026-08-28 9:56 ` [PATCH v2 6/6] selftests/cgroup: Add CPU release tests for type-change validation failures Guopeng Zhang
2026-09-02 9:05 ` kernel test robot
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=12386c03-e7a1-4d7f-b829-1402d74a11fe@linux.dev \
--to=guopeng.zhang@linux.dev \
--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=tj@kernel.org \
--cc=zhangguopeng@kylinos.cn \
/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