From nobody Sun Dec 14 02:02:10 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 7A23226A1A8; Fri, 8 Aug 2025 09:39:43 +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=1754645986; cv=none; b=eFRNlG70v7x+vtUsqgK1EGg6imFswOR3/Fp5Y5VkK4fbF/P1qd1aovjhsf3XHrycyoHfyn9YX/WmyCVuXSCvj3OGdXYuBC/n4SYn0AUXTVpQXkwWhAt+bKxVtxKbnPmJTAX3GfShWKiwBEo+dmPjGYQKiqz/7GQ7YVY39pN4GWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754645986; c=relaxed/simple; bh=pgxmGpjnHnFyN7uX4DglrytT1ogOQKsOseVKGgGQJqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PmqXsM9nHc/tpDAeH61XZu3r6xB69mgDBNoBrz9K05rjfVjHSvFBEwO134BxEDbc/U3+UpMIKoPqjsxBgpOlEwjEclA/uPLt2pWYOGc+zHP7gx13Q3buz9AK2tQbPPULuRmGi7NUA9BykJSYdLQaHv4NJnCni5fJtBUYVIiOkyA= 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 4byzWx6dXdzKHMsQ; Fri, 8 Aug 2025 17:39:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 0DF941A1C1C; Fri, 8 Aug 2025 17:39:41 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgCXo7XPxZVooOS_Cw--.51716S3; Fri, 08 Aug 2025 17:39:40 +0800 (CST) From: Chen Ridong To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, longman@redhat.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next 1/4] cpuset: remove redundant CS_ONLINE flag Date: Fri, 8 Aug 2025 09:25:12 +0000 Message-Id: <20250808092515.764820-2-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250808092515.764820-1-chenridong@huaweicloud.com> References: <20250808092515.764820-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: Syh0CgCXo7XPxZVooOS_Cw--.51716S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1xGFyxtFyxAw4DAr48Crg_yoW5tF4UpF 1DCFyUKw45G3W7CaykG3yqq34fKws3Z3WUKFyrK3s5AF1ayFya9F1kZ345JFyYyFWkCrWU AF4SvrWY9a48trJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUV89N UUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The CS_ONLINE flag was introduced prior to the CSS_ONLINE flag in the cpuset subsystem. Currently, the flag setting sequence is as follows: 1. cpuset_css_online() sets CS_ONLINE 2. css->flags gets CSS_ONLINE set ... 3. cgroup->kill_css sets CSS_DYING 4. cpuset_css_offline() clears CS_ONLINE 5. css->flags clears CSS_ONLINE The is_cpuset_online() check currently occurs between steps 1 and 3. However, it would be equally safe to perform this check between steps 2 and 3, as CSS_ONLINE provides the same synchronization guarantee as CS_ONLINE. Since CS_ONLINE is redundant with CSS_ONLINE and provides no additional synchronization benefits, we can safely remove it to simplify the code. Signed-off-by: Chen Ridong Acked-by: Waiman Long --- include/linux/cgroup.h | 5 +++++ kernel/cgroup/cpuset-internal.h | 3 +-- kernel/cgroup/cpuset.c | 4 +--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index b18fb5fcb38e..ae73dbb19165 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -354,6 +354,11 @@ static inline bool css_is_dying(struct cgroup_subsys_s= tate *css) return css->flags & CSS_DYING; } =20 +static inline bool css_is_online(struct cgroup_subsys_state *css) +{ + return css->flags & CSS_ONLINE; +} + static inline bool css_is_self(struct cgroup_subsys_state *css) { if (css =3D=3D &css->cgroup->self) { diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index 383963e28ac6..75b3aef39231 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -38,7 +38,6 @@ enum prs_errcode { =20 /* bits in struct cpuset flags field */ typedef enum { - CS_ONLINE, CS_CPU_EXCLUSIVE, CS_MEM_EXCLUSIVE, CS_MEM_HARDWALL, @@ -202,7 +201,7 @@ static inline struct cpuset *parent_cs(struct cpuset *c= s) /* convenient tests for these bits */ static inline bool is_cpuset_online(struct cpuset *cs) { - return test_bit(CS_ONLINE, &cs->flags) && !css_is_dying(&cs->css); + return css_is_online(&cs->css) && !css_is_dying(&cs->css); } =20 static inline int is_cpu_exclusive(const struct cpuset *cs) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index f74d04429a29..cf7cd2255265 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -207,7 +207,7 @@ static inline void notify_partition_change(struct cpuse= t *cs, int old_prs) * parallel, we may leave an offline CPU in cpu_allowed or some other mask= s. */ static struct cpuset top_cpuset =3D { - .flags =3D BIT(CS_ONLINE) | BIT(CS_CPU_EXCLUSIVE) | + .flags =3D BIT(CS_CPU_EXCLUSIVE) | BIT(CS_MEM_EXCLUSIVE) | BIT(CS_SCHED_LOAD_BALANCE), .partition_root_state =3D PRS_ROOT, .relax_domain_level =3D -1, @@ -3498,7 +3498,6 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) cpus_read_lock(); mutex_lock(&cpuset_mutex); =20 - set_bit(CS_ONLINE, &cs->flags); if (is_spread_page(parent)) set_bit(CS_SPREAD_PAGE, &cs->flags); if (is_spread_slab(parent)) @@ -3573,7 +3572,6 @@ static void cpuset_css_offline(struct cgroup_subsys_s= tate *css) cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); =20 cpuset_dec(); - clear_bit(CS_ONLINE, &cs->flags); =20 mutex_unlock(&cpuset_mutex); cpus_read_unlock(); --=20 2.34.1 From nobody Sun Dec 14 02:02:10 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 7A16A234964; Fri, 8 Aug 2025 09:39:43 +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=1754645985; cv=none; b=PL+3i5gKpkqqIovi0Vh7qX2hrw9FVrR5xJWaC2eYn3qEyQ5gkwRaBJ6saF+10A1wdhzrm0i1L2uZpcHgnOI4bcaHFBAQbl/vOHiW/LkeqY+USIHuhNnMC+LFJj+yg4YiEOlrU9xzGgckOPJcAIB7AezJfBPzRzTgNo35prhejZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754645985; c=relaxed/simple; bh=nuvDQkTuXmlWPc3BCR56LkiqLEc43VVTTjcKcdBiriQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EZgm5Y89K3qpOmxxVgL7NywSNf6jaMlLOGGQ9x9EkoAvg6Oz8eJFnjhne0KffIMK8qLv4c67D/w0WA7Z1/hEucOrUrtTFOlptK7iqL7dr4PiNcT2ACTcaMbYoWNunhsA09GV7T0WdXz3DBS+xN8a3J9GwF2z+bSCQ2paGfbulG8= 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 4byzWy04TBzKHMsQ; Fri, 8 Aug 2025 17:39:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 1FACC1A1C15; Fri, 8 Aug 2025 17:39:41 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgCXo7XPxZVooOS_Cw--.51716S4; Fri, 08 Aug 2025 17:39:40 +0800 (CST) From: Chen Ridong To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, longman@redhat.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next 2/4] cpuset: add helpers for cpuset related locks Date: Fri, 8 Aug 2025 09:25:13 +0000 Message-Id: <20250808092515.764820-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250808092515.764820-1-chenridong@huaweicloud.com> References: <20250808092515.764820-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: Syh0CgCXo7XPxZVooOS_Cw--.51716S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Zr4kZF4DKF1DCFWUGrW5Awb_yoW8Zw48pF yDK347JrW5AF18u343Gw1Uua48Kw1kWa1UG3WkJa4rZFy2vF1q9F1DCr9xXr15Kr47CF1U AFsI93ya9a4DJrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0jN t3UUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Add guard_cpus_read_and_cpuset and guard_cpuset helpers for cpuset, which will be user for subsequent patched to make code concise; Signed-off-by: Chen Ridong --- include/linux/cpuset.h | 1 + kernel/cgroup/cpuset-internal.h | 2 ++ kernel/cgroup/cpuset.c | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 2ddb256187b5..6153de28acf0 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -74,6 +74,7 @@ extern void inc_dl_tasks_cs(struct task_struct *task); extern void dec_dl_tasks_cs(struct task_struct *task); extern void cpuset_lock(void); extern void cpuset_unlock(void); +extern void guard_cpuset(void); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mas= k); extern bool cpuset_cpus_allowed_fallback(struct task_struct *p); extern bool cpuset_cpu_is_isolated(int cpu); diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index 75b3aef39231..084e19fe33d5 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -277,6 +277,8 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file *o= f, char *buf, size_t nbytes, loff_t off); int cpuset_common_seq_show(struct seq_file *sf, void *v); =20 +void guard_cpus_read_and_cpuset(void); + /* * cpuset-v1.c */ diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index cf7cd2255265..f6cdb5cdffe8 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -260,6 +260,17 @@ void cpuset_unlock(void) mutex_unlock(&cpuset_mutex); } =20 +void guard_cpuset(void) +{ + guard(mutex)(&cpuset_mutex); +} + +void guard_cpus_read_and_cpuset(void) +{ + guard(cpus_read_lock)(); + guard(mutex)(&cpuset_mutex); +} + static DEFINE_SPINLOCK(callback_lock); =20 void cpuset_callback_lock_irq(void) --=20 2.34.1 From nobody Sun Dec 14 02:02:10 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 A809B26D4F7; Fri, 8 Aug 2025 09:39:43 +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=1754645986; cv=none; b=BVSC6KxjfdiURsLqGOcDhL3sORx89Zl54pWX3Z8yZ5QfRAcZL5DCe6Z0FGm05aYuLDEUIMSFGBymE+vJNm3KHzJM95hWUSYkSODkJUcWOgy2eC0LGr7vMRc70AE0H1eurXgxI6jLHfLZVci4rLhOGMI40wQY/1BPOuIoUieX7vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754645986; c=relaxed/simple; bh=Mg80xmJK9bQ8a2X6BBD010qfIsSEnKAortDyuVurY40=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IWSU1rNyRqcmwNd4uxQebmW3HfCkObnzcyEHpSfT/lYZ66wWf6fmTYfo2Jgs028yAse8H7B/yp50mkNXCfx7gy4Nb9jgYLnrJ06zqjM5uAEHkmV5guU7aQ50oyF237+mBVJNhcUS9A6WzEEb76Yxgefm5QOpma1sDApx2bFi3YA= 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 4byzWy499PzYQvC4; Fri, 8 Aug 2025 17:39:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 370191A1208; Fri, 8 Aug 2025 17:39:41 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgCXo7XPxZVooOS_Cw--.51716S5; Fri, 08 Aug 2025 17:39:40 +0800 (CST) From: Chen Ridong To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, longman@redhat.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next 3/4] cpuset: use guard_cpus_read_and_cpuset to make code concise Date: Fri, 8 Aug 2025 09:25:14 +0000 Message-Id: <20250808092515.764820-4-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250808092515.764820-1-chenridong@huaweicloud.com> References: <20250808092515.764820-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: Syh0CgCXo7XPxZVooOS_Cw--.51716S5 X-Coremail-Antispam: 1UD129KBjvJXoWxKr1rJFW8GrWDXr1kCw1kuFg_yoW7Ar48pF 909rW7JayUJr4kuw4fGa4DuF1rKw10gF4UGFykG3WrAFy2yFnI9Fy8GasYgry5Gr9rCrW5 JFnFgws09ayUJF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8Ru WJUUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong Several functions currently implement manual locking sequences for both cpus_read_lock() and cpuset_mutex. Replace these repetitive patterns with the new guard_cpus_read_and_cpuset() helper. Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset-v1.c | 22 +++++++--------------- kernel/cgroup/cpuset.c | 39 ++++++++++----------------------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c index b69a7db67090..70685b90759c 100644 --- a/kernel/cgroup/cpuset-v1.c +++ b/kernel/cgroup/cpuset-v1.c @@ -169,10 +169,10 @@ static int cpuset_write_s64(struct cgroup_subsys_stat= e *css, struct cftype *cft, cpuset_filetype_t type =3D cft->private; int retval =3D -ENODEV; =20 - cpus_read_lock(); - cpuset_lock(); + guard_cpus_read_and_cpuset(); + if (!is_cpuset_online(cs)) - goto out_unlock; + return retval; =20 switch (type) { case FILE_SCHED_RELAX_DOMAIN_LEVEL: @@ -183,9 +183,6 @@ static int cpuset_write_s64(struct cgroup_subsys_state = *css, struct cftype *cft, retval =3D -EINVAL; break; } -out_unlock: - cpuset_unlock(); - cpus_read_unlock(); return retval; } =20 @@ -454,12 +451,9 @@ static int cpuset_write_u64(struct cgroup_subsys_state= *css, struct cftype *cft, cpuset_filetype_t type =3D cft->private; int retval =3D 0; =20 - cpus_read_lock(); - cpuset_lock(); - if (!is_cpuset_online(cs)) { - retval =3D -ENODEV; - goto out_unlock; - } + guard_cpus_read_and_cpuset(); + if (!is_cpuset_online(cs)) + return -ENODEV; =20 switch (type) { case FILE_CPU_EXCLUSIVE: @@ -497,9 +491,7 @@ static int cpuset_write_u64(struct cgroup_subsys_state = *css, struct cftype *cft, retval =3D -EINVAL; break; } -out_unlock: - cpuset_unlock(); - cpus_read_unlock(); + return retval; } =20 diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index f6cdb5cdffe8..110d2b93ff96 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3235,15 +3235,14 @@ ssize_t cpuset_write_resmask(struct kernfs_open_fil= e *of, int retval =3D -ENODEV; =20 buf =3D strstrip(buf); - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + guard_cpus_read_and_cpuset(); if (!is_cpuset_online(cs)) - goto out_unlock; + goto out; =20 trialcs =3D alloc_trial_cpuset(cs); if (!trialcs) { retval =3D -ENOMEM; - goto out_unlock; + goto out; } =20 switch (of_cft(of)->private) { @@ -3264,9 +3263,7 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file = *of, free_cpuset(trialcs); if (force_sd_rebuild) rebuild_sched_domains_locked(); -out_unlock: - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); +out: flush_workqueue(cpuset_migrate_mm_wq); return retval ?: nbytes; } @@ -3370,12 +3367,9 @@ static ssize_t cpuset_partition_write(struct kernfs_= open_file *of, char *buf, return -EINVAL; =20 css_get(&cs->css); - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + guard_cpus_read_and_cpuset(); if (is_cpuset_online(cs)) retval =3D update_prstate(cs, val); - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); css_put(&cs->css); return retval ?: nbytes; } @@ -3506,8 +3500,7 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) if (!parent) return 0; =20 - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + guard_cpus_read_and_cpuset(); =20 if (is_spread_page(parent)) set_bit(CS_SPREAD_PAGE, &cs->flags); @@ -3529,7 +3522,7 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) spin_unlock_irq(&callback_lock); =20 if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags)) - goto out_unlock; + return 0; =20 /* * Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is @@ -3548,7 +3541,7 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) cpuset_for_each_child(tmp_cs, pos_css, parent) { if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) { rcu_read_unlock(); - goto out_unlock; + return 0; } } rcu_read_unlock(); @@ -3559,9 +3552,6 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) cpumask_copy(cs->cpus_allowed, parent->cpus_allowed); cpumask_copy(cs->effective_cpus, parent->cpus_allowed); spin_unlock_irq(&callback_lock); -out_unlock: - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); return 0; } =20 @@ -3576,16 +3566,12 @@ static void cpuset_css_offline(struct cgroup_subsys= _state *css) { struct cpuset *cs =3D css_cs(css); =20 - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + guard_cpus_read_and_cpuset(); =20 if (!cpuset_v2() && is_sched_load_balance(cs)) cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); =20 cpuset_dec(); - - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); } =20 /* @@ -3597,16 +3583,11 @@ static void cpuset_css_killed(struct cgroup_subsys_= state *css) { struct cpuset *cs =3D css_cs(css); =20 - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + guard_cpus_read_and_cpuset(); =20 /* Reset valid partition back to member */ if (is_partition_valid(cs)) update_prstate(cs, PRS_MEMBER); - - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); - } =20 static void cpuset_css_free(struct cgroup_subsys_state *css) --=20 2.34.1 From nobody Sun Dec 14 02:02:10 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 7A1D224E01D; Fri, 8 Aug 2025 09:39:43 +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=1754645987; cv=none; b=X7E5Bz+Y4YuBn5dXislu/RfMN7ZMVqNfgktIzMao5Om3tfI7gG7TuZDh6itIGR8XwHiYo6F88aGI8umfA/E8w/D9+JTEJlW6YfrDm+W98HVazzBDOB5nPZbivrSMds2I3nkgAF0bXOuN5RNLonLOKNYOIo78Cu509Dpzg+gqPhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754645987; c=relaxed/simple; bh=Ex95s0uF8ODB8eGIswPHwhKG9L1mxT9yhGmcc8dJy9A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dg2172inAgj5KvK8wXRphjasj1mC3b5BZrrpieYlPoAxlTDUCUeaTUYAiRxwQwI6AW6c8JlvRHmp7hUS+9G+knofPW6wyu3DoHTUrLHpR5FACa9QLc3BildvXs0ps+VOSs8Q5CzdvwX2ckziG323pk+hAGENOTuuZLyrebgLlGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4byzWy1D66zKHMsW; Fri, 8 Aug 2025 17:39:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 464C81A018D; Fri, 8 Aug 2025 17:39:41 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgCXo7XPxZVooOS_Cw--.51716S6; Fri, 08 Aug 2025 17:39:41 +0800 (CST) From: Chen Ridong To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, longman@redhat.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com Subject: [PATCH -next 4/4] cpuset: replace cpuset_lock() with guard_cpuset() Date: Fri, 8 Aug 2025 09:25:15 +0000 Message-Id: <20250808092515.764820-5-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250808092515.764820-1-chenridong@huaweicloud.com> References: <20250808092515.764820-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: Syh0CgCXo7XPxZVooOS_Cw--.51716S6 X-Coremail-Antispam: 1UD129KBjvJXoWxur17Zr18Jw1UtryxuF43GFg_yoW5XFW5pF ZI9347JFWrAr18u34UWw15uFySgw1kCa1UAF95G34rAry2yF429r1kJa9xGr1rKry3CFW5 WF9rK3ya9FyDtaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2 AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6r W5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF 7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7I U0189tUUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ Content-Type: text/plain; charset="utf-8" From: Chen Ridong The guard_cpuset() is introduced, we can replace all cpuset_lock() usage with it and remove the cpuset_lock(). Signed-off-by: Chen Ridong --- include/linux/cpuset.h | 2 -- kernel/cgroup/cpuset.c | 10 ---------- kernel/sched/syscalls.c | 15 +++++---------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 6153de28acf0..1baf12f4be19 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -72,8 +72,6 @@ extern void cpuset_force_rebuild(void); extern void cpuset_update_active_cpus(void); extern void inc_dl_tasks_cs(struct task_struct *task); extern void dec_dl_tasks_cs(struct task_struct *task); -extern void cpuset_lock(void); -extern void cpuset_unlock(void); extern void guard_cpuset(void); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mas= k); extern bool cpuset_cpus_allowed_fallback(struct task_struct *p); diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 110d2b93ff96..04ed73d0887e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -250,16 +250,6 @@ static struct cpuset top_cpuset =3D { =20 static DEFINE_MUTEX(cpuset_mutex); =20 -void cpuset_lock(void) -{ - mutex_lock(&cpuset_mutex); -} - -void cpuset_unlock(void) -{ - mutex_unlock(&cpuset_mutex); -} - void guard_cpuset(void) { guard(mutex)(&cpuset_mutex); diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index 77ae87f36e84..954f6e9af41b 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -577,8 +577,10 @@ int __sched_setscheduler(struct task_struct *p, * information. */ if (dl_policy(policy) || dl_policy(p->policy)) { - cpuset_locked =3D true; - cpuset_lock(); + if (!cpuset_locked) { + guard_cpuset(); + cpuset_locked =3D true; + } } =20 /* @@ -660,8 +662,6 @@ int __sched_setscheduler(struct task_struct *p, if (unlikely(oldpolicy !=3D -1 && oldpolicy !=3D p->policy)) { policy =3D oldpolicy =3D -1; task_rq_unlock(rq, p, &rf); - if (cpuset_locked) - cpuset_unlock(); goto recheck; } =20 @@ -733,11 +733,8 @@ int __sched_setscheduler(struct task_struct *p, head =3D splice_balance_callbacks(rq); task_rq_unlock(rq, p, &rf); =20 - if (pi) { - if (cpuset_locked) - cpuset_unlock(); + if (pi) rt_mutex_adjust_pi(p); - } =20 /* Run balance callbacks after we've adjusted the PI chain: */ balance_callbacks(rq, head); @@ -747,8 +744,6 @@ int __sched_setscheduler(struct task_struct *p, =20 unlock: task_rq_unlock(rq, p, &rf); - if (cpuset_locked) - cpuset_unlock(); return retval; } =20 --=20 2.34.1