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] [day] [month] [year] [list]
Message-ID: <7b2a1645-6271-4f90-acea-cb12ba10cf81@huaweicloud.com>
Date: Sat, 16 Aug 2025 08:23:08 +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, christophe.jaillet@...adoo.fr
Subject: Re: [-next v2 4/4] cpuset: add helpers for cpus read and cpuset_mutex
 locks



On 2025/8/16 3:13, Waiman Long wrote:
> On 8/13/25 11:58 PM, Chen Ridong wrote:
>>
>> On 2025/8/14 11:27, Waiman Long wrote:
>>> On 8/13/25 11:13 PM, Waiman Long wrote:
>>>> On 8/13/25 8:44 PM, Chen Ridong wrote:
>>>>> On 2025/8/14 4:09, Waiman Long wrote:
>>>>>> On 8/13/25 4:29 AM, Chen Ridong wrote:
>>>>>>> From: Chen Ridong <chenridong@...wei.com>
>>>>>>>
>>>>>>> cpuset: add helpers for cpus_read_lock and cpuset_mutex
>>>>>>>
>>>>>>> Replace repetitive locking patterns with new helpers:
>>>>>>> - cpus_read_cpuset_lock()
>>>>>>> - cpus_read_cpuset_unlock()
>>>>>>>
>>>>>>> This makes the code cleaner and ensures consistent lock ordering.
>>>>>>>
>>>>>>> Signed-off-by: Chen Ridong <chenridong@...wei.com>
>>>>>>> ---
>>>>>>>     kernel/cgroup/cpuset-internal.h |  2 ++
>>>>>>>     kernel/cgroup/cpuset-v1.c       | 12 +++------
>>>>>>>     kernel/cgroup/cpuset.c          | 48 +++++++++++++++------------------
>>>>>>>     3 files changed, 28 insertions(+), 34 deletions(-)
>>>>>>>
>>>>>>> diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h
>>>>>>> index 75b3aef39231..6fb00c96044d 100644
>>>>>>> --- a/kernel/cgroup/cpuset-internal.h
>>>>>>> +++ b/kernel/cgroup/cpuset-internal.h
>>>>>>> @@ -276,6 +276,8 @@ int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs, int
>>>>>>> turning_on)
>>>>>>>     ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
>>>>>>>                         char *buf, size_t nbytes, loff_t off);
>>>>>>>     int cpuset_common_seq_show(struct seq_file *sf, void *v);
>>>>>>> +void cpus_read_cpuset_lock(void);
>>>>>>> +void cpus_read_cpuset_unlock(void);
>>>>>> The names are not intuitive. I would prefer just extend the cpuset_lock/unlock to include
>>>>>> cpus_read_lock/unlock and we use cpuset_lock/unlock consistently in the cpuset code. Also,
>>>>>> there is
>>>>>> now no external user of cpuset_lock/unlock, we may as well remove them from
>>>>>> include/linux/cpuset.h.
>>>>>>
>>>>>> Cheers,
>>>>>> Longman
>>>>> I like the idea and have considered it.
>>>>> However, I noticed that cpuset_locked is being used in __sched_setscheduler.
>>>> Right, I overloooked the cpuset_lock() call in kernel/sched/syscall.c. So we can't remove it from
>>>> include/linux/cpuset.h.
>>>>
>>>> This call is invoked to ensure cpusets information is stable. However, it doesn't hurt if the
>>>> cpus_read_lock() is also acquired as a result. Alternatively, we can use a name like
>>>> cpuset_full_lock() to include cpus_read_lock().
>>> I have a correction. According to commit d74b27d63a8b ("cgroup/cpuset: Change cpuset_rwsem and
>>> hotplug lock order") , sched_scheduler() can be called while holding cpus_hotplug_lock. So we should
>>> keep cpuset_lock() as it is.
>>>
>>> Cheers,
>>> Longman
>> Thank you Longman, this is very helpful.
>>
>> I had considered whether we can add cpus_read_lock() to the cpuset_lock, but based on your
>> explanation, I now understand this approach would not work.
>>
>> For clarity, would it be acceptable to rename:
>> cpus_read_cpuset_lock() -> cpuset_full_lock()
>> cpus_read_cpuset_unlock() -> cpuset_full_unlock()
> 
> Yes, that is what I want to see. Note that taking both cpus_read_lock() and cpuset_mutex are needed
> to modify cpuset data. Taking just cpuset_mutex will prevent other from making changes to the cpuset
> data, but is not enough to make modification.
> 
> Cheers,
> Longman
> 
>>

See, I will add the comments to clarify how to use these helpers.

-- 
Best regards,
Ridong


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ