From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379871; b=2BoFH2VojbwyNetS87FIS9ZaL2nK74YBRTMy+AIq0Pk6wbTMO9Cepddqz0JntNjsM7h6 OB5yLWBJFbZ4vwZ1bVSMwSTpeYJGkj73usIurpbOBOC1jmflFdp85i61dwjaKGVUzdV9d V4RqvPHSKOZcjWJxkXE0z1zXDH9rld4PQpw1pYPZS6lCg7DNkm15b6HExl9rwW12diEIM zNKuu1UNlaEK6s6PXzdaI+1uGPygFV92wP55uQ2UxWQwsjsoTGavFbGOEFo7FV2XB//Cw eIr39/UUfmWBqwgHJyjsUp5XdD4AmskIx2rNopIorPlW55hOfp+67aYs1hs5LSUZKKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379871; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YVZq/2NjuPiKnEkuJKe79lsDlpydLCB6ok0J4pCNExo=; b=IaLax3pmRJLdk7trCqZT2ZP1aGtYi1ONI/akZ70e7B0diKyuIK3t3nTvyDZ6ZJLBJnyP n50ddriMyIjj1M4dgCbiaEsiaJHxjeHv3DHWzI6fWW9aP1BSXgIzV9QgSC8LA0uKKogL5 soP5+aexyyBzayjDR9sE74F6Tm8GRaPaeJ8VHWk+kDVdUqdc/txbaARTvimQP+8Oz5v7h 5PMJJj56HDhls9gHZjPpw52XVHRRsVL525lpuvjR7iAnRlxI9bIGkfzy0ZytdtIs0jra9 BFEF/DHfL1ss1C9w942KTmQIWhBBB4yEllAgrHQTm3cpaydBeFh+utr8uGMRIeipIrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PGL+yQxn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 956ED606A322; Fri, 4 Dec 2026 10:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PGL+yQxn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 132FA1F00897; Fri, 4 Dec 2026 10:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379871; bh=YVZq/2NjuPiKnEkuJKe79lsDlpydLCB6ok0J4pCNExo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PGL+yQxnM8HKDq7ZRAxJLHfz7z4i7Q6ralBOPqQ/G95QymN/by98VCi9/23Z+mRhb IOgcQipLUNBMv/oKkrAdEXElfXKeE5WfkViUEfHlyFYIN6uVOUSNjhsD4CrU8ZPwAs 9WVo6Mk1ncUrZC1jZBNbbMkEARENFBFP/k0H4AGQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Waiman Long , Ridong Chen , Tejun Heo , Sasha Levin Subject: [PATCH 6.18 044/703] cgroup/cpuset: Correctly set isolated_cpus when switching partition state Date: Fri, 4 Dec 2026 18:59:03 +0900 Message-ID: <20261204100628.813541318@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Waiman Long [ Upstream commit 56681bc448a80bb2473026b41c44c133766bc38d ] When update_prstate() is called to switch the partition state from root to isolated or vice versa, the whole effective_xcpus is passed to isolated_cpus_update(). However, if there are child partitions present, some of the effective_xcpus are dedicated to those child partitions and their partition states will remain the same or get invalidated in the case of child root partition with isolated parent in the latter update_cpumasks_hier() call. In the latter case, their exclusive CPUs will be returned to their parent. Therefore isolated_cpus may be set incorrectly with child partitions underneath. Fix that by excluding their exclusive CPUs in computing the correct cpumask of exclusive CPUs used by that partition alone. Add new test cases into test_cpuset_prs.sh to test for such cases. Fixes: 11e5f407b64a ("cgroup/cpuset: Keep track of CPUs in isolated partitions") Cc: stable@vger.kernel.org # v6.8+ Signed-off-by: Waiman Long Reviewed-by: Ridong Chen Tested-by: Ridong Chen Signed-off-by: Tejun Heo [ sashal: Context differs because the tree lacks the PERR_ISOPARENT check and has a different if/else shape, and the selftest matrix has different neighboring rows; the two new selftest rows carry :S+, which test_cpuset_prs.sh still needs on this tree, and the other added lines are unchanged. ] Signed-off-by: Sasha Levin --- kernel/cgroup/cpuset.c | 21 ++++++++++++++++++- .../selftests/cgroup/test_cpuset_prs.sh | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9bd1753dbcbe2..52eed70c2eb43 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3235,7 +3235,26 @@ static int update_prstate(struct cpuset *cs, int new_prs) disable_partition = true; err = PERR_HKEEPING; } else { + struct cgroup_subsys_state *css; + struct cpuset *child; + + /* + * Need to scan child partitions, if present, and + * exclude their effective_xcpus from cs. In the case + * of switching to isolated partition with child root + * partitions, those child partitions will be + * invalidated in update_cpumasks_hier(). + */ isolcpus_updated = true; + cpumask_copy(tmpmask.new_cpus, cs->effective_xcpus); + rcu_read_lock(); + cpuset_for_each_child(child, css, cs) { + if (!is_partition_valid(child)) + continue; + cpumask_andnot(tmpmask.new_cpus, tmpmask.new_cpus, + child->effective_xcpus); + } + rcu_read_unlock(); } } else { /* @@ -3273,7 +3292,7 @@ static int update_prstate(struct cpuset *cs, int new_prs) if (!is_partition_valid(cs)) reset_partition_data(cs); else if (isolcpus_updated) - isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus); + isolated_cpus_update(old_prs, new_prs, tmpmask.new_cpus); spin_unlock_irq(&callback_lock); update_isolation_cpumasks(isolcpus_updated); diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index 25eef20c17466..af083a527b24e 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -441,6 +441,13 @@ TEST_MATRIX=( "C1-4:P1:S+ C3-4:P2 . . T:C4-6 . . . 0 A1:5-6|A2:4 A1:P1|A2:P2 4" "C1-4:P1:S+ C1-2:P2 . . T:C4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # Switch PRS state (root <=> isolated) will properly update cpuset.cpus.isolated + # even if child partitions are present. + " C1-6:P1:S+ C3-6:P1:S+ C5-6:P2 . . P2 . . 0 A1:1-2|A2:3-4|A3:5-6 \ + A1:P1|A2:P2|A3:P2 3-6" + " C1-6:P1:S+ C3-6:P2:S+ C5-6:P2 . . P1 . . 0 A1:1-2|A2:3-4|A3:5-6 \ + A1:P1|A2:P1|A3:P2 5-6" + # # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ -------- -- 2.53.0