From: Chen Ridong <chenridong@huawei.com>
Refactor cpus_allowed_validate_change to handle the special case where
cpuset.cpus can be set even when violating partition sibling CPU
exclusivity rules. This differs from the general validation logic in
validate_change. Add a wrapper function to properly handle this
exceptional case.
The trialcs->prs_err field is cleared before performing validation checks
for both CPU changes and partition errors. If cpus_allowed_validate_change
fails its validation, trialcs->prs_err is set to PERR_NOTEXCL. If partition
validation fails, the specific error code returned by validate_partition
is assigned to trialcs->prs_err.
With the partition validation status now directly available through
trialcs->prs_err, the local boolean variable 'invalidate' becomes
redundant and can be safely removed.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
Reviewed-by: Waiman Long <longman@redhat.com>
---
kernel/cgroup/cpuset.c | 84 ++++++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 39 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index aaf8244b3cea..ab8572038fce 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2417,6 +2417,42 @@ static enum prs_errcode validate_partition(struct cpuset *cs, struct cpuset *tri
return PERR_NONE;
}
+static int cpus_allowed_validate_change(struct cpuset *cs, struct cpuset *trialcs,
+ struct tmpmasks *tmp)
+{
+ int retval;
+ struct cpuset *parent = parent_cs(cs);
+
+ retval = validate_change(cs, trialcs);
+
+ if ((retval == -EINVAL) && cpuset_v2()) {
+ struct cgroup_subsys_state *css;
+ struct cpuset *cp;
+
+ /*
+ * The -EINVAL error code indicates that partition sibling
+ * CPU exclusivity rule has been violated. We still allow
+ * the cpumask change to proceed while invalidating the
+ * partition. However, any conflicting sibling partitions
+ * have to be marked as invalid too.
+ */
+ trialcs->prs_err = PERR_NOTEXCL;
+ rcu_read_lock();
+ cpuset_for_each_child(cp, css, parent) {
+ struct cpumask *xcpus = user_xcpus(trialcs);
+
+ if (is_partition_valid(cp) &&
+ cpumask_intersects(xcpus, cp->effective_xcpus)) {
+ rcu_read_unlock();
+ update_parent_effective_cpumask(cp, partcmd_invalidate, NULL, tmp);
+ rcu_read_lock();
+ }
+ }
+ rcu_read_unlock();
+ retval = 0;
+ }
+ return retval;
+}
/**
* update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
@@ -2429,8 +2465,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
{
int retval;
struct tmpmasks tmp;
- struct cpuset *parent = parent_cs(cs);
- bool invalidate = false;
bool force = false;
int old_prs = cs->partition_root_state;
enum prs_errcode prs_err;
@@ -2447,12 +2481,10 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
return -ENOMEM;
compute_trialcs_excpus(trialcs, cs);
+ trialcs->prs_err = PERR_NONE;
- prs_err = validate_partition(cs, trialcs);
- if (prs_err) {
- invalidate = true;
- cs->prs_err = prs_err;
- }
+ if (cpus_allowed_validate_change(cs, trialcs, &tmp) < 0)
+ goto out_free;
/*
* Check all the descendants in update_cpumasks_hier() if
@@ -2460,40 +2492,14 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
*/
force = !cpumask_equal(cs->effective_xcpus, trialcs->effective_xcpus);
- retval = validate_change(cs, trialcs);
-
- if ((retval == -EINVAL) && cpuset_v2()) {
- struct cgroup_subsys_state *css;
- struct cpuset *cp;
-
- /*
- * The -EINVAL error code indicates that partition sibling
- * CPU exclusivity rule has been violated. We still allow
- * the cpumask change to proceed while invalidating the
- * partition. However, any conflicting sibling partitions
- * have to be marked as invalid too.
- */
- invalidate = true;
- rcu_read_lock();
- cpuset_for_each_child(cp, css, parent) {
- struct cpumask *xcpus = user_xcpus(trialcs);
-
- if (is_partition_valid(cp) &&
- cpumask_intersects(xcpus, cp->effective_xcpus)) {
- rcu_read_unlock();
- update_parent_effective_cpumask(cp, partcmd_invalidate, NULL, &tmp);
- rcu_read_lock();
- }
- }
- rcu_read_unlock();
- retval = 0;
+ prs_err = validate_partition(cs, trialcs);
+ if (prs_err) {
+ trialcs->prs_err = prs_err;
+ cs->prs_err = prs_err;
}
- if (retval < 0)
- goto out_free;
-
if (is_partition_valid(cs) ||
- (is_partition_invalid(cs) && !invalidate)) {
+ (is_partition_invalid(cs) && !trialcs->prs_err)) {
struct cpumask *xcpus = trialcs->effective_xcpus;
if (cpumask_empty(xcpus) && is_partition_invalid(cs))
@@ -2504,7 +2510,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
*/
if (is_remote_partition(cs))
remote_cpus_update(cs, NULL, xcpus, &tmp);
- else if (invalidate)
+ else if (trialcs->prs_err)
update_parent_effective_cpumask(cs, partcmd_invalidate,
NULL, &tmp);
else
--
2.34.1
From: Chen Ridong <chenridong@huawei.com>
The commit c6366739804f ("cpuset: refactor cpus_allowed_validate_change")
inadvertently removed the error return when cpus_allowed_validate_change()
fails. This patch restores the proper error handling by returning retval
when the validation check fails.
Fixes: c6366739804f ("cpuset: refactor cpus_allowed_validate_change")
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
kernel/cgroup/cpuset.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 506a7178f0b3..20dface3c3e0 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2515,7 +2515,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
compute_trialcs_excpus(trialcs, cs);
trialcs->prs_err = PERR_NONE;
- if (cpus_allowed_validate_change(cs, trialcs, &tmp) < 0)
+ retval = cpus_allowed_validate_change(cs, trialcs, &tmp);
+ if (retval < 0)
goto out_free;
/*
--
2.34.1
On Fri, Sep 19, 2025 at 09:49:03AM +0000, Chen Ridong wrote: > From: Chen Ridong <chenridong@huawei.com> > > The commit c6366739804f ("cpuset: refactor cpus_allowed_validate_change") > inadvertently removed the error return when cpus_allowed_validate_change() > fails. This patch restores the proper error handling by returning retval > when the validation check fails. > > Fixes: c6366739804f ("cpuset: refactor cpus_allowed_validate_change") > Signed-off-by: Chen Ridong <chenridong@huawei.com> Applied to cgroup/for-6.18. Thanks. -- tejun
On 2025/9/20 0:43, Tejun Heo wrote: > On Fri, Sep 19, 2025 at 09:49:03AM +0000, Chen Ridong wrote: >> From: Chen Ridong <chenridong@huawei.com> >> >> The commit c6366739804f ("cpuset: refactor cpus_allowed_validate_change") >> inadvertently removed the error return when cpus_allowed_validate_change() >> fails. This patch restores the proper error handling by returning retval >> when the validation check fails. >> >> Fixes: c6366739804f ("cpuset: refactor cpus_allowed_validate_change") >> Signed-off-by: Chen Ridong <chenridong@huawei.com> > > Applied to cgroup/for-6.18. > > Thanks. > Thank you very much. -- Best regards, Ridong
On 2025/9/19 17:49, Chen Ridong wrote: > From: Chen Ridong <chenridong@huawei.com> > > The commit c6366739804f ("cpuset: refactor cpus_allowed_validate_change") > inadvertently removed the error return when cpus_allowed_validate_change() > fails. This patch restores the proper error handling by returning retval > when the validation check fails. > > Fixes: c6366739804f ("cpuset: refactor cpus_allowed_validate_change") > Signed-off-by: Chen Ridong <chenridong@huawei.com> > --- > kernel/cgroup/cpuset.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index 506a7178f0b3..20dface3c3e0 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -2515,7 +2515,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, > compute_trialcs_excpus(trialcs, cs); > trialcs->prs_err = PERR_NONE; > > - if (cpus_allowed_validate_change(cs, trialcs, &tmp) < 0) > + retval = cpus_allowed_validate_change(cs, trialcs, &tmp); > + if (retval < 0) > goto out_free; > > /* Hi Longman, TJ, Sorry about the bug introduced in patch 8. Could you please apply this patch to fix the issue? -- Best regards, Ridong
© 2016 - 2025 Red Hat, Inc.