From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796327933; b=JdMJfVdfWZbGro4ISvvIzXrNAulqeEfK0mMqkzo9dKWJuz9ugTH2NkRHyTmwwteGaFhk mYkYwN+K2dF31W6LtBQY1KYf4tO7BodnnHkSiHuLE3GbUgyO3dXBp/X5pVHM0gR5pp4O6 ZfvLPr/64Heh8uv0jyDnGjLuuUPr6boDwf3f51X1/Zorp13V4tsCHAqlRDGYTcfl2B5mf RkVLMIMC9n/Wxc9xgB3ROg90wEb6PfG0CjKetyt+u8ikcrjs1VeiUsRQEPTq+hviEiNXf yGJNH2OcpraizH+yiJFTwA57DT2U42BnyfAlj9lck4ZvgH+6MHqhC50UqZLGfnoy8Mg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327933; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=w9vvjx0OjpMe5bc6rB1sYQurwJJxH2evOlpzVmWM8Ms=; b=uDPavvVmz/ulPXtmpGRjMowuJzoRLxZjiBvdNuKsGhbK1DpsTPPCl59ND1YW5dSAmbyC hmfEVEddTv9koxJqU9ddEaZPWuV5E9xK3J+jrUCUrIh/8XLI+NiIoqFNWOXb3dXCrjEXu pq9KHWpfHUpTiecmhrTdCFeH2vtUTwn7vXq/pxnLMn/ZtMFwtQR2ZJAQzB4xDDe9RofsE AlDCmW6nj8/SS6jy2t6s9rgnQf9zfM64SFldBpcSG0K4zHZgikpdekL4Cv4a/Qp1+aseh N9waP8MjI8NmFfQ5LA+HGoklIcu/vUYtHy2fs9tH1aOctD0IGcsGUQrG0DrpPwT1DHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oPXB8vWe; arc=none smtp.remote-ip=74.125.82.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 756ED606A695 for ; Thu, 3 Dec 2026 19:58:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 756ED606A695 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oPXB8vWe Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1b5ade5e0c1so310832c88.1 for ; Thu, 03 Dec 2026 11:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796327932; x=1796932732; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=w9vvjx0OjpMe5bc6rB1sYQurwJJxH2evOlpzVmWM8Ms=; b=oPXB8vWe7ooKZwSPqvSGkpNgikNC9hAtl2a7rOehUDAFxtQ+gpzaCHRTlyHEzbxx+z R4g3TNtT/0SnA+E7tJKB1KU9/uc0Rfa+lQcx4J1oMSTDk68oatd7J1w6oPGjnuoR/lq5 T9CRgrztn6/b0ff38+eWpbfqs/NcHR0EYF8L0uI/nAoH5xBkCCWEd3o8x1Tj0zBCPZTh vc+mObo5lVFnddn83ZlJMlVBiiddeWdirApOjcn5VjXg/c1L3q/PjfkdbJoUBi9CA3Io NVyS+TPJEHUICa4wQ20utn13DneG5xMshBtjYYJqfEAi5X8Rb6aHIHpqHWY4c18206yn /ckA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796327932; x=1796932732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=w9vvjx0OjpMe5bc6rB1sYQurwJJxH2evOlpzVmWM8Ms=; b=0Wuu52KpKXj+WQaxg9eEPOtEDAm7VCyB8kbsq1kfiG21uiRliTzvacDevSI+NUbeVn dVE40x3tqT5dq3qX8/aFsGFVSM94PqFQAPjYob6erQWhXixwuRlb46cVRuzln+qddrw8 iMsiN/i5DOyCZ2OPNjixVp20G/300DNMt8udBHwCFD7ci/fXQvmQSV+GoAY2xohFG53o xEOvBE7K8bFCyeaukNxwHarREBrDQg8eqxjK0evZSIvfJIdMt7YmOPhsdZGpirripq1D bNcFMO/fPLwtfEkCydCuEz8oPPiIWRDLd2AmiyDtIYPIkIJ471mBqrN5rhE2O5g//j2z IRDg== X-Forwarded-Encrypted: i=1; AL+hErH0UuwYp6KyT6qpA+jSeq/Ui5s7I57nmQ9VgTdtBew8Cl+F9moWJyx0hj3o6CgyFTadyDmMajNZVIDGnVI=@vger.kernel.org X-Gm-Message-State: APuU4Z+KAOCZVJXw/9+e31tHs7r1Bvo+sN6qBzNR/e6kGk1qoCjlkUcR QL/2JvIu5Dhv6ju0NY/DUFuIbtNp9BYLux0XJWxgkM/zJOmJCVnKt4g4 X-Gm-Gg: AZFdTZcrpZXrP95zfUCTEDFPSYKepHJ2Y3G/LxsQ3HgVqFQ365PlP3bG990dWQB1Seq UzKhG4PAOJljDM58jBZWp82LHs5lYLewtyDtQDxsENaKOGz3AxWQPAntzINTzsAiVN98RR9dwHu PidL2X3eu265xGXPPzyY9nreeNLa11K+UCQpZHSPzlR9voRCSJCUDT0dEytP+5qrKazNXT2wthi +np13FjpGw4vBSU6908Oh28WCTu63nxLOlqURk3cfCkXXM8QPwBDNqxpfeSESqnqSirlMMwYodH Zq+DL4tdZUHA8bFLgd8vs8DXR/xzDg4lbecB8gXsZY9Uu0L887rRNoq0LYowk3AU7rs6nfQn/K3 krgKko+MyKV/Kdu/prqdFULYj8VWeV5EEj3+tQfmYsWQzzSMiMjLZCJLDQenR51WjW6fKlVYQ6+ C6c1hldyFp9CdFpczHtzIwLaXyp32Qj3I9FhBtZ8YTR06MIjiPYi31QZwW4Mc9/NTfrF7w4JbDu i5r7/8setKTexSVK+Pt726cvW3pLz8MkfAM/P4dWuAoALBNVLzVX4rmA5S78QiGIpm9h24z7ciK OS7tHma6+M9IdkMLAwFjCL1JTUrBLwdO/hB6PSxBEWy59lln+qOtZk+DGh6rYud8Ow== X-Received: by 2002:a05:7022:b056:20b0:1b3:ac53:da84 with SMTP id a92af1059eb24-1b5568e371bmr47663789c88.32.1796327931396; Thu, 03 Dec 2026 11:58:51 -0800 (PST) Received: from 6610b1a2ef46 ([203.116.140.24]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6455949sm327613c88.9.2026.12.03.11.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 11:58:50 -0800 (PST) From: Hang Zhengyang To: Waiman Long , Ridong Chen , Tejun Heo Cc: Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan , cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Date: Thu, 3 Dec 2026 19:58:42 +0000 Message-ID: <20261203195843.187930-2-hang.zhengyang1010@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203195843.187930-1-hang.zhengyang1010@gmail.com> References: <20261203195843.187930-1-hang.zhengyang1010@gmail.com> X-Mailing-List: linux-kernel@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 When a valid partition is switched between "root" and "isolated", update_prstate() updates isolated_cpus with the CPUs the partition has and then calls update_cpumasks_hier(). That recomputes the exclusive CPUs of the partition with compute_excpus(), which leaves out the exclusive CPUs of its siblings. If the partition has no cpuset.cpus.exclusive and a sibling has released exclusive CPUs since the partition was created, the partition gets them, but they are not taken from the parent, or from the top cpuset for a remote partition. update_cpumasks_hier() does that for child partitions, but not for the cpuset it starts from. Example on an 8-CPU system: cd /sys/fs/cgroup echo +cpuset > cgroup.subtree_control mkdir A1 B1 echo 3-4 > A1/cpuset.cpus.exclusive echo 2-5 > B1/cpuset.cpus echo root > B1/cpuset.cpus.partition # B1: 2,5, root: 0-1,3-4,6-7 echo > A1/cpuset.cpus.exclusive # B1 is still 2,5 echo isolated > B1/cpuset.cpus.partition B1 now has CPUs 2-5, the root cpuset still has 0-1,3-4,6-7, and cpuset.cpus.isolated shows only 2,5. Switching from isolated to root instead makes two load balancing partitions overlap: WARNING: kernel/cgroup/cpuset.c:919 at rebuild_sched_domains_locked+0x4f8/0x890 The same happens when the sibling was a partition root that became a member or was removed. A remote partition also triggers a warning in remote_partition_disable() when it becomes a member later. Take the new CPUs after the new state is set, as update_cpumasks_hier() does for child partitions: with update_parent_effective_cpumask() for a local partition and with remote_cpus_update() for a remote one. If the parent can't give them up, for example because it has tasks and no other CPUs, the partition becomes invalid. With this patch, B1 gets CPUs 2-5 in both directions, the root cpuset keeps 0-1,6-7, and cpuset.cpus.isolated shows 2-5 when B1 is isolated. Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict") Cc: stable@vger.kernel.org # v7.0+ Signed-off-by: Hang Zhengyang --- kernel/cgroup/cpuset.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index aa82080dd1fa..bc5b0fa5199b 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1909,11 +1909,11 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, * update_prstate(). An error code may be returned and the caller will check * for error. * - * The partcmd_update command is used by update_cpumasks_hier() with newmask - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used - * by update_cpumask() with NULL newmask. In both cases, the callers won't - * check for error and so partition_root_state and prs_err will be updated - * directly. + * The partcmd_update command is used by update_cpumasks_hier() and + * update_prstate() with newmask NULL and update_cpumask() with newmask set. + * The partcmd_invalidate is used by update_cpumask() with NULL newmask. In + * both cases, the callers won't check for error and so partition_root_state + * and prs_err will be updated directly. */ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, struct cpumask *newmask, @@ -2081,6 +2081,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, * This can be called from: * 1) update_cpumasks_hier() * 2) cpuset_hotplug_update_tasks() + * 3) update_prstate() * * Check to see if it can be transitioned from valid to * invalid partition or vice versa. @@ -2213,9 +2214,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, } /* - * For partcmd_update without newmask, it is being called from - * cpuset_handle_hotplug(). Update the load balance flag and - * scheduling domain accordingly. + * For partcmd_update without newmask, update the load balance flag + * and scheduling domain accordingly. */ if ((cmd == partcmd_update) && !newmask) update_partition_sd_lb(cs, old_prs); @@ -3008,8 +3008,9 @@ static int update_prstate(struct cpuset *cs, int new_prs) ? PRS_ROOT : parent->partition_root_state; /* - * A change in load balance state only, no change in cpumasks. - * Need to update isolated_cpus. + * A change in load balance state. Need to update isolated_cpus. + * The cpumasks change only if a sibling has released exclusive + * CPUs, see below. */ if (prstate_housekeeping_conflict(new_prs, parent_prs, cs->effective_xcpus, NULL)) @@ -3077,6 +3078,26 @@ static int update_prstate(struct cpuset *cs, int new_prs) isolated_cpus_update(new_prs, tmpmask.new_cpus); spin_unlock_irq(&callback_lock); + /* + * A sibling may have released exclusive CPUs since cs became a + * partition. update_cpumasks_hier() recomputes the effective CPUs of + * cs and would include them, so take them from the parent, or from + * the top cpuset for a remote partition, first. This has to come + * after the new partition state is set so that the new CPUs are + * accounted with it. If the CPUs can't be given, cs becomes invalid. + */ + if (isolcpus_updated) { + if (is_remote_partition(cs)) { + compute_excpus(cs, tmpmask.new_cpus); + if (!cpumask_equal(cs->effective_xcpus, tmpmask.new_cpus)) + remote_cpus_update(cs, NULL, tmpmask.new_cpus, + &tmpmask); + } else { + update_parent_effective_cpumask(cs, partcmd_update, + NULL, &tmpmask); + } + } + /* Force update if partition is disabled & update effective_xcpus */ update_cpumasks_hier(cs, &tmpmask, disable_partition); -- 2.53.0