From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BC8A7E110; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; cv=none; b=IuZitHynSJohV5qI15qiuo4AlCvJO4AP18v4q9MIuTVNymvgvaml4UQAce8qnAvg2ljjya9rD42VPOrwz/erxqVI/ITXl9OYCPKmyM6f5Rh8G4xDFVZ+fG67C3mmxuUVEjl1hUCTNfEnZVHEp2Bl6shOi+VdhWH+GxbX0iQ+K/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; c=relaxed/simple; bh=PClwcw6MLmYnbj3aJGU10bMmVQOuXt4DrvAM4ql7vCw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b++Wiw/AOoXm65RQmIfYasw6I+x2DdM9cpkPaHnydnEXFlCczZMXIHrogplrEtBrhjgpt4kDTGElnd/H7RSqG4lEXyPpKyJZgDlbhOJYcj5HV3WJzf3DaQ5uqW+h/U0M0EFS04dwes7rPCQ4VX/1jaqOnJiGCO1+B9mjTPwAA9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3p4yf8zYQtfn; Thu, 25 Dec 2025 20:45:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 0C14A4056C; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S3; Thu, 25 Dec 2025 20:45:50 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 01/21] cpuset: add early empty cpumask check in partition_xcpus_add/del Date: Thu, 25 Dec 2025 12:30:38 +0000 Message-Id: <20251225123058.231765-2-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tw1fKw4xGFyxtry7Kr18Grg_yoW8GFy7pF 15GFW7JrWrKr15C3sFqan3Wrnagws5GFy2ya1Fqw1rJFy7W3W09Fyqk3s0q3WrWayDCrWU ZFsIvrsFgF17AwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBG14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAVWUtw CF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j 6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64 vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0x vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUfDGrUUUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Add a check for an empty cpumask at the start of partition_xcpus_add() and partition_xcpus_del(). This allows the functions to return early, avoiding unnecessary computation when there is no work to be done. With these changes, partition_xcpus_add() and partition_xcpus_del() can be called even if xcpus is empty. The caller no longer needs to check whether xcpus is empty, eliminating many conditional statements. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 7ac7665f0bb6..ffc732adf9a3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1202,10 +1202,13 @@ static void partition_xcpus_add(int new_prs, struct= cpuset *parent, { WARN_ON_ONCE(new_prs < 0); lockdep_assert_held(&callback_lock); + + if (cpumask_empty(xcpus)) + return; + if (!parent) parent =3D &top_cpuset; =20 - if (parent =3D=3D &top_cpuset) cpumask_or(subpartitions_cpus, subpartitions_cpus, xcpus); =20 @@ -1229,6 +1232,10 @@ static void partition_xcpus_del(int old_prs, struct = cpuset *parent, { WARN_ON_ONCE(old_prs < 0); lockdep_assert_held(&callback_lock); + + if (cpumask_empty(xcpus)) + return; + if (!parent) parent =3D &top_cpuset; =20 --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C031F92E; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; cv=none; b=Ij7WPzswNnql5QXhKwOTXcNISTx+/pTIwXVjgsQmt3Jg1NBkKTr3dLGIgYxffxW8ATX9PmpaNN6RUuRL/uqmOph8bekxfhHHtc5F3mbCo7ieqUfd1obPEzw/fdpeOGGdr916jdIku+obIW177D+7rYIeLpMSulZNNs02veMhEHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; c=relaxed/simple; bh=BGDGcF2rAUB26YRz0BfZCQp/rHxFjlNPUGc40BkvS8A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OMRpoXEGyEcnq03TjCOFQCbKE7qpkghxG3RNmJjmg5VlbiU/3xTU/Tlc0lnvmzrVa7Jb3qKoEzlPAguGOKnmHQdaIeSSS4/JZFYs7sPHQ8FblCmk4wah4qsDxtCEWhvah9lH+Vo2NAQ49Dgsa2u3ZO+HAQd6nXeGFf2yMx4ORR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3p5FC7zYQv0M; Thu, 25 Dec 2025 20:45:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 1683340590; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S4; Thu, 25 Dec 2025 20:45:50 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 02/21] cpuset: generalize the validate_partition() interface Date: Thu, 25 Dec 2025 12:30:39 +0000 Message-Id: <20251225123058.231765-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGrWfXrWDCF1DCryfXF1kKrg_yoWrZryrpF y5GrW7J3yUtryak34ktas7Cw1Y9wnrX3WDtwnxJ3WSvFy7t34qyFyj9ws0yryfX39rG34U ZanI9F4fWFy7C3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBC14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAVWUtw CF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j 6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64 vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0x vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfU1c_TUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Refactor validate_partition() to accept a more generic parameter set, making the interface flexible enough to handle both local and remote partition validation scenarios. Additionally, a check for whether isolated CPUs can be updated has been added to validate_partition(). Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 87 +++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index ffc732adf9a3..4543c2452be0 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1442,6 +1442,41 @@ static inline bool is_local_partition(struct cpuset = *cs) return is_partition_valid(cs) && !is_remote_partition(cs); } =20 +/** + * validate_partition - Validate a cpuset partition configuration + * @cs: The cpuset to validate + * @new_prs: The proposed new partition root state + * @new_excpus: The new effective exclusive CPUs mask to validate + * @add: exclusive CPUs to be added + * @del: exclusive CPUs to be deleted + * + * Return: PRS error code (0 if valid, non-zero error code if invalid) + */ +static enum prs_errcode validate_partition(struct cpuset *cs, int new_prs, + struct cpumask *new_excpus, struct cpumask *add, struct cpumask *del) +{ + struct cpuset *parent =3D parent_cs(cs); + int parent_prs =3D parent->partition_root_state; + + if (new_prs =3D=3D PRS_MEMBER) + return PERR_NONE; + + if (cpumask_empty(new_excpus)) + return PERR_INVCPUS; + + if (prstate_housekeeping_conflict(new_prs, new_excpus)) + return PERR_HKEEPING; + + if ((new_prs =3D=3D PRS_ISOLATED) && (new_prs !=3D parent_prs) && + !isolated_cpus_can_update(add, del)) + return PERR_HKEEPING; + + if (tasks_nocpu_error(parent, cs, new_excpus)) + return PERR_NOCPUS; + + return PERR_NONE; +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update @@ -1718,22 +1753,9 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus)); new_prs =3D (cmd =3D=3D partcmd_enable) ? PRS_ROOT : PRS_ISOLATED; =20 - /* - * Enabling partition root is not allowed if its - * effective_xcpus is empty. - */ - if (cpumask_empty(xcpus)) - return PERR_INVCPUS; - - if (prstate_housekeeping_conflict(new_prs, xcpus)) - return PERR_HKEEPING; - - if ((new_prs =3D=3D PRS_ISOLATED) && (new_prs !=3D parent_prs) && - !isolated_cpus_can_update(xcpus, NULL)) - return PERR_HKEEPING; - - if (tasks_nocpu_error(parent, cs, xcpus)) - return PERR_NOCPUS; + part_error =3D validate_partition(cs, new_prs, xcpus, xcpus, NULL); + if (part_error) + return part_error; =20 /* * This function will only be called when all the preliminary @@ -2294,36 +2316,6 @@ static int parse_cpuset_cpulist(const char *buf, str= uct cpumask *out_mask) return 0; } =20 -/** - * validate_partition - Validate a cpuset partition configuration - * @cs: The cpuset to validate - * @trialcs: The trial cpuset containing proposed configuration changes - * - * If any validation check fails, the appropriate error code is set in the - * cpuset's prs_err field. - * - * Return: PRS error code (0 if valid, non-zero error code if invalid) - */ -static enum prs_errcode validate_partition(struct cpuset *cs, struct cpuse= t *trialcs) -{ - struct cpuset *parent =3D parent_cs(cs); - - if (cs_is_member(trialcs)) - return PERR_NONE; - - if (cpumask_empty(trialcs->effective_xcpus)) - return PERR_INVCPUS; - - if (prstate_housekeeping_conflict(trialcs->partition_root_state, - trialcs->effective_xcpus)) - return PERR_HKEEPING; - - if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) - return PERR_NOCPUS; - - return PERR_NONE; -} - static int cpus_allowed_validate_change(struct cpuset *cs, struct cpuset *= trialcs, struct tmpmasks *tmp) { @@ -2378,7 +2370,8 @@ static void partition_cpus_change(struct cpuset *cs, = struct cpuset *trialcs, if (cs_is_member(cs)) return; =20 - prs_err =3D validate_partition(cs, trialcs); + prs_err =3D validate_partition(cs, trialcs->partition_root_state, + trialcs->effective_xcpus, trialcs->effective_xcpus, NULL); if (prs_err) trialcs->prs_err =3D cs->prs_err =3D prs_err; =20 --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D354B652; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666757; cv=none; b=hd32NJRn27USP+qnknoSzq/KYpzPbgROotB1uOsPBcjphRRUaQa+9JX8XW3cXq22+JRAsmFr3ul5BSuF0TP2NakvlLESDDRrTlImQQScG3PPSpQ/R4FU8iffB9P471jNJ35dFb4SFqYrQh5un8DpvF1GjrQ+m+R72kdC+/Qc4Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666757; c=relaxed/simple; bh=moIaCb89mdVky4zpojCE8mSOkoUY6pDGbjFLWXlWu+s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RYqljl9BwICyCjnDQfa5TvCpJzbSqcthq+nZqaz0FuR1T4mx9otA96xKvMeKxMrI/OELXUFcGxEDosnBEjFr190l98m4HbaXAelFTWm3bmX/7tsyC0q5T7C+vVylA6C193fgz7CHucMR8SNFU7swrFikgfudk+YPY4TsieHx/8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT495fZGzKHMRw; Thu, 25 Dec 2025 20:45:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 2380940578; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S5; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 03/21] cpuset: introduce partition_enable() Date: Thu, 25 Dec 2025 12:30:40 +0000 Message-Id: <20251225123058.231765-4-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S5 X-Coremail-Antispam: 1UD129KBjvJXoWxAF4rKrW5Jw15JF43GF48JFb_yoW5WrWkpF n8Cr43J3yUKry3C3sxXFs7uw4Fgan7XF17twnxX3WrX3W7Ja4qka4jk398ta1jqryDG345 ZanIgr4xWFnrA3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBC14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAVWUtw CF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j 6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64 vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0x vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUYdb1UUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Add partition_enable() to consolidate updates to key cpuset structures during partition enablement, including: 1. remote_partition 2. effective_xcpus 3. partition_root_state 4. prs_err Key operations performed: 1. Invokes partition_xcpus_add() to assign exclusive CPUs 2. Maintains remote partition flag 3. Syncs the effective_xcpus mask 4. Updates partition_root_state and prs_err 5. Triggers scheduler domain rebuilds 6. Sends partition change notifications This helper enables transitions between root and isolated states. All fields except remote_sibling are reassigned during the transition. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 4543c2452be0..dbcb5e4d1f2c 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1477,6 +1477,54 @@ static enum prs_errcode validate_partition(struct cp= uset *cs, int new_prs, return PERR_NONE; } =20 +static void partition_state_update(struct cpuset *cs, int new_prs, + enum prs_errcode prs_err) +{ + lockdep_assert_held(&callback_lock); + + cs->partition_root_state =3D new_prs; + WRITE_ONCE(cs->prs_err, prs_err); + if (!is_partition_valid(cs)) + reset_partition_data(cs); +} + +/** + * partition_enable - Transitions a cpuset to a partition root + * @cs: The cpuset to enable partition for + * @parent: Parent cpuset of @cs, NULL for remote parent + * @new_prs: New partition state to set + * @new_excpus: New effective exclusive CPUs mask for the partition + * + * Transitions a cpuset to a partition root, only for v2. + * It supports the transition between root and isolated partition. + */ +static void partition_enable(struct cpuset *cs, struct cpuset *parent, + int new_prs, struct cpumask *new_excpus) +{ + int old_prs; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(new_prs <=3D 0); + WARN_ON_ONCE(!cpuset_v2()); + + if (cs->partition_root_state =3D=3D new_prs) + return; + + old_prs =3D cs->partition_root_state; + spin_lock_irq(&callback_lock); + /* enable partition should only add exclusive cpus */ + partition_xcpus_add(new_prs, parent, new_excpus); + /* enable remote partition */ + if (!parent) + cs->remote_partition =3D true; + cpumask_copy(cs->effective_xcpus, new_excpus); + partition_state_update(cs, new_prs, PERR_NONE); + spin_unlock_irq(&callback_lock); + update_isolation_cpumasks(); + cpuset_force_rebuild(); + notify_partition_change(cs, old_prs); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60CD37263B; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666757; cv=none; b=E4sN260g7rwkuS4JFfjFzHJHe7r4ySRdTbtfjEDhgxUjismyXWo0oy94fedtkrbImgiagK6u5vGVER7GWR+OZxNGZuXx2iP3gieNaRprz3dZrXhSZ7Yt1cFqYNwoCvl8cooQrnr5NoXcBlZ+2OoCo6odimBafsAOPDzD6DiF+oo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666757; c=relaxed/simple; bh=0T9kISK2w8BIvPD5DMPZ+zWF1jhhxroUrxQ3iqUGseA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MK601ZktSBvyuW9iYwjhcCw2dPZ8I8M+XYbfdMXVT0to165A9hIB5hZzEv+u3KZWocOQY5iwULFpIXqRndiK3gNHJ9+/nAj5ztILbHi2gepsxBCTIO6mFlOR7qhboTKBGJAS+vnOe1nFJ2Jm4WKOoX2D7c56ej1lVce45reVop8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3p64yGzYQv0M; Thu, 25 Dec 2025 20:45:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 2EC4440579; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S6; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 04/21] cpuset: introduce partition_disable() Date: Thu, 25 Dec 2025 12:30:41 +0000 Message-Id: <20251225123058.231765-5-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S6 X-Coremail-Antispam: 1UD129KBjvJXoW7CryUtryUuF13Zr1kJF4fXwb_yoW8Kw43pF 1DCr43t3yYgr13u3sxJan7uw1rKa1kXFW7tw17Xw1rXFy7Aa4qva4vk39Iv3WUXFyDW345 ZFsIqr4xWF17A3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUYcTQUUUU U X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Add partition_disable() to consolidate updates to key cpuset structures during partition disablement, including: 1. remote_partition 2. effective_xcpus 3. partition_root_state 4. prs_err Key operations performed: 1. Cleaning up remote_partition 2. Removing exclusive CPUs via partition_xcpus_del() 3. Recomputing effective exclusive CPUs mask 4. Updating partition state and error status 5. Triggering required scheduler domain rebuilds 6. Clear exclusive flag. 7. Sends partition change notifications Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index dbcb5e4d1f2c..d1bf1a2f6acd 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1525,6 +1525,39 @@ static void partition_enable(struct cpuset *cs, stru= ct cpuset *parent, notify_partition_change(cs, old_prs); } =20 +/** + * partition_disable - Disable partition root state for a cpuset + * @cs: The cpuset to disable partition for + * @parent: Parent cpuset of @cs, NULL for remote parent + * @new_prs: New partition root state (should be non-positive) + * @prs_err: Error code to set if disabling due to validation failure + */ +static void partition_disable(struct cpuset *cs, struct cpuset *parent, + int new_prs, enum prs_errcode prs_err) +{ + int old_prs; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(new_prs > 0); + WARN_ON_ONCE(!cpuset_v2()); + + old_prs =3D cs->partition_root_state; + spin_lock_irq(&callback_lock); + cs->remote_partition =3D false; + /* disable a partition should only delete exclusive cpus */ + partition_xcpus_del(cs->partition_root_state, + parent, cs->effective_xcpus); + /* effective_xcpus may need to be changed */ + compute_excpus(cs, cs->effective_xcpus); + partition_state_update(cs, new_prs, prs_err); + spin_unlock_irq(&callback_lock); + update_isolation_cpumasks(); + cpuset_force_rebuild(); + /* Clear exclusive flag; no errors are expected */ + update_partition_exclusive_flag(cs, new_prs); + notify_partition_change(cs, old_prs); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C8A3398A; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; cv=none; b=PQQma5CQRY4+PqjhBWifnzEjsxb82ftd1kEJRtiFjOlR8OWAjFD9+RcKHQEoqdOr1WZv3WZO6zVe59tPbQdbEkyahsLyO2U8ICFKpDcPZRoA9sZpRtjrOinV/2Fvmc4Z1GM/lk73TnyPsxejpyrrIIQ7MY8/NJOF/GPt2qJ9DvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; c=relaxed/simple; bh=noJjTz8hMt2aO/yE9IMhRT1Jb6U14CD/n5WEzxKrX+g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H54n7Smh2AN3ANz+QRBTQ+Ju+MdKIzJxkOUeolCJISau8V0jZqD7GcGykeRfKI+YakmeIY8JgPZnTgwUmcJkfhzGS+NwfSj67cdq/VtWGNgQtaUqJ+2+4k5yd0tJNXL/znzIPc28qcDXvdaAsH3pUiVv5zvNnIislXqb5xsGP6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3p6FjszYQv52; Thu, 25 Dec 2025 20:45:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 393684058C; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S7; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 05/21] cpuset: introduce partition_update() Date: Thu, 25 Dec 2025 12:30:42 +0000 Message-Id: <20251225123058.231765-6-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S7 X-Coremail-Antispam: 1UD129KBjvJXoWxuF45Xw43ur1kCFWxWr4rKrg_yoW5Wr4UpF ykCr43XayUKr13u3sxJFs7uw4rKa1vqF17twnrXr1rJFy2y3Wvv34qy398Jr1UX39rGry5 XFnIqr4SgF17AwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUYcTQUUUU U X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Introduce partition_update() to centralize updates to key cpuset structures during a partition update, including: 1. effective_xcpus 2. exclusive_cpus Key operations performed: 1. Adding and removing exclusive CPUs via partition_xcpus_add()/del() 2. Synchronizing the effective exclusive CPUs mask 3. Updating the exclusive CPUs mask when modification is required 4. Triggering necessary system updates and workqueue synchronization 5. Updating the partition's exclusive flag 6. Sending partition change notifications Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d1bf1a2f6acd..b0744a1074ad 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1558,6 +1558,51 @@ static void partition_disable(struct cpuset *cs, str= uct cpuset *parent, notify_partition_change(cs, old_prs); } =20 +/** + * partition_update - Update an existing partition configuration + * @cs: The cpuset to update + * @prs: Partition root state (must be positive) + * @xcpus: New exclusive CPUs mask for the partition (NULL to keep current) + * @excpus: New effective exclusive CPUs mask + * @tmp: Temporary masks + * + * Updates partition-related fields. The tmp->addmask is the CPU mask that + * will be added to the subpartitions_cpus and removed from parent's + * effective_cpus, and the tmp->delmask vice versa. + */ +static void partition_update(struct cpuset *cs, int prs, struct cpumask *x= cpus, + struct cpumask *excpus, struct tmpmasks *tmp) +{ + struct cpuset *parent; + int old_prs; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(!cpuset_v2()); + WARN_ON_ONCE(prs <=3D 0); + + if (cpumask_empty(tmp->addmask) && + cpumask_empty(tmp->delmask)) + return; + + parent =3D is_remote_partition(cs) ? NULL : parent_cs(cs); + old_prs =3D cs->partition_root_state; + spin_lock_irq(&callback_lock); + partition_xcpus_add(prs, parent, tmp->addmask); + partition_xcpus_del(prs, parent, tmp->delmask); + /* + * Need to update effective_xcpus and exclusive_cpus now as + * update_sibling_cpumasks() below may iterate back to the same cs. + */ + cpumask_copy(cs->effective_xcpus, excpus); + if (xcpus) + cpumask_copy(cs->exclusive_cpus, xcpus); + spin_unlock_irq(&callback_lock); + update_isolation_cpumasks(); + cpuset_force_rebuild(); + update_partition_exclusive_flag(cs, prs); + notify_partition_change(cs, old_prs); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D2E71373; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; cv=none; b=XQ5ltFawM3Yp9kQTprIMAek1XvUksrmFSYgOPcSEjERYFrLuEphREvSKchiK36+eODhnVHADhuwT1SZgfuV4SK6b9+ptkjg6lnq2wry7fCfolVEXs2JYESkIp/XW5PahojS0p9jvO7Nus7+f6vgeiXQ5SXucW79bTM6Kw3vucSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; c=relaxed/simple; bh=9YvAGNi+mNMzWEKdjdf2RclZ4Z8K76JcQcUDY4FWkxQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BTBUYadSkudVFfWZVfeAaNmHzTaZxD7IJStfRjvapyk+AZ9IyddJoPLoZelHDxkkV1ZSLHG0vTFfY1umRHnhB+jP6S1DTkLYf2jKWS/ZAkkdpRGtxlX3OEPKBP+i+QENk7X2RUFMUHYWahHzN3ecprFUzjDo+fSgx1SateawzW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT496jGQzKHMfh; Thu, 25 Dec 2025 20:45:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 481324056C; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S8; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 06/21] cpuset: use partition_enable() for remote partition enablement Date: Thu, 25 Dec 2025 12:30:43 +0000 Message-Id: <20251225123058.231765-7-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S8 X-Coremail-Antispam: 1UD129KBjvJXoWrZFy5Jw13JFy3ZFy5CF1Utrb_yoW8Jr1rpF 1agr47Gr98Xr1UC39FqFs29w1fKa1DGF42y3Z8Gw1rZ3W7A3WUK340k390qw1Yqa9rCF1U Z3WavF4SgFy7A37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Now that the partition_enable() helper is available, replace the existing implementation for remote partition enablement with this centralized function to unify the enablement logic. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index b0744a1074ad..0c62157c1d04 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1642,15 +1642,7 @@ static int remote_partition_enable(struct cpuset *cs= , int new_prs, prstate_housekeeping_conflict(new_prs, tmp->new_cpus)) return PERR_HKEEPING; =20 - spin_lock_irq(&callback_lock); - partition_xcpus_add(new_prs, NULL, tmp->new_cpus); - cs->remote_partition =3D true; - cpumask_copy(cs->effective_xcpus, tmp->new_cpus); - spin_unlock_irq(&callback_lock); - update_isolation_cpumasks(); - cpuset_force_rebuild(); - cs->prs_err =3D 0; - + partition_enable(cs, NULL, new_prs, tmp->new_cpus); /* * Propagate changes in top_cpuset's effective_cpus down the hierarchy. */ --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C332AD2C; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; cv=none; b=JYq/xgHw0gBCHG1QFrsmtsXxgy17MFTE0+IFugrKFjBaLJtKZsG09eYYAP9H19IsVkcwyDEjM7rAqIMa9jhiUyBhzHJcSUW4HHgJ9l0VY+owvn3lGuW1O8JeapkxFi37Hs8OY5T3LIHI3j504kR8vpZAWlHGJFPe5oMMWhUexqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666755; c=relaxed/simple; bh=cO/z1lPS/1foP1bqyi42AkzaQBAU7k+dYR5WEzpXNpc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b3yOEmvlvynjcNq2gaHrJw7/ISxGXZC2CEWCE6ZjVcv1mtKL73ussqghKxAXue5a4Y7ptG3B/MuPulq1s0Obz1f2/a/GD/K0Oe9IK7pJaIF5ZLEhd4UnIQkdIFDhmwG3gP5S6QDcYwFxUj0PqZaoWNVI/NP2j2g9fQuqqYdziWQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q00t7zYQv5n; Thu, 25 Dec 2025 20:45:10 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 563C54056D; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S9; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 07/21] cpuset: use partition_disable() for remote partition disablement Date: Thu, 25 Dec 2025 12:30:44 +0000 Message-Id: <20251225123058.231765-8-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S9 X-Coremail-Antispam: 1UD129KBjvJXoW7WrWxCFyxJryDtFyfKr43trb_yoW8CF48pF 13Cr47GFW5WF15uay7JFsruw1rKanrJF9rtw17W34rXF17Aa4v9a42k39Yva4jgFWDWry5 Z3Z0gr48XF17AwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Now that the partition_disable() helper is available, replace the existing implementation for remote partition disablement with this centralized function to unify the disablement logic. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 0c62157c1d04..9bcc13b7ea08 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1662,6 +1662,8 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, */ static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *t= mp) { + int new_prs; + WARN_ON_ONCE(!is_remote_partition(cs)); /* * When a CPU is offlined, top_cpuset may end up with no available CPUs, @@ -1672,20 +1674,8 @@ static void remote_partition_disable(struct cpuset *= cs, struct tmpmasks *tmp) WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus) && !cpumask_empty(subpartitions_cpus)); =20 - spin_lock_irq(&callback_lock); - cs->remote_partition =3D false; - partition_xcpus_del(cs->partition_root_state, NULL, cs->effective_xcpus); - if (cs->prs_err) - cs->partition_root_state =3D -cs->partition_root_state; - else - cs->partition_root_state =3D PRS_MEMBER; - - /* effective_xcpus may need to be changed */ - compute_excpus(cs, cs->effective_xcpus); - reset_partition_data(cs); - spin_unlock_irq(&callback_lock); - update_isolation_cpumasks(); - cpuset_force_rebuild(); + new_prs =3D cs->prs_err ? -cs->partition_root_state : PRS_MEMBER; + partition_disable(cs, NULL, new_prs, cs->prs_err); =20 /* * Propagate changes in top_cpuset's effective_cpus down the hierarchy. --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D38AE55A; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; cv=none; b=LLoZThshSlkyTKK4oce++KI7fX9khi4FibRyW0EIuia1F1qkeIoDDFNYoMNr9l2LTQ4r5paHrbv3TsXv5khpg5NY5tZzEzmFAyQctp9xS0G8wRuUVdCtKit4E0h1zf0qUeVNsNPLCHIm83S4S0/KLBc683yYIhdxuOSlcoQjUcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; c=relaxed/simple; bh=v7uksGN1CrM8YcGspl4JJUGLxd0MV5MftavhCF8OE4A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pSXnxaENF5fsDPWoAIU9eZBaky7aIQSL3NHT4L2r8RaC5IrjW3nJ9KRNTFrlCbW55QXGqEszD7xEdDrkTHbZxgBep2yn50glQloEpIXc2dnOZZ4/TdXfQHHTyOY9LvFnV+lsD2lYdCxFjMvt3v7uU6jq1iP1Ywyc2VviXyiz0hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B0TSqzKHMhR; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 66A174056E; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S10; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 08/21] cpuset: use partition_update() for remote partition update Date: Thu, 25 Dec 2025 12:30:45 +0000 Message-Id: <20251225123058.231765-9-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S10 X-Coremail-Antispam: 1UD129KBjvJXoWxJF4UZw17WFW8ur47GF1UGFg_yoW5Gr1xpF yfGr42qa90qr1UC34Utan29rn5Ka1DtFWqy3ZrX34rAFy7C3W0y34Uta98XFy5W39rWr15 AFZIqr42qFy7uwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Now that the partition_update() helper is available, use it to replace the existing remote partition update logic. This unifies the update path through a single centralized function. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9bcc13b7ea08..73d9a8df3072 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1697,7 +1697,6 @@ static void remote_partition_disable(struct cpuset *c= s, struct tmpmasks *tmp) static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, struct cpumask *excpus, struct tmpmasks *tmp) { - bool adding, deleting; int prs =3D cs->partition_root_state; =20 if (WARN_ON_ONCE(!is_remote_partition(cs))) @@ -1710,15 +1709,15 @@ static void remote_cpus_update(struct cpuset *cs, s= truct cpumask *xcpus, goto invalidate; } =20 - adding =3D cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); - deleting =3D cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); + cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); + cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); =20 /* * Additions of remote CPUs is only allowed if those CPUs are * not allocated to other partitions and there are effective_cpus * left in the top cpuset. */ - if (adding) { + if (!cpumask_empty(tmp->addmask)) { WARN_ON_ONCE(cpumask_intersects(tmp->addmask, subpartitions_cpus)); if (!capable(CAP_SYS_ADMIN)) cs->prs_err =3D PERR_ACCESS; @@ -1732,23 +1731,7 @@ static void remote_cpus_update(struct cpuset *cs, st= ruct cpumask *xcpus, goto invalidate; } =20 - spin_lock_irq(&callback_lock); - if (adding) - partition_xcpus_add(prs, NULL, tmp->addmask); - if (deleting) - partition_xcpus_del(prs, NULL, tmp->delmask); - /* - * Need to update effective_xcpus and exclusive_cpus now as - * update_sibling_cpumasks() below may iterate back to the same cs. - */ - cpumask_copy(cs->effective_xcpus, excpus); - if (xcpus) - cpumask_copy(cs->exclusive_cpus, xcpus); - spin_unlock_irq(&callback_lock); - update_isolation_cpumasks(); - if (adding || deleting) - cpuset_force_rebuild(); - + partition_update(cs, cs->partition_root_state, xcpus, excpus, tmp); /* * Propagate changes in top_cpuset's effective_cpus down the hierarchy. */ --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCC82322DD4; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; cv=none; b=ttecN13eFJmVhBojTTcuWyYZs1iDtW0jtTZcaXhC/Imp2O0+5Nappfiebo81AaB2r0rfU39eu8SPg2+DkFP4G6ASf5tBk4ZLdYzQ+dN/RvY/K+bH6OkjzVLH9Z9eHdJ2jizIod9ncPKRaXzsSplHhD3+Jl4JUTFe3/GC7rOfh74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; c=relaxed/simple; bh=AmkywKE1kek5N/SO7TNWTpG/4hYPc6YpRyDpYrbl9X4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oKbdJhrCpgerKFA4D+2D4h9c6FSqTQsHiA8u60lKWwExjy1WTHuiF2RG8hdS1W+kFJTs9yD6Juq0F+C7W4nZWWuOcWDh9lmcAg3zvipkokHTeVR/1ZLcHu6FpvM5bod7ZHRZcxwaSAMG3V2SrQWv2MYD7/hBtLUYZLHqnp05tCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q0mxQzYQv60; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 722584056F; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S11; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 09/21] cpuset: introduce local_partition_enable() Date: Thu, 25 Dec 2025 12:30:46 +0000 Message-Id: <20251225123058.231765-10-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S11 X-Coremail-Antispam: 1UD129KBjvJXoWxWryUXw4Dtry8tr48XF43Wrg_yoWruw1DpF y7GrZFqFWjqryrC39xJan7Cw1rKws8tFZFywnxX34rXFy7Aw4vyFy0y39xtFyjgayDury5 Za9Fqr4xWFyUArUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ From: Chen Ridong The partition_enable() function introduced in the previous patch can be reused to enable local partitions. The local_partition_enable() function is introduced, which factors out the local partition enablement logic from update_parent_effective_cpumask(). After passing local partition validation checks, it delegates to partition_enable() to complete the partition setup. This refactoring creates a clear separation between local and remote partition operations while maintaining code reuse through the shared partition_enable() infrastructure. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 86 ++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 73d9a8df3072..4146e9e7d104 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1743,6 +1743,52 @@ static void remote_cpus_update(struct cpuset *cs, st= ruct cpumask *xcpus, remote_partition_disable(cs, tmp); } =20 +/** + * local_partition_enable - Enable local partition for a cpuset + * @cs: Target cpuset to become a local partition root + * @new_prs: New partition root state to apply + * @tmp: Temporary masks for CPU calculations + * + * Return: 0 on success, error code on failure + */ +static int local_partition_enable(struct cpuset *cs, + int new_prs, struct tmpmasks *tmp) +{ + struct cpuset *parent =3D parent_cs(cs); + enum prs_errcode err; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ + + /* + * The parent must be a partition root. + * The new cpumask, if present, or the current cpus_allowed must + * not be empty. + */ + if (!is_partition_valid(parent)) { + return is_partition_invalid(parent) + ? PERR_INVPARENT : PERR_NOTPART; + } + + /* + * Need to call compute_excpus() in case + * exclusive_cpus not set. Sibling conflict should only happen + * if exclusive_cpus isn't set. + */ + if (compute_excpus(cs, tmp->new_cpus)) + WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus)); + + err =3D validate_partition(cs, new_prs, tmp->new_cpus, tmp->new_cpus, NUL= L); + if (err) + return err; + + partition_enable(cs, parent, new_prs, tmp->new_cpus); + + cpuset_update_tasks_cpumask(parent, tmp->addmask); + update_sibling_cpumasks(parent, cs, tmp); + return 0; +} + /** * update_parent_effective_cpumask - update effective_cpus mask of parent = cpuset * @cs: The cpuset that requests change in partition root state @@ -1833,35 +1879,7 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, =20 nocpu =3D tasks_nocpu_error(parent, cs, xcpus); =20 - if ((cmd =3D=3D partcmd_enable) || (cmd =3D=3D partcmd_enablei)) { - /* - * Need to call compute_excpus() in case - * exclusive_cpus not set. Sibling conflict should only happen - * if exclusive_cpus isn't set. - */ - xcpus =3D tmp->delmask; - if (compute_excpus(cs, xcpus)) - WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus)); - new_prs =3D (cmd =3D=3D partcmd_enable) ? PRS_ROOT : PRS_ISOLATED; - - part_error =3D validate_partition(cs, new_prs, xcpus, xcpus, NULL); - if (part_error) - return part_error; - - /* - * This function will only be called when all the preliminary - * checks have passed. At this point, the following condition - * should hold. - * - * (cs->effective_xcpus & cpu_active_mask) =E2=8A=86 parent->effective_c= pus - * - * Warn if it is not the case. - */ - cpumask_and(tmp->new_cpus, xcpus, cpu_active_mask); - WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus)); - - deleting =3D true; - } else if (cmd =3D=3D partcmd_disable) { + if (cmd =3D=3D partcmd_disable) { /* * May need to add cpus back to parent's effective_cpus * (and maybe removed from subpartitions_cpus/isolated_cpus) @@ -2993,14 +3011,10 @@ static int update_prstate(struct cpuset *cs, int ne= w_prs) * If parent is valid partition, enable local partiion. * Otherwise, enable a remote partition. */ - if (is_partition_valid(parent)) { - enum partition_cmd cmd =3D (new_prs =3D=3D PRS_ROOT) - ? partcmd_enable : partcmd_enablei; - - err =3D update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask); - } else { + if (is_partition_valid(parent)) + err =3D local_partition_enable(cs, new_prs, &tmpmask); + else err =3D remote_partition_enable(cs, new_prs, &tmpmask); - } } else if (old_prs && new_prs) { /* * A change in load balance state only, no change in cpumasks. --=20 2.34.1 From nobody Mon Feb 9 03:52:32 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCC05322DD0; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; cv=none; b=bsqzgQE+fABVjSRcPI/6wCMy3HBYGHG0NkjNm6zW+C1sB2cYs4QaREei33Bj/05JiK+QzaEU5vx6ZUh+MM1+aj8Ob3bildNOMczK67KeELVO5fzT9qAU06LRSHU4RJPAqkYxAoPj/34m3/2xaQB69OaXIU6+3JbgynJ/TkATRVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; c=relaxed/simple; bh=ZY9ySRKh0PSc/UDYu+NzAUS+LMgLq1DFfOJEhXxVRvc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pbKhH/mrSWrizkyV8yC6Oq0L3NjxbdMpwxpTlJw6/O8Xx6axLPKINRUS+zdmXR/lXHJQMUqSE/Wkjt3/se8kzRfegir88AdN4mBr3jRWB+yFvjB5y6t4m0bbdYtRkzUv/JNfM70Rhk3IzBYGYRvKtsNBCfsRR8S/VxzG6wB8HNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q1FRwzYQv5y; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 7F3A540576; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S12; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 10/21] cpuset: introduce local_partition_disable() Date: Thu, 25 Dec 2025 12:30:47 +0000 Message-Id: <20251225123058.231765-11-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S12 X-Coremail-Antispam: 1UD129KBjvJXoWxGF1xXw47CryxXFy8Kr43GFg_yoW5Aw4DpF y7GrW3K3yUXFy7uasrXan7Aw1Fgws7JayxtwnrWayfJF17A3Wv9Fy0v3yvv3WjgFyDG347 ZFn0qr4UWF1xArUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The partition_disable() function introduced earlier can be extended to handle local partition disablement. The local_partition_disable() functions is introduced, which extracts the local partition disable logic from update_parent_effective_cpumask(). It calls partition_disable() to complete the disablement process. This refactoring establishes a clear separation between local and remote partition operations while promoting code reuse through the shared partition_disable() infrastructure. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 43 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 4146e9e7d104..27179db4cd22 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1789,6 +1789,31 @@ static int local_partition_enable(struct cpuset *cs, return 0; } =20 +/** + * local_partition_disable - Disable a local partition + * @cs: Target cpuset (local partition root) to disable + * @part_error: partition error when @cs is disabled + * @tmp: Temporary masks for CPU calculations + */ +static void local_partition_disable(struct cpuset *cs, enum prs_errcode pa= rt_error, + struct tmpmasks *tmp) +{ + struct cpuset *parent =3D parent_cs(cs); + int new_prs; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ + + if (!is_partition_valid(cs)) + return; + + new_prs =3D part_error ? -cs->partition_root_state : 0; + partition_disable(cs, parent, new_prs, part_error); + + cpuset_update_tasks_cpumask(parent, tmp->addmask); + update_sibling_cpumasks(parent, cs, tmp); +} + /** * update_parent_effective_cpumask - update effective_cpus mask of parent = cpuset * @cs: The cpuset that requests change in partition root state @@ -1879,19 +1904,7 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, =20 nocpu =3D tasks_nocpu_error(parent, cs, xcpus); =20 - if (cmd =3D=3D partcmd_disable) { - /* - * May need to add cpus back to parent's effective_cpus - * (and maybe removed from subpartitions_cpus/isolated_cpus) - * for valid partition root. xcpus may contain CPUs that - * shouldn't be removed from the two global cpumasks. - */ - if (is_partition_valid(cs)) { - cpumask_copy(tmp->addmask, cs->effective_xcpus); - adding =3D true; - } - new_prs =3D PRS_MEMBER; - } else if (newmask) { + if (newmask) { /* * Empty cpumask is not allowed */ @@ -3034,9 +3047,7 @@ static int update_prstate(struct cpuset *cs, int new_= prs) if (is_remote_partition(cs)) remote_partition_disable(cs, &tmpmask); else - update_parent_effective_cpumask(cs, partcmd_disable, - NULL, &tmpmask); - + local_partition_disable(cs, PERR_NONE, &tmpmask); /* * Invalidation of child partitions will be done in * update_cpumasks_hier(). --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D3B01096F; Thu, 25 Dec 2025 12:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; cv=none; b=YUdqrC1uPxe3C6159ppOniASL2Jp5IPPjonokYxzucaYNtJrmGbpUGYsu14grc76c+N9oRWcoc4ZkraFoEdXSGMN0EDts1DkNRmmul2PEd3RNW/enhcPPG05W4eDlzHppPeTqGJXiE80ago1YIemA6SCy2/2jWgXK9yyryFWTZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666756; c=relaxed/simple; bh=p+wP1mMC8gaHmC7CnNCKb2rUi91QHEdpPXjVtJtCo8k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WlsNK4zG0yHSEbutHmhQS069qbIe92OgIBZAD2/DLLwvsadbUY51cjNGL1/DnxABNqusBCY7j/v/vIwBtdGa9I35aXonzkPnGTK6mNIDe5+0k8c/jqx5swS5gSqZwWMVs9x32OpyZbOvH5UFePBpEDqveqTJsx5igm2jicKm9xw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B1ZBJzKHMj0; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 8A21A40579; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S13; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 11/21] cpuset: user local_partition_disable() to invalidate local partition Date: Thu, 25 Dec 2025 12:30:48 +0000 Message-Id: <20251225123058.231765-12-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S13 X-Coremail-Antispam: 1UD129KBjvJXoWxGw18Ar17AF18uF15Xw4fZrb_yoW5KFy5pF y3CrW7tayUGr15uasxXan2934FganrJa4qy3ZxXayrJFy7A3WvyF1jva9av345Xa4kGryU ZayYgr4fGFy7ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Build on the local_partition_disable() infrastructure introduced in the previous patch to handle local partition invalidation. Additionally, correct the transition logic in cpuset_hotplug_update_tasks() when determining whether to transition an invalid partition root, the check should be based on non-empty user_xcpus rather than non-empty effective_xcpus. This correction addresses the scenario where exclusive_cpus is not set but cpus_allowed is configured. In this case, effective_xcpus may be empty even though the partition should be considered for re-enablement. The user_xcpus based check ensures proper partition state transitions under these conditions. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 27179db4cd22..8f70867a9fe4 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1874,22 +1874,6 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, adding =3D deleting =3D false; old_prs =3D new_prs =3D cs->partition_root_state; =20 - if (cmd =3D=3D partcmd_invalidate) { - if (is_partition_invalid(cs)) - return 0; - - /* - * Make the current partition invalid. - */ - if (is_partition_valid(parent)) - adding =3D cpumask_and(tmp->addmask, - xcpus, parent->effective_xcpus); - if (old_prs > 0) - new_prs =3D -old_prs; - - goto write_error; - } - /* * The parent must be a partition root. * The new cpumask, if present, or the current cpus_allowed must @@ -2465,7 +2449,7 @@ static int cpus_allowed_validate_change(struct cpuset= *cs, struct cpuset *trialc if (is_partition_valid(cp) && cpumask_intersects(xcpus, cp->effective_xcpus)) { rcu_read_unlock(); - update_parent_effective_cpumask(cp, partcmd_invalidate, NULL, tmp); + local_partition_disable(cp, PERR_NOTEXCL, tmp); rcu_read_lock(); } } @@ -2505,8 +2489,7 @@ static void partition_cpus_change(struct cpuset *cs, = struct cpuset *trialcs, trialcs->effective_xcpus, tmp); } else { if (trialcs->prs_err) - update_parent_effective_cpumask(cs, partcmd_invalidate, - NULL, tmp); + local_partition_disable(cs, trialcs->prs_err, tmp); else update_parent_effective_cpumask(cs, partcmd_update, trialcs->effective_xcpus, tmp); @@ -3916,18 +3899,21 @@ static void cpuset_hotplug_update_tasks(struct cpus= et *cs, struct tmpmasks *tmp) if (is_local_partition(cs) && (!is_partition_valid(parent) || tasks_nocpu_error(parent, cs, &new_cpus) || - cpumask_empty(subpartitions_cpus))) + cpumask_empty(subpartitions_cpus))) { partcmd =3D partcmd_invalidate; + local_partition_disable(cs, cs->prs_err, tmp); + } /* * On the other hand, an invalid partition root may be transitioned - * back to a regular one with a non-empty effective xcpus. + * back to a regular one with a non-empty user xcpus. */ else if (is_partition_valid(parent) && is_partition_invalid(cs) && - !cpumask_empty(cs->effective_xcpus)) + !cpumask_empty(user_xcpus(cs))) { partcmd =3D partcmd_update; + update_parent_effective_cpumask(cs, partcmd, NULL, tmp); + } =20 if (partcmd >=3D 0) { - update_parent_effective_cpumask(cs, partcmd, NULL, tmp); if ((partcmd =3D=3D partcmd_invalidate) || is_partition_valid(cs)) { compute_partition_effective_cpumask(cs, &new_cpus); cpuset_force_rebuild(); --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7464323406; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; cv=none; b=izMicOMiDs0KALvKsUQn8MSo7m5QdDLTRn3hOCJf372SNPQnzy6DLuT4lVN+e8bZUpEVg0q3wfqXOo7BisbTMJdCBjQwyfGODf0mL9Eh+mW2ZmwddoUQxOMcxo2XivN2wfG+3mKpaik5NBri+TfdIOxBM/s91ArHJrVUoTDAgvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; c=relaxed/simple; bh=lSjTHnOiErLSSSD/0QWpKmoJTr8DgaTsTRgROtfFXPY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FM9H+PGX3POISh6qmLDz7sZy2KF9CxOnqg3r6xd8O3sJRAwhO2eh6vbEWLGPupnUCRLeB7GxbW8YGx+7P3Zg2JVKDVh0BrAJTGuWG6a/mIMJ7DnmEAImenRKs97cwcfZIYgvE3EsCLejNbSHNaCMnHulIR6KyPqpMWiDTkyWnQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q23QlzYQv5q; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 9BAAA4058F; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S14; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 12/21] cpuset: introduce local_partition_update() Date: Thu, 25 Dec 2025 12:30:49 +0000 Message-Id: <20251225123058.231765-13-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S14 X-Coremail-Antispam: 1UD129KBjvJXoW3WFWkXr4rWrWkurW8uw18Grg_yoW3CrW8pF yUCr42q3yUKry5u343tan7Cws5Kws2qF9Fy3ZxJ3WrJFy7t34vya4jya9Ivr45XFZrG345 Za90qF4xWFy7CwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The local_partition_update() function replaces the command partcmd_update previously handled within update_parent_effective_cpumask(). The update logic follows a state-based approach: 1. Validation check: First verify if the local partition is currently valid 2. Invalidation handling: If the partition is invalid, trigger invalidation 3. State transition: If an invalid partition has no errors, transition to valid 4. cpumask updates: For local partition that only cpu maks changes, use partition_update() to handle partition change. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 151 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 146 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 8f70867a9fe4..b16b15befca7 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1743,6 +1743,62 @@ static void remote_cpus_update(struct cpuset *cs, st= ruct cpumask *xcpus, remote_partition_disable(cs, tmp); } =20 +static bool is_user_xcpus_exclusive(struct cpuset *cs) +{ + struct cpuset *parent =3D parent_cs(cs); + struct cgroup_subsys_state *css; + struct cpuset *child; + bool exclusive =3D true; + + rcu_read_lock(); + cpuset_for_each_child(child, css, parent) { + if (child =3D=3D cs) + continue; + if (!cpusets_are_exclusive(cs, child)) { + exclusive =3D false; + break; + } + } + rcu_read_unlock(); + return exclusive; +} + +/** + * validate_local_partition - Validate for local partition + * @cs: Target cpuset to validate + * @new_prs: New partition root state to validate + * @excpus: New exclusive effectuve CPUs mask to validate + * @excl_check: Flag to enable exclusive CPUs ownership validation + * @tmp: Temporary masks + * + * Return: PERR_NONE if validation passes, appropriate error code otherwise + * + * Important: The caller must ensure that @cs's cpu mask is updated before + * invoking this function when exclusive CPU validation is required. + */ +static enum prs_errcode validate_local_partition(struct cpuset *cs, int ne= w_prs, + struct cpumask *excpus, bool excl_check, struct tmpmasks *tmp) +{ + struct cpuset *parent =3D parent_cs(cs); + + /* + * The parent must be a partition root. + * The new cpumask, if present, or the current cpus_allowed must + * not be empty. + */ + if (!is_partition_valid(parent)) { + return is_partition_invalid(parent) + ? PERR_INVPARENT : PERR_NOTPART; + } + + if (excl_check && !is_user_xcpus_exclusive(cs)) + return PERR_NOTEXCL; + + if (!tmp) + return validate_partition(cs, new_prs, excpus, excpus, NULL); + return validate_partition(cs, new_prs, excpus, tmp->addmask, tmp->delmask= ); +} + /** * local_partition_enable - Enable local partition for a cpuset * @cs: Target cpuset to become a local partition root @@ -1814,6 +1870,85 @@ static void local_partition_disable(struct cpuset *c= s, enum prs_errcode part_err update_sibling_cpumasks(parent, cs, tmp); } =20 +/** + * __local_partition_update - Update local partition configuration + * @cs: Target cpuset to update + * @xcpus: New exclusive CPU mask + * @excpus: New effective exclusive CPU mask + * @tmp: Temporary mask storage for intermediate calculations + * @excl_check: Flag to enable exclusivity validation + * + * Handles updates to local CPU partition configurations by validating + * changes, managing state transitions, and propagating updates through + * the cpuset hierarchy. + * + * Note on exclusivity checking: Exclusivity validation is required when + * transitioning from an invalid to valid partition state. However, when + * updating cpus_allowed or exclusive_cpus, exclusivity should have already + * been verified by validate_change(). In such cases, excl_check must be + * false since the cs cpumasks are not yet updated. + * + * Return: Partition error code (PERR_NONE indicates success) + */ +static int __local_partition_update(struct cpuset *cs, struct cpumask *xcp= us, + struct cpumask *excpus, struct tmpmasks *tmp, + bool excl_check) +{ + struct cpuset *parent =3D parent_cs(cs); + int part_error =3D PERR_NONE; /* Partition error? */ + int old_prs, new_prs; + + lockdep_assert_held(&cpuset_mutex); + /* For local partition only */ + if (WARN_ON_ONCE(is_remote_partition(cs) || cs_is_member(cs))) + return PERR_NONE; + + old_prs =3D cs->partition_root_state; + /* + * If new_prs < 0, it might transition to valid partition state. + * Use absolute value for validation checks. + */ + new_prs =3D old_prs < 0 ? -old_prs : old_prs; + cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); + cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); + part_error =3D validate_local_partition(cs, new_prs, excpus, + excl_check, tmp); + if (part_error) { + local_partition_disable(cs, part_error, tmp); + return part_error; + } + + /* Nothing changes, return PERR_NONE */ + if (new_prs =3D=3D old_prs && + (cpumask_empty(tmp->addmask) && cpumask_empty(tmp->delmask))) + return PERR_NONE; + + /* + * If partition was previously invalid but now passes checks, + * re-enable it and update related flags. + * Otherwise, partition state doesn't change, only cpumasks change. + */ + if (is_partition_invalid(cs)) { + partition_enable(cs, parent, new_prs, excpus); + update_partition_exclusive_flag(cs, new_prs); + update_partition_sd_lb(cs, old_prs); + } else { + partition_update(cs, new_prs, xcpus, excpus, tmp); + } + + cpuset_update_tasks_cpumask(parent, tmp->addmask); + update_sibling_cpumasks(parent, cs, tmp); + return PERR_NONE; +} + +static int local_partition_update(struct cpuset *cs, struct tmpmasks *tmp) +{ + struct cpuset *parent =3D parent_cs(cs); + + cpumask_and(tmp->new_cpus, user_xcpus(cs), parent->effective_xcpus); + return __local_partition_update(cs, NULL, tmp->new_cpus, tmp, true); +} + /** * update_parent_effective_cpumask - update effective_cpus mask of parent = cpuset * @cs: The cpuset that requests change in partition root state @@ -2291,9 +2426,16 @@ static void update_cpumasks_hier(struct cpuset *cs, = struct tmpmasks *tmp, if (!css_tryget_online(&cp->css)) continue; rcu_read_unlock(); + /* + * The tmp->new_cpus may by modified. + * Update effective_cpus before passing tmp to other functions. + */ + spin_lock_irq(&callback_lock); + cpumask_copy(cp->effective_cpus, tmp->new_cpus); + spin_unlock_irq(&callback_lock); =20 if (update_parent) { - update_parent_effective_cpumask(cp, partcmd_update, NULL, tmp); + local_partition_update(cp, tmp); /* * The cpuset partition_root_state may become * invalid. Capture it. @@ -2302,7 +2444,6 @@ static void update_cpumasks_hier(struct cpuset *cs, s= truct tmpmasks *tmp, } =20 spin_lock_irq(&callback_lock); - cpumask_copy(cp->effective_cpus, tmp->new_cpus); cp->partition_root_state =3D new_prs; if (!cpumask_empty(cp->exclusive_cpus) && (cp !=3D cs)) compute_excpus(cp, cp->effective_xcpus); @@ -2491,8 +2632,8 @@ static void partition_cpus_change(struct cpuset *cs, = struct cpuset *trialcs, if (trialcs->prs_err) local_partition_disable(cs, trialcs->prs_err, tmp); else - update_parent_effective_cpumask(cs, partcmd_update, - trialcs->effective_xcpus, tmp); + __local_partition_update(cs, trialcs->exclusive_cpus, + trialcs->effective_xcpus, tmp, false); } } =20 @@ -3910,7 +4051,7 @@ static void cpuset_hotplug_update_tasks(struct cpuset= *cs, struct tmpmasks *tmp) else if (is_partition_valid(parent) && is_partition_invalid(cs) && !cpumask_empty(user_xcpus(cs))) { partcmd =3D partcmd_update; - update_parent_effective_cpumask(cs, partcmd, NULL, tmp); + local_partition_update(cs, tmp); } =20 if (partcmd >=3D 0) { --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD6743233E3; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; cv=none; b=gtYFeEMldY9uPGvZYGnChAsTiEDFtBove2ZDGBksywPuUSfihppmJpwLblzPpzOzLfSRJf5jxgqHoKJfcJrr7oDSuaBT6+UvPr9buTQrVXfn9ragrLneoYa0iDYnGTyUJBvk1rWk90uaIkt5Md1OeegIwLk/bURm7v1I6glogeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; c=relaxed/simple; bh=WHo8jbu0LlfxQ9CsK0AZuLDHg1O6GxeIvrF+IS7trcs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gkj9QldNzlvPabEHHbLL1lxeW5Hv3pgUlubxLVx7JTCLdnTuXgz2gJaAiXRtMPNHjYgeVH8hUTxY0Q4qYudr6EijM+EzxahR9du10T7G1BmjJtDfifzNsTM3xNNIaOA6caYeqS9kEB9lzIFfrUnSxyO2CpmW0cqKRi6xMeguiVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B2f4vzKHMjw; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id B4A174058C; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S15; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 13/21] cpuset: remove update_parent_effective_cpumask Date: Thu, 25 Dec 2025 12:30:50 +0000 Message-Id: <20251225123058.231765-14-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S15 X-Coremail-Antispam: 1UD129KBjvJXoW3GryxJr15Jr48AFy5ury5CFg_yoWfKrW8pr yUGrZrXFWDtr18C39Fqan7uw1rKwsFqa4qy3s8W3WfAFy7A3WvyryjyanYqFW5W3yDX34U Za90gr4fXF17AFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Clean up by removing the update_parent_effective_cpumask() function. Its logic has now been fully replaced and centralized by the new helper functions. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 282 ----------------------------------------- 1 file changed, 282 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index b16b15befca7..d4489079bff9 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1949,288 +1949,6 @@ static int local_partition_update(struct cpuset *cs= , struct tmpmasks *tmp) return __local_partition_update(cs, NULL, tmp->new_cpus, tmp, true); } =20 -/** - * update_parent_effective_cpumask - update effective_cpus mask of parent = cpuset - * @cs: The cpuset that requests change in partition root state - * @cmd: Partition root state change command - * @newmask: Optional new cpumask for partcmd_update - * @tmp: Temporary addmask and delmask - * Return: 0 or a partition root state error code - * - * For partcmd_enable*, the cpuset is being transformed from a non-partiti= on - * root to a partition root. The effective_xcpus (cpus_allowed if - * effective_xcpus not set) mask of the given cpuset will be taken away fr= om - * parent's effective_cpus. The function will return 0 if all the CPUs lis= ted - * in effective_xcpus can be granted or an error code will be returned. - * - * For partcmd_disable, the cpuset is being transformed from a partition - * root back to a non-partition root. Any CPUs in effective_xcpus will be - * given back to parent's effective_cpus. 0 will always be returned. - * - * For partcmd_update, if the optional newmask is specified, the cpu list = is - * to be changed from effective_xcpus to newmask. Otherwise, effective_xcp= us is - * assumed to remain the same. The cpuset should either be a valid or inva= lid - * partition root. The partition root state may change from valid to inval= id - * or vice versa. An error code will be returned if transitioning from - * invalid to valid violates the exclusivity rule. - * - * For partcmd_invalidate, the current partition will be made invalid. - * - * The partcmd_enable* and partcmd_disable commands are used by - * update_prstate(). An error code may be returned and the caller will che= ck - * for error. - * - * The partcmd_update command is used by update_cpumasks_hier() with newma= sk - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is u= sed - * 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, - struct tmpmasks *tmp) -{ - struct cpuset *parent =3D parent_cs(cs); - int adding; /* Adding cpus to parent's effective_cpus */ - int deleting; /* Deleting cpus from parent's effective_cpus */ - int old_prs, new_prs; - int part_error =3D PERR_NONE; /* Partition error? */ - struct cpumask *xcpus =3D user_xcpus(cs); - int parent_prs =3D parent->partition_root_state; - bool nocpu; - - lockdep_assert_held(&cpuset_mutex); - WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ - - /* - * new_prs will only be changed for the partcmd_update and - * partcmd_invalidate commands. - */ - adding =3D deleting =3D false; - old_prs =3D new_prs =3D cs->partition_root_state; - - /* - * The parent must be a partition root. - * The new cpumask, if present, or the current cpus_allowed must - * not be empty. - */ - if (!is_partition_valid(parent)) { - return is_partition_invalid(parent) - ? PERR_INVPARENT : PERR_NOTPART; - } - if (!newmask && xcpus_empty(cs)) - return PERR_CPUSEMPTY; - - nocpu =3D tasks_nocpu_error(parent, cs, xcpus); - - if (newmask) { - /* - * Empty cpumask is not allowed - */ - if (cpumask_empty(newmask)) { - part_error =3D PERR_CPUSEMPTY; - goto write_error; - } - - /* Check newmask again, whether cpus are available for parent/cs */ - nocpu |=3D tasks_nocpu_error(parent, cs, newmask); - - /* - * partcmd_update with newmask: - * - * Compute add/delete mask to/from effective_cpus - * - * For valid partition: - * addmask =3D exclusive_cpus & ~newmask - * & parent->effective_xcpus - * delmask =3D newmask & ~exclusive_cpus - * & parent->effective_xcpus - * - * For invalid partition: - * delmask =3D newmask & parent->effective_xcpus - * The partition may become valid soon. - */ - if (is_partition_invalid(cs)) { - adding =3D false; - deleting =3D cpumask_and(tmp->delmask, - newmask, parent->effective_xcpus); - } else { - cpumask_andnot(tmp->addmask, xcpus, newmask); - adding =3D cpumask_and(tmp->addmask, tmp->addmask, - parent->effective_xcpus); - - cpumask_andnot(tmp->delmask, newmask, xcpus); - deleting =3D cpumask_and(tmp->delmask, tmp->delmask, - parent->effective_xcpus); - } - - /* - * TBD: Invalidate a currently valid child root partition may - * still break isolated_cpus_can_update() rule if parent is an - * isolated partition. - */ - if (is_partition_valid(cs) && (old_prs !=3D parent_prs)) { - if ((parent_prs =3D=3D PRS_ROOT) && - /* Adding to parent means removing isolated CPUs */ - !isolated_cpus_can_update(tmp->delmask, tmp->addmask)) - part_error =3D PERR_HKEEPING; - if ((parent_prs =3D=3D PRS_ISOLATED) && - /* Adding to parent means adding isolated CPUs */ - !isolated_cpus_can_update(tmp->addmask, tmp->delmask)) - part_error =3D PERR_HKEEPING; - } - - /* - * The new CPUs to be removed from parent's effective CPUs - * must be present. - */ - if (deleting) { - cpumask_and(tmp->new_cpus, tmp->delmask, cpu_active_mask); - WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus)); - } - - /* - * Make partition invalid if parent's effective_cpus could - * become empty and there are tasks in the parent. - */ - if (nocpu && (!adding || - !cpumask_intersects(tmp->addmask, cpu_active_mask))) { - part_error =3D PERR_NOCPUS; - deleting =3D false; - adding =3D cpumask_and(tmp->addmask, - xcpus, parent->effective_xcpus); - } - } else { - /* - * partcmd_update w/o newmask - * - * delmask =3D effective_xcpus & parent->effective_cpus - * - * This can be called from: - * 1) update_cpumasks_hier() - * 2) cpuset_hotplug_update_tasks() - * - * Check to see if it can be transitioned from valid to - * invalid partition or vice versa. - * - * A partition error happens when parent has tasks and all - * its effective CPUs will have to be distributed out. - */ - if (nocpu) { - part_error =3D PERR_NOCPUS; - if (is_partition_valid(cs)) - adding =3D cpumask_and(tmp->addmask, - xcpus, parent->effective_xcpus); - } else if (is_partition_invalid(cs) && !cpumask_empty(xcpus) && - cpumask_subset(xcpus, parent->effective_xcpus)) { - struct cgroup_subsys_state *css; - struct cpuset *child; - bool exclusive =3D true; - - /* - * Convert invalid partition to valid has to - * pass the cpu exclusivity test. - */ - rcu_read_lock(); - cpuset_for_each_child(child, css, parent) { - if (child =3D=3D cs) - continue; - if (!cpusets_are_exclusive(cs, child)) { - exclusive =3D false; - break; - } - } - rcu_read_unlock(); - if (exclusive) - deleting =3D cpumask_and(tmp->delmask, - xcpus, parent->effective_cpus); - else - part_error =3D PERR_NOTEXCL; - } - } - -write_error: - if (part_error) - WRITE_ONCE(cs->prs_err, part_error); - - if (cmd =3D=3D partcmd_update) { - /* - * Check for possible transition between valid and invalid - * partition root. - */ - switch (cs->partition_root_state) { - case PRS_ROOT: - case PRS_ISOLATED: - if (part_error) - new_prs =3D -old_prs; - break; - case PRS_INVALID_ROOT: - case PRS_INVALID_ISOLATED: - if (!part_error) - new_prs =3D -old_prs; - break; - } - } - - if (!adding && !deleting && (new_prs =3D=3D old_prs)) - return 0; - - /* - * Transitioning between invalid to valid or vice versa may require - * changing CS_CPU_EXCLUSIVE. In the case of partcmd_update, - * validate_change() has already been successfully called and - * CPU lists in cs haven't been updated yet. So defer it to later. - */ - if ((old_prs !=3D new_prs) && (cmd !=3D partcmd_update)) { - int err =3D update_partition_exclusive_flag(cs, new_prs); - - if (err) - return err; - } - - /* - * Change the parent's effective_cpus & effective_xcpus (top cpuset - * only). - * - * Newly added CPUs will be removed from effective_cpus and - * newly deleted ones will be added back to effective_cpus. - */ - spin_lock_irq(&callback_lock); - if (old_prs !=3D new_prs) - cs->partition_root_state =3D new_prs; - - /* - * Adding to parent's effective_cpus means deletion CPUs from cs - * and vice versa. - */ - if (adding) - partition_xcpus_del(old_prs, parent, tmp->addmask); - if (deleting) - partition_xcpus_add(new_prs, parent, tmp->delmask); - - spin_unlock_irq(&callback_lock); - update_isolation_cpumasks(); - - if ((old_prs !=3D new_prs) && (cmd =3D=3D partcmd_update)) - update_partition_exclusive_flag(cs, new_prs); - - if (adding || deleting) { - cpuset_update_tasks_cpumask(parent, tmp->addmask); - update_sibling_cpumasks(parent, cs, tmp); - } - - /* - * For partcmd_update without newmask, it is being called from - * cpuset_handle_hotplug(). Update the load balance flag and - * scheduling domain accordingly. - */ - if ((cmd =3D=3D partcmd_update) && !newmask) - update_partition_sd_lb(cs, old_prs); - - notify_partition_change(cs, old_prs); - return 0; -} - /** * compute_partition_effective_cpumask - compute effective_cpus for partit= ion * @cs: partition root cpuset --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDDA93233ED; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; cv=none; b=Ix+6XOB9ycDUHV/tk+keUQdLtzYRGn4JBwWZncxBx18TW30vPe4EVmgQ1zkrnOWeMEL8no2i0WBfEIoGSWKgsmTfHdwfBMbJPVXlYbX+tcwcbLmNGYjl0/2Ckcxk/TINJzOAsj19IfpHcHuj7EaJ+oK2Zf7D2bseImcu+Sj5QcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; c=relaxed/simple; bh=O0AiP1pB582/fo2zZeuRTypP7jALMr7OFyyfUAKucY8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WaEsKliqgzcQ/xZ8P/Dd3axedF6Mw3a4O4fTIvx/Av6hMRPhxSsNqhNcOd349dFQC11ZpBv3PGyJ2ISUbeM68rEij7kSDeBelpA/M2Pj8Gd+qVSu+EHdOwjDkuUCf57CIqAM0hp+niYrrgMD8LOxuWSEQSqCmam02swC6gYlAxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B38gRzKHMjq; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id C47CA4056B; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S16; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 14/21] cpuset: remove redundant partition field updates Date: Thu, 25 Dec 2025 12:30:51 +0000 Message-Id: <20251225123058.231765-15-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S16 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw18JF47CFy3KF1rCw4xCrg_yoW8CF1rpF WDurW7trWYgryrC39rGan2gr15KanFqa4DtFnrJw1rCFy7C3Wq9Fyqq390vF1jq3srCr4U ZFn0vrWSv3ZrurDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong With the previous patch series, partition-related fields are now properly managed during partition enable, disable, and update operations. There should be no need to set these fields outside of these dedicated partition operations. This patch removes the redundant partition field updates from the cpumask setting code path. However, one exception remains: when setting cpuset.cpus.exclusive on a non-partition cpuset, update_exclusive_cpumask() must still set effective_xcpus directly. This is necessary because no partition operation is invoked in this scenario, yet effective_xcpus needs to be properly initialized. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d4489079bff9..a1df78a75575 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2397,9 +2397,6 @@ static int update_cpumask(struct cpuset *cs, struct c= puset *trialcs, =20 spin_lock_irq(&callback_lock); cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed); - cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); - if ((old_prs > 0) && !is_partition_valid(cs)) - reset_partition_data(cs); spin_unlock_irq(&callback_lock); =20 /* effective_cpus/effective_xcpus will be updated here */ @@ -2463,8 +2460,6 @@ static int update_exclusive_cpumask(struct cpuset *cs= , struct cpuset *trialcs, spin_lock_irq(&callback_lock); cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus); cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); - if ((old_prs > 0) && !is_partition_valid(cs)) - reset_partition_data(cs); spin_unlock_irq(&callback_lock); =20 /* --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D731C2AD2C; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; cv=none; b=tlfszMXno2h+xg59ZclrQcmT2arGl8fW8vY0EoLgwIpCUDT/0iTLGJ7l57bzNZGFjLjnhkjn6rWn9aM6vNx9GTzDvZFN6oNhnx6YO8igP/kNqLuRSwXnKw6uFCtprITKmy4cl7AA8Hd3Uw8jG8KYvQHYrgigWayo8E2ZwO+kNPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; c=relaxed/simple; bh=dDqQHo/kcKiA+eNZqCMpoFB91WRsN40u0+GqFcg8384=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T4TMVDIHlOo2zHHw+Y8yM7kC08GwEPLpqx+1vA7deM6vrNRiqdhbusM4ZTqXFG9kH2wbcVnSDeZrj4HF2c9VBNekTjoLCDgJ6AEEOfTie9J1xXPtpMXEMoecohJCoykwy/6HiN11jKytpORWeRxMYH4YDuwRqAERnwL8CZVthas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q3sHMzYQv6Q; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id DB0FD40575; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S17; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 15/21] cpuset: simplify partition update logic for hotplug tasks Date: Thu, 25 Dec 2025 12:30:52 +0000 Message-Id: <20251225123058.231765-16-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S17 X-Coremail-Antispam: 1UD129KBjvJXoW3Xr48Gw18GrWUtr4DWw48JFb_yoW7WFWfpF y3CrW7tayUGr1YkasxJFs7A3yrKwn7JF1qy3ZxJ3yrJF17Zw1vyFyjk395Zay5X34DXryU Za4DWr4xXF17ArDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Simplify the partition update logic in cpuset_hotplug_update_tasks() by calling the unified local_partition_update() interface. For local partitions, the previous patch introduced local_partition_update which handles both validation state transitions: - Invalidates local partitions that fail validation checks - Transitions invalid partitions to valid state when no errors are detected This eliminates the need for separate transition logic in cpuset_hotplug_update_tasks(), which can now simply call local_partition_update() to handle all local partition changes. For remote partitions, the logic is adjusted to always proceed to update_tasks regardless of whether the partition was disabled, as the original skip condition was not valid for remote partitions. This change maintains existing functionality while simplifying the code path. The partition_cmd emum type can now be safely removed as it is no longer referenced by any code paths after the partition update logic simplification. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 75 ++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a1df78a75575..99413472a0fb 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1072,17 +1072,6 @@ static void compute_effective_cpumask(struct cpumask= *new_cpus, cpumask_and(new_cpus, cs->cpus_allowed, parent->effective_cpus); } =20 -/* - * Commands for update_parent_effective_cpumask - */ -enum partition_cmd { - partcmd_enable, /* Enable partition root */ - partcmd_enablei, /* Enable isolated partition root */ - partcmd_disable, /* Disable partition root */ - partcmd_update, /* Update parent's effective_cpus */ - partcmd_invalidate, /* Make partition invalid */ -}; - static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *= cs, struct tmpmasks *tmp); =20 @@ -3701,8 +3690,6 @@ static void cpuset_hotplug_update_tasks(struct cpuset= *cs, struct tmpmasks *tmp) static nodemask_t new_mems; bool cpus_updated; bool mems_updated; - bool remote; - int partcmd =3D -1; struct cpuset *parent; retry: wait_event(cpuset_attach_wq, cs->attach_in_progress =3D=3D 0); @@ -3729,50 +3716,38 @@ static void cpuset_hotplug_update_tasks(struct cpus= et *cs, struct tmpmasks *tmp) * Compute effective_cpus for valid partition root, may invalidate * child partition roots if necessary. */ - remote =3D is_remote_partition(cs); - if (remote || (is_partition_valid(cs) && is_partition_valid(parent))) + if (is_remote_partition(cs)) { compute_partition_effective_cpumask(cs, &new_cpus); - - if (remote && (cpumask_empty(subpartitions_cpus) || - (cpumask_empty(&new_cpus) && - partition_is_populated(cs, NULL)))) { - cs->prs_err =3D PERR_HOTPLUG; - remote_partition_disable(cs, tmp); - compute_effective_cpumask(&new_cpus, cs, parent); - remote =3D false; + if (cpumask_empty(subpartitions_cpus) || + (cpumask_empty(&new_cpus) && + partition_is_populated(cs, NULL))) { + cs->prs_err =3D PERR_HOTPLUG; + remote_partition_disable(cs, tmp); + compute_effective_cpumask(&new_cpus, cs, parent); + } + goto update_tasks; } =20 /* - * Force the partition to become invalid if either one of - * the following conditions hold: - * 1) empty effective cpus but not valid empty partition. - * 2) parent is invalid or doesn't grant any cpus to child - * partitions. - * 3) subpartitions_cpus is empty. - */ - if (is_local_partition(cs) && - (!is_partition_valid(parent) || - tasks_nocpu_error(parent, cs, &new_cpus) || - cpumask_empty(subpartitions_cpus))) { - partcmd =3D partcmd_invalidate; - local_partition_disable(cs, cs->prs_err, tmp); - } - /* - * On the other hand, an invalid partition root may be transitioned - * back to a regular one with a non-empty user xcpus. + * The subpartitions_cpus may be cleared if no CPUs remain available for + * the top_cpuset. In this case, disable the local partition directly. + * Otherwise, local_partition_update will handle the automatic transition + * between valid and invalid partition states. */ - else if (is_partition_valid(parent) && is_partition_invalid(cs) && - !cpumask_empty(user_xcpus(cs))) { - partcmd =3D partcmd_update; + if (is_local_partition(cs) && cpumask_empty(subpartitions_cpus)) + local_partition_disable(cs, PERR_HOTPLUG, tmp); + else local_partition_update(cs, tmp); - } =20 - if (partcmd >=3D 0) { - if ((partcmd =3D=3D partcmd_invalidate) || is_partition_valid(cs)) { - compute_partition_effective_cpumask(cs, &new_cpus); - cpuset_force_rebuild(); - } - } + /* + * Recompute effective CPU mask after partition state update: + * - For valid partitions: calculate partition-specific effective CPUs + * - For invalid partitions: compute member effective CPU mask + */ + if (is_partition_valid(cs)) + compute_partition_effective_cpumask(cs, &new_cpus); + else + compute_effective_cpumask(&new_cpus, cs, parent); =20 update_tasks: cpus_updated =3D !cpumask_equal(&new_cpus, cs->effective_cpus); --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4F603242D2; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; cv=none; b=cawuPA31nWPDTV8W7RNdO4Mib8NMc/s40joGqXXCSx/QarD84zLlQGd3s3+qaGB2tZNZLQ9aMiulH/H+lB8gAOJ90taIzcP2OnXE52iCtrafSQeQuQpKblLWeod2rADRAibYM02HHtKAJIWa2PtlrrwWi6R7YC9e6Yp6HUnSkfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; c=relaxed/simple; bh=6LpipWrKZ2mLS6tvyQUvySD/o77gRSK+J41HB0jNX5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HdaU178Cqcf1uzCNO0ZqB+Q53ITz9CfwU4jAPrMd1/S0nYL2eHk+W/A7IZVVqw/qnBL1g186k9xy3BGOPqsn6UPSbgKWRY4wZTMbs4YHCunY+l3CKTjD2eqRXd7vli1aXhVAUsbtiY+GvbEqf8BDOnPIT/6QJ/syefLtxGz8Rto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B4G3lzKHMkB; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id E93D240577; Thu, 25 Dec 2025 20:45:51 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S18; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 16/21] cpuset: use partition_disable for compute_partition_effective_cpumask Date: Thu, 25 Dec 2025 12:30:53 +0000 Message-Id: <20251225123058.231765-17-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S18 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFWkZF15Ary5Jw45Xw1DJrb_yoW8KF43pF n7Ar47GFWUX345u3y7ta97uw15Gws2q3Wqyr13Xw1fXFy2y3Z0ya42yaySqrWjqr97W34U Z3Z0qr4xKan7CFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Replace the partition invalidation logic in the compute_partition_effective_cpumask() with a call to partition_disable(). This centralizes partition state management and ensures consistent handling of partition disable operations throughout the cpuset subsystem. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 99413472a0fb..96a82a3e9add 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -174,15 +174,6 @@ static inline bool cs_is_member(const struct cpuset *c= s) return cs->partition_root_state =3D=3D PRS_MEMBER; } =20 -/* - * Callers should hold callback_lock to modify partition_root_state. - */ -static inline void make_partition_invalid(struct cpuset *cs) -{ - if (cs->partition_root_state > 0) - cs->partition_root_state =3D -cs->partition_root_state; -} - /* * Send notification event of whenever partition_root_state changes. */ @@ -1960,6 +1951,7 @@ static void compute_partition_effective_cpumask(struc= t cpuset *cs, struct cgroup_subsys_state *css; struct cpuset *child; bool populated =3D partition_is_populated(cs, NULL); + enum prs_errcode prs_err; =20 /* * Check child partition roots to see if they should be @@ -1982,24 +1974,17 @@ static void compute_partition_effective_cpumask(str= uct cpuset *cs, * partition root. */ WARN_ON_ONCE(is_remote_partition(child)); - child->prs_err =3D 0; + prs_err =3D 0; if (!cpumask_subset(child->effective_xcpus, cs->effective_xcpus)) - child->prs_err =3D PERR_INVCPUS; + prs_err =3D PERR_INVCPUS; else if (populated && cpumask_subset(new_ecpus, child->effective_xcpus)) - child->prs_err =3D PERR_NOCPUS; - - if (child->prs_err) { - int old_prs =3D child->partition_root_state; + prs_err =3D PERR_NOCPUS; =20 - /* - * Invalidate child partition - */ - spin_lock_irq(&callback_lock); - make_partition_invalid(child); - spin_unlock_irq(&callback_lock); - notify_partition_change(child, old_prs); + if (prs_err) { + partition_disable(child, cs, -child->partition_root_state, + prs_err); continue; } cpumask_andnot(new_ecpus, new_ecpus, --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D88DC323416; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; cv=none; b=ZM3xV1yi7knvnbJ4nZc4S+TomwLr4YPLBckZqtvx0Gr8Vf1WdBl3L7s230XC/7is5wtw2aX6JjpnFbXmQLB3wQu3z4jDoHH1x1YeQtCm3Na45371QOX5aM7grl5XGJ3Iww87RhdVEExz32I/B3iFBVfV0zr4S93dYBZSztnsj28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; c=relaxed/simple; bh=Iy91mrmJo/8w0ZsPcBJ6E2mEaG54jDurlR/SQr4Vze4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sHo7DETz0JD/ammDFwyN2A4OP+oj2Z+FuFd55cTw55yAOKolVgV+UKuhO4vlN+ZEz9arrigdjcwjpU5Of056zVQAmWVgUCyQTRZ3hocelvP8X/5bGYDehMxLvXV/mHgyWD7i32qmVRYhLVBUEJ7VjqZqr19oESrW0II7PhnrAr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B4dxBzKHMkB; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 01B134056B; Thu, 25 Dec 2025 20:45:52 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S19; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 17/21] cpuset: use validate_local_partition in local_partition_enable Date: Thu, 25 Dec 2025 12:30:54 +0000 Message-Id: <20251225123058.231765-18-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S19 X-Coremail-Antispam: 1UD129KBjvJXoW7Zr47Kw4ruFW3WF1DCF1kGrg_yoW8Xr17pF n3KrWxG3y5GF15C39rJan29ws3KwsrtF1jy3Zxt3yrXF17J3WDKFy8t3yDAw1jqFZrCr15 XFy3Zr4Iga42k37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Replace the partition error checks within `local_partition_enable()` by utilizing the common `validate_local_partition()` function. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 96a82a3e9add..183975c86d0c 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1796,16 +1796,6 @@ static int local_partition_enable(struct cpuset *cs, lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ =20 - /* - * The parent must be a partition root. - * The new cpumask, if present, or the current cpus_allowed must - * not be empty. - */ - if (!is_partition_valid(parent)) { - return is_partition_invalid(parent) - ? PERR_INVPARENT : PERR_NOTPART; - } - /* * Need to call compute_excpus() in case * exclusive_cpus not set. Sibling conflict should only happen @@ -1814,7 +1804,7 @@ static int local_partition_enable(struct cpuset *cs, if (compute_excpus(cs, tmp->new_cpus)) WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus)); =20 - err =3D validate_partition(cs, new_prs, tmp->new_cpus, tmp->new_cpus, NUL= L); + err =3D validate_local_partition(cs, new_prs, tmp->new_cpus, false, NULL); if (err) return err; =20 --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 485ED19D8AC; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666763; cv=none; b=tgZ8v93UpRzWM/VQvwXkPv4GRXJIF1BWb+J20khZlTRuVVbhifC1HBBk8RW2wWqjXf2vqPeaSUxdBDdYgfrjdD1NMq5skDv3o3rsS7Vj+sdUGT6/OjtuCxC7U3pUskzrqI5q1OY6ZJKsvYnmEWZQuYKqDbFAWqhaW9hIBC2bMg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666763; c=relaxed/simple; bh=jIoHEZruMC6rQrpAdDaA2ixzAXbwvcARUL0amQaZ/Qk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rpXHOblgAnvkQAfHXnQ9H0uDabcc6BsUSN8OLJc2khFvoe2ceBNpcY6bKQhOIeJnmGRBRRun65zkzq46g54qoi2frnCskPdKxj5XpfpSHiy1rAE3dXuYmsLAevBqlEMmSe4alt2ncp5wRCSK8GCbzjLJ/NhPA4pLkT/Pz/NENRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q5FTjzYQv6s; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 159634056E; Thu, 25 Dec 2025 20:45:52 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S20; Thu, 25 Dec 2025 20:45:51 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 18/21] cpuset: introduce validate_remote_partition Date: Thu, 25 Dec 2025 12:30:55 +0000 Message-Id: <20251225123058.231765-19-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S20 X-Coremail-Antispam: 1UD129KBjvJXoW3XF4rtr15Gr4UuryxtF17Awb_yoW3Kw1xpF y7Gr4xKFWUJr15C34UJan7uwn5KwsrtF9Fyw13X3ySvFy7A34vyFyjk390ya4UW3srW345 Za90gr47WFy7AwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong This introduces validate_remote_partition() to consolidate validation logic for remote partition operations. It will be used by both remote_partition_enable() and remote_partition_disable(). The new function performs the following checks: 1. Privilege requirement: only CAP_SYS_ADMIN can add CPUs to a remote partition. 2. Conflict check: ensure added CPUs are not in any existing sub-partitions and that there is at least one online CPU in the excluded mask. 3. Resource check: prevent allocating all top cpuset's effective CPUs to remote partitions. 4. Common partition validation. Additionally, this patch adds error handling for remote_partition_disable() so that cs->prs_err can be updated centrally. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 118 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 183975c86d0c..9a7b02d79fee 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1583,6 +1583,47 @@ static void partition_update(struct cpuset *cs, int = prs, struct cpumask *xcpus, notify_partition_change(cs, old_prs); } =20 +/** + * validate_remote_partition - Validate for remote partition + * @cs: Target cpuset to validate + * @new_prs: New partition root state to validate + * @excpus: New exclusive effectuve CPUs mask to validate + * @add: exclusive CPUs to be added + * @del: exclusive CPUs to be deleted, can be NULL + * + * Return: PERR_NONE if validation passes, appropriate error code otherwise + */ +static enum prs_errcode validate_remote_partition(struct cpuset *cs, + int new_prs, struct cpumask *excpus, struct cpumask *add, struct cpumask = *del) +{ + /* + * The user must have sysadmin privilege. + */ + if (!cpumask_empty(add) && !capable(CAP_SYS_ADMIN)) + return PERR_ACCESS; + + /* + * Additions of remote CPUs is only allowed if those CPUs are + * not allocated to other partitions and there are effective_cpus + * left in the top cpuset. + * + * The effective_xcpus mask can contain offline CPUs, but there must + * be at least one or more online CPUs present before it can be enabled. + */ + if (cpumask_intersects(add, subpartitions_cpus) || + !cpumask_intersects(excpus, cpu_active_mask)) + return PERR_INVCPUS; + + /* + * It is not allowed that all effective_cpus of top_cpuset are + * distributed remote partition + */ + if (cpumask_subset(top_cpuset.effective_cpus, excpus)) + return PERR_NOCPUS; + + return validate_partition(cs, new_prs, excpus, add, del); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update @@ -1596,31 +1637,15 @@ static void partition_update(struct cpuset *cs, int= prs, struct cpumask *xcpus, static int remote_partition_enable(struct cpuset *cs, int new_prs, struct tmpmasks *tmp) { - /* - * The user must have sysadmin privilege. - */ - if (!capable(CAP_SYS_ADMIN)) - return PERR_ACCESS; =20 - /* - * The requested exclusive_cpus must not be allocated to other - * partitions and it can't use up all the root's effective_cpus. - * - * The effective_xcpus mask can contain offline CPUs, but there must - * be at least one or more online CPUs present before it can be enabled. - * - * Note that creating a remote partition with any local partition root - * above it or remote partition root underneath it is not allowed. - */ + enum prs_errcode err; + compute_excpus(cs, tmp->new_cpus); WARN_ON_ONCE(cpumask_intersects(tmp->new_cpus, subpartitions_cpus)); - if (!cpumask_intersects(tmp->new_cpus, cpu_active_mask) || - cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) - return PERR_INVCPUS; - if (((new_prs =3D=3D PRS_ISOLATED) && - !isolated_cpus_can_update(tmp->new_cpus, NULL)) || - prstate_housekeeping_conflict(new_prs, tmp->new_cpus)) - return PERR_HKEEPING; + err =3D validate_remote_partition(cs, new_prs, tmp->new_cpus, + tmp->new_cpus, NULL); + if (err) + return err; =20 partition_enable(cs, NULL, new_prs, tmp->new_cpus); /* @@ -1640,7 +1665,8 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, * * cpuset_mutex must be held by the caller. */ -static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *t= mp) +static void remote_partition_disable(struct cpuset *cs, + enum prs_errcode prs_err, struct tmpmasks *tmp) { int new_prs; =20 @@ -1654,8 +1680,8 @@ static void remote_partition_disable(struct cpuset *c= s, struct tmpmasks *tmp) WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus) && !cpumask_empty(subpartitions_cpus)); =20 - new_prs =3D cs->prs_err ? -cs->partition_root_state : PRS_MEMBER; - partition_disable(cs, NULL, new_prs, cs->prs_err); + new_prs =3D prs_err ? -cs->partition_root_state : PRS_MEMBER; + partition_disable(cs, NULL, new_prs, prs_err); =20 /* * Propagate changes in top_cpuset's effective_cpus down the hierarchy. @@ -1677,39 +1703,19 @@ static void remote_partition_disable(struct cpuset = *cs, struct tmpmasks *tmp) static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, struct cpumask *excpus, struct tmpmasks *tmp) { - int prs =3D cs->partition_root_state; + enum prs_errcode err; =20 if (WARN_ON_ONCE(!is_remote_partition(cs))) return; =20 WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus)); - - if (cpumask_empty(excpus)) { - cs->prs_err =3D PERR_CPUSEMPTY; - goto invalidate; - } - cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); =20 - /* - * Additions of remote CPUs is only allowed if those CPUs are - * not allocated to other partitions and there are effective_cpus - * left in the top cpuset. - */ - if (!cpumask_empty(tmp->addmask)) { - WARN_ON_ONCE(cpumask_intersects(tmp->addmask, subpartitions_cpus)); - if (!capable(CAP_SYS_ADMIN)) - cs->prs_err =3D PERR_ACCESS; - else if (cpumask_intersects(tmp->addmask, subpartitions_cpus) || - cpumask_subset(top_cpuset.effective_cpus, tmp->addmask)) - cs->prs_err =3D PERR_NOCPUS; - else if ((prs =3D=3D PRS_ISOLATED) && - !isolated_cpus_can_update(tmp->addmask, tmp->delmask)) - cs->prs_err =3D PERR_HKEEPING; - if (cs->prs_err) - goto invalidate; - } + err =3D validate_remote_partition(cs, cs->partition_root_state, excpus, + tmp->addmask, tmp->delmask); + if (err) + return remote_partition_disable(cs, err, tmp); =20 partition_update(cs, cs->partition_root_state, xcpus, excpus, tmp); /* @@ -1718,9 +1724,6 @@ static void remote_cpus_update(struct cpuset *cs, str= uct cpumask *xcpus, cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus); update_sibling_cpumasks(&top_cpuset, NULL, tmp); return; - -invalidate: - remote_partition_disable(cs, tmp); } =20 static bool is_user_xcpus_exclusive(struct cpuset *cs) @@ -2302,11 +2305,11 @@ static void partition_cpus_change(struct cpuset *cs= , struct cpuset *trialcs, prs_err =3D validate_partition(cs, trialcs->partition_root_state, trialcs->effective_xcpus, trialcs->effective_xcpus, NULL); if (prs_err) - trialcs->prs_err =3D cs->prs_err =3D prs_err; + trialcs->prs_err =3D prs_err; =20 if (is_remote_partition(cs)) { if (trialcs->prs_err) - remote_partition_disable(cs, tmp); + remote_partition_disable(cs, trialcs->prs_err, tmp); else remote_cpus_update(cs, trialcs->exclusive_cpus, trialcs->effective_xcpus, tmp); @@ -2846,7 +2849,7 @@ static int update_prstate(struct cpuset *cs, int new_= prs) * disables child partitions. */ if (is_remote_partition(cs)) - remote_partition_disable(cs, &tmpmask); + remote_partition_disable(cs, PERR_NONE, &tmpmask); else local_partition_disable(cs, PERR_NONE, &tmpmask); /* @@ -3696,8 +3699,7 @@ static void cpuset_hotplug_update_tasks(struct cpuset= *cs, struct tmpmasks *tmp) if (cpumask_empty(subpartitions_cpus) || (cpumask_empty(&new_cpus) && partition_is_populated(cs, NULL))) { - cs->prs_err =3D PERR_HOTPLUG; - remote_partition_disable(cs, tmp); + remote_partition_disable(cs, PERR_HOTPLUG, tmp); compute_effective_cpumask(&new_cpus, cs, parent); } goto update_tasks; --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D89C23242A4; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; cv=none; b=cXFh0pqAYlGO+da2WixjNKoi9pbc6s+ZU2xWX/cd3zqyaBM/Fjdrmocp9qkYs/iKs0ioc4B0efhdI7Os/lCwH2GRnDPaJKpC4g5srbctKUPutEoTB1a64/2+w6GlZae4WNn/lmETCNEpBvtEI2HkDWeDejjmFOcVNxW4NiHjpMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666760; c=relaxed/simple; bh=MXyGhiP8Ypkw+qa7sBXRPy6LWOA4tDDAUtV6YiFZV+c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ualMs+ytKwFBrud10A0b3RuZMRUdr+y/UHheLJUs6j2mLfT2jRFZtJWBjBB90dF1gyBuHBBU18pkIl0pYY1SWaHh3vNP3Z85PWeBpDFQZ9wD9a8SEtHttYFUDsc7eAR5j67r9mq3CD1Ga+Dl+5lnjC/3K/swRj9dBhL8jczjxiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.198]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dcT4B5hDczKHMlT; Thu, 25 Dec 2025 20:45:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 25E6B40574; Thu, 25 Dec 2025 20:45:52 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S21; Thu, 25 Dec 2025 20:45:52 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 19/21] cpuset: simplify the update_prstate() function Date: Thu, 25 Dec 2025 12:30:56 +0000 Message-Id: <20251225123058.231765-20-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S21 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyxZw47Zw43Jw4xGry7Awb_yoWrWrWfpr yYkFWIgFWUtr15u3s8Gan7uw4Fgw4ktFyjyr9xW34rX3W2yas29Fyjy39ayay5WF9rG3y5 Z3Z0gr48GF47AwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong This patch introduces partition_switch to handle both local partition and remote partition root state switches between "root" and "isolated". It first validates the partition viavalidate_partition() to check its validity. If validation fails, it returns an error and disables the partition; if validation passes, it enables the partition with the new root state. With partition_switch introduced, update_prstate() can be simplified. The partition-related assignments in update_prstate() are redundant, as these operations are already handled by partition_enable() and partition_disable(). They are therefore removed. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 58 +++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9a7b02d79fee..7f46cead4d97 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1538,6 +1538,24 @@ static void partition_disable(struct cpuset *cs, str= uct cpuset *parent, notify_partition_change(cs, old_prs); } =20 +static int partition_switch(struct cpuset *cs, int new_prs) +{ + enum prs_errcode err; + struct cpuset *parent; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(new_prs < 0 || !is_partition_valid(cs)); + WARN_ON_ONCE(!cpuset_v2()); + + err =3D validate_partition(cs, new_prs, cs->effective_cpus, + cs->effective_cpus, NULL); + if (err) + return err; + parent =3D is_remote_partition(cs) ? NULL : parent_cs(cs); + partition_enable(cs, parent, new_prs, cs->effective_cpus); + return 0; +} + /** * partition_update - Update an existing partition configuration * @cs: The cpuset to update @@ -2784,7 +2802,6 @@ static int update_prstate(struct cpuset *cs, int new_= prs) int err =3D PERR_NONE, old_prs =3D cs->partition_root_state; struct cpuset *parent =3D parent_cs(cs); struct tmpmasks tmpmask; - bool isolcpus_updated =3D false; =20 if (old_prs =3D=3D new_prs) return 0; @@ -2833,16 +2850,8 @@ static int update_prstate(struct cpuset *cs, int new= _prs) else err =3D remote_partition_enable(cs, new_prs, &tmpmask); } else if (old_prs && new_prs) { - /* - * A change in load balance state only, no change in cpumasks. - * Need to update isolated_cpus. - */ - if (((new_prs =3D=3D PRS_ISOLATED) && - !isolated_cpus_can_update(cs->effective_xcpus, NULL)) || - prstate_housekeeping_conflict(new_prs, cs->effective_xcpus)) - err =3D PERR_HKEEPING; - else - isolcpus_updated =3D true; + /* Root state switches, eg, root --> isolated */ + err =3D partition_switch(cs, new_prs); } else { /* * Switching back to member is always allowed even if it @@ -2858,36 +2867,15 @@ static int update_prstate(struct cpuset *cs, int ne= w_prs) */ } out: - /* - * Make partition invalid & disable CS_CPU_EXCLUSIVE if an error - * happens. - */ - if (err) { - new_prs =3D -new_prs; - update_partition_exclusive_flag(cs, new_prs); - } - - spin_lock_irq(&callback_lock); - cs->partition_root_state =3D new_prs; - WRITE_ONCE(cs->prs_err, err); - if (!is_partition_valid(cs)) - reset_partition_data(cs); - else if (isolcpus_updated) - isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus); - spin_unlock_irq(&callback_lock); - update_isolation_cpumasks(); + /* Make partition invalid if an error happens */ + if (err) + partition_disable(cs, parent, -new_prs, err); =20 /* Force update if switching back to member & update effective_xcpus */ update_cpumasks_hier(cs, &tmpmask, !new_prs); =20 - /* A newly created partition must have effective_xcpus set */ - WARN_ON_ONCE(!old_prs && (new_prs > 0) - && cpumask_empty(cs->effective_xcpus)); - /* Update sched domains and load balance flag */ update_partition_sd_lb(cs, old_prs); - - notify_partition_change(cs, old_prs); if (force_sd_rebuild) rebuild_sched_domains_locked(); free_tmpmasks(&tmpmask); --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4866E3246EC; Thu, 25 Dec 2025 12:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; cv=none; b=jN1Y0rWrcFVvJOG5Hy8rHblHsJfjs8mU/TaPCNXpVJX9Ixt85MZfQe3b1DN06dcW8XCsCt7ZZndf50yV5H7sOJVfPX/eDPJa2rlTHEGieV5aw2wNlV2jtvct31AJmU7KS76SMQnB/hbQ33bR2G2D2HC6/a/i0rBsi3UpLOP3VlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666761; c=relaxed/simple; bh=mdTbDxTnHTde/DH21CpI4AmcTJ6C4aF/nojVer3foSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=duZ45ILK64hPM8fDa7mAygoIUpyma6CN9i8pr10sVs2aw07zR+bhQP/a7vScIoJBKBRtFgBL8xGEe3G9Vad3+m6pfyHpNpDBBoLXxnefQ/weiVjAYgi5XdmNLdujbInYc803u1S8sPtqSSQl8CCZb9S8Vv86xFwMJRj0jEaJ61s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.170]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q65VDzYQv6Q; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 3242C4056F; Thu, 25 Dec 2025 20:45:52 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S22; Thu, 25 Dec 2025 20:45:52 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 20/21] cpuset: remove prs_err clear when notify_partition_change Date: Thu, 25 Dec 2025 12:30:57 +0000 Message-Id: <20251225123058.231765-21-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S22 X-Coremail-Antispam: 1UD129KBjvdXoWrtFyfCw48uryktw4fWry3Jwb_yoW3uFcE93 409r1vqryrXFyIg3WYka1SqrWvya1UAr1vyas0qrW5AF12kwn3WwnFqr98Jrn8Za1xXrnx Aas3GFZa9FsFqjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbDkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v26r126r 1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbx9NDUU UUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The prs_err should be properly set when partition state is set, it does't have to reset in the notify_partition_change, just remove it. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 7f46cead4d97..23c0ad5ed37e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -182,10 +182,6 @@ static inline void notify_partition_change(struct cpus= et *cs, int old_prs) if (old_prs =3D=3D cs->partition_root_state) return; cgroup_file_notify(&cs->partition_file); - - /* Reset prs_err if not invalid */ - if (is_partition_valid(cs)) - WRITE_ONCE(cs->prs_err, PERR_NONE); } =20 /* --=20 2.34.1 From nobody Mon Feb 9 03:52:33 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70B5F324B09; Thu, 25 Dec 2025 12:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; cv=none; b=bVPsg/mmtCueo+OOqLOVGdog64Roj7CZRfdgV3gkMq6qU0cI5MUJ5Friit1VlxzyS8uaLy5pyv0rEdKjFhgIWq0peTn4hBQG1uNPtMuT+gClg6Ahl40nVAegDU6UNWwQbWE5d37XfPKH2X17d2qjzFuNgttV/O4XxNv5dZhjB6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766666762; c=relaxed/simple; bh=ZmXqgYU/gemj/ulTXbBoRMrTqgoYM8aqWNWTHB79w00=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cG1EXhlNhaPd8J4KwwAb7r/jMLwSdTSoEQ2FoZY3xfKMOIKOO1meHAXGRzgaSEePvhiSJthrmqWNkJvwqrKtCKkenYM13I38zrovNX48F7w4IyJLk3tgGCfXy1LY2gMfTyFjPAM0lIazjDAUhKfricGkbeOYSWvjCuUxYkvY9mI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4dcT3q6K4tzYQv71; Thu, 25 Dec 2025 20:45:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 3CCC34058C; Thu, 25 Dec 2025 20:45:52 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgDHdfb1MU1pT76_BQ--.27441S23; Thu, 25 Dec 2025 20:45:52 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huaweicloud.com Subject: [PATCH RESEND -next 21/21] cpuset: Remove unnecessary validation in partition_cpus_change Date: Thu, 25 Dec 2025 12:30:58 +0000 Message-Id: <20251225123058.231765-22-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251225123058.231765-1-chenridong@huaweicloud.com> References: <20251225123058.231765-1-chenridong@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHdfb1MU1pT76_BQ--.27441S23 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw47tw4UXrW7Kw4DXryrWFg_yoW8Jw4kpF y7Gr4UGay5Wr1jkayDJas293s8K3ZrZF1UtFnxJa4fWF12qa4qka4jy39xZFyfXF9rCa48 Z3ZIvr4qgFW2y37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AKxVWUAV WUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr 1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvYLPU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong When user-configured CPUs (including cpuset.cpus and cpuset.cpus.exclusive) are modified, the partition may either be disabled or updated. Both local and remote partitions update can fully validate their own validity: if the validation fails, the partition will be disabled. Therefore, the validationin partition_cpus_change is redundant and can be removed. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 23c0ad5ed37e..87decf96a577 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2311,16 +2311,9 @@ static int cpus_allowed_validate_change(struct cpuse= t *cs, struct cpuset *trialc static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialc= s, struct tmpmasks *tmp) { - enum prs_errcode prs_err; - if (cs_is_member(cs)) return; =20 - prs_err =3D validate_partition(cs, trialcs->partition_root_state, - trialcs->effective_xcpus, trialcs->effective_xcpus, NULL); - if (prs_err) - trialcs->prs_err =3D prs_err; - if (is_remote_partition(cs)) { if (trialcs->prs_err) remote_partition_disable(cs, trialcs->prs_err, tmp); --=20 2.34.1