Skip to contentSkip to conversation

FAILED: patch "[PATCH] cgroup/cpuset: Fix task checking when enabling a partition" failed to apply to 6.12-stable tree

PATCH Sasha Levin 1 participant 1 message Nov 7

Subsystems (4)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x f5b5cf2be574df6f25cbf1b000960340bff9a0bb
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From f5b5cf2be574df6f25cbf1b000960340bff9a0bb Mon Sep 17 00:00:00 2001
From: Guopeng Zhang <[email protected]>
Date: Tue, 20 Oct 2026 21:36:15 +0800
Subject: [PATCH] cgroup/cpuset: Fix task checking when enabling a partition

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")
Cc [email protected] # v6.19+
---
 kernel/cgroup/cpuset.c                            | 4 ++--
 tools/testing/selftests/cgroup/test_cpuset_prs.sh | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -2
index 585a982249ad9..71644482faa7f 100644
@@ -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;
 		}
tools/testing/selftests/cgroup/test_cpuset_prs.sh +3 -0
index d04aad697b96f..9978c560b3986 100755
@@ -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"
Signature · 1 line
2.53.0