kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] rtmutex_api: provide correct extern functions
@ 2025-05-31  6:07 Paolo Bonzini
  2025-05-31  6:38 ` Randy Dunlap
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2025-05-31  6:07 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: mlevitsk, Randy Dunlap, Peter Zijlstra

Commit fb49f07ba1d9 ("locking/mutex: implement mutex_lock_killable_nest_lock")
changed the set of functions that mutex.c defines when CONFIG_DEBUG_LOCK_ALLOC
is set.

- it removed the "extern" declaration of mutex_lock_killable_nested from
  include/linux/mutex.h, and replaced it with a macro since it could be
  treated as a special case of _mutex_lock_killable.  It also removed a
  definition of the function in kernel/locking/mutex.c.

- likewise, it replaced mutex_trylock() with the more generic
  mutex_trylock_nest_lock() and replaced mutex_trylock() with a macro.

However, it left the old definitions in place in kernel/locking/rtmutex_api.c,
which causes failures when building with CONFIG_RT_MUTEXES=y.  Bring over
the changes.

Fixes: fb49f07ba1d9 ("locking/mutex: implement mutex_lock_killable_nest_lock")
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
	This time, with brain connected.

 kernel/locking/rtmutex_api.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c
index 191e4720e546..f21e59a0525e 100644
--- a/kernel/locking/rtmutex_api.c
+++ b/kernel/locking/rtmutex_api.c
@@ -544,12 +544,12 @@ int __sched mutex_lock_interruptible_nested(struct mutex *lock,
 }
 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
 
-int __sched mutex_lock_killable_nested(struct mutex *lock,
-					    unsigned int subclass)
+int __sched _mutex_lock_killable(struct mutex *lock, unsigned int subclass,
+				 struct lockdep_map *nest_lock)
 {
-	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, NULL, _RET_IP_);
+	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, nest_lock, _RET_IP_);
 }
-EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
+EXPORT_SYMBOL_GPL(_mutex_lock_killable);
 
 void __sched mutex_lock_io_nested(struct mutex *lock, unsigned int subclass)
 {
@@ -563,6 +563,21 @@ void __sched mutex_lock_io_nested(struct mutex *lock, unsigned int subclass)
 }
 EXPORT_SYMBOL_GPL(mutex_lock_io_nested);
 
+int __sched _mutex_trylock_nest_lock(struct mutex *lock,
+				     struct lockdep_map *nest_lock)
+{
+	int ret;
+
+	if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
+		return 0;
+
+	ret = __rt_mutex_trylock(&lock->rtmutex);
+	if (ret)
+		mutex_acquire_nest(&lock->dep_map, 0, 1, nest_lock, _RET_IP_);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(_mutex_trylock_nest_lock);
 #else /* CONFIG_DEBUG_LOCK_ALLOC */
 
 void __sched mutex_lock(struct mutex *lock)
@@ -591,22 +606,16 @@ void __sched mutex_lock_io(struct mutex *lock)
 	io_schedule_finish(token);
 }
 EXPORT_SYMBOL(mutex_lock_io);
-#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 int __sched mutex_trylock(struct mutex *lock)
 {
-	int ret;
-
 	if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
 		return 0;
 
-	ret = __rt_mutex_trylock(&lock->rtmutex);
-	if (ret)
-		mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
-
-	return ret;
+	return __rt_mutex_trylock(&lock->rtmutex);
 }
 EXPORT_SYMBOL(mutex_trylock);
+#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 void __sched mutex_unlock(struct mutex *lock)
 {
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] rtmutex_api: provide correct extern functions
  2025-05-31  6:07 [PATCH v2] rtmutex_api: provide correct extern functions Paolo Bonzini
@ 2025-05-31  6:38 ` Randy Dunlap
  0 siblings, 0 replies; 2+ messages in thread
From: Randy Dunlap @ 2025-05-31  6:38 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm; +Cc: mlevitsk, Peter Zijlstra



On 5/30/25 11:07 PM, Paolo Bonzini wrote:
> Commit fb49f07ba1d9 ("locking/mutex: implement mutex_lock_killable_nest_lock")
> changed the set of functions that mutex.c defines when CONFIG_DEBUG_LOCK_ALLOC
> is set.
> 
> - it removed the "extern" declaration of mutex_lock_killable_nested from
>   include/linux/mutex.h, and replaced it with a macro since it could be
>   treated as a special case of _mutex_lock_killable.  It also removed a
>   definition of the function in kernel/locking/mutex.c.
> 
> - likewise, it replaced mutex_trylock() with the more generic
>   mutex_trylock_nest_lock() and replaced mutex_trylock() with a macro.
> 
> However, it left the old definitions in place in kernel/locking/rtmutex_api.c,
> which causes failures when building with CONFIG_RT_MUTEXES=y.  Bring over
> the changes.
> 
> Fixes: fb49f07ba1d9 ("locking/mutex: implement mutex_lock_killable_nest_lock")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Tested-by: Randy Dunlap <rdunlap@infradead.org>

Thanks!

> ---
> 	This time, with brain connected.
> 
>  kernel/locking/rtmutex_api.c | 33 +++++++++++++++++++++------------
>  1 file changed, 21 insertions(+), 12 deletions(-)
> 
> diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c
> index 191e4720e546..f21e59a0525e 100644
> --- a/kernel/locking/rtmutex_api.c
> +++ b/kernel/locking/rtmutex_api.c
> @@ -544,12 +544,12 @@ int __sched mutex_lock_interruptible_nested(struct mutex *lock,
>  }
>  EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
>  
> -int __sched mutex_lock_killable_nested(struct mutex *lock,
> -					    unsigned int subclass)
> +int __sched _mutex_lock_killable(struct mutex *lock, unsigned int subclass,
> +				 struct lockdep_map *nest_lock)
>  {
> -	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, NULL, _RET_IP_);
> +	return __mutex_lock_common(lock, TASK_KILLABLE, subclass, nest_lock, _RET_IP_);
>  }
> -EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
> +EXPORT_SYMBOL_GPL(_mutex_lock_killable);
>  
>  void __sched mutex_lock_io_nested(struct mutex *lock, unsigned int subclass)
>  {
> @@ -563,6 +563,21 @@ void __sched mutex_lock_io_nested(struct mutex *lock, unsigned int subclass)
>  }
>  EXPORT_SYMBOL_GPL(mutex_lock_io_nested);
>  
> +int __sched _mutex_trylock_nest_lock(struct mutex *lock,
> +				     struct lockdep_map *nest_lock)
> +{
> +	int ret;
> +
> +	if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
> +		return 0;
> +
> +	ret = __rt_mutex_trylock(&lock->rtmutex);
> +	if (ret)
> +		mutex_acquire_nest(&lock->dep_map, 0, 1, nest_lock, _RET_IP_);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(_mutex_trylock_nest_lock);
>  #else /* CONFIG_DEBUG_LOCK_ALLOC */
>  
>  void __sched mutex_lock(struct mutex *lock)
> @@ -591,22 +606,16 @@ void __sched mutex_lock_io(struct mutex *lock)
>  	io_schedule_finish(token);
>  }
>  EXPORT_SYMBOL(mutex_lock_io);
> -#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
>  
>  int __sched mutex_trylock(struct mutex *lock)
>  {
> -	int ret;
> -
>  	if (IS_ENABLED(CONFIG_DEBUG_RT_MUTEXES) && WARN_ON_ONCE(!in_task()))
>  		return 0;
>  
> -	ret = __rt_mutex_trylock(&lock->rtmutex);
> -	if (ret)
> -		mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
> -
> -	return ret;
> +	return __rt_mutex_trylock(&lock->rtmutex);
>  }
>  EXPORT_SYMBOL(mutex_trylock);
> +#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
>  
>  void __sched mutex_unlock(struct mutex *lock)
>  {

-- 
~Randy

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-31  6:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-31  6:07 [PATCH v2] rtmutex_api: provide correct extern functions Paolo Bonzini
2025-05-31  6:38 ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).