From: Waiman Long <longman@redhat.com>
To: Guopeng Zhang <guopeng.zhang@linux.dev>, tj@kernel.org
Cc: ridong.chen@linux.dev, hannes@cmpxchg.org, mkoutny@suse.com,
shuah@kernel.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Guopeng Zhang <zhangguopeng@kylinos.cn>
Subject: Re: [PATCH] cgroup/cpuset: Fix task checking when enabling a partition
Date: Wed, 21 Oct 2026 23:34:48 -0400 [thread overview]
Message-ID: <d8786672-a864-4029-8b15-ecfc7f0d734a@redhat.com> (raw)
In-Reply-To: <20261020133615.124373-1-guopeng.zhang@linux.dev>
On 10/20/26 9:36 AM, Guopeng Zhang wrote:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>
> Creating a child partition can fail when tasks are present in its
> descendants, even though the parent has no tasks of its own.
>
> On a cgroup v2 system with CPUs 0-7 online:
>
> cd /sys/fs/cgroup
> echo +cpuset > cgroup.subtree_control
> mkdir A
> echo 1-2 > A/cpuset.cpus
> echo root > A/cpuset.cpus.partition
> echo +cpuset > A/cgroup.subtree_control
> mkdir A/B
> echo 1-2 > A/B/cpuset.cpus
> echo +cpuset > A/B/cgroup.subtree_control
> mkdir A/B/C
> echo 1-2 > A/B/C/cpuset.cpus
> echo $$ > A/B/C/cgroup.procs
> echo root > A/B/cpuset.cpus.partition
> cat A/B/cpuset.cpus.partition
> root invalid (Parent unable to distribute cpu downstream)
> cat A/cpuset.cpus.effective
> 1-2
>
> B should be a valid root, leaving A with an empty effective CPU list.
> The task in C belongs to B's partition and does not need CPUs in A.
>
> partition_is_populated() is called with B as excluded_child, but
> continue only skips B in the pre-order walk. The walk still visits C
> and finds the task there, so A is considered populated.
>
> Fix this by skipping the whole excluded subtree with
> css_rightmost_descendant(), as is already done for valid child
> partitions. Also add a test case to test_cpuset_prs.sh with a task in
> a grandchild cpuset.
>
> Fixes: b1bcaed1e39a ("cpuset: Treat cpusets in attaching as populated")
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> ---
> kernel/cgroup/cpuset.c | 4 ++--
> tools/testing/selftests/cgroup/test_cpuset_prs.sh | 3 +++
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 585a982249ad..71644482faa7 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -478,10 +478,10 @@ static inline bool partition_is_populated(struct cpuset *cs,
>
> rcu_read_lock();
> cpuset_for_each_descendant_pre(cp, pos_css, cs) {
> - if (cp == cs || cp == excluded_child)
> + if (cp == cs)
> continue;
>
> - if (is_partition_valid(cp)) {
> + if (cp == excluded_child || is_partition_valid(cp)) {
> pos_css = css_rightmost_descendant(pos_css);
> continue;
> }
> diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> index d04aad697b96..9978c560b398 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> @@ -452,6 +452,9 @@ TEST_MATRIX=(
> # Enabling partition with child cpusets is allowed
> " C0-1 C1 . C2-3 P1 . . . 0 A1:0-1|A2:1 A1:P1"
>
> + # Tasks below a new partition belong to it, not to its parent.
> + " C1-2:P1 C1-2 C1-2:T . . P1 . . 0 A1:|A2:1-2|A3:1-2 A1:P1|A2:P1"
> +
> # A partition root with non-partition root parent is invalid| but it
> # can be made valid if its parent becomes a partition root too.
> " C0-1 C1 . C2-3 . P2 . . 0 A1:0-1|A2:1 A1:P0|A2:P-2"
Reviewed-by: Waiman Long <longman@redhat.com>
prev parent reply other threads:[~2026-10-22 3:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 13:36 Guopeng Zhang
2026-10-22 3:34 ` Waiman Long [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=d8786672-a864-4029-8b15-ecfc7f0d734a@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 \
--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
all inboxes | Powered by JetHome®