aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2012-08-19 12:10:19 -0700
committerBrian Behlendorf <[email protected]>2012-08-27 12:00:55 -0700
commit3e904f40b4f24db61798ca8c8a9027731cf2ced6 (patch)
treec125889abf40608464a3a5c6840301755c967b2a
parenteb0f407a2b9089113ef6f2402ebd887511315b43 (diff)
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 <[email protected]>
-rw-r--r--include/sys/mutex.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/include/sys/mutex.h b/include/sys/mutex.h
index 213bc2477..905eed50e 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()) { \