Re: [PATCH-next v3.1 09/11] cgroup/cpuset: Release invalid isolated CPUs with a shrunk root partition parent

From: Guopeng Zhang

Date: Mon Oct 26 2026 - 04:56:08 EST




在 2026/10/26 07:53, Waiman Long 写道:
> It is also reported by sashiko that there may be leakages of isolated
> CPUs when a root partition parent shrinks its effective_xcpus with
> isolated partition children. Leakage here means that isolated_cpus may
> contain extra CPUs that are not in any isolated partitions and not boot
> time isolated. Those CPUs cannot be used in any isolated partitions
> anymore.
>
> There are 2 different cases here. The effective_xcpus becomes empty and
> the isolated partition should be invalidated in this case. Alternatively
> some of its effective_xcpus are not in parent's effective xcpus but
> still have some valid effective_xcpus left. The isolated partition can
> remain valid. In both cases, the invalid isolated CPUs will have to be
> released from isolated_cpus if appropriate.
>
> Fix that by calling isolated_cpus_release() to release those isolated
> CPUs from isolated_cpus.
>
> New test cases are added to test_cpuset_prs.sh to test this.
>
> Fixes: 11e5f407b64a ("cgroup/cpuset: Keep track of CPUs in isolated partitions")
> Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
> ---
> kernel/cgroup/cpuset.c | 16 +++++++++++++++-
> .../testing/selftests/cgroup/test_cpuset_prs.sh | 6 ++++++
> 2 files changed, 21 insertions(+), 1 deletion(-)
>
> [v3.1] Fix the typo "cs->effective_cpus" => "cs->effective_xcpus".
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 6d224e614e74..9a2a6f727929 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2012,8 +2012,22 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> *
> * A partition error happens when parent has tasks and all
> * its effective CPUs will have to be distributed out.
> + *
> + * For an isolated partition with a shrunk root partition parent
> + * we may need to return some or all of its isolated CPUs.
> */
> - if (nocpu || cpumask_empty(tmp->delmask)) {
> + nocpu |= cpumask_empty(tmp->delmask);
> + if ((parent_prs == PRS_ROOT) && (old_prs == PRS_ISOLATED)) {
> + cpumask_clear(tmp->addmask);
> + if (nocpu)
> + cpumask_copy(tmp->addmask, cs->effective_xcpus);
> + else if (!cpumask_subset(cs->effective_xcpus, parent->effective_xcpus))
> + cpumask_andnot(tmp->addmask, cs->effective_xcpus,
> + parent->effective_xcpus);
> + if (!cpumask_empty(tmp->addmask))
> + isolated_cpus_release(cs, tmp->addmask);
> + }
> + if (nocpu) {
> part_error = PERR_NOCPUS;
> if (is_partition_valid(cs))
> adding = cpumask_and(tmp->addmask,
> diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> index d7d0bef0a17a..ceb1a3b4f94e 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
> @@ -522,6 +522,12 @@ TEST_MATRIX=(
> # 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 ."
>
> + # When a root partition parent with an isolated partition child is shrunk
> + # so that its effective xcpus is no longer a superset of its child effective
> + # xcpus, the invalid isolated CPUs should be removed from cpuset.cpus.isolated.
> + " C1-4:P1 C3-4:P2 . . T:C4-6 . . . 0 A1:5-6|A2:4 A1:P1|A2:P2 4"
> + " C1-4:P1 C1-2:P2 . . T:C4-6 . . . 0 A1:4-6|A2:4-6 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
> # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------

Reviewed-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
Tested-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>

Thanks,
Guopeng