The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: "Sun Shaojie" <sunshaojie@kylinos.cn>,
	"Chen Ridong" <chenridong@huaweicloud.com>,
	"Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation
Date: Wed, 13 May 2026 11:02:58 -0400	[thread overview]
Message-ID: <8325838a-0e30-43d6-a04c-1ecdf42867cb@redhat.com> (raw)
In-Reply-To: <20260513103738.442779-1-sunshaojie@kylinos.cn>

On 5/13/26 6:37 AM, 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
>
> dmesg will also show a WARNING from generate_sched_domains() reporting
> overlapping partition root effective_cpus.
>
> Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict")
> Signed-off-by: sunshaojie <sunshaojie@kylinos.cn>
> Test-by: Chen Ridong <chenridong@huaweicloud.com>
> Reviewed-by: Chen Ridong <chenridong@huaweicloud.com>
>
> ---
> Changes in v2:
> - Updated Fixes tag per review by Chen Ridong
> ---
>   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;
>   

Thanks for catching this bug.

Reviewed-by: Waiman Long <longman@redhat.com>


  reply	other threads:[~2026-05-13 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 10:37 [PATCH v2] cgroup/cpuset: Return only actually allocated CPUs during partition invalidation Sun Shaojie
2026-05-13 15:02 ` Waiman Long [this message]
2026-05-13 18:57 ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8325838a-0e30-43d6-a04c-1ecdf42867cb@redhat.com \
    --to=longman@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@huaweicloud.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=sunshaojie@kylinos.cn \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox