From 3e904f40b4f24db61798ca8c8a9027731cf2ced6 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Sun, 19 Aug 2012 12:10:19 -0700 Subject: [PATCH] Mutex ASSERT on self deadlock Generate an assertion if we're going to deadlock the system by attempting to acquire a mutex the process is already holding. There are currently no known instances of this under normal operation, but it _might_ be possible when using a ZVOL as a swap device. I want to ensure we catch this immediately if it were to occur. Signed-off-by: Brian Behlendorf --- include/sys/mutex.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/sys/mutex.h b/include/sys/mutex.h index 213bc24778..905eed50e6 100644 --- a/include/sys/mutex.h +++ b/include/sys/mutex.h @@ -78,8 +78,12 @@ mutex_owner(kmutex_t *mp) }) #define mutex_tryenter(mp) mutex_trylock(&(mp)->m) -#define mutex_enter(mp) mutex_lock(&(mp)->m) -#define mutex_exit(mp) mutex_unlock(&(mp)->m) +#define mutex_enter(mp) \ +({ \ + ASSERT3P(mutex_owner(mp), !=, current); \ + mutex_lock(&(mp)->m); \ + }) +#define mutex_exit(mp) mutex_unlock(&(mp)->m) #ifdef HAVE_GPL_ONLY_SYMBOLS # define mutex_enter_nested(mp, sc) mutex_lock_nested(&(mp)->m, sc) @@ -171,6 +175,7 @@ spl_mutex_clear_owner(kmutex_t *mp) _rc_ = 0; \ _count_ = 0; \ _owner_ = mutex_owner(mp); \ + ASSERT3P(_owner_, !=, current); \ \ while (_owner_ && task_curr(_owner_) && \ _count_ <= spl_mutex_spin_max()) { \