From: Waiman Long <longman@redhat.com>
To: "Ridong Chen" <ridong.chen@linux.dev>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Guopeng Zhang <guopeng.zhang@linux.dev>
Subject: Re: [PATCH-next 2/6] cgroup/cpuset: Properly compute effective xcpus in update_parent_effective_cpumask()
Date: Fri, 23 Oct 2026 12:56:59 -0400 [thread overview]
Message-ID: <057b3c65-430c-42eb-adfe-02579fdd7360@redhat.com> (raw)
In-Reply-To: <d4ce3eba-b48a-4e63-af0f-87cd27d04e4c@linux.dev>
On 10/23/26 2:45 AM, Ridong Chen wrote:
>
>
> On 10/22/2026 11:16 AM, Waiman Long wrote:
>> Since the introduction of cpuset.cpus.exclusive in commit
>> e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2"), a
>> compute_effective_exclusive_cpumask() helper which is later renamed to
>> compute_excpus() is added to compute the effective xcpus of a partition
>> root. However update_parent_effective_cpumask() is not updated in all
>> proper places to use the new helper to check if a given cpuset should
>> remain a valid partition root. This can cause a cpuset to incorrectly
>> remain a valid partition root even if no effective xcpus is left.
>>
>> Fix that problem by using compute_excpus() to compute the effective
>> xcpus
>> into delmask in all cases except partcmd_disable and partcmd_invalidate
>> and use it for tasks_nocpu_error() check as well as checking its
>> emptiness. This enables us to catch invalid partition root more
>> accurately in update_parent_effective_cpumask().
>>
>> Some test case are added to test_cpuset_prs.sh for invalidating a
>> partition root due to its effective xcpus becoming empty as well as
>> making sure that an invalid partition can only be revived when exclusive
>> CPUs are available agin.
>>
>> Fixes: e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>> kernel/cgroup/cpuset.c | 36 +++++++++----------
>> .../selftests/cgroup/test_cpuset_prs.sh | 6 ++++
>> 2 files changed, 22 insertions(+), 20 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 7ead8c3b7974..db6e4663f4be 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -1798,7 +1798,6 @@ static int
>> update_parent_effective_cpumask(struct cpuset *cs, int cmd,
>> int deleting; /* Deleting cpus from parent's
>> effective_cpus */
>> int old_prs, new_prs;
>> int part_error = PERR_NONE; /* Partition error? */
>> - struct cpumask *xcpus = user_xcpus(cs);
>> int parent_prs = parent->partition_root_state;
>> bool nocpu;
>> @@ -1841,30 +1840,29 @@ static int
>> update_parent_effective_cpumask(struct cpuset *cs, int cmd,
>> if (!newmask && xcpus_empty(cs))
>> return PERR_CPUSEMPTY;
>> - nocpu = tasks_nocpu_error(parent, cs, xcpus);
>> + /*
>> + * Except for partcmd_disable, use delmask to compute the current
>> + * effective xcpus value and use it for tasks_nocpu_error check.
>> + */
>> + if (cmd != partcmd_disable) {
>> + compute_excpus(cs, tmp->delmask);
>> + nocpu = tasks_nocpu_error(parent, cs, tmp->delmask);
>> + }
>> if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) {
>> - /*
>> - * Need to call compute_excpus() in case
>> - * exclusive_cpus not set. Sibling conflict should only happen
>> - * if exclusive_cpus isn't set.
>> - */
>> - xcpus = tmp->delmask;
>> - if (compute_excpus(cs, xcpus))
>> - WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus));
>> new_prs = (cmd == partcmd_enable) ? PRS_ROOT : PRS_ISOLATED;
>> /*
>> * Enabling partition root is not allowed if its
>> * effective_xcpus is empty.
>> */
>> - if (cpumask_empty(xcpus))
>> + if (cpumask_empty(tmp->delmask))
>> return PERR_INVCPUS;
>> - if (prstate_housekeeping_conflict(new_prs, parent_prs,
>> xcpus, NULL))
>> + if (prstate_housekeeping_conflict(new_prs, parent_prs,
>> tmp->delmask, NULL))
>> return PERR_HKEEPING;
>> - if (tasks_nocpu_error(parent, cs, xcpus))
>> + if (nocpu)
>> return PERR_NOCPUS;
>
> update_parent_effective_cpumask is only used for the local partition.
> So I'd suggest adding a local_partition_validate helper, which can be
> used for both partition enable and update. For now this logic is
> spread out, and many corner cases would easily be missed.
I am thinking about breaking up update_parent_effective_cpumask() to be
more like what we are doing with remote partition to share as much
common part as possible. This cleanup work will be in a later patch
series. Since this is a fix patch, I don't want to make too many changes
to make it hard to backport to earlier releases.
Cheers,
Longman
next prev parent reply other threads:[~2026-10-23 16:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 3:16 [PATCH-next 0/6] cgroup/cpuset: Miscellaneous bug fixes Waiman Long
2026-10-22 3:16 ` [PATCH-next 1/6] cgroup/cpuset: Find furthest isolated ancestor for invalidated isolated partition Waiman Long
2026-10-22 13:25 ` Guopeng Zhang
2026-10-22 16:19 ` Waiman Long
2026-10-23 6:24 ` Ridong Chen
2026-10-23 16:48 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 2/6] cgroup/cpuset: Properly compute effective xcpus in update_parent_effective_cpumask() Waiman Long
2026-10-22 13:45 ` Guopeng Zhang
2026-10-22 14:47 ` Waiman Long
2026-10-23 1:41 ` Guopeng Zhang
2026-10-22 15:00 ` Waiman Long
2026-10-23 1:53 ` Guopeng Zhang
2026-10-23 20:45 ` Waiman Long
2026-10-23 6:45 ` Ridong Chen
2026-10-23 16:56 ` Waiman Long [this message]
2026-10-23 7:42 ` Guopeng Zhang
2026-10-22 3:16 ` [PATCH-next 3/6] cgroup/cpuset: Fix incorrect effective_cpus bug in update_cpumasks_hier() Waiman Long
2026-10-23 7:07 ` Ridong Chen
2026-10-23 17:01 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 4/6] cgroup/cpuset: Minor fixes to prstate_housekeeping_conflict() Waiman Long
2026-10-22 14:15 ` Guopeng Zhang
2026-10-22 14:35 ` Waiman Long
2026-10-22 3:16 ` [PATCH-next 5/6] selftests/cgroup: Check for a single range nohz_full CPUs before running test matrix Waiman Long
2026-10-22 14:09 ` Guopeng Zhang
2026-10-22 3:16 ` [PATCH-next 6/6] cgroup/cpuset: Prevent recursive call of remote_cpus_update() via update_cpumasks_hier() Waiman Long
2026-10-22 14:23 ` Guopeng Zhang
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=057b3c65-430c-42eb-adfe-02579fdd7360@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=guopeng.zhang@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=shuah@kernel.org \
--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
all inboxes | Powered by JetHome®