Skip to contentSkip to conversation

cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors

PATCH In review Tao Cui 3 participants 4 messages Jun 2

Subsystems (2)
lore
Share & tools
lore

Tao Cui

author
#0 lore raw

PATCH v2 1/1 cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors

From: Tao Cui <[email protected]>

update_prstate() stores the error code in cs->prs_err and transitions the partition to an invalid state, but always returns 0. The caller cpuset_partition_write() uses "return retval ?: nbytes", so the write syscall always appears to succeed from userspace even when the partition became invalid. Return -EINVAL when err is set so userspace can detect the failure immediately.

Assisted-by Claude:claude-opus-4-7
---
 kernel/cgroup/cpuset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/cpuset.c +1 -1
index 591e3aa487fc..8605b4da610e 100644
@@ -2965,7 +2965,7 @@ static int update_prstate(struct cpuset *cs, int new_prs)
 	if (force_sd_rebuild)
 		rebuild_sched_domains_locked();
 	free_tmpmasks(&tmpmask);
-	return 0;
+	return err ? -EINVAL : 0;
 }
 
 static struct cpuset *cpuset_attach_old_cs;
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi.

Quoted 7 lines · Tao Cui

update_prstate() stores the error code in cs->prs_err and transitions the partition to an invalid state, but always returns 0. The caller cpuset_partition_write() uses "return retval ?: nbytes", so the write syscall always appears to succeed from userspace even when the partition became invalid.
Return -EINVAL when err is set so userspace can detect
the failure immediately.

This is quite a visible UAPI change (a write can succeed to invalidate a partition) and users are meant to watch for cpuset.cpus.partition state anyway for asynchronous changes.

I'd not change this gratuitously.

Michal

author
#2 lore raw

Hi Michal,

You are absolutely right. Looking at this again, this patch is total suckage.

Returning 0 here is the correct declarative UAPI behavior. The invalid state records intent and can recover later when resources become available. Returning -EINVAL would only make things worse since the state has already been mutated.

Sorry for the noise. I'll drop this patch.

--
Tao

Quoted 19 lines · Michal Koutný

Hi.

Quoted 7 lines · Tao Cui

update_prstate() stores the error code in cs->prs_err and transitions the partition to an invalid state, but always returns 0. The caller cpuset_partition_write() uses "return retval ?: nbytes", so the write syscall always appears to succeed from userspace even when the partition became invalid.
Return -EINVAL when err is set so userspace can detect
the failure immediately.

This is quite a visible UAPI change (a write can succeed to invalidate a partition) and users are meant to watch for cpuset.cpus.partition state anyway for asynchronous changes.

I'd not change this gratuitously.

Michal

maintainer
#3 lore raw
In reply to Michal Koutný
Quoted 10 lines · Michal Koutný

Hi.

Quoted 7 lines · Tao Cui

update_prstate() stores the error code in cs->prs_err and transitions the partition to an invalid state, but always returns 0. The caller cpuset_partition_write() uses "return retval ?: nbytes", so the write syscall always appears to succeed from userspace even when the partition became invalid.
Return -EINVAL when err is set so userspace can detect
the failure immediately.

Quoted 3 lines

This is quite a visible UAPI change (a write can succeed to invalidate a partition) and users are meant to watch for cpuset.cpus.partition state anyway for asynchronous changes.

Right, it is purposely done to not return a write error when writing any cpuset control files. The only exception is cpuset.cpus.exclusive which can return failure when  an exclusive CPU has been taken. It is documented in cgroup-v2.rst.

Cheers,
Longman