All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors
@ 2026-06-02  4:55 Tao Cui
  2026-06-02  7:46 ` Michal Koutný
  0 siblings, 1 reply; 4+ messages in thread
From: Tao Cui @ 2026-06-02  4:55 UTC (permalink / raw)
  To: longman, chenridong, tj, hannes, mkoutny, cgroups; +Cc: linux-kernel, Tao Cui

From: Tao Cui <cuitao@kylinos.cn>

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
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
 kernel/cgroup/cpuset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 591e3aa487fc..8605b4da610e 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors
  2026-06-02  4:55 [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors Tao Cui
@ 2026-06-02  7:46 ` Michal Koutný
  2026-06-02  8:19   ` Tao Cui
  2026-06-02 18:41   ` Waiman Long
  0 siblings, 2 replies; 4+ messages in thread
From: Michal Koutný @ 2026-06-02  7:46 UTC (permalink / raw)
  To: Tao Cui; +Cc: longman, chenridong, tj, hannes, cgroups, linux-kernel, Tao Cui

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

Hi.

On Tue, Jun 02, 2026 at 12:55:21PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
> 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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors
  2026-06-02  7:46 ` Michal Koutný
@ 2026-06-02  8:19   ` Tao Cui
  2026-06-02 18:41   ` Waiman Long
  1 sibling, 0 replies; 4+ messages in thread
From: Tao Cui @ 2026-06-02  8:19 UTC (permalink / raw)
  To: Michal Koutný
  Cc: cui.tao, longman, chenridong, tj, hannes, cgroups, linux-kernel,
	Tao Cui

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

在 2026/6/2 15:46, Michal Koutný 写道:
> Hi.
> 
> On Tue, Jun 02, 2026 at 12:55:21PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
>> 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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors
  2026-06-02  7:46 ` Michal Koutný
  2026-06-02  8:19   ` Tao Cui
@ 2026-06-02 18:41   ` Waiman Long
  1 sibling, 0 replies; 4+ messages in thread
From: Waiman Long @ 2026-06-02 18:41 UTC (permalink / raw)
  To: Michal Koutný, Tao Cui
  Cc: chenridong, tj, hannes, cgroups, linux-kernel, Tao Cui


On 6/2/26 3:46 AM, Michal Koutný wrote:
> Hi.
>
> On Tue, Jun 02, 2026 at 12:55:21PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
>> 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.

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-02 18:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02  4:55 [PATCH v2] cgroup/cpuset: Fix update_prstate() always returning 0 on partition errors Tao Cui
2026-06-02  7:46 ` Michal Koutný
2026-06-02  8:19   ` Tao Cui
2026-06-02 18:41   ` Waiman Long

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.