lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <931a4ff2-f240-403b-adff-822449b49d31@huaweicloud.com>
Date: Thu, 13 Nov 2025 09:36:19 +0800
From: Chen Ridong <chenridong@...weicloud.com>
To: Waiman Long <llong@...hat.com>, tj@...nel.org, hannes@...xchg.org,
 mkoutny@...e.com
Cc: cgroups@...r.kernel.org, linux-kernel@...r.kernel.org,
 lujialin4@...wei.com, chenridong@...wei.com
Subject: Re: [PATCH RFC v2 02/22] cpuset: add early empty cpumask check in
 partition_xcpus_add/del



On 2025/11/13 4:18, Waiman Long wrote:
> On 10/25/25 2:48 AM, Chen Ridong wrote:
>> From: Chen Ridong <chenridong@...wei.com>
>>
>> Add a check for an empty cpumask at the start of partition_xcpus_add()
>> and partition_xcpus_del(). This allows the functions to return early,
>> avoiding unnecessary computation when there is no work to be done.
>>
>> Signed-off-by: Chen Ridong <chenridong@...wei.com>
>> ---
>>   kernel/cgroup/cpuset.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 6af4d80b53c4..3ba9ca4e8f5e 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -1345,6 +1345,9 @@ static bool partition_xcpus_add(int new_prs, struct cpuset *parent,
>>         WARN_ON_ONCE(new_prs < 0);
>>       lockdep_assert_held(&callback_lock);
>> +    if (cpumask_empty(xcpus))
>> +        return false;
>> +
>>       if (!parent)
>>           parent = &top_cpuset;
>>   @@ -1377,6 +1380,9 @@ static bool partition_xcpus_del(int old_prs, struct cpuset *parent,
>>         WARN_ON_ONCE(old_prs < 0);
>>       lockdep_assert_held(&callback_lock);
>> +    if (cpumask_empty(xcpus))
>> +        return false;
>> +
>>       if (!parent)
>>           parent = &top_cpuset;
>>   
> 
> partition_xcpus_add() and partition_xcpus_del() are supposed to be called only when action is really
> needed. The empty xcpus check should be done earlier to avoid calling them in the first  place. So
> unless you are planning to change the logic that they will always be called even if action is not
> really needed. If so, you have to state in the commit log.
> 
> Cheers,
> Longman
> 

Thanks Longman,

partition_xcpus_add() and partition_xcpus_del() are called in serial contexts. If we move the check
outside these functions, we’ll end up with more conditional statements like this:

if (!is_empty(xxx))
	partition_xcpus_add()/partition_xcpus_del()

So I prefer to handle the check inside the functions themselves. This way, we don’t need to care
whether xcpus is empty when calling them—and the overhead is negligible.

I’ll update the commit log to clarify that these functions can be called even when the action isn’t
strictly necessary.

-- 
Best regards,
Ridong


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ