From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: "Waiman Long" <longman@redhat.com>,
"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 <zhangguopeng@kylinos.cn>
Subject: Re: [PATCH-next 6/6] cgroup/cpuset: Prevent recursive call of remote_cpus_update() via update_cpumasks_hier()
Date: Thu, 22 Oct 2026 22:23:24 +0800 [thread overview]
Message-ID: <d2e1f385-6730-4ce4-8be9-1de3d830eeef@linux.dev> (raw)
In-Reply-To: <20261022031643.1351877-7-longman@redhat.com>
在 2026/10/22 11:16, Waiman Long 写道:
> Guopeng reports that changing the cpumask of a remote partition root
> may set the effective_cpus of the top_cpuset incorrectly. It is
> due to the following call sequence:
>
> update_cpumask()
> -> partition_cpus_change()
> -> remote_cpus_update()
> -> update_sibling_cpumasks()
> -> update_cpumasks_hier()
> -> remote_cpus_update()
>
> The second remote_cpus_update() call passes in the cs->effective_xcpus
> instead of the trialcs->effective_xcpus of the first remote_cpus_update()
> call. As a result, the second call can revert what has been done in
> the first call leading to incorrect effective_cpus of the top_cpuset
> as well as subpartitions_cpus.
>
> Fix that by adding a new remote_partition_updating flag into the cpuset
> structure to indicate that a remote partition is being updated and
> update_cpumasks_hier() should skip the whole subtree as update_cpumask()
> or update_exclusive_cpumask() which calls partition_cpus_change()
> will eventually calls update_cpumasks_hier() for that subtree anyway.
>
> This new flag is currently set only in remote_cpus_update() to prevent
> recursive call of remote_cpus_update() on the same cpuset.
>
> A test case is added to test_cpuset_prs.sh to verify this change.
>
> Reported-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> Link: https://lore.kernel.org/lkml/20261010075947.333549-2-guopeng.zhang@linux.dev
> Fixes: f62a5d39368e ("cgroup/cpuset: Remove remote_partition_check() & make update_cpumasks_hier() handle remote partition")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> kernel/cgroup/cpuset-internal.h | 5 +++++
> kernel/cgroup/cpuset.c | 13 +++++++++----
> tools/testing/selftests/cgroup/test_cpuset_prs.sh | 1 +
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h
> index 2e44dc8634dc..1ba94ffaff9d 100644
> --- a/kernel/cgroup/cpuset-internal.h
> +++ b/kernel/cgroup/cpuset-internal.h
> @@ -161,6 +161,11 @@ struct cpuset {
> */
> bool remote_partition;
>
> + /*
> + * Set to true when a remote partition is undergoing update.
> + */
> + bool remote_partition_updating;
> +
> /*
> * number of SCHED_DEADLINE tasks attached to this cpuset, so that we
> * know when to rebuild associated root domain bandwidth information.
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 6e1bef12f86d..952b31246d62 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1736,6 +1736,7 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
> goto invalidate;
> }
>
> + cs->remote_partition_updating = true;
> spin_lock_irq(&callback_lock);
> if (adding)
> partition_xcpus_add(prs, NULL, tmp->addmask);
> @@ -1757,6 +1758,7 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
> */
> cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
> update_sibling_cpumasks(&top_cpuset, NULL, tmp);
> + cs->remote_partition_updating = false;
> return;
>
> invalidate:
> @@ -2208,16 +2210,19 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
> old_prs = new_prs = cp->partition_root_state;
>
> /*
> - * For child remote partition root (!= cs), we need to call
> - * remote_cpus_update() if effective_xcpus will be changed.
> - * Otherwise, we can skip the whole subtree.
> + * For a child remote partition with remote_partition_updating
> + * set, we can skip the whole subtree as the this function will
> + * be called eventually. We can also skip the subtree if the
> + * effective_xcpus isn't going to be changed. Otherwise, we
> + * will have to call remote_cpus_update().
> *
> * remote_cpus_update() will reuse tmp->new_cpus only after
> * its value is being processed.
> */
> if (remote && (cp != cs)) {
> compute_excpus(cp, tmp->new_cpus);
> - if (cpumask_equal(cp->effective_xcpus, tmp->new_cpus)) {
> + if (cp->remote_partition_updating ||
> + cpumask_equal(cp->effective_xcpus, tmp->new_cpus)) {
> 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 5bc144836bdf..19c50819065c 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> @@ -347,6 +347,7 @@ TEST_MATRIX=(
> " C0-3 C1-3 C2-3 C4 X2-3 X2-3 X2-3:P2 P2:C4-5 0 A3:2-3|B1:4-5 A3:P2|B1:P2 2-5"
> " C4:X0-3 X1-3 X2-3 . . P2 . . 0 A1:4|A2:1-3|A3:1-3 A2:P2 1-3"
> " C4:X0-3 X1-3 X2-3 . . . P2 . 0 A1:4|A2:4|A3:2-3 A3:P2 2-3"
> + " CX1-6 C1-4:P1 . C4-5 . C1-3 . . 0 A1:4-6|A2:1-3|B1:4-5 A2:P1"
>
> # Nested remote/local partition tests
> " C0-3 C1-3 C2-3 C4-5 X2-3 X2-3:P1 P2 P1 0 A1:0-1|A2:|A3:2-3|B1:4-5 \
Reviewed-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Tested-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Thanks,
Guopeng
prev parent reply other threads:[~2026-10-22 14:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 3:16 [PATCH-next 0/6] cgroup/cpuset: Miscellaneous bug fixes Waiman Long
2026-10-22 3:16 ` [PATCH-next 1/6] cgroup/cpuset: Find furthest isolated ancestor for invalidated isolated partition Waiman Long
2026-10-22 13:25 ` Guopeng Zhang
2026-10-22 16:19 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 2/6] cgroup/cpuset: Properly compute effective xcpus in update_parent_effective_cpumask() Waiman Long
2026-10-22 13:45 ` Guopeng Zhang
2026-10-22 14:47 ` Waiman Long
2026-10-22 15:00 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 3/6] cgroup/cpuset: Fix incorrect effective_cpus bug in update_cpumasks_hier() Waiman Long
2026-10-22 3:16 ` [PATCH-next 4/6] cgroup/cpuset: Minor fixes to prstate_housekeeping_conflict() Waiman Long
2026-10-22 14:15 ` Guopeng Zhang
2026-10-22 14:35 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 5/6] selftests/cgroup: Check for a single range nohz_full CPUs before running test matrix Waiman Long
2026-10-22 14:09 ` Guopeng Zhang
2026-10-22 3:16 ` [PATCH-next 6/6] cgroup/cpuset: Prevent recursive call of remote_cpus_update() via update_cpumasks_hier() Waiman Long
2026-10-22 14:23 ` Guopeng Zhang [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=d2e1f385-6730-4ce4-8be9-1de3d830eeef@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
all inboxes | Powered by JetHome®