[PATCH -next 1/6] cpuset: add assert_cpuset_lock_held helper

Chen Ridong posted 6 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH -next 1/6] cpuset: add assert_cpuset_lock_held helper
Posted by Chen Ridong 1 month, 3 weeks ago
From: Chen Ridong <chenridong@huawei.com>

Add assert_cpuset_lock_held() to allow other subsystems to verify that
cpuset_mutex is held.

Suggested-by: Waiman Long <longman@redhat.com>
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 include/linux/cpuset.h | 2 ++
 kernel/cgroup/cpuset.c | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
index a98d3330385c..af0e76d10476 100644
--- a/include/linux/cpuset.h
+++ b/include/linux/cpuset.h
@@ -74,6 +74,7 @@ extern void inc_dl_tasks_cs(struct task_struct *task);
 extern void dec_dl_tasks_cs(struct task_struct *task);
 extern void cpuset_lock(void);
 extern void cpuset_unlock(void);
+extern void assert_cpuset_lock_held(void);
 extern void cpuset_cpus_allowed_locked(struct task_struct *p, struct cpumask *mask);
 extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
 extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
@@ -195,6 +196,7 @@ static inline void inc_dl_tasks_cs(struct task_struct *task) { }
 static inline void dec_dl_tasks_cs(struct task_struct *task) { }
 static inline void cpuset_lock(void) { }
 static inline void cpuset_unlock(void) { }
+static inline void assert_cpuset_lock_held(void) { }
 
 static inline void cpuset_cpus_allowed_locked(struct task_struct *p,
 					struct cpumask *mask)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index fea577b4016a..a5ad124ea1cf 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -271,6 +271,11 @@ void cpuset_unlock(void)
 	mutex_unlock(&cpuset_mutex);
 }
 
+void assert_cpuset_lock_held(void)
+{
+	lockdep_assert_held(&cpuset_mutex);
+}
+
 /**
  * cpuset_full_lock - Acquire full protection for cpuset modification
  *
-- 
2.34.1
Re: [PATCH -next 1/6] cpuset: add assert_cpuset_lock_held helper
Posted by Waiman Long 1 month, 3 weeks ago
On 12/17/25 3:49 AM, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Add assert_cpuset_lock_held() to allow other subsystems to verify that
> cpuset_mutex is held.

Sorry, I should have added the "lockdep_" prefix when I mentioned adding 
this helper function to be consistent with the others. Could you update 
the patch to add that?

Thanks,
Longman

>
> Suggested-by: Waiman Long <longman@redhat.com>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>   include/linux/cpuset.h | 2 ++
>   kernel/cgroup/cpuset.c | 5 +++++
>   2 files changed, 7 insertions(+)
>
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index a98d3330385c..af0e76d10476 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -74,6 +74,7 @@ extern void inc_dl_tasks_cs(struct task_struct *task);
>   extern void dec_dl_tasks_cs(struct task_struct *task);
>   extern void cpuset_lock(void);
>   extern void cpuset_unlock(void);
> +extern void assert_cpuset_lock_held(void);
>   extern void cpuset_cpus_allowed_locked(struct task_struct *p, struct cpumask *mask);
>   extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
>   extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
> @@ -195,6 +196,7 @@ static inline void inc_dl_tasks_cs(struct task_struct *task) { }
>   static inline void dec_dl_tasks_cs(struct task_struct *task) { }
>   static inline void cpuset_lock(void) { }
>   static inline void cpuset_unlock(void) { }
> +static inline void assert_cpuset_lock_held(void) { }
>   
>   static inline void cpuset_cpus_allowed_locked(struct task_struct *p,
>   					struct cpumask *mask)
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index fea577b4016a..a5ad124ea1cf 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -271,6 +271,11 @@ void cpuset_unlock(void)
>   	mutex_unlock(&cpuset_mutex);
>   }
>   
> +void assert_cpuset_lock_held(void)
> +{
> +	lockdep_assert_held(&cpuset_mutex);
> +}
> +
>   /**
>    * cpuset_full_lock - Acquire full protection for cpuset modification
>    *
Re: [PATCH -next 1/6] cpuset: add assert_cpuset_lock_held helper
Posted by Chen Ridong 1 month, 3 weeks ago

On 2025/12/18 1:02, Waiman Long wrote:
> On 12/17/25 3:49 AM, Chen Ridong wrote:
>> From: Chen Ridong <chenridong@huawei.com>
>>
>> Add assert_cpuset_lock_held() to allow other subsystems to verify that
>> cpuset_mutex is held.
> 
> Sorry, I should have added the "lockdep_" prefix when I mentioned adding this helper function to be
> consistent with the others. Could you update the patch to add that?
> 

Thank you.

I was tangled on whether to add the lockdep_ prefix, since lockdep_assert_cpus_held has it. But I
named it as you suggested originally. I'll update the patch accordingly.

> 
>>
>> Suggested-by: Waiman Long <longman@redhat.com>
>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>> ---
>>   include/linux/cpuset.h | 2 ++
>>   kernel/cgroup/cpuset.c | 5 +++++
>>   2 files changed, 7 insertions(+)
>>
>> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
>> index a98d3330385c..af0e76d10476 100644
>> --- a/include/linux/cpuset.h
>> +++ b/include/linux/cpuset.h
>> @@ -74,6 +74,7 @@ extern void inc_dl_tasks_cs(struct task_struct *task);
>>   extern void dec_dl_tasks_cs(struct task_struct *task);
>>   extern void cpuset_lock(void);
>>   extern void cpuset_unlock(void);
>> +extern void assert_cpuset_lock_held(void);
>>   extern void cpuset_cpus_allowed_locked(struct task_struct *p, struct cpumask *mask);
>>   extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
>>   extern bool cpuset_cpus_allowed_fallback(struct task_struct *p);
>> @@ -195,6 +196,7 @@ static inline void inc_dl_tasks_cs(struct task_struct *task) { }
>>   static inline void dec_dl_tasks_cs(struct task_struct *task) { }
>>   static inline void cpuset_lock(void) { }
>>   static inline void cpuset_unlock(void) { }
>> +static inline void assert_cpuset_lock_held(void) { }
>>     static inline void cpuset_cpus_allowed_locked(struct task_struct *p,
>>                       struct cpumask *mask)
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index fea577b4016a..a5ad124ea1cf 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -271,6 +271,11 @@ void cpuset_unlock(void)
>>       mutex_unlock(&cpuset_mutex);
>>   }
>>   +void assert_cpuset_lock_held(void)
>> +{
>> +    lockdep_assert_held(&cpuset_mutex);
>> +}
>> +
>>   /**
>>    * cpuset_full_lock - Acquire full protection for cpuset modification
>>    *
> 

-- 
Best regards,
Ridong