From nobody Sat Feb 7 08:23:16 2026 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 9592B76056; Fri, 16 Aug 2024 08:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797309; cv=none; b=N/jndNFNHXoifH3JCd2t0dao7o/5GhqgLdW61KuvGS/akaEMwe8ScMmtqTT+rtNmBTpW38mVoNuWqlVXeoNEFWsw2dNQbh9l343Y2CEr7wOhrWoXsp2Q5Qj+Bgw5fzs/qg2GVwvvrRZ73J49yRto9wrGGVOKTqxoLHYd1sQqUEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797309; c=relaxed/simple; bh=K0UEXoH/fXxsU2M6msDw9lrpONepQ8q4QEg68oanFc8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EeKASk3IKsGISfN0ZOVTen0ZiwlZy5WgV2YYYvbRioG96pIEwErYBDALER0+QR9YAfTHgrwYZsFUvdc2HOWZ90UvSf8jbLgyRdF6/zn0hGQjF3Yahf7Yg5lHU4LqDswsVeaI+HeDQos6csPWFNl8DwApsUnjNrDpxQ85NxhKF88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WlZtp6mvcz20lrJ; Fri, 16 Aug 2024 16:30:26 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id 054FD1A016C; Fri, 16 Aug 2024 16:35:03 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 16:35:02 +0800 From: Chen Ridong To: , , , , , , CC: , Subject: [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Date: Fri, 16 Aug 2024 08:27:25 +0000 Message-ID: <20240816082727.2779-2-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816082727.2779-1-chenridong@huawei.com> References: <20240816082727.2779-1-chenridong@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" When enable a remote partition, I found that: cd /sys/fs/cgroup/ mkdir test mkdir test/test1 echo +cpuset > cgroup.subtree_control echo +cpuset > test/cgroup.subtree_control echo 3 > test/test1/cpuset.cpus echo root > test/test1/cpuset.cpus.partition cat test/test1/cpuset.cpus.partition root invalid (Parent is not a partition root) The parent of a remote partition could not be a root. This is due to the emtpy effective_xcpus. It would be better to prompt the message "invalid cpu list in cpuset.cpus.exclusive". Signed-off-by: Chen Ridong --- kernel/cgroup/cpuset.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index e34fd6108b06..fdd5346616d3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -80,6 +80,7 @@ enum prs_errcode { PERR_HOTPLUG, PERR_CPUSEMPTY, PERR_HKEEPING, + PERR_PMT, }; =20 static const char * const perr_strings[] =3D { @@ -91,6 +92,7 @@ static const char * const perr_strings[] =3D { [PERR_HOTPLUG] =3D "No cpu available due to hotplug", [PERR_CPUSEMPTY] =3D "cpuset.cpus and cpuset.cpus.exclusive are empty", [PERR_HKEEPING] =3D "partition config conflicts with housekeeping setup", + [PERR_PMT] =3D "Enable partition not permitted", }; =20 struct cpuset { @@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, * The user must have sysadmin privilege. */ if (!capable(CAP_SYS_ADMIN)) - return 0; + return PERR_PMT; =20 /* * The requested exclusive_cpus must not be allocated to other @@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, if (cpumask_empty(tmp->new_cpus) || cpumask_intersects(tmp->new_cpus, subpartitions_cpus) || cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) - return 0; + return PERR_INVCPUS; =20 spin_lock_irq(&callback_lock); isolcpus_updated =3D partition_xcpus_add(new_prs, NULL, tmp->new_cpus); @@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, */ update_tasks_cpumask(&top_cpuset, tmp->new_cpus); update_sibling_cpumasks(&top_cpuset, NULL, tmp); - return 1; + return 0; } =20 /* @@ -3151,24 +3153,26 @@ static int update_prstate(struct cpuset *cs, int ne= w_prs) goto out; =20 if (!old_prs) { - enum partition_cmd cmd =3D (new_prs =3D=3D PRS_ROOT) - ? partcmd_enable : partcmd_enablei; - /* - * cpus_allowed and exclusive_cpus cannot be both empty. - */ - if (xcpus_empty(cs)) { - err =3D PERR_CPUSEMPTY; - goto out; - } + * 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; =20 - err =3D update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask); - /* - * If an attempt to become local partition root fails, - * try to become a remote partition root instead. - */ - if (err && remote_partition_enable(cs, new_prs, &tmpmask)) - err =3D 0; + /* + * cpus_allowed and exclusive_cpus cannot be both empty. + */ + if (xcpus_empty(cs)) { + err =3D PERR_CPUSEMPTY; + goto out; + } + + err =3D update_parent_effective_cpumask(cs, cmd, NULL, &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 Sat Feb 7 08:23:16 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 E953912E1E9; Fri, 16 Aug 2024 08:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797308; cv=none; b=JhBX9eABOwZUV4/euf8P7wRFwgxwwdnIdvBmvHUwQhchJGD8QDRLnUlK4e8Fy+dsRPnVw2e5clz3lTaJy0yeAuK6LL7ef230KWR8KOLevf2LaoJMLFTrfxeKzE8st8x8WpzS6zPVW6uaksXELufOTygnphN6VcrgiR90tavLT9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797308; c=relaxed/simple; bh=Y7vmq3Xksg5NQcc6IqJ0dapj9CjWvtwa3OlxrJvHff8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rSb4dCNfjEYr5YVWgFDPY9ctMjoqdJ0vfmgWJOXsXgvqFku9T0OQcS7h34gKsWfpX2DfMRpU1t5ZI86ugRZLlujLTZ37wUIbTFrussnoH9UYosE+eHg3pPszEy4XSBayeKYEtXYM6mH2mppc3/5zl46ogGD0Ps55KrKHiKM3o9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WlZzp37zlzcdR7; Fri, 16 Aug 2024 16:34:46 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id 7324418009B; Fri, 16 Aug 2024 16:35:03 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 16:35:02 +0800 From: Chen Ridong To: , , , , , , CC: , Subject: [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus Date: Fri, 16 Aug 2024 08:27:26 +0000 Message-ID: <20240816082727.2779-3-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816082727.2779-1-chenridong@huawei.com> References: <20240816082727.2779-1-chenridong@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" Both fetch_xcpus and user_xcpus functions are used to retrieve the value of exclusive_cpus. If exclusive_cpus is not set, cpus_allowed is the implicit value used as exclusive in a local partition. I can not imagine a scenario where effective_xcpus is not empty when exclusive_cpus is empty. Therefore, I suggest removing the fetch_xcpus function. Signed-off-by: Chen Ridong Reviewed-by: Saket Kumar Bhaskar =20 Reviewed-by: Waiman Long --- kernel/cgroup/cpuset.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index fdd5346616d3..8be0259065f5 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -771,13 +771,6 @@ static inline bool xcpus_empty(struct cpuset *cs) cpumask_empty(cs->exclusive_cpus); } =20 -static inline struct cpumask *fetch_xcpus(struct cpuset *cs) -{ - return !cpumask_empty(cs->exclusive_cpus) ? cs->exclusive_cpus : - cpumask_empty(cs->effective_xcpus) ? cs->cpus_allowed - : cs->effective_xcpus; -} - /* * cpusets_are_exclusive() - check if two cpusets are exclusive * @@ -785,8 +778,8 @@ static inline struct cpumask *fetch_xcpus(struct cpuset= *cs) */ static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset= *cs2) { - struct cpumask *xcpus1 =3D fetch_xcpus(cs1); - struct cpumask *xcpus2 =3D fetch_xcpus(cs2); + struct cpumask *xcpus1 =3D user_xcpus(cs1); + struct cpumask *xcpus2 =3D user_xcpus(cs2); =20 if (cpumask_intersects(xcpus1, xcpus2)) return false; @@ -2585,7 +2578,7 @@ static int update_cpumask(struct cpuset *cs, struct c= puset *trialcs, invalidate =3D true; rcu_read_lock(); cpuset_for_each_child(cp, css, parent) { - struct cpumask *xcpus =3D fetch_xcpus(trialcs); + struct cpumask *xcpus =3D user_xcpus(trialcs); =20 if (is_partition_valid(cp) && cpumask_intersects(xcpus, cp->effective_xcpus)) { --=20 2.34.1 From nobody Sat Feb 7 08:23:16 2026 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 76107136E21; Fri, 16 Aug 2024 08:35:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797310; cv=none; b=PfAgzbYktOM8I0rVXl5NGi0MJD+2alYdRbzprerHvapeUqF4bfBq5VFwBZPzyr7TlEnlF6IJpxeUxJd6BRU0fOvm6KAiOZEpXRnfUtRXFw0LnxDxSNPvD9+EnRQZD6yMI4NC2qkT5WWcJX9DkmWZhxG9YnVr6xkC2TYMXD1E3LI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723797310; c=relaxed/simple; bh=SCwFfgAFPR5wylSjlK+s1jBfcRqdchYZvSsCvVnfYPg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VoPqmpTzqNxAK0nHt2/ptXEfMgJBYtiSWM9/lhL7ouyITTzjIEhNoV9GRp6rfhvKOcn4i/QXURx/ZZElB3fdduidV9vVqPLLCWxWzOJ3nwjBrCnuAhfiKVtvyYhx3GDEFeeTiD+8WSYAS/aiVB/kJX6d1obFXSAKmCfIP5Sly/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WlZtT4cMTz1j6YG; Fri, 16 Aug 2024 16:30:09 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id E183C1A016C; Fri, 16 Aug 2024 16:35:03 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 16:35:03 +0800 From: Chen Ridong To: , , , , , , CC: , Subject: [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Date: Fri, 16 Aug 2024 08:27:27 +0000 Message-ID: <20240816082727.2779-4-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816082727.2779-1-chenridong@huawei.com> References: <20240816082727.2779-1-chenridong@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" use_parent_ecpus is used to track whether the children are using the parent's effective_cpus. When a parent's effective_cpus is changed due to changes in a child partition's effective_xcpus, any child using parent'effective_cpus must call update_cpumasks_hier. However, if a child is not a valid partition, it is sufficient to determine whether to call update_cpumasks_hier based on whether the child's effective_cpus is going to change. To make the code more succinct, it is suggested to remove use_parent_ecpus. Signed-off-by: Chen Ridong Reviewed-by: Waiman Long --- kernel/cgroup/cpuset.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 8be0259065f5..71c24542966b 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -185,12 +185,6 @@ struct cpuset { /* partition root state */ int partition_root_state; =20 - /* - * Default hierarchy only: - * use_parent_ecpus - set if using parent's effective_cpus - */ - int use_parent_ecpus; - /* * number of SCHED_DEADLINE tasks attached to this cpuset, so that we * know when to rebuild associated root domain bandwidth information. @@ -1505,11 +1499,8 @@ static void reset_partition_data(struct cpuset *cs) if (is_cpu_exclusive(cs)) clear_bit(CS_CPU_EXCLUSIVE, &cs->flags); } - if (!cpumask_and(cs->effective_cpus, - parent->effective_cpus, cs->cpus_allowed)) { - cs->use_parent_ecpus =3D true; + if (!cpumask_and(cs->effective_cpus, parent->effective_cpus, cs->cpus_all= owed)) cpumask_copy(cs->effective_cpus, parent->effective_cpus); - } } =20 /* @@ -1683,8 +1674,6 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, spin_lock_irq(&callback_lock); isolcpus_updated =3D partition_xcpus_add(new_prs, NULL, tmp->new_cpus); list_add(&cs->remote_sibling, &remote_children); - if (cs->use_parent_ecpus) - cs->use_parent_ecpus =3D false; spin_unlock_irq(&callback_lock); update_unbound_workqueue_cpumask(isolcpus_updated); =20 @@ -2309,13 +2298,8 @@ static void update_cpumasks_hier(struct cpuset *cs, = struct tmpmasks *tmp, * it is a partition root that has explicitly distributed * out all its CPUs. */ - if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) { + if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) cpumask_copy(tmp->new_cpus, parent->effective_cpus); - if (!cp->use_parent_ecpus) - cp->use_parent_ecpus =3D true; - } else if (cp->use_parent_ecpus) { - cp->use_parent_ecpus =3D false; - } =20 if (remote) goto get_css; @@ -2452,8 +2436,7 @@ static void update_sibling_cpumasks(struct cpuset *pa= rent, struct cpuset *cs, * Check all its siblings and call update_cpumasks_hier() * if their effective_cpus will need to be changed. * - * With the addition of effective_xcpus which is a subset of - * cpus_allowed. It is possible a change in parent's effective_cpus + * It is possible a change in parent's effective_cpus * due to a change in a child partition's effective_xcpus will impact * its siblings even if they do not inherit parent's effective_cpus * directly. @@ -2467,8 +2450,7 @@ static void update_sibling_cpumasks(struct cpuset *pa= rent, struct cpuset *cs, cpuset_for_each_child(sibling, pos_css, parent) { if (sibling =3D=3D cs) continue; - if (!sibling->use_parent_ecpus && - !is_partition_valid(sibling)) { + if (!is_partition_valid(sibling)) { compute_effective_cpumask(tmp->new_cpus, sibling, parent); if (cpumask_equal(tmp->new_cpus, sibling->effective_cpus)) @@ -4128,7 +4110,6 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) if (is_in_v2_mode()) { cpumask_copy(cs->effective_cpus, parent->effective_cpus); cs->effective_mems =3D parent->effective_mems; - cs->use_parent_ecpus =3D true; } spin_unlock_irq(&callback_lock); =20 @@ -4194,9 +4175,6 @@ static void cpuset_css_offline(struct cgroup_subsys_s= tate *css) is_sched_load_balance(cs)) update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); =20 - if (cs->use_parent_ecpus) - cs->use_parent_ecpus =3D false; - cpuset_dec(); clear_bit(CS_ONLINE, &cs->flags); =20 --=20 2.34.1