Linux cgroups development
 help / color / mirror / Atom feed
* [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation
@ 2026-05-12  9:00 Sun Shaojie
  2026-05-13  6:55 ` Chen Ridong
  2026-05-13 19:52 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Sun Shaojie @ 2026-05-12  9:00 UTC (permalink / raw)
  To: Waiman Long, Chen Ridong, Tejun Heo, Johannes Weiner,
	Michal Koutný
  Cc: cgroups, linux-kernel, sunshaojie

From: sunshaojie <sunshaojie@kylinos.cn>

In update_parent_effective_cpumask() with partcmd_invalidate, the CPUs
to return to the parent are computed as:

    adding = cpumask_and(tmp->addmask, xcpus, parent->effective_xcpus);

where xcpus = user_xcpus(cs) which returns cs->exclusive_cpus (if set)
or cs->cpus_allowed. When exclusive_cpus is not set, user_xcpus(cs) can
contain CPUs that were never actually granted to the partition due to
sibling exclusion in compute_excpus(). Consequently, the invalidation
may return CPUs to the parent that remain in use by sibling partitions,
causing overlapping effective_cpus and triggering the
WARN_ON_ONCE(1) in generate_sched_domains().

Use cs->effective_xcpus instead, which reflects the CPUs actually
granted to this partition.

Reproducer (on a 4-CPU machine):

    cd /sys/fs/cgroup
    mkdir a1 b1

    # a1 becomes partition root with CPUs 0-1
    echo "0-1" > a1/cpuset.cpus
    echo "root" > a1/cpuset.cpus.partition

    # b1 becomes partition root with CPUs 1-2, but sibling exclusion
    # reduces its effective_xcpus to CPU 2 only
    echo "1-2" > b1/cpuset.cpus
    echo "root" > b1/cpuset.cpus.partition

    # b1 changes cpus_allowed to 0-1 -> partition invalidation
    echo "0-1" > b1/cpuset.cpus

    # Expected: CPUs 2-3  (only CPU 2 returned from b1)
    # Actual:   CPUs 1-3  (CPU 0-1 returned, overlapping with a1)
    cat cpuset.cpus.effective

dmesg will also show a WARNING from generate_sched_domains() reporting
overlapping partition root effective_cpus.

Fixes: 0c7f293efc87 ("cgroup/cpuset: Add cpuset.cpus.exclusive.effective for v2")
Signed-off-by: sunshaojie <sunshaojie@kylinos.cn>
---
 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 1335e437098e..2311470ef077 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1715,7 +1715,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
 		 */
 		if (is_partition_valid(parent))
 			adding = cpumask_and(tmp->addmask,
-					     xcpus, parent->effective_xcpus);
+					     cs->effective_xcpus,
+					     parent->effective_xcpus);
 		if (old_prs > 0)
 			new_prs = -old_prs;
 
-- 
2.43.0


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

* Re: [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation
  2026-05-12  9:00 [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation Sun Shaojie
@ 2026-05-13  6:55 ` Chen Ridong
  2026-05-13 19:52 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Chen Ridong @ 2026-05-13  6:55 UTC (permalink / raw)
  To: Sun Shaojie, Waiman Long, Tejun Heo, Johannes Weiner,
	Michal Koutný
  Cc: cgroups, linux-kernel



On 2026/5/12 17:00, Sun Shaojie wrote:
> From: sunshaojie <sunshaojie@kylinos.cn>
> 
> In update_parent_effective_cpumask() with partcmd_invalidate, the CPUs
> to return to the parent are computed as:
> 
>     adding = cpumask_and(tmp->addmask, xcpus, parent->effective_xcpus);
> 
> where xcpus = user_xcpus(cs) which returns cs->exclusive_cpus (if set)
> or cs->cpus_allowed. When exclusive_cpus is not set, user_xcpus(cs) can
> contain CPUs that were never actually granted to the partition due to
> sibling exclusion in compute_excpus(). Consequently, the invalidation
> may return CPUs to the parent that remain in use by sibling partitions,
> causing overlapping effective_cpus and triggering the
> WARN_ON_ONCE(1) in generate_sched_domains().
> 
> Use cs->effective_xcpus instead, which reflects the CPUs actually
> granted to this partition.
> 
> Reproducer (on a 4-CPU machine):
> 
>     cd /sys/fs/cgroup
>     mkdir a1 b1
> 
>     # a1 becomes partition root with CPUs 0-1
>     echo "0-1" > a1/cpuset.cpus
>     echo "root" > a1/cpuset.cpus.partition
> 
>     # b1 becomes partition root with CPUs 1-2, but sibling exclusion
>     # reduces its effective_xcpus to CPU 2 only
>     echo "1-2" > b1/cpuset.cpus
>     echo "root" > b1/cpuset.cpus.partition
> 
>     # b1 changes cpus_allowed to 0-1 -> partition invalidation
>     echo "0-1" > b1/cpuset.cpus
> 
>     # Expected: CPUs 2-3  (only CPU 2 returned from b1)
>     # Actual:   CPUs 1-3  (CPU 0-1 returned, overlapping with a1)
>     cat cpuset.cpus.effective
> 

Thank you for providing the reproducer. I was able to reproduce the issue.

#cd /sys/fs/cgroup
#mkdir a1 b1
#
#echo "0-1" > a1/cpuset.cpus
#echo "root" > a1/cpuset.cpus.partition
#echo "1-2" > b1/cpuset.cpus
#echo "root" > b1/cpuset.cpus.partition
#echo "0-1" > b1/cpuset.cpus
#cat cpuset.cpus.effective
1-3


 WARNING: kernel/cgroup/cpuset.c:867 at
rebuild_sched_domains_locked+0x32c/0x510, CPU#3: bash/540
 Modules linked in:
 CPU: 3 UID: 0 PID: 540 Comm: bash Not tainted 7.1.0-rc2-next-20260508 #1122
PREEMPT(full)
 Call Trace:
  <TASK>
  ? kfree+0x1fb/0x540
  ? update_cpumasks_hier+0x34d/0xa30
  cpuset_update_sd_hk_unlock+0x7b/0x90
  cpuset_write_resmask+0x3f0/0xc70
  kernfs_fop_write_iter+0x14c/0x200
  vfs_write+0x362/0x510
  ksys_write+0x6b/0xe0
  do_syscall_64+0xba/0x5a0
  entry_SYSCALL_64_after_hwframe+0x4b/0x53

And this patch can fix this issue.

> dmesg will also show a WARNING from generate_sched_domains() reporting
> overlapping partition root effective_cpus.
> 
> Fixes: 0c7f293efc87 ("cgroup/cpuset: Add cpuset.cpus.exclusive.effective for v2")
> Signed-off-by: sunshaojie <sunshaojie@kylinos.cn>

I think the Fixes tag should point to commit 2a3602030d80 ("cgroup/cpuset: Don't
invalidate sibling partitions on cpuset.cpus conflict"). Before this commit, the
issue should not have been reproducible, since a1/b1 would have been invalidated
if they were in conflict. No warning is observed in dmesg when resetting to
commit 7cc1720589d8 ("cpuset: remove v1-specific code from generate_sched_domains").

Other than that, the patch looks good to me.

Test-by: Chen Ridong <chenridong@huaweicloud.com>
Reviewed-by: Chen Ridong <chenridong@huaweicloud.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 1335e437098e..2311470ef077 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1715,7 +1715,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
>  		 */
>  		if (is_partition_valid(parent))
>  			adding = cpumask_and(tmp->addmask,
> -					     xcpus, parent->effective_xcpus);
> +					     cs->effective_xcpus,
> +					     parent->effective_xcpus);
>  		if (old_prs > 0)
>  			new_prs = -old_prs;
>  

-- 
Best regards,
Ridong


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

* Re: [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation
  2026-05-12  9:00 [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation Sun Shaojie
  2026-05-13  6:55 ` Chen Ridong
@ 2026-05-13 19:52 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-05-13 19:52 UTC (permalink / raw)
  To: Sun Shaojie
  Cc: Waiman Long, Chen Ridong, Johannes Weiner, Michal Koutný,
	cgroups, linux-kernel

Hello,

On Tue, May 12, 2026 at 05:00:34PM +0800, Sun Shaojie wrote:
> From: sunshaojie <sunshaojie@kylinos.cn>
...
> Fixes: 0c7f293efc87 ("cgroup/cpuset: Add cpuset.cpus.exclusive.effective for v2")
> Signed-off-by: sunshaojie <sunshaojie@kylinos.cn>

I applied as-is to cgroup/for-7.1-fixes but from next time on please
capitalize and put a space between first and last name.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2026-05-13 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12  9:00 [PATCH] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation Sun Shaojie
2026-05-13  6:55 ` Chen Ridong
2026-05-13 19:52 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox