[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250409014136.2816971-2-mlevitsk@redhat.com>
Date: Tue, 8 Apr 2025 21:41:33 -0400
From: Maxim Levitsky <mlevitsk@...hat.com>
To: kvm@...r.kernel.org
Cc: Alexander Potapenko <glider@...gle.com>,
"H. Peter Anvin" <hpa@...or.com>,
Suzuki K Poulose <suzuki.poulose@....com>,
kvm-riscv@...ts.infradead.org,
Oliver Upton <oliver.upton@...ux.dev>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Jing Zhang <jingzhangos@...gle.com>,
Waiman Long <longman@...hat.com>,
x86@...nel.org,
Kunkun Jiang <jiangkunkun@...wei.com>,
Boqun Feng <boqun.feng@...il.com>,
Anup Patel <anup@...infault.org>,
Albert Ou <aou@...s.berkeley.edu>,
kvmarm@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Zenghui Yu <yuzenghui@...wei.com>,
Borislav Petkov <bp@...en8.de>,
Alexandre Ghiti <alex@...ti.fr>,
Keisuke Nishimura <keisuke.nishimura@...ia.fr>,
Sebastian Ott <sebott@...hat.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Atish Patra <atishp@...shpatra.org>,
Paul Walmsley <paul.walmsley@...ive.com>,
Randy Dunlap <rdunlap@...radead.org>,
Will Deacon <will@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>,
linux-riscv@...ts.infradead.org,
Marc Zyngier <maz@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
Joey Gouly <joey.gouly@....com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Andre Przywara <andre.przywara@....com>,
Thomas Gleixner <tglx@...utronix.de>,
Sean Christopherson <seanjc@...gle.com>,
Catalin Marinas <catalin.marinas@....com>,
Maxim Levitsky <mlevitsk@...hat.com>,
Bjorn Helgaas <bhelgaas@...gle.com>
Subject: [PATCH v2 1/4] locking/mutex: implement mutex_trylock_nested
Allow to specify the lockdep subclass in mutex_trylock
instead of hardcoding it to 0.
Signed-off-by: Maxim Levitsky <mlevitsk@...hat.com>
---
include/linux/mutex.h | 8 ++++++++
kernel/locking/mutex.c | 14 +++++++++++---
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 2143d05116be..ea568d6c4c68 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -193,7 +193,15 @@ extern void mutex_lock_io(struct mutex *lock);
*
* Returns 1 if the mutex has been acquired successfully, and 0 on contention.
*/
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+extern int mutex_trylock_nested(struct mutex *lock, unsigned int subclass);
+#define mutex_trylock(lock) mutex_trylock_nested(lock, 0)
+#else
extern int mutex_trylock(struct mutex *lock);
+#define mutex_trylock_nested(lock, subclass) mutex_trylock(lock)
+#endif
+
extern void mutex_unlock(struct mutex *lock);
extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 555e2b3a665a..5e3078865f2b 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -1062,6 +1062,7 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,
#endif
+#ifndef CONFIG_DEBUG_LOCK_ALLOC
/**
* mutex_trylock - try to acquire the mutex, without waiting
* @lock: the mutex to be acquired
@@ -1077,18 +1078,25 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,
* mutex must be released by the same task that acquired it.
*/
int __sched mutex_trylock(struct mutex *lock)
+{
+ MUTEX_WARN_ON(lock->magic != lock);
+ return __mutex_trylock(lock);
+}
+EXPORT_SYMBOL(mutex_trylock);
+#else
+int __sched mutex_trylock_nested(struct mutex *lock, unsigned int subclass)
{
bool locked;
MUTEX_WARN_ON(lock->magic != lock);
-
locked = __mutex_trylock(lock);
if (locked)
- mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
+ mutex_acquire(&lock->dep_map, subclass, 1, _RET_IP_);
return locked;
}
-EXPORT_SYMBOL(mutex_trylock);
+EXPORT_SYMBOL(mutex_trylock_nested);
+#endif
#ifndef CONFIG_DEBUG_LOCK_ALLOC
int __sched
--
2.26.3
Powered by blists - more mailing lists