* [PATCH] lockdep: constify usage of struct lock_class_key where possible
@ 2026-04-28 21:05 Heiner Kallweit
2026-04-29 17:04 ` Waiman Long
2026-05-04 7:28 ` Peter Zijlstra
0 siblings, 2 replies; 6+ messages in thread
From: Heiner Kallweit @ 2026-04-28 21:05 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long
Cc: Linux Kernel Mailing List
Constify usage of struct lock_class_key where possible. This requires
to constify also usage of struct lockdep_subclass_key in two places.
Especially relevant is constification of lockdep_map.key, as it makes
clear that the key isn't changed during lifetime of struct lockdep_map.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
include/linux/lockdep.h | 18 ++++++++++--------
include/linux/lockdep_types.h | 2 +-
kernel/locking/lockdep.c | 12 ++++++------
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 621566345..3fa2b62f2 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
* to lockdep:
*/
-extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
+void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
+ const struct lock_class_key *key, int subclass,
+ u8 inner, u8 outer, u8 lock_type);
static inline void
lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, int subclass, u8 inner, u8 outer)
+ const struct lock_class_key *key, int subclass,
+ u8 inner, u8 outer)
{
lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
}
static inline void
lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, int subclass, u8 inner)
+ const struct lock_class_key *key, int subclass, u8 inner)
{
lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
}
static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, int subclass)
+ const struct lock_class_key *key, int subclass)
{
lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
}
@@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
#define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
#define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
-extern void lock_set_class(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, unsigned int subclass,
- unsigned long ip);
+void lock_set_class(struct lockdep_map *lock, const char *name,
+ const struct lock_class_key *key, unsigned int subclass,
+ unsigned long ip);
#define lock_set_novalidate_class(l, n, i) \
lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
index eae115a26..0d3df9019 100644
--- a/include/linux/lockdep_types.h
+++ b/include/linux/lockdep_types.h
@@ -184,7 +184,7 @@ void clear_lock_stats(struct lock_class *class);
* This is embedded into specific lock instances:
*/
struct lockdep_map {
- struct lock_class_key *key;
+ const struct lock_class_key *key;
struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
const char *name;
u8 wait_type_outer; /* can be taken in this context */
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index f13883162..fe1415260 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -888,7 +888,7 @@ static int count_matching_names(struct lock_class *new_class)
static noinstr struct lock_class *
look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
{
- struct lockdep_subclass_key *key;
+ const struct lockdep_subclass_key *key;
struct hlist_head *hash_head;
struct lock_class *class;
@@ -1286,7 +1286,7 @@ static bool is_dynamic_key(const struct lock_class_key *key)
static struct lock_class *
register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
{
- struct lockdep_subclass_key *key;
+ const struct lockdep_subclass_key *key;
struct hlist_head *hash_head;
struct lock_class *class;
int idx;
@@ -4937,8 +4937,8 @@ static inline int check_wait_context(struct task_struct *curr,
* Initialize a lock instance's lock-class mapping info:
*/
void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, int subclass,
- u8 inner, u8 outer, u8 lock_type)
+ const struct lock_class_key *key, int subclass,
+ u8 inner, u8 outer, u8 lock_type)
{
int i;
@@ -5408,7 +5408,7 @@ static int reacquire_held_locks(struct task_struct *curr, unsigned int depth,
static int
__lock_set_class(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, unsigned int subclass,
+ const struct lock_class_key *key, unsigned int subclass,
unsigned long ip)
{
struct task_struct *curr = current;
@@ -5733,7 +5733,7 @@ static noinstr void check_flags(unsigned long flags)
}
void lock_set_class(struct lockdep_map *lock, const char *name,
- struct lock_class_key *key, unsigned int subclass,
+ const struct lock_class_key *key, unsigned int subclass,
unsigned long ip)
{
unsigned long flags;
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible
2026-04-28 21:05 [PATCH] lockdep: constify usage of struct lock_class_key where possible Heiner Kallweit
@ 2026-04-29 17:04 ` Waiman Long
2026-04-29 19:40 ` Heiner Kallweit
2026-05-04 7:28 ` Peter Zijlstra
1 sibling, 1 reply; 6+ messages in thread
From: Waiman Long @ 2026-04-29 17:04 UTC (permalink / raw)
To: Heiner Kallweit, Peter Zijlstra, Ingo Molnar, Will Deacon,
Boqun Feng
Cc: Linux Kernel Mailing List
On 4/28/26 5:05 PM, Heiner Kallweit wrote:
> Constify usage of struct lock_class_key where possible. This requires
> to constify also usage of struct lockdep_subclass_key in two places.
>
> Especially relevant is constification of lockdep_map.key, as it makes
> clear that the key isn't changed during lifetime of struct lockdep_map.
Other than making clear that the lock_class_key isn't being modified, is
there other benefit of making this change like helping compiler to
generate better code?
Cheers,
Longman
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> include/linux/lockdep.h | 18 ++++++++++--------
> include/linux/lockdep_types.h | 2 +-
> kernel/locking/lockdep.c | 12 ++++++------
> 3 files changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 621566345..3fa2b62f2 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
> * to lockdep:
> */
>
> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, int subclass,
> + u8 inner, u8 outer, u8 lock_type);
>
> static inline void
> lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass, u8 inner, u8 outer)
> + const struct lock_class_key *key, int subclass,
> + u8 inner, u8 outer)
> {
> lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
> }
>
> static inline void
> lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass, u8 inner)
> + const struct lock_class_key *key, int subclass, u8 inner)
> {
> lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
> }
>
> static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass)
> + const struct lock_class_key *key, int subclass)
> {
> lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
> }
> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>
> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, unsigned int subclass,
> - unsigned long ip);
> +void lock_set_class(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, unsigned int subclass,
> + unsigned long ip);
>
> #define lock_set_novalidate_class(l, n, i) \
> lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
> diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
> index eae115a26..0d3df9019 100644
> --- a/include/linux/lockdep_types.h
> +++ b/include/linux/lockdep_types.h
> @@ -184,7 +184,7 @@ void clear_lock_stats(struct lock_class *class);
> * This is embedded into specific lock instances:
> */
> struct lockdep_map {
> - struct lock_class_key *key;
> + const struct lock_class_key *key;
> struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
> const char *name;
> u8 wait_type_outer; /* can be taken in this context */
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index f13883162..fe1415260 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -888,7 +888,7 @@ static int count_matching_names(struct lock_class *new_class)
> static noinstr struct lock_class *
> look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
> {
> - struct lockdep_subclass_key *key;
> + const struct lockdep_subclass_key *key;
> struct hlist_head *hash_head;
> struct lock_class *class;
>
> @@ -1286,7 +1286,7 @@ static bool is_dynamic_key(const struct lock_class_key *key)
> static struct lock_class *
> register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
> {
> - struct lockdep_subclass_key *key;
> + const struct lockdep_subclass_key *key;
> struct hlist_head *hash_head;
> struct lock_class *class;
> int idx;
> @@ -4937,8 +4937,8 @@ static inline int check_wait_context(struct task_struct *curr,
> * Initialize a lock instance's lock-class mapping info:
> */
> void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass,
> - u8 inner, u8 outer, u8 lock_type)
> + const struct lock_class_key *key, int subclass,
> + u8 inner, u8 outer, u8 lock_type)
> {
> int i;
>
> @@ -5408,7 +5408,7 @@ static int reacquire_held_locks(struct task_struct *curr, unsigned int depth,
>
> static int
> __lock_set_class(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, unsigned int subclass,
> + const struct lock_class_key *key, unsigned int subclass,
> unsigned long ip)
> {
> struct task_struct *curr = current;
> @@ -5733,7 +5733,7 @@ static noinstr void check_flags(unsigned long flags)
> }
>
> void lock_set_class(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, unsigned int subclass,
> + const struct lock_class_key *key, unsigned int subclass,
> unsigned long ip)
> {
> unsigned long flags;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible
2026-04-29 17:04 ` Waiman Long
@ 2026-04-29 19:40 ` Heiner Kallweit
2026-04-29 20:34 ` Waiman Long
0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2026-04-29 19:40 UTC (permalink / raw)
To: Waiman Long, Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng
Cc: Linux Kernel Mailing List
On 29.04.2026 19:04, Waiman Long wrote:
> On 4/28/26 5:05 PM, Heiner Kallweit wrote:
>> Constify usage of struct lock_class_key where possible. This requires
>> to constify also usage of struct lockdep_subclass_key in two places.
>>
>> Especially relevant is constification of lockdep_map.key, as it makes
>> clear that the key isn't changed during lifetime of struct lockdep_map.
>
> Other than making clear that the lock_class_key isn't being modified, is there other benefit of making this change like helping compiler to generate better code?
>
Doing an objdump -o kernel/locking/lockdep.o I see no difference in section
sizes. Hence at least with gcc it doesn't seem to affect code generation.
I didn't check whether it affects callers of e.g. lockdep_init_map_wait().
> Cheers,
> Longman
>
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> include/linux/lockdep.h | 18 ++++++++++--------
>> include/linux/lockdep_types.h | 2 +-
>> kernel/locking/lockdep.c | 12 ++++++------
>> 3 files changed, 17 insertions(+), 15 deletions(-)
>>
>> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
>> index 621566345..3fa2b62f2 100644
>> --- a/include/linux/lockdep.h
>> +++ b/include/linux/lockdep.h
>> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
>> * to lockdep:
>> */
>> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
>> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>> + const struct lock_class_key *key, int subclass,
>> + u8 inner, u8 outer, u8 lock_type);
>> static inline void
>> lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass, u8 inner, u8 outer)
>> + const struct lock_class_key *key, int subclass,
>> + u8 inner, u8 outer)
>> {
>> lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
>> }
>> static inline void
>> lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass, u8 inner)
>> + const struct lock_class_key *key, int subclass, u8 inner)
>> {
>> lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
>> }
>> static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass)
>> + const struct lock_class_key *key, int subclass)
>> {
>> lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
>> }
>> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
>> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
>> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, unsigned int subclass,
>> - unsigned long ip);
>> +void lock_set_class(struct lockdep_map *lock, const char *name,
>> + const struct lock_class_key *key, unsigned int subclass,
>> + unsigned long ip);
>> #define lock_set_novalidate_class(l, n, i) \
>> lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
>> diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
>> index eae115a26..0d3df9019 100644
>> --- a/include/linux/lockdep_types.h
>> +++ b/include/linux/lockdep_types.h
>> @@ -184,7 +184,7 @@ void clear_lock_stats(struct lock_class *class);
>> * This is embedded into specific lock instances:
>> */
>> struct lockdep_map {
>> - struct lock_class_key *key;
>> + const struct lock_class_key *key;
>> struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
>> const char *name;
>> u8 wait_type_outer; /* can be taken in this context */
>> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
>> index f13883162..fe1415260 100644
>> --- a/kernel/locking/lockdep.c
>> +++ b/kernel/locking/lockdep.c
>> @@ -888,7 +888,7 @@ static int count_matching_names(struct lock_class *new_class)
>> static noinstr struct lock_class *
>> look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
>> {
>> - struct lockdep_subclass_key *key;
>> + const struct lockdep_subclass_key *key;
>> struct hlist_head *hash_head;
>> struct lock_class *class;
>> @@ -1286,7 +1286,7 @@ static bool is_dynamic_key(const struct lock_class_key *key)
>> static struct lock_class *
>> register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
>> {
>> - struct lockdep_subclass_key *key;
>> + const struct lockdep_subclass_key *key;
>> struct hlist_head *hash_head;
>> struct lock_class *class;
>> int idx;
>> @@ -4937,8 +4937,8 @@ static inline int check_wait_context(struct task_struct *curr,
>> * Initialize a lock instance's lock-class mapping info:
>> */
>> void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass,
>> - u8 inner, u8 outer, u8 lock_type)
>> + const struct lock_class_key *key, int subclass,
>> + u8 inner, u8 outer, u8 lock_type)
>> {
>> int i;
>> @@ -5408,7 +5408,7 @@ static int reacquire_held_locks(struct task_struct *curr, unsigned int depth,
>> static int
>> __lock_set_class(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, unsigned int subclass,
>> + const struct lock_class_key *key, unsigned int subclass,
>> unsigned long ip)
>> {
>> struct task_struct *curr = current;
>> @@ -5733,7 +5733,7 @@ static noinstr void check_flags(unsigned long flags)
>> }
>> void lock_set_class(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, unsigned int subclass,
>> + const struct lock_class_key *key, unsigned int subclass,
>> unsigned long ip)
>> {
>> unsigned long flags;
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible
2026-04-29 19:40 ` Heiner Kallweit
@ 2026-04-29 20:34 ` Waiman Long
0 siblings, 0 replies; 6+ messages in thread
From: Waiman Long @ 2026-04-29 20:34 UTC (permalink / raw)
To: Heiner Kallweit, Peter Zijlstra, Ingo Molnar, Will Deacon,
Boqun Feng
Cc: Linux Kernel Mailing List
On 4/29/26 3:40 PM, Heiner Kallweit wrote:
> On 29.04.2026 19:04, Waiman Long wrote:
>> On 4/28/26 5:05 PM, Heiner Kallweit wrote:
>>> Constify usage of struct lock_class_key where possible. This requires
>>> to constify also usage of struct lockdep_subclass_key in two places.
>>>
>>> Especially relevant is constification of lockdep_map.key, as it makes
>>> clear that the key isn't changed during lifetime of struct lockdep_map.
>> Other than making clear that the lock_class_key isn't being modified, is there other benefit of making this change like helping compiler to generate better code?
>>
> Doing an objdump -o kernel/locking/lockdep.o I see no difference in section
> sizes. Hence at least with gcc it doesn't seem to affect code generation.
> I didn't check whether it affects callers of e.g. lockdep_init_map_wait().
I asked because just stating the nature of the lock_class_key doesn't
contribute much to the lockdep code. I am not against this change, but
it is up others to decide if they will take the patch.
Cheers,
Longman
>
>> Cheers,
>> Longman
>>
>>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>>> ---
>>> include/linux/lockdep.h | 18 ++++++++++--------
>>> include/linux/lockdep_types.h | 2 +-
>>> kernel/locking/lockdep.c | 12 ++++++------
>>> 3 files changed, 17 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
>>> index 621566345..3fa2b62f2 100644
>>> --- a/include/linux/lockdep.h
>>> +++ b/include/linux/lockdep.h
>>> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
>>> * to lockdep:
>>> */
>>> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
>>> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>>> + const struct lock_class_key *key, int subclass,
>>> + u8 inner, u8 outer, u8 lock_type);
>>> static inline void
>>> lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, int subclass, u8 inner, u8 outer)
>>> + const struct lock_class_key *key, int subclass,
>>> + u8 inner, u8 outer)
>>> {
>>> lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
>>> }
>>> static inline void
>>> lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, int subclass, u8 inner)
>>> + const struct lock_class_key *key, int subclass, u8 inner)
>>> {
>>> lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
>>> }
>>> static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, int subclass)
>>> + const struct lock_class_key *key, int subclass)
>>> {
>>> lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
>>> }
>>> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
>>> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
>>> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>>> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, unsigned int subclass,
>>> - unsigned long ip);
>>> +void lock_set_class(struct lockdep_map *lock, const char *name,
>>> + const struct lock_class_key *key, unsigned int subclass,
>>> + unsigned long ip);
>>> #define lock_set_novalidate_class(l, n, i) \
>>> lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
>>> diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
>>> index eae115a26..0d3df9019 100644
>>> --- a/include/linux/lockdep_types.h
>>> +++ b/include/linux/lockdep_types.h
>>> @@ -184,7 +184,7 @@ void clear_lock_stats(struct lock_class *class);
>>> * This is embedded into specific lock instances:
>>> */
>>> struct lockdep_map {
>>> - struct lock_class_key *key;
>>> + const struct lock_class_key *key;
>>> struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
>>> const char *name;
>>> u8 wait_type_outer; /* can be taken in this context */
>>> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
>>> index f13883162..fe1415260 100644
>>> --- a/kernel/locking/lockdep.c
>>> +++ b/kernel/locking/lockdep.c
>>> @@ -888,7 +888,7 @@ static int count_matching_names(struct lock_class *new_class)
>>> static noinstr struct lock_class *
>>> look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
>>> {
>>> - struct lockdep_subclass_key *key;
>>> + const struct lockdep_subclass_key *key;
>>> struct hlist_head *hash_head;
>>> struct lock_class *class;
>>> @@ -1286,7 +1286,7 @@ static bool is_dynamic_key(const struct lock_class_key *key)
>>> static struct lock_class *
>>> register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
>>> {
>>> - struct lockdep_subclass_key *key;
>>> + const struct lockdep_subclass_key *key;
>>> struct hlist_head *hash_head;
>>> struct lock_class *class;
>>> int idx;
>>> @@ -4937,8 +4937,8 @@ static inline int check_wait_context(struct task_struct *curr,
>>> * Initialize a lock instance's lock-class mapping info:
>>> */
>>> void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, int subclass,
>>> - u8 inner, u8 outer, u8 lock_type)
>>> + const struct lock_class_key *key, int subclass,
>>> + u8 inner, u8 outer, u8 lock_type)
>>> {
>>> int i;
>>> @@ -5408,7 +5408,7 @@ static int reacquire_held_locks(struct task_struct *curr, unsigned int depth,
>>> static int
>>> __lock_set_class(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, unsigned int subclass,
>>> + const struct lock_class_key *key, unsigned int subclass,
>>> unsigned long ip)
>>> {
>>> struct task_struct *curr = current;
>>> @@ -5733,7 +5733,7 @@ static noinstr void check_flags(unsigned long flags)
>>> }
>>> void lock_set_class(struct lockdep_map *lock, const char *name,
>>> - struct lock_class_key *key, unsigned int subclass,
>>> + const struct lock_class_key *key, unsigned int subclass,
>>> unsigned long ip)
>>> {
>>> unsigned long flags;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible
2026-04-28 21:05 [PATCH] lockdep: constify usage of struct lock_class_key where possible Heiner Kallweit
2026-04-29 17:04 ` Waiman Long
@ 2026-05-04 7:28 ` Peter Zijlstra
2026-05-04 20:37 ` Heiner Kallweit
1 sibling, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2026-05-04 7:28 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long,
Linux Kernel Mailing List
On Tue, Apr 28, 2026 at 11:05:25PM +0200, Heiner Kallweit wrote:
> Constify usage of struct lock_class_key where possible. This requires
> to constify also usage of struct lockdep_subclass_key in two places.
>
> Especially relevant is constification of lockdep_map.key, as it makes
> clear that the key isn't changed during lifetime of struct lockdep_map.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> include/linux/lockdep.h | 18 ++++++++++--------
> include/linux/lockdep_types.h | 2 +-
> kernel/locking/lockdep.c | 12 ++++++------
> 3 files changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 621566345..3fa2b62f2 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
> * to lockdep:
> */
>
> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, int subclass,
> + u8 inner, u8 outer, u8 lock_type);
> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>
> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, unsigned int subclass,
> - unsigned long ip);
> +void lock_set_class(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, unsigned int subclass,
> + unsigned long ip);
>
It is also silently removing extern, why?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible
2026-05-04 7:28 ` Peter Zijlstra
@ 2026-05-04 20:37 ` Heiner Kallweit
0 siblings, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2026-05-04 20:37 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long,
Linux Kernel Mailing List
On 04.05.2026 09:28, Peter Zijlstra wrote:
> On Tue, Apr 28, 2026 at 11:05:25PM +0200, Heiner Kallweit wrote:
>> Constify usage of struct lock_class_key where possible. This requires
>> to constify also usage of struct lockdep_subclass_key in two places.
>>
>> Especially relevant is constification of lockdep_map.key, as it makes
>> clear that the key isn't changed during lifetime of struct lockdep_map.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> include/linux/lockdep.h | 18 ++++++++++--------
>> include/linux/lockdep_types.h | 2 +-
>> kernel/locking/lockdep.c | 12 ++++++------
>> 3 files changed, 17 insertions(+), 15 deletions(-)
>>
>> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
>> index 621566345..3fa2b62f2 100644
>> --- a/include/linux/lockdep.h
>> +++ b/include/linux/lockdep.h
>> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
>> * to lockdep:
>> */
>>
>> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
>> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
>> + const struct lock_class_key *key, int subclass,
>> + u8 inner, u8 outer, u8 lock_type);
>
>> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
>> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
>> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>>
>> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
>> - struct lock_class_key *key, unsigned int subclass,
>> - unsigned long ip);
>> +void lock_set_class(struct lockdep_map *lock, const char *name,
>> + const struct lock_class_key *key, unsigned int subclass,
>> + unsigned long ip);
>>
>
> It is also silently removing extern, why?
When touching this function prototype anyway, make it compliant with coding standard.
See https://www.kernel.org/doc/html/v7.0/process/coding-style.html, section 6.1.
"Do not use the extern keyword with function declarations as this makes lines longer
and isn’t strictly necessary."
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-04 20:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 21:05 [PATCH] lockdep: constify usage of struct lock_class_key where possible Heiner Kallweit
2026-04-29 17:04 ` Waiman Long
2026-04-29 19:40 ` Heiner Kallweit
2026-04-29 20:34 ` Waiman Long
2026-05-04 7:28 ` Peter Zijlstra
2026-05-04 20:37 ` Heiner Kallweit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox