Skip to contentSkip to conversation

include/linux/rtmutex.h: NOOP rt_mutex_destroy if !CONFIG_DEBUG_RT_MUTEXES

PATCH In review Alex Goins 2 participants 3 messages Oct 26, 2016 – Dec 3, 2016 Locking primitives

lore
Share & tools
lore

Alex Goins

author
#0 lore raw

PATCH 1/1 include/linux/rtmutex.h: NOOP rt_mutex_destroy if !CONFIG_DEBUG_RT_MUTEXES

mutex_destroy is no-op inline when DEBUG_MUTEX is not enabled. When mutex_destroy is indirectly used by non-GPL kernel modules that use inline functions such as reservation_object_fini(), users can use a kernel with DEBUG_MUTEX disabled to avoid a dependence on the GPL-only symbol mutex_destroy.

The RT Linux patches replace mutex_destroy with rt_mutex_destroy. Currently, rt_mutex_destroy is GPL_ONLY irrespective of whether mutex debugging is enabled.

This patch aligns rt_mutex_destroy with mutex_destroy by using the same no-op inline technique. This allows non-GPL modules to access the same functionality with RT Linux as with regular Linux.

---
 include/linux/rtmutex.h  | 7 ++++++-
 kernel/locking/rtmutex.c | 5 ++---
 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/rtmutex.h +6 -1
index 1abba5c..741e844 100644
@@ -56,6 +56,12 @@ struct hrtimer_sleeper;
 #endif
 
 #ifdef CONFIG_DEBUG_RT_MUTEXES
+ extern void rt_mutex_destroy(struct rt_mutex *lock);
+#else
+ static inline void rt_mutex_destroy(struct rt_mutex *lock) {}
+#endif
+
+#ifdef CONFIG_DEBUG_RT_MUTEXES
 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
 	, .name = #mutexname, .file = __FILE__, .line = __LINE__
 # define rt_mutex_init(mutex)			__rt_mutex_init(mutex, __func__)
@@ -87,7 +93,6 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock)
 }
 
 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
-extern void rt_mutex_destroy(struct rt_mutex *lock);
 
 extern void rt_mutex_lock(struct rt_mutex *lock);
 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
kernel/locking/rtmutex.c +2 -3
index 1ec0f48..8d3a80e 100644
@@ -1513,6 +1513,7 @@ bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
 	return rt_mutex_slowunlock(lock, wqh);
 }
 
+#ifdef CONFIG_DEBUG_RT_MUTEXES
 /**
  * rt_mutex_destroy - mark a mutex unusable
  * @lock: the mutex to be destroyed
@@ -1524,12 +1525,10 @@ bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
 void rt_mutex_destroy(struct rt_mutex *lock)
 {
 	WARN_ON(rt_mutex_is_locked(lock));
-#ifdef CONFIG_DEBUG_RT_MUTEXES
 	lock->magic = NULL;
-#endif
 }
-
 EXPORT_SYMBOL_GPL(rt_mutex_destroy);
+#endif
 
 /**
  * __rt_mutex_init - initialize the rt lock
Signature · 1 line
1.9.1
author
#1 lore raw

Pinging in case this got buried.

Thanks,
Alex

Reviewed-by on v1 1/1
#2 lore raw
In reply to Alex Goins

This seems consistent with the spirit of DEBUG_MUTEX in non-RT kernels, so hopefully this is acceptable to the RT maintainers.

Thanks,
- Andy

Quoted 71 lines · Alex Goins

mutex_destroy is no-op inline when DEBUG_MUTEX is not enabled. When mutex_destroy is indirectly used by non-GPL kernel modules that use inline functions such as reservation_object_fini(), users can use a kernel with DEBUG_MUTEX disabled to avoid a dependence on the GPL-only symbol mutex_destroy.

The RT Linux patches replace mutex_destroy with rt_mutex_destroy. Currently, rt_mutex_destroy is GPL_ONLY irrespective of whether mutex debugging is enabled.

This patch aligns rt_mutex_destroy with mutex_destroy by using the same no-op inline technique. This allows non-GPL modules to access the same functionality with RT Linux as with regular Linux.

---
 include/linux/rtmutex.h  | 7 ++++++-
 kernel/locking/rtmutex.c | 5 ++---
 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/rtmutex.h +6 -1
index 1abba5c..741e844 100644
@@ -56,6 +56,12 @@ struct hrtimer_sleeper;
 #endif
 
 #ifdef CONFIG_DEBUG_RT_MUTEXES
+ extern void rt_mutex_destroy(struct rt_mutex *lock);
+#else
+ static inline void rt_mutex_destroy(struct rt_mutex *lock) {}
+#endif
+
+#ifdef CONFIG_DEBUG_RT_MUTEXES
 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
 	, .name = #mutexname, .file = __FILE__, .line = __LINE__
 # define rt_mutex_init(mutex)			__rt_mutex_init(mutex, __func__)
@@ -87,7 +93,6 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock)
 }
 
 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
-extern void rt_mutex_destroy(struct rt_mutex *lock);
 
 extern void rt_mutex_lock(struct rt_mutex *lock);
 extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
kernel/locking/rtmutex.c +2 -3
index 1ec0f48..8d3a80e 100644
@@ -1513,6 +1513,7 @@ bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
 	return rt_mutex_slowunlock(lock, wqh);
 }
 
+#ifdef CONFIG_DEBUG_RT_MUTEXES
 /**
  * rt_mutex_destroy - mark a mutex unusable
  * @lock: the mutex to be destroyed
@@ -1524,12 +1525,10 @@ bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
 void rt_mutex_destroy(struct rt_mutex *lock)
 {
 	WARN_ON(rt_mutex_is_locked(lock));
-#ifdef CONFIG_DEBUG_RT_MUTEXES
 	lock->magic = NULL;
-#endif
 }
-
 EXPORT_SYMBOL_GPL(rt_mutex_destroy);
+#endif
 
 /**
  * __rt_mutex_init - initialize the rt lock