Re: [PATCH 2/2] cgroup/cpuset: Fix invalid local partition recovery

From: Guopeng Zhang

Date: Thu Oct 22 2026 - 01:57:59 EST




在 2026/10/22 11:28, Waiman Long 写道:
> On 10/10/26 3:59 AM, Guopeng Zhang wrote:
>> From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
>>
>> An invalid local partition may fail to recover after its exclusive CPU
>> list is changed to a valid one.
>>
>> This can be reproduced on a cgroup v2 system with CPUs 0-7 online:
>>
>>      cd /sys/fs/cgroup
>>      echo +cpuset > cgroup.subtree_control
>>      mkdir A
>>      echo 0-7 > A/cpuset.cpus
>>      echo 0-7 > A/cpuset.cpus.exclusive
>>      echo root > A/cpuset.cpus.partition
>>      cat A/cpuset.cpus.partition
>>      echo 1 > A/cpuset.cpus.exclusive
>>      cat A/cpuset.cpus.partition
>>
>> The first read reports root invalid because all CPUs were requested.
>> After the mask is changed to CPU 1, the partition should become valid,
>> but it remains invalid with PERR_NOCPUS.
>>
>> update_exclusive_cpumask() calls partition_cpus_change() before updating
>> cs->exclusive_cpus. update_parent_effective_cpumask() then gets the
>> old 0-7 mask from user_xcpus() and sets PERR_NOCPUS even though the new
>> mask leaves CPUs for the parent.
>>
>> Move the exclusive_cpus update before partition_cpus_change() so that
>> the partition update sees the new mask.
>>
>> Fixes: 46c521bac592 ("cgroup/cpuset: Enable invalid to valid local partition transition")
>> Signed-off-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
>> ---
>>   kernel/cgroup/cpuset.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index de7553459adc..e96bc66ffa07 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -2546,10 +2546,14 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
>>           return -ENOMEM;
>>         trialcs->prs_err = PERR_NONE;
>> -    partition_cpus_change(cs, trialcs, &tmp);
>>         spin_lock_irq(&callback_lock);
>>       cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus);
>> +    spin_unlock_irq(&callback_lock);
>> +
>> +    partition_cpus_change(cs, trialcs, &tmp);
>> +
>> +    spin_lock_irq(&callback_lock);
>>       cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus);
>>       if ((old_prs > 0) && !is_partition_valid(cs))
>>           reset_partition_data(cs);
>
> With the patch series that I have just sent out, I can't reproduce this problem. My patch 2 of the series change update_parent_effective_cpumask() to not use user_xcpus() anymore. So that should fix the problem.
>

Thanks for checking this issue. I'll also test some other scenarios
with your new patch series applied.

Thanks,
Guopeng