From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.245 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792503390; b=fXLy78DJBlC2UnpUvrquiDP3de2a34EyHTaHRjxtb99PGTiP0K0HfcZmX8D+iBPT8U6O /EbHNKz4ET940fcoViQBhYqWDmH0y0MkCWjmRYywA1eKFpP13mTM1rKI2dmoudOC2B6Rh Uepbp5Gm3ulYkLV0tE8bGbCvPlQuCJbOZps307EfD1NJXUniqoSUYtEs817SJUvptsC4C 2XcawyY+jal/HQCMXGyQToYUWFxAdEAN7k4SUk5H5c74lsMVgmv0b5lx8WeIvgcIsmbJY tvpQ0brzf+uW+APq2Jy/hvn8maypz/4XwciShOu4hXGV7qGeCln6jhcsHUjw5DyJ+0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792503390; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=mf8k7XTI/zTxzeprUjIQpoEOfwu4NGyWtykxH2O6lr0=; b=jUtJuYlmgD5xDccjbT+2kOnXXUCMTvuj8EQzyYp30QSltYrHF9CZgfUzkANMnSKoE8x0 YfT8Tny716o+d6/ZGlV/Bp4Mrxe8m1r0zjzJH9ie33bkdshfVsxqgYAvv87xg79vkCymJ mFO7CmKvnBUrq1qAM2Y7nh/jvgAuUt1YuLdjXgTQ6Af8mj2bGa3iK+MeEzf1B1C70Tbds vAaZeg1fpJ4nV9D3pQ4QfCFm/uSNDxlxrLYIv5RFsmjArDHoCoPeG2XfTD8ynXhyB6Rfo qYg3y/vFHvIDkeM4O5pXYXe9go68Mjw6Z24dlARoVHij1NsOCXk3xCJsSwt9gbeEgXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=nXYALqhI; arc=none smtp.remote-ip=95.215.58.245 Received: from mta1.migadu.com (out-245.mta1.migadu.com [95.215.58.245]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B721A60A2629 for ; Tue, 20 Oct 2026 13:36:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B721A60A2629 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=nXYALqhI X-Envelope-To: cgroups@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=mqlNuzWiK+UMeR8XNNFBfexTXPgP+qQFSEcNjwZbRo8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1792503387; v=1; x=1793108187; b=nXYALqhIsk/+8IQpcxem6LS7uYF43CkJc8z9FwTDZuyD19wC/UyAN/vafAGO+fCE0t3XjaFY +ITlMB4v/t5fiXpvDs/1xfChD3K+7BuBLaU3IH5SFwAKVU+RX/7PNzHqWPFEJElsFyhpEx+nN0o RNdaHk3gjXZYDk+TqTLJZRL4= X-Envelope-To: cgroups@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 3c43797985b64205; Tue, 20 Oct 2026 13:36:26 +0000 X-Mizu-Trace-ID: 3c43797985b64205 X-Migadu-Flow: FLOW_OUT From: Guopeng Zhang To: longman@redhat.com, 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 Subject: [PATCH] cgroup/cpuset: Fix task checking when enabling a partition Date: Tue, 20 Oct 2026 21:36:15 +0800 Message-ID: <20261020133615.124373-1-guopeng.zhang@linux.dev> X-Mailer: git-send-email 2.43.0 X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Guopeng Zhang 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 --- 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" -- 2.43.0