From nobody Wed Oct 1 21:23:22 2025 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 7ED712BE631 for ; Sun, 28 Sep 2025 07:29:02 +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=1759044544; cv=none; b=aLo2G+tUhw17CsqMEqdCa2Pm2V1gJLBq6wviVxkmSKv7byMCwpjG7IoSl7XceGs0H7wLzbNJ2la/EnckN8UlUso2zUSZH5bc4948gkREvqpZcTd6pinvDLJG0NZ2ksPJAV8epdaxKLjLg0q8DNiwzinFNrtKUaXhyCrEkK0M0aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044544; c=relaxed/simple; bh=UPE/Fq93EsTvybhJhC6i4JhGmkmhzfL1i+enUm6fsx8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ncTmlevmyHHF5SM9CcvfI7XEflkYdKRV6aNnSEkgfSntwzT7B9tbL4HL2eLoMHJRLG5H+RBgHvwH97vNpb4y1sN+JaCgR0DcYUx1UGPUv6+PSFOr2EBPCSHl0agTNalPYAPJENTvwdnUYVw8+fNTWiRKHAWMFQ44MlijB3EEruw= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCD5gbrzYQvf8; Sun, 28 Sep 2025 15:28:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id AAB1B1A1718; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S3; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 01/16] cpuset: use update_partition_sd_lb in update_cpumasks_hier Date: Sun, 28 Sep 2025 07:12:51 +0000 Message-Id: <20250928071306.3797436-2-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr18WF1DGF45JF48CF1rJFb_yoW8ZF1rpF 9FkayxJa1Y9r1UC34UZan29ryfXa1kXFy5t3ZxtF1rJF13ta1YyFyv9a93JFWUKF90kF1U Ar1q9r42g3ZYyrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Kb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr4 1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK 67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI 8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU7qjgUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong For cgroup v2, when a cpuset is not a valid partition root, it inherits the CS_SCHED_LOAD_BALANCE flag from its parent. The existing logic in update_cpumasks_hier() manually handled this inheritance condition. This patch replaces the inline implementation with a call to the dedicated update_partition_sd_lb() helper function, which already encapsulates the same logic. The helper function comprehensively handles both the load balance flag update and the necessary scheduling domain rebuild decision. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 52468d2c178a..052f9e0c7a65 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1257,6 +1257,8 @@ static void update_partition_sd_lb(struct cpuset *cs,= int old_prs) bool rebuild_domains =3D (new_prs > 0) || (old_prs > 0); bool new_lb; =20 + if (!cpuset_v2()) + return; /* * If cs is not a valid partition root, the load balance state * will follow its parent. @@ -2276,19 +2278,7 @@ static void update_cpumasks_hier(struct cpuset *cs, = struct tmpmasks *tmp, !cpumask_equal(cp->cpus_allowed, cp->effective_cpus)); =20 cpuset_update_tasks_cpumask(cp, cp->effective_cpus); - - /* - * On default hierarchy, inherit the CS_SCHED_LOAD_BALANCE - * from parent if current cpuset isn't a valid partition root - * and their load balance states differ. - */ - if (cpuset_v2() && !is_partition_valid(cp) && - (is_sched_load_balance(parent) !=3D is_sched_load_balance(cp))) { - if (is_sched_load_balance(parent)) - set_bit(CS_SCHED_LOAD_BALANCE, &cp->flags); - else - clear_bit(CS_SCHED_LOAD_BALANCE, &cp->flags); - } + update_partition_sd_lb(cp, old_prs); =20 /* * On legacy hierarchy, if the effective cpumask of any non- --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 86423226D02 for ; Sun, 28 Sep 2025 07:28: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=1759044540; cv=none; b=RD3G2XVbSmpCpNAi3ZdXdjfYj0uJCuX7vEs4Qo0YTypGJLZaU/gAXbhWtZ+aUwSavpZy9ASF2L43Ahg9MY9GCSqzW07MTWfUA6+ejixtd0fdRd11XgCBMmKhvcirYylgR1N7h/2q7QQJRBBjAZ87lIgv2H6N59lTb7nNPP4pES4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044540; c=relaxed/simple; bh=9brNlO4NlISnv5/bLGaaY6qPZIeV9JVoCd1zgROL1hA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A+t6kNF1OdSrZBON5TSGkEFlpU64ZM9FyLAfiyURgp+n46tflhAN9+j+h3XjGPE2v5ds14eN+R27DJ1z6tGGB/d4QcYXbZviaRut+WGhsM6gIOx6xWccN6ATxhOS9iun1Jv+phEAbx6ND1EFZFP0M2lD7jnFV0MjkvTpbFlSIGg= 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.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCG3P3hzKHN6c; Sun, 28 Sep 2025 15:28:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id ADE761A1017; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S4; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 02/16] cpuset: generalize validate_partition() interface Date: Sun, 28 Sep 2025 07:12:52 +0000 Message-Id: <20250928071306.3797436-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGrWDJFW7WFW3uF43Wry3Arb_yoWrWryxpF y5GrW7G3yUtryaka4kta97Cw1YgwnrX3WDt3sxJ3WSvFy7tw1vyFyj9390vryfW39rGw1U ZanI9F4fWF9rAwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Kb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr4 1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK 67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI 8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUcTmhUUUUU 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 local partition enablement validation scenarios. This prepares the function for broader use cases beyond its current validation scope while maintaining backward compatibility with existing callers. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 77 ++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 052f9e0c7a65..0787904321a9 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1702,6 +1702,34 @@ static bool prstate_housekeeping_conflict(int prstat= e, struct cpumask *new_cpus) return false; } =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 exclusize CPUs mask to validate + * + * 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 cpuset *parent =3D parent_cs(cs); + + 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 (tasks_nocpu_error(parent, cs, new_excpus)) + return PERR_NOCPUS; + + return PERR_NONE; +} + /** * update_parent_effective_cpumask - update effective_cpus mask of parent = cpuset * @cs: The cpuset that requests change in partition root state @@ -1805,19 +1833,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 (tasks_nocpu_error(parent, cs, xcpus)) - return PERR_NOCPUS; - + part_error =3D validate_partition(cs, new_prs, xcpus); + 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 @@ -2367,36 +2385,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) { @@ -2451,7 +2439,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); if (prs_err) trialcs->prs_err =3D cs->prs_err =3D prs_err; =20 --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 828C12BE636 for ; Sun, 28 Sep 2025 07:29:02 +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=1759044544; cv=none; b=FXCeAPtKnf4cdZNqnGSaRBzuTa1FFaKCRUr0Xt2IglReALZryZHvRogka6USukfOAa9TxvoB19BYTIRmMr677Z8+JH+EgzMVjGsku92/q6hgA9aHKVrntZnHZTXveHJoFt5T1drLSGiIufuzbw6oO3V2Hpr1Atvd+c9SZN2+9eE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044544; c=relaxed/simple; bh=n07w+BAygcFwNSAZpd/xFKzdgXtBLBNGeVdkBIR1ZDo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KXG3BLOgHNKsfKSRbHGKau5+iK/wyDQPd8mOJkVVlxNFHiRKK6HDTqOEi/347JnTNuWe3a0ECoPpfvUlUK/rD3yVKwN/WcSM8R34aQfZErLVaeB3bD/n9JwJaUEQHYCY5Lr7WXODBEz4dh4QE+dfsqG8quNeAKbAk+EmQteXXCk= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCD61DRzYQvfC; Sun, 28 Sep 2025 15:28:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id B3E411A0C76; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S5; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 03/16] cpuset: factor out partition_enable() function Date: Sun, 28 Sep 2025 07:12:53 +0000 Message-Id: <20250928071306.3797436-4-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGFykKw1ktFWruF13ZFyfCrg_yoWrGFWUpF y5Cr4xtayUtry3C39xJFs7uwsYgws7tF12ywnxW34fXa43J3Wqka4jk390q3WYgryDGry5 Zan0qF4xWF17CwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Kb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr4 1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK 67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI 8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUwhFxUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Extract the core partition enablement logic into a dedicated partition_enable() function. This refactoring centralizes updates to key cpuset data structures including remote_sibling, effective_xcpus, partition_root_state, and prs_err. The function handles the complete partition enablement workflow: - Adding exclusive CPUs via partition_xcpus_add() - Managing remote sibling relationships - Synchronizing effective exclusive CPUs mask - Updating partition state and error status - Triggering required scheduler domain rebuilds This creates a coherent interface for partition operations and establishes a foundation for future local partition support while maintaining existing remote partition behavior. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 55 +++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 0787904321a9..43ce62f4959c 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1515,6 +1515,49 @@ static inline bool is_local_partition(struct cpuset = *cs) return is_partition_valid(cs) && !is_remote_partition(cs); } =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 root state to set + * @new_excpus: New exclusive CPUs mask for the partition + * + * Transitions a cpuset to a partition root, only for v2. + */ +static void partition_enable(struct cpuset *cs, struct cpuset *parent, + int new_prs, struct cpumask *new_excpus) +{ + bool isolcpus_updated; + + 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; + + spin_lock_irq(&callback_lock); + /* enable partition should only add exclusive cpus */ + isolcpus_updated =3D partition_xcpus_add(new_prs, parent, new_excpus); + list_add(&cs->remote_sibling, &remote_children); + cpumask_copy(cs->effective_xcpus, new_excpus); + partition_state_update(cs, new_prs, PERR_NONE); + spin_unlock_irq(&callback_lock); + update_unbound_workqueue_cpumask(isolcpus_updated); + cpuset_force_rebuild(); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update @@ -1528,8 +1571,6 @@ static inline bool is_local_partition(struct cpuset *= cs) static int remote_partition_enable(struct cpuset *cs, int new_prs, struct tmpmasks *tmp) { - bool isolcpus_updated; - /* * The user must have sysadmin privilege. */ @@ -1552,15 +1593,7 @@ static int remote_partition_enable(struct cpuset *cs= , int new_prs, cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) return PERR_INVCPUS; =20 - spin_lock_irq(&callback_lock); - isolcpus_updated =3D partition_xcpus_add(new_prs, NULL, tmp->new_cpus); - list_add(&cs->remote_sibling, &remote_children); - cpumask_copy(cs->effective_xcpus, tmp->new_cpus); - spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); - 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 Wed Oct 1 21:23:22 2025 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 80F7F2BE635 for ; Sun, 28 Sep 2025 07:29:02 +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=1759044545; cv=none; b=p1cb0S1y1nGbghdwkHx4QUtxNtN3iclZaoww+8Kr5i75pkIu/EPwC83DkNNYSFwodjthUuJtjPKlE+nq26YnveLtN33OqvmKb8rL9XXmCk+UX5sb11LZXhE43eNd87eCRcOIEtukkXC3b2ukM8KD4JnrQia4X3x9x66JcF7n6tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044545; c=relaxed/simple; bh=L/Z4MPj9KNffXczu0mrMhkxO7Cy5of6BEJ7dMlLNlN8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y8cvrVO49ZGPQDizUFI8y7IV9m1uLrXFaxBO9hOQLx0UujXhrw4TQul2dk+QcMxfp6anezNslJxHkG0ouOD51ZTKF8pGa0+nlqx7c0kLg1sdaX/B9IKRN45C/qfjQ/ymbFaPpJwm8grKz08tJQdTxtCDy9vTWJqcFvuim+FxMQM= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCD64N6zYQvfF; Sun, 28 Sep 2025 15:28:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id BB5DC1A14B8; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S6; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 04/16] cpuset: factor out partition_disable() function Date: Sun, 28 Sep 2025 07:12:54 +0000 Message-Id: <20250928071306.3797436-5-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S6 X-Coremail-Antispam: 1UD129KBjvJXoWxZr4DZr4kZryrCw1rtr1UWrg_yoWrJF1UpF 15CrWfKFWUXr13ua9rJFs29w1rKw4kXF17t347WryrXFy3J3Wqya4jk39Yv3WUXryDG3y5 Za1qgr48XF12y3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Extract the core partition disablement logic into a dedicated partition_disable() function. This refactoring centralizes updates to key cpuset data structures including remote_sibling, effective_xcpus, partition_root_state, and prs_err. The function handles the complete partition disablement workflow: - Removing exclusive CPUs via partition_xcpus_del() - Cleaning up remote sibling relationships - Recomputing effective exclusive CPUs mask - Updating partition state and error status - Triggering required scheduler domain rebuilds This creates a symmetric interface with partition_enable() and establishes a foundation for future local partition support while maintaining existing remote partition behavior. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 49 +++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 43ce62f4959c..1944410ae872 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1558,6 +1558,35 @@ static void partition_enable(struct cpuset *cs, stru= ct cpuset *parent, cpuset_force_rebuild(); } =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) +{ + bool isolcpus_updated; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(new_prs > 0); + WARN_ON_ONCE(!cpuset_v2()); + + spin_lock_irq(&callback_lock); + list_del_init(&cs->remote_sibling); + /* disable a partition should only delete exclusive cpus */ + isolcpus_updated =3D 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_unbound_workqueue_cpumask(isolcpus_updated); + cpuset_force_rebuild(); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update @@ -1613,27 +1642,13 @@ static int remote_partition_enable(struct cpuset *c= s, int new_prs, */ static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *t= mp) { - bool isolcpus_updated; + int new_prs; =20 WARN_ON_ONCE(!is_remote_partition(cs)); WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus)); =20 - spin_lock_irq(&callback_lock); - list_del_init(&cs->remote_sibling); - isolcpus_updated =3D 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_unbound_workqueue_cpumask(isolcpus_updated); - cpuset_force_rebuild(); - + new_prs =3D cs->prs_err ? -cs->partition_root_state : PRS_MEMBER; + partition_disable(cs, NULL, new_prs, cs->prs_err); /* * Propagate changes in top_cpuset's effective_cpus down the hierarchy. */ --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 8630254918 for ; Sun, 28 Sep 2025 07:28: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=1759044540; cv=none; b=iy/n/lIpYOZorJuBPCDVDGT2NnN4feZWUhMI6ZvXcA0i7x2+g+vWakeyNscjz7pKq3JFl/IzF69G4jsUR5EPOUaAeoImuT2+wVlBAL1HgYmii+CWhsjSwewjBdRcbS1HRQt0mDsGxGW2c/6DwjWKYqPjhOjn4hJnROx3gzfaXQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044540; c=relaxed/simple; bh=CxGfb5aoco/r2OsuXIST3DwEQqsexsoB3qpLfdr0Zac=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sgsicx5RJR/6xLAU6ZseQcCZXEePL/uHnvPceNURAStECNl6FofZmPHh1IxtMZjlHNDWSA0bqUo4AIjDG0mN3542mcL/aMHxeeyJzF+BB1jq01YBpCPACAqJrZudbwblJmiPxp27837CDjYMwmNFdxdzXhbXnfIKQCPw4J0PP88= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCG4F9dzKHNHG; Sun, 28 Sep 2025 15:28:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id CDE941A1488; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S7; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 05/16] cpuset: factor out partition_update() function Date: Sun, 28 Sep 2025 07:12:55 +0000 Message-Id: <20250928071306.3797436-6-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S7 X-Coremail-Antispam: 1UD129KBjvJXoWxtryfZF1rXw4kZFyUtrWDArb_yoW7Xr1rpF yUCr4IqayUtr13u3sxtan2kws5Kw4ktF9FywnrX34rJFy3Ga4vya4jya98XFy5W34DWry5 ZFZ0qr42qF17CwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Extract the core partition update logic into a dedicated partition_update() function. This refactoring centralizes updates to key cpuset data structures including remote_sibling, effective_xcpus, partition_root_state, and prs_err. The function handles the complete partition update workflow: - Adding and removing exclusive CPUs via partition_xcpus_add()/del() - Managing remote sibling relationships - Synchronizing effective exclusive CPUs mask - Updating partition state and error status - Triggering required system updates and workqueue synchronization This creates a coherent interface for partition operations and establishes a foundation for enhanced partition management while maintaining existing remote partition behavior. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 71 ++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 1944410ae872..0e2f95daf459 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1587,6 +1587,49 @@ static void partition_disable(struct cpuset *cs, str= uct cpuset *parent, cpuset_force_rebuild(); } =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) +{ + bool isolcpus_updated; + bool excl_updated; + struct cpuset *parent; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(!cpuset_v2()); + WARN_ON_ONCE(prs <=3D 0); + + parent =3D is_remote_partition(cs) ? NULL : parent_cs(cs); + excl_updated =3D !cpumask_empty(tmp->addmask) || + !cpumask_empty(tmp->delmask); + + spin_lock_irq(&callback_lock); + isolcpus_updated =3D partition_xcpus_add(prs, parent, tmp->addmask); + isolcpus_updated |=3D 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_unbound_workqueue_cpumask(isolcpus_updated); + if (excl_updated) + cpuset_force_rebuild(); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition r= oot * @cs: the cpuset to update @@ -1669,10 +1712,6 @@ 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) { - bool adding, deleting; - int prs =3D cs->partition_root_state; - int isolcpus_updated =3D 0; - if (WARN_ON_ONCE(!is_remote_partition(cs))) return; =20 @@ -1683,15 +1722,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; @@ -1702,23 +1741,7 @@ static void remote_cpus_update(struct cpuset *cs, st= ruct cpumask *xcpus, goto invalidate; } =20 - spin_lock_irq(&callback_lock); - if (adding) - isolcpus_updated +=3D partition_xcpus_add(prs, NULL, tmp->addmask); - if (deleting) - isolcpus_updated +=3D 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_unbound_workqueue_cpumask(isolcpus_updated); - 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 Wed Oct 1 21:23:22 2025 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 864812343C0 for ; Sun, 28 Sep 2025 07:28: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=1759044540; cv=none; b=GMpap7OpQLCICbcm2ofNTiyzeHqcwfurOUOU7S2w5OkwtOUR2EedJr/05TIx0vmbJqSdOtVx9H2YkmIByH0mtDAeakMIITOPymqn2G7go6IMsTMBSdAexl5YBZr/5V/Q9reXTuC6xrPdlQ9bk8qzJGydjER2rl5JOdUxALsDyQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044540; c=relaxed/simple; bh=JiFxHyxl7+klQ0+MY99lkKT7c6mupzGqEByVIe28XOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=IX1OVbwyFMYJ4yUdpeJqBXxKzEG/bGKRnP+cJVYTaKHnh7HtPNX0jWjUMfGQJR9ahWtNA6aiemptiNJaF04JBPy1OlbYNpnzn7CyYBWlm4rEcRGtBiJowsv0KD0pEavqmxzwlgS+6Rs+R67w1oDZfripxjRW5rTsOtoELpN3V0M= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCG4TxfzKHNHK; Sun, 28 Sep 2025 15:28:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id D86391A171D; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S8; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 06/16] cpuset: introduce local_partition_enable() Date: Sun, 28 Sep 2025 07:12:56 +0000 Message-Id: <20250928071306.3797436-7-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S8 X-Coremail-Antispam: 1UD129KBjvJXoW3XFy7ArW3XrWrJr1fArWkWFg_yoWxWw4rpF yUGrsrtFWUtryrC39xJan7Cw4rKw4ktFW2ywnxX34rXFy7Aw1vyFy0y390qFyjgrWDZry5 Za9Fqr4xWFy7ArUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1l_M7UUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ From: Chen Ridong The partition_enable() function introduced in the previous patch can be reused to enable local partitions. First, partition_enable() was enhanced to support local partition enabling by properly handling parent's nr_subparts counter and adding notification operations. Then, 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 | 111 +++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 37 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 0e2f95daf459..154992cdfe9a 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1539,6 +1539,7 @@ static void partition_enable(struct cpuset *cs, struc= t cpuset *parent, int new_prs, struct cpumask *new_excpus) { bool isolcpus_updated; + int old_prs; =20 lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(new_prs <=3D 0); @@ -1547,15 +1548,21 @@ static void partition_enable(struct cpuset *cs, str= uct cpuset *parent, if (cs->partition_root_state =3D=3D new_prs) return; =20 + old_prs =3D cs->partition_root_state; spin_lock_irq(&callback_lock); /* enable partition should only add exclusive cpus */ isolcpus_updated =3D partition_xcpus_add(new_prs, parent, new_excpus); - list_add(&cs->remote_sibling, &remote_children); + /* enable remote partition */ + if (!parent) + list_add(&cs->remote_sibling, &remote_children); + else if (!is_partition_valid(cs)) + parent->nr_subparts +=3D 1; cpumask_copy(cs->effective_xcpus, new_excpus); partition_state_update(cs, new_prs, PERR_NONE); spin_unlock_irq(&callback_lock); update_unbound_workqueue_cpumask(isolcpus_updated); cpuset_force_rebuild(); + notify_partition_change(cs, old_prs); } =20 /** @@ -1801,6 +1808,68 @@ static enum prs_errcode validate_partition(struct cp= uset *cs, int new_prs, return PERR_NONE; } =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 + * + * This function enables local partition root capability for a cpuset by + * validating prerequisites, computing exclusive CPUs, and updating the + * partition hierarchy. + * + * 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 part_error; + + 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)); + + part_error =3D validate_partition(cs, new_prs, tmp->new_cpus); + 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_cp= us + * + * Warn if it is not the case. + * addmask is used as temporary variable. + */ + cpumask_and(tmp->addmask, tmp->new_cpus, cpu_active_mask); + WARN_ON_ONCE(!cpumask_subset(tmp->addmask, parent->effective_cpus)); + 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 @@ -1893,35 +1962,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); - 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; - subparts_delta++; - } 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) @@ -3045,14 +3086,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 Wed Oct 1 21:23:22 2025 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 7BFA82BE62C for ; Sun, 28 Sep 2025 07:29:02 +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=1759044545; cv=none; b=ZnjXm9nkzI26GdKE33X0o7cyJ2BSpGIa66gry+0fEUL2XTaRihSUDUFpDnuucKtipJBb5rwJxtqwbh86UFn6K53+xtnabWhqRoNVqtT+1v0CXdIHWOvWP2+9ZLSBMRgGQRoWB3LWkCOMbTytGUofmWo0N+1hMVUVTdyhTr0KPZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044545; c=relaxed/simple; bh=y+/W8vdbErT6Gts1FZ5Hg4C5dqqAVkYABYrsAxjr7nY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m77ifuN87ISffRAlciybM2t+jmIvl92zh2h1k6jOLfj6nqr9auczQNmeotpfKkEj/MahZ6MGC2rmuZLl+9q/T6sWUVsPQwDKIFIeKvNrEohVYwzaarq2J/FDv6bp77ojccIZjXjsHlEQZO+7grZ20jIGMSBfFm+T5s1n/QBw0Xo= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF0KBzzYQvfN; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id E728B1A0C83; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S9; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 07/16] cpuset: introduce local_partition_disable() Date: Sun, 28 Sep 2025 07:12:57 +0000 Message-Id: <20250928071306.3797436-8-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S9 X-Coremail-Antispam: 1UD129KBjvJXoWxGF1xXw1fWr4DWryxWFyUZFb_yoWrurWfpF yUGrW7KayjqFy3ua47Jan7Aw4rKws7JayxtwnxW34rJFy7J3WvvFy0ya95Z3W8WryDGry7 ZFZ0qr4UWF17ArUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1l_M7UUUUU== 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. First, partition_disable() was enhanced to support local partitions by properly managing the parent's nr_subparts counter and integrating notification operations. Then, local_partition_disable() 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 | 60 ++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 154992cdfe9a..87ba43e93540 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1576,13 +1576,20 @@ static void partition_disable(struct cpuset *cs, st= ruct cpuset *parent, int new_prs, enum prs_errcode prs_err) { bool isolcpus_updated; + int old_prs; =20 lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(new_prs > 0); WARN_ON_ONCE(!cpuset_v2()); =20 + old_prs =3D cs->partition_root_state; spin_lock_irq(&callback_lock); list_del_init(&cs->remote_sibling); + if (parent && is_partition_valid(parent) && + is_partition_valid(cs)) { + parent->nr_subparts -=3D 1; + WARN_ON_ONCE(parent->nr_subparts < 0); + } /* disable a partition should only delete exclusive cpus */ isolcpus_updated =3D partition_xcpus_del(cs->partition_root_state, parent, cs->effective_xcpus); @@ -1592,6 +1599,9 @@ static void partition_disable(struct cpuset *cs, stru= ct cpuset *parent, spin_unlock_irq(&callback_lock); update_unbound_workqueue_cpumask(isolcpus_updated); cpuset_force_rebuild(); + /* Clear exclusive flag; no errors are expected */ + update_partition_exclusive_flag(cs, new_prs); + notify_partition_change(cs, old_prs); } =20 /** @@ -1870,6 +1880,37 @@ 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 + * @tmp: Temporary masks for CPU calculations + */ +static void local_partition_disable(struct cpuset *cs, struct tmpmasks *tm= p) +{ + struct cpuset *parent =3D parent_cs(cs); + bool cpumask_updated =3D false; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ + + if (!is_partition_valid(cs)) + return; + + /* + * 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. + */ + cpumask_updated =3D !cpumask_empty(cs->effective_xcpus); + partition_disable(cs, parent, PRS_MEMBER, PERR_NONE); + + if (cpumask_updated) { + 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 @@ -1962,20 +2003,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; - subparts_delta--; - } - new_prs =3D PRS_MEMBER; - } else if (newmask) { + if (newmask) { /* * Empty cpumask is not allowed */ @@ -3104,9 +3132,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, &tmpmask); /* * Invalidation of child partitions will be done in * update_cpumasks_hier(). --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 809AF2BE634 for ; Sun, 28 Sep 2025 07:29:02 +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=1759044544; cv=none; b=PR2G/tLltTph/oNIGx5BbKwVWvdf4kcIPMBEFKZR709q8jfC9a4X/O3T88Rjj4ZyoJ12lgVkrv5+BCxE5D3LYH/w2OwS6iVbozNRAUsHsmpRKAXXw2x5H4HAs/XNRIPR1CJCUBP22+waR+RRhVsoa/MiRhEwZZit6ruyLnE8lhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044544; c=relaxed/simple; bh=tBZbVtmHl7Kl6Pt/bBqGdnQWbYaXbgpHUkZ7GuXtx/8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yet5f5FZDqmP32tJlPVuQn3vaTBumtKgC5nKDrADKQjQ3eVr58avBhgPkRcHp6Mlp1GFZPjzRQlPb+LcHj3SCi/5zsRE2s4Qz3jz6FTP0TRfcCg0DpDzvziSXxqmefo1gEfZzV8WyuPRFWuq/4zAKayjNfQuevzYgZhjUjKV7oQ= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF0g4jzYQvfP; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id F22C41A0A61; Sun, 28 Sep 2025 15:28:54 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S10; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 08/16] cpuset: introduce local_partition_invalidate() Date: Sun, 28 Sep 2025 07:12:58 +0000 Message-Id: <20250928071306.3797436-9-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S10 X-Coremail-Antispam: 1UD129KBjvJXoWxtrWrWryfZw15Jr4kKw1rWFg_yoW7Xr1UpF y7CrW7t3yUJryru343Jan7Zw4rKws7XasFywnxJayrJF17J3WvyF1jya9avw15XF98GryU Za90gr4xGFy7A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1l_M7UUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Build on the partition_disable() infrastructure introduced in the previous patch to handle local partition invalidation. The local_partition_invalidate() function factors out the local partition invalidation logic from update_parent_effective_cpumask(), which delegates to partition_disable() to complete the invalidation process. 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_cpus 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_cpus-based check ensures proper partition state transitions under these conditions. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 66 +++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 87ba43e93540..e460d03286ba 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1911,6 +1911,39 @@ static void local_partition_disable(struct cpuset *c= s, struct tmpmasks *tmp) } } =20 +/** + * local_partition_invalidate - Invalidate a local partition + * @cs: Target cpuset (local partition root) to invalidate + * @tmp: Temporary masks + */ +static void local_partition_invalidate(struct cpuset *cs, struct tmpmasks = *tmp) +{ + struct cpumask *xcpus =3D user_xcpus(cs); + struct cpuset *parent =3D parent_cs(cs); + int new_prs =3D cs->partition_root_state; + bool cpumask_updated =3D false; + + lockdep_assert_held(&cpuset_mutex); + WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ + + if (is_partition_invalid(cs)) + return; + /* + * Make the current partition invalid. + */ + if (is_partition_valid(parent)) + cpumask_updated =3D cpumask_and(tmp->addmask, + xcpus, parent->effective_xcpus); + if (cs->partition_root_state > 0) + new_prs =3D -cs->partition_root_state; + + partition_disable(cs, parent, new_prs, cs->prs_err); + if (cpumask_updated) { + 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 @@ -1972,23 +2005,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; - subparts_delta--; - } - goto write_error; - } - /* * The parent must be a partition root. * The new cpumask, if present, or the current cpus_allowed must @@ -2552,7 +2568,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_invalidate(cp, tmp); rcu_read_lock(); } } @@ -2592,8 +2608,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_invalidate(cs, tmp); else update_parent_effective_cpumask(cs, partcmd_update, trialcs->effective_xcpus, tmp); @@ -4037,18 +4052,21 @@ static void cpuset_hotplug_update_tasks(struct cpus= et *cs, struct tmpmasks *tmp) * partitions. */ if (is_local_partition(cs) && (!is_partition_valid(parent) || - tasks_nocpu_error(parent, cs, &new_cpus))) + tasks_nocpu_error(parent, cs, &new_cpus))) { partcmd =3D partcmd_invalidate; + local_partition_invalidate(cs, 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 Wed Oct 1 21:23:22 2025 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 7B5E02BDC2C for ; Sun, 28 Sep 2025 07:29:06 +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=1759044549; cv=none; b=rWTX0lLgZ7/GBHYY+J0ZTGUFI9eXb61Bmurr7j5TGgknWlYuxe46K1pfwrvrrfhKEwJoDjVvm60+neMdFZ3dHQ5cnsJGgGmmcIt4Eud8TE49IwBfkK4usprhmmiKPWb/w/bF/kBqVr2UDpYm//qxuVwXMCR8cfyt6Nlnw1yTa6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044549; c=relaxed/simple; bh=IAs/lO4cm/XSZWDjMQ3kkD62j7v2MO+jHOJcO6PbYJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GUa8YcM9gs8hgjEX1dJSm8Ti/W2WMl2QJKPInHexLnBDNyAz1tpHMl1OWTjzdBss6epQHmuDvtpMav+GobX8ixbq5Xed7M6004Yt6FUne7f9Jduq7abeWH0PJSYmPKzJ51njwZoALD+h9UPhz4NgkgoP1rZXhZt27vYQkBF5wXk= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF1CGdzYQvf1; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 10B8C1A1012; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S11; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 09/16] cpuset: introduce local_partition_update() Date: Sun, 28 Sep 2025 07:12:59 +0000 Message-Id: <20250928071306.3797436-10-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S11 X-Coremail-Antispam: 1UD129KBjvAXoW3uw48Kw4kAF4fWF4rKrWUXFb_yoW8Ar4xKo W3JF48A3s3Jw1UWFs0ywn2kFWkWw4vy343t3Wqvr9rur13Aw1DK3W3J3Zav34fXrWrtr98 XF9aq3y8Cry7AF4Dn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYX7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UM6wAUUUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Extend the partition_update() infrastructure to handle local partition updates. 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. cpus updates: For local partition that only cpu maks changes, use partition_update() to handle partition change. With the introduction of this function, update_parent_effective_cpumask() function is removed, simplifying the partition update code path and creating a cleaner separation between local and remote partition operations. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 376 +++++++++++++---------------------------- 1 file changed, 122 insertions(+), 254 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index e460d03286ba..d0217db04b69 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1622,12 +1622,14 @@ static void partition_update(struct cpuset *cs, int= prs, struct cpumask *xcpus, bool isolcpus_updated; bool excl_updated; struct cpuset *parent; + int old_prs; =20 lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(!cpuset_v2()); WARN_ON_ONCE(prs <=3D 0); =20 parent =3D is_remote_partition(cs) ? NULL : parent_cs(cs); + old_prs =3D cs->partition_root_state; excl_updated =3D !cpumask_empty(tmp->addmask) || !cpumask_empty(tmp->delmask); =20 @@ -1645,6 +1647,8 @@ static void partition_update(struct cpuset *cs, int p= rs, struct cpumask *xcpus, update_unbound_workqueue_cpumask(isolcpus_updated); if (excl_updated) cpuset_force_rebuild(); + update_partition_exclusive_flag(cs, prs); + notify_partition_change(cs, old_prs); } =20 /* @@ -1790,6 +1794,27 @@ static bool prstate_housekeeping_conflict(int prstat= e, struct cpumask *new_cpus) return false; } =20 +static bool cpuset_user_cpus_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_partition - Validate a cpuset partition configuration * @cs: The cpuset to validate @@ -1818,6 +1843,39 @@ static enum prs_errcode validate_partition(struct cp= uset *cs, int new_prs, return PERR_NONE; } =20 +/** + * local_partition_check - 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 + * + * 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 local_partition_check(struct cpuset *cs, int new_p= rs, + struct cpumask *excpus, bool excl_check) +{ + 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 && !cpuset_user_cpus_exclusive(cs)) + return PERR_NOTEXCL; + + return validate_partition(cs, new_prs, excpus); +} + /** * local_partition_enable - Enable local partition for a cpuset * @cs: Target cpuset to become a local partition root @@ -1945,280 +2003,85 @@ static void local_partition_invalidate(struct cpus= et *cs, struct tmpmasks *tmp) } =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. + * __local_partition_update - Update local CPU 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 * - * 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. + * Handles updates to local CPU partition configurations by validating + * changes, managing state transitions, and propagating updates through + * the cpuset hierarchy. * - * For partcmd_invalidate, the current partition will be made invalid. + * 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. * - * 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. + * Return: Partition error code (PERR_NONE indicates success) */ -static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, - struct cpumask *newmask, - struct tmpmasks *tmp) +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 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? */ - int subparts_delta =3D 0; - int isolcpus_updated =3D 0; - struct cpumask *xcpus =3D user_xcpus(cs); - bool nocpu; + int old_prs, new_prs; + bool cpumask_updated =3D false; =20 lockdep_assert_held(&cpuset_mutex); - WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ + /* For local partition only */ + if (WARN_ON_ONCE(is_remote_partition(cs) || cs_is_member(cs))) + return PERR_NONE; =20 + old_prs =3D cs->partition_root_state; /* - * new_prs will only be changed for the partcmd_update and - * partcmd_invalidate commands. + * If new_prs < 0, it might transition to valid partition state. + * Use absolute value for validation checks. */ - 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 - */ - 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); - } - /* - * 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; - subparts_delta--; - } - break; - case PRS_INVALID_ROOT: - case PRS_INVALID_ISOLATED: - if (!part_error) { - new_prs =3D -old_prs; - subparts_delta++; - } - break; - } + new_prs =3D old_prs < 0 ? -old_prs : old_prs; + part_error =3D local_partition_check(cs, new_prs, excpus, excl_check); + if (part_error) { + local_partition_invalidate(cs, tmp); + return part_error; } =20 - if (!adding && !deleting && (new_prs =3D=3D old_prs)) - return 0; + /* Nothing changes, return PERR_NONE */ + if (new_prs =3D=3D old_prs && cpumask_equal(excpus, cs->effective_xcpus)) + return PERR_NONE; =20 /* - * 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 partition was previously invalid but now passes checks, + * enable it and update related flags */ - if ((old_prs !=3D new_prs) && (cmd !=3D partcmd_update)) { - int err =3D update_partition_exclusive_flag(cs, new_prs); - - if (err) - return err; + if (is_partition_invalid(cs) && !part_error) { + partition_enable(cs, parent, new_prs, excpus); + update_partition_exclusive_flag(cs, new_prs); + update_partition_sd_lb(cs, old_prs); + return part_error; } =20 + cpumask_updated =3D cpumask_andnot(tmp->addmask, excpus, cs->effective_xc= pus); + cpumask_updated |=3D cpumask_andnot(tmp->delmask, cs->effective_xcpus, ex= cpus); + partition_update(cs, new_prs, xcpus, excpus, tmp); /* - * 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; - if (new_prs <=3D 0) - cs->nr_subparts =3D 0; - } - /* - * Adding to parent's effective_cpus means deletion CPUs from cs - * and vice versa. + * Propagate changes in parent's effective_cpus down the hierarchy. */ - if (adding) - isolcpus_updated +=3D partition_xcpus_del(old_prs, parent, - tmp->addmask); - if (deleting) - isolcpus_updated +=3D partition_xcpus_add(new_prs, parent, - tmp->delmask); - - if (is_partition_valid(parent)) { - parent->nr_subparts +=3D subparts_delta; - WARN_ON_ONCE(parent->nr_subparts < 0); - } - spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); - - if ((old_prs !=3D new_prs) && (cmd =3D=3D partcmd_update)) - update_partition_exclusive_flag(cs, new_prs); - - if (adding || deleting) { + if (cpumask_updated) { cpuset_update_tasks_cpumask(parent, tmp->addmask); update_sibling_cpumasks(parent, cs, tmp); } + return part_error; +} =20 - /* - * 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); +static int local_partition_update(struct cpuset *cs, struct tmpmasks *tmp) +{ + struct cpuset *parent =3D parent_cs(cs); =20 - notify_partition_change(cs, old_prs); - return 0; + cpumask_and(tmp->new_cpus, user_xcpus(cs), parent->effective_xcpus); + return __local_partition_update(cs, NULL, tmp->new_cpus, tmp, true); } =20 /** @@ -2419,9 +2282,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. @@ -2430,7 +2300,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); @@ -2610,8 +2479,8 @@ static void partition_cpus_change(struct cpuset *cs, = struct cpuset *trialcs, if (trialcs->prs_err) local_partition_invalidate(cs, 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 @@ -4063,9 +3932,8 @@ 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); } - if (partcmd >=3D 0) { if ((partcmd =3D=3D partcmd_invalidate) || is_partition_valid(cs)) { compute_partition_effective_cpumask(cs, &new_cpus); --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 863671DE2C2 for ; Sun, 28 Sep 2025 07:28: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=1759044540; cv=none; b=D46t6KxKRVXWir/Dv3ILo8jRr/K2mMi3uB/WLHuVgv9o3kzdhIN02XN4nAddDVpza74yPdvf8+4C7mbavsgS4StSl7u0ixpKyajw+6G76bX89HVyMne2HSn9fuEoFDIWIifr05uckxqXqH/pLvppNerYn457EC9s4qkm44n80FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044540; c=relaxed/simple; bh=SxFxR6Ns5XasCUopMm/fRSBQ6qabP9nw45vzUsP6pgE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MbhRgxMd620asjlEYNI1iMcM+lQbWwcGyZ8GwKBOXDAR9vkR6C2Z/U2gwBSxvzwwvNd0buurXYdO6Lsx4qrkmijk523G60jeX3+PB0GMlcIM/I9KJ/6CTrDk7Eu0lcggp7i0Og0SFTT3PEgd23DfofOn3NTxcMn5KE/5gxMgx7I= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCG65gtzKHNHj; Sun, 28 Sep 2025 15:28:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 19AE81A1733; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S12; Sun, 28 Sep 2025 15:28:54 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 10/16] cpuset: remove redundant partition field updates Date: Sun, 28 Sep 2025 07:13:00 +0000 Message-Id: <20250928071306.3797436-11-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S12 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw18JF47CFy3KF1rCw4xCrg_yoW8CF1rpF yDurW7trWYgryrC39rGan2gr1UKanFqayDtFnrJw1rCFy2k3Wq9ryvq390vF1jq3srCr4U ZFn0vrWSv3ZrurDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1l_M7UUUUU== 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 d0217db04b69..9e98df542715 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2526,9 +2526,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 */ @@ -2592,8 +2589,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 Wed Oct 1 21:23:22 2025 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 7B6552C0290 for ; Sun, 28 Sep 2025 07:29:06 +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=1759044548; cv=none; b=ur0EZQfLnptGsl2wIieO+zUKtCxPqbu2MLrLlYvhquCC6O06d5GF7jO7ypKfvQIfzlk9276g390IiLtf7Rb6XxanmPWyBh1kzkk+WpXvQpOxi6agznctTnShPv5UJ+MH4+wrBdUQ/HcYau/cqbqAvKHVtQrU8pO+QoH713Rf61s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044548; c=relaxed/simple; bh=m7+wQpMl4dpOGgdg8LlUvDJq4UWL+pBw91BUjBbG7eI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QffuAdDCPT4S7MHrfkhrkazKUyJXATs+CEWeuVWuH8DxE9n/fgFoyQAcx49IKxNHuF5m6wLJwn3cC0TDbfnhZmRFdpXTQF1AYhZe+OLOPlIVfgfp/2Mv9GmFDpHhpLcoheWGljTnqb/g7KZ8uQ5scWZ0ZNUlDM2nfQj5bOENCMI= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF1tghzYQvfb; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 283E31A0D72; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S13; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 11/16] cpuset: simplify partition update logic for hotplug tasks Date: Sun, 28 Sep 2025 07:13:01 +0000 Message-Id: <20250928071306.3797436-12-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S13 X-Coremail-Antispam: 1UD129KBjvJXoW3Xr48GFW7GFWruw4fCFWDXFb_yoW7ArW7pF y3CrW7tayUGr15u3sxJFs7Z3yrGws7JFyqy3ZxJ34rJF12ya4vyFyjk395ZayYqryDXry7 Zayqgr4xJF17CrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1l_M7UUUUU== 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. This patch simplifies the logic by always proceeding to update_tasks for remote partitions, regardless of whether they were disabled or not. Since the original code didn't perform any meaningful operations for non-disabled remote partitions, this change should not affect functionality. The partition_cmd mechanism 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 | 67 ++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 9e98df542715..a1896a199c8b 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1211,17 +1211,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 @@ -2062,6 +2051,9 @@ static int __local_partition_update(struct cpuset *cs= , struct cpumask *xcpus, update_partition_sd_lb(cs, old_prs); return part_error; } + /* Nothing changes, return PERR_NONE */ + if (new_prs =3D=3D old_prs && cpumask_equal(excpus, cs->effective_xcpus)) + return PERR_NONE; =20 cpumask_updated =3D cpumask_andnot(tmp->addmask, excpus, cs->effective_xc= pus); cpumask_updated |=3D cpumask_andnot(tmp->delmask, cs->effective_xcpus, ex= cpus); @@ -3868,8 +3860,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); @@ -3896,16 +3886,15 @@ 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(&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(&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 /* @@ -3913,28 +3902,24 @@ static void cpuset_hotplug_update_tasks(struct cpus= et *cs, struct tmpmasks *tmp) * 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. - */ - if (is_local_partition(cs) && (!is_partition_valid(parent) || - tasks_nocpu_error(parent, cs, &new_cpus))) { - partcmd =3D partcmd_invalidate; - local_partition_invalidate(cs, tmp); - } - /* + * partitions. + * * On the other hand, an invalid partition root may be transitioned * back to a regular one with a non-empty user xcpus. + * + * local_partition_update can handle these cases. */ - else if (is_partition_valid(parent) && is_partition_invalid(cs) && - !cpumask_empty(user_xcpus(cs))) { - partcmd =3D partcmd_update; - local_partition_update(cs, tmp); - } - if (partcmd >=3D 0) { - if ((partcmd =3D=3D partcmd_invalidate) || is_partition_valid(cs)) { - compute_partition_effective_cpumask(cs, &new_cpus); - cpuset_force_rebuild(); - } - } + local_partition_update(cs, tmp); + + /* + * 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 Wed Oct 1 21:23:22 2025 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 A0ED121CC58 for ; Sun, 28 Sep 2025 07:29:01 +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=1759044543; cv=none; b=mgkMUCwzMBTrwONgt0OBHKy4/wtcowDUS0lkIciqrqQbf43hAe7VpaJ80R/45VRbgSpKGcV56bzC0H/IBvv2CQZDeK8b/7FER1sk/IoTNJ5W7FDTUaui3t/TBJNItpS4M+U/LGa83S0qjCJIfEQBGIcDhaQPsux1fEw1lSMEF2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044543; c=relaxed/simple; bh=GYS8UKcTIHZPaBWuqA9dsfyhy9xWi3PU5d4oS/pAJaU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PskUNCbc3TzYM2PY8CN74dRTcQevkUM/LTbOdWu6ng+uzmOVc1E5z4oC1UfrtmoD/ToDZv2XN4m8TqtqbHGyz3rvAEPPrR9Iv3MI//VYFwtG4r1zBnnBKjt3peOJbTQkWWsyRD/QocBUvhwSuEzqx0Xa0PEYPjZvXjqhEot6Y6k= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCG6rctzKHNJ8; Sun, 28 Sep 2025 15:28:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 35BA31A173F; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S14; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 12/16] cpuset: unify local partition disable and invalidate Date: Sun, 28 Sep 2025 07:13:02 +0000 Message-Id: <20250928071306.3797436-13-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S14 X-Coremail-Antispam: 1UD129KBjvJXoW3Jw4fAF4UArWUGF1xCF18Grg_yoW7GFWkpF y3Jr42grWUXFy5u34UJFs7Aw1fKwn7JFZ2ywnxWa4fXF17A3WvvFy0y39Yva45XF9rG347 Za1qgr48XF1xCwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The local_partition_invalidate() and local_partition_disable() functions contain similar logic that can be unified into a single implementation. This patch consolidates both functions into local_partition_disable(), creating symmetry with the existing remote_partition_disable() function. To support this unification, the partition error code is added as an input parameter to local_partition_disable(), allowing proper recording of the disablement reason for both invalid and regular disable operations. This refactoring reduces code duplication and establishes a consistent interface for partition disable operations across both local and remote partition types. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 53 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a1896a199c8b..6625b803ba02 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1932,10 +1932,12 @@ static int local_partition_enable(struct cpuset *cs, * @cs: Target cpuset (local partition root) to disable * @tmp: Temporary masks for CPU calculations */ -static void local_partition_disable(struct cpuset *cs, struct tmpmasks *tm= p) +static void local_partition_disable(struct cpuset *cs, enum prs_errcode pa= rt_error, + struct tmpmasks *tmp) { struct cpuset *parent =3D parent_cs(cs); bool cpumask_updated =3D false; + int new_prs; =20 lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ @@ -1943,48 +1945,21 @@ static void local_partition_disable(struct cpuset *= cs, struct tmpmasks *tmp) if (!is_partition_valid(cs)) return; =20 + if (part_error) + new_prs =3D -cs->partition_root_state; + else + new_prs =3D 0; /* * 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. */ - cpumask_updated =3D !cpumask_empty(cs->effective_xcpus); - partition_disable(cs, parent, PRS_MEMBER, PERR_NONE); - - if (cpumask_updated) { - cpuset_update_tasks_cpumask(parent, tmp->addmask); - update_sibling_cpumasks(parent, cs, tmp); - } -} - -/** - * local_partition_invalidate - Invalidate a local partition - * @cs: Target cpuset (local partition root) to invalidate - * @tmp: Temporary masks - */ -static void local_partition_invalidate(struct cpuset *cs, struct tmpmasks = *tmp) -{ - struct cpumask *xcpus =3D user_xcpus(cs); - struct cpuset *parent =3D parent_cs(cs); - int new_prs =3D cs->partition_root_state; - bool cpumask_updated =3D false; - - lockdep_assert_held(&cpuset_mutex); - WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ - - if (is_partition_invalid(cs)) - return; - /* - * Make the current partition invalid. - */ if (is_partition_valid(parent)) - cpumask_updated =3D cpumask_and(tmp->addmask, - xcpus, parent->effective_xcpus); - if (cs->partition_root_state > 0) - new_prs =3D -cs->partition_root_state; + cpumask_updated =3D !cpumask_empty(cs->effective_xcpus); + + partition_disable(cs, parent, new_prs, part_error); =20 - partition_disable(cs, parent, new_prs, cs->prs_err); if (cpumask_updated) { cpuset_update_tasks_cpumask(parent, tmp->addmask); update_sibling_cpumasks(parent, cs, tmp); @@ -2033,7 +2008,7 @@ static int __local_partition_update(struct cpuset *cs= , struct cpumask *xcpus, new_prs =3D old_prs < 0 ? -old_prs : old_prs; part_error =3D local_partition_check(cs, new_prs, excpus, excl_check); if (part_error) { - local_partition_invalidate(cs, tmp); + local_partition_disable(cs, part_error, tmp); return part_error; } =20 @@ -2429,7 +2404,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(); - local_partition_invalidate(cp, tmp); + local_partition_disable(cp, PERR_NOTEXCL, tmp); rcu_read_lock(); } } @@ -2469,7 +2444,7 @@ static void partition_cpus_change(struct cpuset *cs, = struct cpuset *trialcs, trialcs->effective_xcpus, tmp); } else { if (trialcs->prs_err) - local_partition_invalidate(cs, tmp); + local_partition_disable(cs, trialcs->prs_err, tmp); else __local_partition_update(cs, trialcs->exclusive_cpus, trialcs->effective_xcpus, tmp, false); @@ -3003,7 +2978,7 @@ static int update_prstate(struct cpuset *cs, int new_= prs) if (is_remote_partition(cs)) remote_partition_disable(cs, &tmpmask); else - local_partition_disable(cs, &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 Wed Oct 1 21:23:22 2025 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 D46A2824BD for ; Sun, 28 Sep 2025 07:44:30 +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=1759045474; cv=none; b=KJFjm25ifqX2xnb1/DHuskCZAwG5QG94897mrEyJHMp6gPb5ExGz+58mkltksoVIi/+xenHCpyrTeKZtB/7UaRXhvJOKrSNbyiwWUXFs+/hl3rXAJwBVH+d3qvVSjan2/lHZszWLZYJpoSpBzty+L0DdIagA26f0UdfWnQ8LgSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759045474; c=relaxed/simple; bh=Q+EMg5TQ8yFYIisOxYmnmLmns5/akqtWB+xBJzo0Jgs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X7OAYH6BapemmyaEVvii4yy35OKqhdAVd8qFAw360bPuGkNrr1AlGv1vkf4S2sj+jCrKmM8bRvDGmx0IHBfYGpb7ml47ua6uUrJjKKeeDAje2vVCOK36T9tgQ6CpUYKPwYKLwl5lQvzHKiFoRYgBaM1cbq98+QgQOUyS/SB1l/A= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF2bH5zYQvfg; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 43D201A1733; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S15; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 13/16] cpuset: use partition_disable for compute_partition_effective_cpumask Date: Sun, 28 Sep 2025 07:13:03 +0000 Message-Id: <20250928071306.3797436-14-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S15 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFWkZF15Ar1rXw4kXryrJFb_yoW5Jr1fpF 1xAr47GFW5X345u3y7ta97uwn8Gws2g3WDtr1fXw1fXFy7Awn0ka42yaySqFWjqr97W34U Z3Z0qr48Gan7AFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU 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 | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 6625b803ba02..20288dbd6ccf 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -170,15 +170,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. */ @@ -2073,6 +2064,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 @@ -2095,26 +2087,20 @@ 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 + if (prs_err) { /* * Invalidate child partition */ - spin_lock_irq(&callback_lock); - make_partition_invalid(child); - cs->nr_subparts--; - child->nr_subparts =3D 0; - spin_unlock_irq(&callback_lock); - notify_partition_change(child, old_prs); + partition_disable(child, parent_cs(child), + -child->partition_root_state, prs_err); continue; } cpumask_andnot(new_ecpus, new_ecpus, --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 A0F3F2BDC2C for ; Sun, 28 Sep 2025 07:29:01 +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=1759044543; cv=none; b=jRTsGuw+LCCtc4bbAeqUHGlByn6taLJybdU+n3sCS1fGQU8K/fICMD66wfzW1EKATkVa1Z9GOlzEHVrau9iaS0aHQTdVAzApvK+K9cW9TA+rLkRA8nIUtzLkbReRyC2IyMqvTxCKGlKlMCoT0ks2kBQQZhnm+XtAcuqnlnzJmsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044543; c=relaxed/simple; bh=mp9ZaWIp0DrgDNjG05KPRnT8NRsqy6SG1i2t2oJIN1A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Y00Ha4bHwASrVoW6hheScICPr+fFDbJlEnvAK0UeCivwOOTUIaXfy2D8Y317xRPTxpic60/z21CNqW258+GQC6HmwOGzU0CDHUhpVsOSQb0xjBNkIxgZWs0wjhhwscAacwSjArjLrF6gQS5hrTse/5uBAk83W/it9gX/sXGJby8= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCH0XYkzKHNJM; Sun, 28 Sep 2025 15:28:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 50C701A174E; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S16; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 14/16] cpuset: fix isolcpus stay in root when isolated partition changes to root Date: Sun, 28 Sep 2025 07:13:04 +0000 Message-Id: <20250928071306.3797436-15-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S16 X-Coremail-Antispam: 1UD129KBjvJXoWxXr47uw4UJryxZw15CFyfZwb_yoWrtw15pF yFka1Iq3yUtw15C3sFqan7uw1rKa1DtFy7tws8W3WfZFy7A3WvyFyjk39YyFy5WFyDGry5 Zas09r48Xa42ywUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ From: Chen Ridong A bug was detected with the following steps: # cd /sys/fs/cgroup/ # mkdir test # echo 9 > test/cpuset.cpus # echo isolated > test/cpuset.cpus.partition # cat test/cpuset.cpus.partition isolated # cat test/cpuset.cpus 9 # echo root > test/cpuset.cpus.partition # cat test/cpuset.cpus 9 # cat test/cpuset.cpus.partition root CPU 9 was initially placed in an isolated partition. When the partition type is changed from isolated to root, CPU 9 remains in what becomes a valid root partition. This violates the rule that isolcpus can only be assigned to isolated partitions. Fix the issue by re-enabling partition validation, which performs comprehensive partition error checking. In the scenario described above, this change causes the operation to fail with housekeeping conflicts, preventing the invalid configuration. Additionally, when enable a local partition, the warning for tmp->addmask not being a subset of parent's effective CPUs was removed. This warning was triggered during local partition re-enablement because the CPUs were already added to exclusive_cpus during the previous enable operation. The subset check is not applicable in this re-enablement scenario. Fixes: f28e22441f35 ("cgroup/cpuset: Add a new isolated cpus.partition type= ") Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 20288dbd6ccf..2aaa688c596f 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1873,6 +1873,7 @@ static int local_partition_enable(struct cpuset *cs, { struct cpuset *parent =3D parent_cs(cs); enum prs_errcode part_error; + bool cpumask_updated =3D false; =20 lockdep_assert_held(&cpuset_mutex); WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ @@ -1899,22 +1900,14 @@ static int local_partition_enable(struct cpuset *cs, if (part_error) return part_error; =20 - /* - * 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_cp= us - * - * Warn if it is not the case. - * addmask is used as temporary variable. - */ - cpumask_and(tmp->addmask, tmp->new_cpus, cpu_active_mask); - WARN_ON_ONCE(!cpumask_subset(tmp->addmask, parent->effective_cpus)); + cpumask_updated =3D cpumask_andnot(tmp->addmask, tmp->new_cpus, + parent->effective_cpus); partition_enable(cs, parent, new_prs, tmp->new_cpus); =20 - cpuset_update_tasks_cpumask(parent, tmp->addmask); - update_sibling_cpumasks(parent, cs, tmp); + if (cpumask_updated) { + cpuset_update_tasks_cpumask(parent, tmp->addmask); + update_sibling_cpumasks(parent, cs, tmp); + } return 0; } =20 @@ -2902,7 +2895,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; @@ -2920,7 +2912,7 @@ static int update_prstate(struct cpuset *cs, int new_= prs) if (err) goto out; =20 - if (!old_prs) { + if (new_prs > 0) { /* * cpus_allowed and exclusive_cpus cannot be both empty. */ @@ -2950,12 +2942,6 @@ static int update_prstate(struct cpuset *cs, int new= _prs) 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. - * Need to update isolated_cpus. - */ - isolcpus_updated =3D true; } else { /* * Switching back to member is always allowed even if it @@ -2985,16 +2971,13 @@ static int update_prstate(struct cpuset *cs, int ne= w_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_unbound_workqueue_cpumask(isolcpus_updated); =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) + WARN_ON_ONCE(!old_prs && (cs->partition_root_state > 0) && cpumask_empty(cs->effective_xcpus)); =20 /* Update sched domains and load balance flag */ --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 CACA32C033C for ; Sun, 28 Sep 2025 07:29:06 +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=1759044548; cv=none; b=KPYYdktif8rdwzc3OfD0m6M39WPOEzREOXDYZYLwDGXv7KXkB06swwpT9mY5bozB6BX9Sm2brAGaEYQAuUjkrsm4oZnV9bU31ocGtfzlgM3l0xjaDDVhQaUBZJW/VL4m8rc2L0xArENB2+POsacWjiF8f+PWRusZkUAizpqlG90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044548; c=relaxed/simple; bh=ywGOVe2rn0IA/yycNEDW2c1NH0cVDxPzQS5KrVJOkxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RwnysJ7VkNzfbZf0x9zL6hh1qZ/MThNc8A1TRSH28ETkpQ24n7pVl+9uAyYg+hv/59ENukoArlfhtVQHG+knWP4nGge6s2wtPj7h+RxqQRgmtdxIiCvKgf+fYbcYLiR98XxjRM8soz8z3gIdb/SGAOSCbUWt5rmxg2P8GXarfd0= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF39G9zYQvfd; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 584DB1A1733; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S17; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 15/16] cpuset: use partition_disable for update_prstate Date: Sun, 28 Sep 2025 07:13:05 +0000 Message-Id: <20250928071306.3797436-16-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S17 X-Coremail-Antispam: 1UD129KBjvJXoW7tr1kJr48ur4kZF43ur1kGrg_yoW8uF1fpa s3Cr47Gw4UXr15u34UWF4xZ3WrWws2qry2yFyDW34xX3W3J3sF9FyYy3ySqa1jyF98G3s8 Z3ZFgr18Xa17CFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUwuWlUUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The update_prstate() function currently handles partition state transitions by directly manipulating partition-related fields. However, when a partition is enabled or disabled through the proper interfaces, these fields are already set correctly, making the direct manipulation redundant. This patch refactors the logic to use partition_disable() when partition errors are detected, ensuring consistent state management. For successful state transitions, the partition-related fields are set appropriately. This change eliminates redundant field manipulation and centralizes partition state management through the established partition_disable() interface, improving code maintainability and consistency. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 2aaa688c596f..a22cf97e6af5 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2961,17 +2961,8 @@ static int update_prstate(struct cpuset *cs, int new= _prs) * 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); - spin_unlock_irq(&callback_lock); + 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); @@ -2983,7 +2974,6 @@ static int update_prstate(struct cpuset *cs, int new_= prs) /* Update sched domains and load balance flag */ update_partition_sd_lb(cs, old_prs); =20 - notify_partition_change(cs, old_prs); if (force_sd_rebuild) rebuild_sched_domains_locked(); free_tmpmasks(&tmpmask); --=20 2.34.1 From nobody Wed Oct 1 21:23:22 2025 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 0B5092C08AF for ; Sun, 28 Sep 2025 07:29:07 +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=1759044548; cv=none; b=JyZZJZl1f2x+iQXvkhLFHIROlo6W4NAqT6WgiwQrzYhE0PRR5wcxxi7iibq5xsA0z2rVak4dhDWVJZ1Yjr1NrCutTkvPVAXbWgqi0ZcVuzgP8fjLDq/W+vDOLEyuIAFdk70xo81U/7Xnad8yXxgq97hou1UcOELSTBpC3/j6sek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759044548; c=relaxed/simple; bh=Tk0wtXwuOGiBv6HCr1E3osb1eSd5LIhoOZ9IPA1fMtM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NruZmOb8jQ+NWIV7OCjZf5WHByNwvWYr3aTyEy+ZaOp45tfhzsODuReqDikz936VbSXe++JgXWRmILVY42uNKIfaUgABcBkLZjXtdF29ORtyr6xYRROOySg7wGmM+C8NXfApMcKQSh92IIYDynhCpwZ0k573pyoelq7KTAqgrBY= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cZGCF3ns9zYQvfh; Sun, 28 Sep 2025 15:28:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 68C701A1102; Sun, 28 Sep 2025 15:28:55 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgAHUhaY49hoiDJLBA--.29596S18; Sun, 28 Sep 2025 15:28:55 +0800 (CST) From: Chen Ridong To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next RFC 16/16] cpuset: remove prs_err clear when notify_partition_change Date: Sun, 28 Sep 2025 07:13:06 +0000 Message-Id: <20250928071306.3797436-17-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250928071306.3797436-1-chenridong@huaweicloud.com> References: <20250928071306.3797436-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: Syh0CgAHUhaY49hoiDJLBA--.29596S18 X-Coremail-Antispam: 1UD129KBjvdXoWrtFyfCw48uryktw4fWry3Jwb_yoW3uFc_C3 4Fgr1vqryrXr1Ig3WYka1SqrWvya1UArnayas0q3y5AF12kwn3uwnFqF98Jrn8Za1xXrn8 Aas3GFnI9FnFgjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbS8YFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x 0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UM6wAUUUUU= 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 a22cf97e6af5..262572af68bb 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -178,10 +178,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