From: Waiman Long <llong@redhat.com>
To: Chen Ridong <chenridong@huaweicloud.com>,
tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] cpuset: treate root invalid trialcs as exclusive
Date: Mon, 17 Nov 2025 10:56:16 -0500 [thread overview]
Message-ID: <e042851e-6cf5-4475-bf4d-a69bb5713c7f@redhat.com> (raw)
In-Reply-To: <20251115093140.1121329-1-chenridong@huaweicloud.com>
On 11/15/25 4:31 AM, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> A test scenario revealed inconsistent results based on operation order:
> Scenario 1:
> #cd /sys/fs/cgroup/
> #mkdir A1
> #mkdir B1
> #echo 1-2 > B1/cpuset.cpus
> #echo 0-1 > A1/cpuset.cpus
> #echo root > A1/cpuset.cpus.partition
> #cat A1/cpuset.cpus.partition
> root invalid (Cpu list in cpuset.cpus not exclusive)
>
> Scenario 2:
> #cd /sys/fs/cgroup/
> #mkdir A1
> #mkdir B1
> #echo 1-2 > B1/cpuset.cpus
> #echo root > A1/cpuset.cpus.partition
> #echo 0-1 > A1/cpuset.cpus
> #cat A1/cpuset.cpus.partition
> root
>
> The second scenario produces an unexpected result: A1 should be marked
> as invalid but is incorrectly recognized as valid. This occurs because
> when validate_change is invoked, A1 (in root-invalid state) may
> automatically transition to a valid partition, with non-exclusive state
> checks against siblings, leading to incorrect validation.
>
> To fix this inconsistency, treat trialcs in root-invalid state as exclusive
> during validation and set the corresponding exclusive flags, ensuring
> consistent behavior regardless of operation order.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> kernel/cgroup/cpuset.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index daf813386260..a189f356b5f1 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2526,6 +2526,18 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs,
> }
> }
>
> +static int init_trialcs(struct cpuset *cs, struct cpuset *trialcs)
> +{
> + trialcs->prs_err = PERR_NONE;
> + /*
> + * If partition_root_state != 0, it may automatically change to a partition,
> + * Therefore, we should treat trialcs as exclusive during validation
> + */
> + if (trialcs->partition_root_state)
> + set_bit(CS_CPU_EXCLUSIVE, &trialcs->flags);
Nit: We usually use the non-atomic version __set_bit() if concurrent
access isn't possible which is true in this case.
> + return compute_trialcs_excpus(trialcs, cs);
> +}
> +
> /**
> * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
> * @cs: the cpuset to consider
> @@ -2551,9 +2563,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> if (alloc_tmpmasks(&tmp))
> return -ENOMEM;
>
> - compute_trialcs_excpus(trialcs, cs);
> - trialcs->prs_err = PERR_NONE;
> -
> + init_trialcs(cs, trialcs);
> retval = cpus_allowed_validate_change(cs, trialcs, &tmp);
> if (retval < 0)
> goto out_free;
> @@ -2612,7 +2622,7 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> * Reject the change if there is exclusive CPUs conflict with
> * the siblings.
> */
> - if (compute_trialcs_excpus(trialcs, cs))
> + if (init_trialcs(cs, trialcs))
> return -EINVAL;
>
> /*
> @@ -2628,7 +2638,6 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> if (alloc_tmpmasks(&tmp))
> return -ENOMEM;
>
> - trialcs->prs_err = PERR_NONE;
> partition_cpus_change(cs, trialcs, &tmp);
>
> spin_lock_irq(&callback_lock);
Acked-by: Waiman Long <longman@redhat.com>
next prev parent reply other threads:[~2025-11-17 15:56 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 13:14 [PATCH v2] cpuset: relax the overlap check for cgroup-v2 Sun Shaojie
2025-11-13 14:57 ` Waiman Long
2025-11-13 17:07 ` Michal Koutný
2025-11-14 1:29 ` Chen Ridong
2025-11-14 16:14 ` Michal Koutný
2025-11-15 0:58 ` Chen Ridong
2025-11-14 0:50 ` Chen Ridong
2025-11-14 5:53 ` Sun Shaojie
2025-11-14 6:24 ` Sun Shaojie
2025-11-14 16:15 ` Michal Koutný
2025-11-15 2:01 ` Chen Ridong
2025-11-15 9:31 ` [PATCH -next] cpuset: treate root invalid trialcs as exclusive Chen Ridong
2025-11-16 14:08 ` [PATCH v2] cpuset: relax the overlap check for cgroup-v2 Sun Shaojie
2025-11-17 4:35 ` [PATCH -next] cpuset: treate root invalid trialcs as exclusive Sun Shaojie
2025-11-17 6:23 ` Chen Ridong
2025-11-17 6:53 ` Sun Shaojie
2025-11-17 7:30 ` Chen Ridong
2025-11-17 15:56 ` Waiman Long [this message]
2025-11-15 9:51 ` [PATCH v2] cpuset: relax the overlap check for cgroup-v2 Chen Ridong
2025-11-15 11:24 ` Sun Shaojie
2025-11-14 6:33 ` Sun Shaojie
2025-11-14 6:59 ` Chen Ridong
2025-11-15 6:02 ` Sun Shaojie
2025-11-15 7:41 ` Chen Ridong
2025-11-17 18:43 ` Waiman Long
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=e042851e-6cf5-4475-bf4d-a69bb5713c7f@redhat.com \
--to=llong@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=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