All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Waiman Long <longman@redhat.com>, Ridong Chen <ridong.chen@linux.dev>
Cc: "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Guopeng Zhang" <zhangguopeng@kylinos.cn>
Subject: [PATCH v4 7/7] cgroup/cpuset: Publish exclusive_cpus before partition updates
Date: Thu, 10 Sep 2026 17:45:46 +0800	[thread overview]
Message-ID: <20260910094546.5852-8-guopeng.zhang@linux.dev> (raw)
In-Reply-To: <20260910094546.5852-1-guopeng.zhang@linux.dev>

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

update_exclusive_cpumask() calls partition_cpus_change() before publishing
the new exclusive_cpus mask. When an invalid partition is recovered,
update_parent_effective_cpumask() therefore gets the old mask from
user_xcpus(). If that mask contains only offline CPUs and the partition is
populated, the valid replacement is rejected with PERR_NOCPUS.

This can be reproduced on a cgroup v2 system with CPUs 1-4 online:

    cd /sys/fs/cgroup
    echo +cpuset > cgroup.subtree_control
    mkdir exclusive-repro
    echo 1-4 > exclusive-repro/cpuset.cpus
    echo isolated > exclusive-repro/cpuset.cpus.partition
    echo +cpuset > exclusive-repro/cgroup.subtree_control
    mkdir exclusive-repro/child
    echo 4 > exclusive-repro/child/cpuset.cpus.exclusive
    echo isolated > exclusive-repro/child/cpuset.cpus.partition
    sleep 1000 & task=$!
    echo $task > exclusive-repro/child/cgroup.procs
    echo 0 > /sys/devices/system/cpu/cpu4/online
    echo 3 > exclusive-repro/child/cpuset.cpus.exclusive
    cat exclusive-repro/child/cpuset.cpus.partition
    echo 1 > /sys/devices/system/cpu/cpu4/online
    kill $task

Without this fix, the child remains invalid after CPU 3 is written because
the recovery path still validates the old CPU 4 mask.

Publish exclusive_cpus after all fallible preparation and before
partition_cpus_change(), as update_cpumask() already does for cpus_allowed.
Keep effective_xcpus unchanged until the partition update has computed the
old-to-new difference.

Fixes: c49b5e89c45f ("cpuset: use partition_cpus_change for setting exclusive cpus")
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
 kernel/cgroup/cpuset.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 80a709bfa4b7..94c56ec8d4f8 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2690,10 +2690,18 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
 		return -ENOMEM;
 
 	trialcs->prs_err = PERR_NONE;
-	partition_cpus_change(cs, trialcs, &tmp);
 
+	/*
+	 * partition_cpus_change() may inspect user_xcpus(cs). Publish the
+	 * configured mask that was used to compute trialcs->effective_xcpus.
+	 */
 	spin_lock_irq(&callback_lock);
 	cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus);
+	spin_unlock_irq(&callback_lock);
+
+	partition_cpus_change(cs, trialcs, &tmp);
+
+	spin_lock_irq(&callback_lock);
 	cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus);
 	if ((old_prs > 0) && !is_partition_valid(cs))
 		reset_partition_data(cs);
-- 
2.43.0


      parent reply	other threads:[~2026-09-10  9:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  9:45 [PATCH v4 0/7] cgroup/cpuset: Fix partition transitions and invalidation Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 1/7] cgroup/cpuset: Factor out child partition validation Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 2/7] cgroup/cpuset: Account for child CPU ownership in partition changes Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 3/7] cgroup/cpuset: Release CPUs when type-change validation fails Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 4/7] cgroup/cpuset: Fix child invalidation after parent CPU changes Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 5/7] cgroup/cpuset: Fix isolation accounting on propagated invalidation Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 6/7] cgroup/cpuset: Publish cpus_allowed before partition updates Guopeng Zhang
2026-09-10  9:45 ` 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=20260910094546.5852-8-guopeng.zhang@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=ridong.chen@linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.