Skip to contentSkip to conversation

locking/mutex: Misc fixlets

PATCH Applied Davidlohr Bueso 4 participants 10 messages Feb 17 – Feb 23 Locking primitives

lore
Share & tools
lore
#0 lore raw

cover locking/mutex: Misc fixlets

Found while eyeballing recent changes to mutex.c. The first two are fixes for 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size").

Thanks!

Davidlohr Bueso (3):
locking/mutex: Rename mutex_init_lockep() locking/mutex: Fix wrong comment for CONFIG_DEBUG_LOCK_ALLOC locking/mutex: Add killable flavor to guard definitions

 include/linux/mutex.h  | 9 ++++++---
 kernel/locking/mutex.c | 4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)

--
2.39.5

#1 lore raw

PATCH 1/3 locking/mutex: Rename mutex_init_lockep()

Typo, this wants to be _lockdep().

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
 include/linux/mutex.h  | 4 ++--
 kernel/locking/mutex.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/mutex.h +2 -2
index ecaa0440f6ec..8126da959088 100644
@@ -87,12 +87,12 @@ do {									\
 	struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key);
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key);
 
 static inline void __mutex_init(struct mutex *lock, const char *name,
 				struct lock_class_key *key)
 {
-	mutex_init_lockep(lock, name, key);
+	mutex_init_lockdep(lock, name, key);
 }
 #else
 extern void mutex_init_generic(struct mutex *lock);
kernel/locking/mutex.c +2 -2
index 2a1d165b3167..c867f6c15530 100644
@@ -171,7 +171,7 @@ static __always_inline bool __mutex_unlock_fast(struct mutex *lock)
 
 #else /* !CONFIG_DEBUG_LOCK_ALLOC */
 
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key)
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key)
 {
 	__mutex_init_generic(lock);
 
@@ -181,7 +181,7 @@ void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_k
 	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
 	lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP);
 }
-EXPORT_SYMBOL(mutex_init_lockep);
+EXPORT_SYMBOL(mutex_init_lockdep);
 #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 static inline void __mutex_set_flag(struct mutex *lock, unsigned long flag)
Signature · 1 line
2.39.5
maintainer
#2 lore raw

Re: [PATCH 1/3] locking/mutex: Rename mutex_init_lockep()

Quoted 1 line · Davidlohr Bueso

Typo, this wants to be _lockdep().

Lol... I *never* saw that until just now.

Reading is hard I suppose :-)

Acked-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] locking/mutex: Rename mutex_init_lockep()

In reply to Davidlohr Bueso
Quoted 42 lines · Davidlohr Bueso

Typo, this wants to be _lockdep().

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
  include/linux/mutex.h  | 4 ++--
  kernel/locking/mutex.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/mutex.h +2 -2
index ecaa0440f6ec..8126da959088 100644
@@ -87,12 +87,12 @@ do {									\
  	struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
 
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key);
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key);
 
  static inline void __mutex_init(struct mutex *lock, const char *name,
  				struct lock_class_key *key)
  {
-	mutex_init_lockep(lock, name, key);
+	mutex_init_lockdep(lock, name, key);
  }
  #else
  extern void mutex_init_generic(struct mutex *lock);
kernel/locking/mutex.c +1 -1
index 2a1d165b3167..c867f6c15530 100644
@@ -171,7 +171,7 @@ static __always_inline bool __mutex_unlock_fast(struct mutex *lock)
 
  #else /* !CONFIG_DEBUG_LOCK_ALLOC */
 
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key)
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key)
  {
  	__mutex_init_generic(lock);
 

kernel/locking/mutex.c void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_k · line 187

Quoted 8 lines
kernel/locking/mutex.c +1 -1
@@ -181,7 +181,7 @@ void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_k
  	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  	lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP);
  }
-EXPORT_SYMBOL(mutex_init_lockep);
+EXPORT_SYMBOL(mutex_init_lockdep);
  #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
  static inline void __mutex_set_flag(struct mutex *lock, unsigned long flag)

Yes, this typo can be easy to miss.

#4 lore raw

[tip: locking/core] locking/mutex: Rename mutex_init_lockep()

In reply to Davidlohr Bueso
The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     8b65eb52d93e4e496bd26e6867152344554eb39e
Gitweb:        https://git.kernel.org/tip/8b65eb52d93e4e496bd26e6867152344554eb39e
Author:        Davidlohr Bueso <[email protected]>
AuthorDate:    Tue, 17 Feb 2026 11:15:10 -08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 23 Feb 2026 11:19:15 +01:00

locking/mutex: Rename mutex_init_lockep()

Typo, this wants to be _lockdep().

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
 include/linux/mutex.h  | 4 ++--
 kernel/locking/mutex.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/mutex.h +2 -2
index ecaa044..8126da9 100644
@@ -87,12 +87,12 @@ do {									\
 	struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key);
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key);
 
 static inline void __mutex_init(struct mutex *lock, const char *name,
 				struct lock_class_key *key)
 {
-	mutex_init_lockep(lock, name, key);
+	mutex_init_lockdep(lock, name, key);
 }
 #else
 extern void mutex_init_generic(struct mutex *lock);
kernel/locking/mutex.c +2 -2
index 2a1d165..c867f6c 100644
@@ -171,7 +171,7 @@ static __always_inline bool __mutex_unlock_fast(struct mutex *lock)
 
 #else /* !CONFIG_DEBUG_LOCK_ALLOC */
 
-void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_key *key)
+void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key)
 {
 	__mutex_init_generic(lock);
 
@@ -181,7 +181,7 @@ void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_class_k
 	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
 	lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP);
 }
-EXPORT_SYMBOL(mutex_init_lockep);
+EXPORT_SYMBOL(mutex_init_lockdep);
 #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 static inline void __mutex_set_flag(struct mutex *lock, unsigned long flag)
#5 lore raw

PATCH 2/3 locking/mutex: Fix wrong comment for CONFIG_DEBUG_LOCK_ALLOC

In reply to Davidlohr Bueso

... that endif block should be CONFIG_DEBUG_LOCK_ALLOC, not CONFIG_LOCKDEP.

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
 include/linux/mutex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mutex.h +1 -1
index 8126da959088..f57d2a97da57 100644
@@ -146,7 +146,7 @@ static inline void __mutex_init(struct mutex *lock, const char *name,
 {
 	mutex_rt_init_generic(lock);
 }
-#endif /* !CONFIG_LOCKDEP */
+#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 #endif /* CONFIG_PREEMPT_RT */
 
 #ifdef CONFIG_DEBUG_MUTEXES
Signature · 1 line
2.39.5
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] locking/mutex: Fix wrong comment for CONFIG_DEBUG_LOCK_ALLOC

Quoted 14 lines · Davidlohr Bueso

... that endif block should be CONFIG_DEBUG_LOCK_ALLOC, not CONFIG_LOCKDEP.

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
  include/linux/mutex.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mutex.h +0 -0
index 8126da959088..f57d2a97da57 100644

include/linux/mutex.h static inline void __mutex_init(struct mutex *lock, const char *name, · line 152

Quoted 8 lines
include/linux/mutex.h +1 -1
@@ -146,7 +146,7 @@ static inline void __mutex_init(struct mutex *lock, const char *name,
  {
  	mutex_rt_init_generic(lock);
  }
-#endif /* !CONFIG_LOCKDEP */
+#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
  #endif /* CONFIG_PREEMPT_RT */
 
  #ifdef CONFIG_DEBUG_MUTEXES
#7 lore raw

[tip: locking/core] locking/mutex: Fix wrong comment for CONFIG_DEBUG_LOCK_ALLOC

In reply to Davidlohr Bueso
The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     babcde3be8c9148aa60a14b17831e8f249854963
Gitweb:        https://git.kernel.org/tip/babcde3be8c9148aa60a14b17831e8f249854963
Author:        Davidlohr Bueso <[email protected]>
AuthorDate:    Tue, 17 Feb 2026 11:15:11 -08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 23 Feb 2026 11:19:16 +01:00

locking/mutex: Fix wrong comment for CONFIG_DEBUG_LOCK_ALLOC

... that endif block should be CONFIG_DEBUG_LOCK_ALLOC, not CONFIG_LOCKDEP.

Fixes 51d7a054521d ("locking/mutex: Redo __mutex_init() to reduce generated code size")
---
 include/linux/mutex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mutex.h +1 -1
index 8126da9..f57d2a9 100644
@@ -146,7 +146,7 @@ static inline void __mutex_init(struct mutex *lock, const char *name,
 {
 	mutex_rt_init_generic(lock);
 }
-#endif /* !CONFIG_LOCKDEP */
+#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 #endif /* CONFIG_PREEMPT_RT */
 
 #ifdef CONFIG_DEBUG_MUTEXES
#8 lore raw

PATCH 3/3 locking/mutex: Add killable flavor to guard definitions

In reply to Davidlohr Bueso

The mutex guard family defines _try and _intr variants but is missing the killable one.

---
 include/linux/mutex.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/mutex.h +3 -0
index f57d2a97da57..2f648ee204e7 100644
@@ -253,6 +253,7 @@ extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock) __cond_a
 DEFINE_LOCK_GUARD_1(mutex, struct mutex, mutex_lock(_T->lock), mutex_unlock(_T->lock))
 DEFINE_LOCK_GUARD_1_COND(mutex, _try, mutex_trylock(_T->lock))
 DEFINE_LOCK_GUARD_1_COND(mutex, _intr, mutex_lock_interruptible(_T->lock), _RET == 0)
+DEFINE_LOCK_GUARD_1_COND(mutex, _kill, mutex_lock_killable(_T->lock), _RET == 0)
 DEFINE_LOCK_GUARD_1(mutex_init, struct mutex, mutex_init(_T->lock), /* */)
 
 DECLARE_LOCK_GUARD_1_ATTRS(mutex,	__acquires(_T), __releases(*(struct mutex **)_T))
@@ -261,6 +262,8 @@ DECLARE_LOCK_GUARD_1_ATTRS(mutex_try,	__acquires(_T), __releases(*(struct mutex
 #define class_mutex_try_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_try, _T)
 DECLARE_LOCK_GUARD_1_ATTRS(mutex_intr,	__acquires(_T), __releases(*(struct mutex **)_T))
 #define class_mutex_intr_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_intr, _T)
+DECLARE_LOCK_GUARD_1_ATTRS(mutex_kill,	__acquires(_T), __releases(*(struct mutex **)_T))
+#define class_mutex_kill_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_kill, _T)
 DECLARE_LOCK_GUARD_1_ATTRS(mutex_init,	__acquires(_T), __releases(*(struct mutex **)_T))
 #define class_mutex_init_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_init, _T)
 
Signature · 1 line
2.39.5
#9 lore raw

[tip: locking/core] locking/mutex: Add killable flavor to guard definitions

The following commit has been merged into the locking/core branch of tip:

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     50214dc4382055352fb1d7b9779550dabf5059e5
Gitweb:        https://git.kernel.org/tip/50214dc4382055352fb1d7b9779550dabf5059e5
Author:        Davidlohr Bueso <[email protected]>
AuthorDate:    Tue, 17 Feb 2026 11:15:12 -08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 23 Feb 2026 11:19:16 +01:00

locking/mutex: Add killable flavor to guard definitions

The mutex guard family defines _try and _intr variants but is missing the killable one.

---
 include/linux/mutex.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/mutex.h +3 -0
index f57d2a9..2f648ee 100644
@@ -253,6 +253,7 @@ extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock) __cond_a
 DEFINE_LOCK_GUARD_1(mutex, struct mutex, mutex_lock(_T->lock), mutex_unlock(_T->lock))
 DEFINE_LOCK_GUARD_1_COND(mutex, _try, mutex_trylock(_T->lock))
 DEFINE_LOCK_GUARD_1_COND(mutex, _intr, mutex_lock_interruptible(_T->lock), _RET == 0)
+DEFINE_LOCK_GUARD_1_COND(mutex, _kill, mutex_lock_killable(_T->lock), _RET == 0)
 DEFINE_LOCK_GUARD_1(mutex_init, struct mutex, mutex_init(_T->lock), /* */)
 
 DECLARE_LOCK_GUARD_1_ATTRS(mutex,	__acquires(_T), __releases(*(struct mutex **)_T))
@@ -261,6 +262,8 @@ DECLARE_LOCK_GUARD_1_ATTRS(mutex_try,	__acquires(_T), __releases(*(struct mutex 
 #define class_mutex_try_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_try, _T)
 DECLARE_LOCK_GUARD_1_ATTRS(mutex_intr,	__acquires(_T), __releases(*(struct mutex **)_T))
 #define class_mutex_intr_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_intr, _T)
+DECLARE_LOCK_GUARD_1_ATTRS(mutex_kill,	__acquires(_T), __releases(*(struct mutex **)_T))
+#define class_mutex_kill_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_kill, _T)
 DECLARE_LOCK_GUARD_1_ATTRS(mutex_init,	__acquires(_T), __releases(*(struct mutex **)_T))
 #define class_mutex_init_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex_init, _T)