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 <behlendorf1@llnl.gov>
This commit is contained in:
Brian Behlendorf 2012-08-19 12:10:19 -07:00
parent eb0f407a2b
commit 3e904f40b4
1 changed files with 7 additions and 2 deletions

View File

@ -78,8 +78,12 @@ mutex_owner(kmutex_t *mp)
}) })
#define mutex_tryenter(mp) mutex_trylock(&(mp)->m) #define mutex_tryenter(mp) mutex_trylock(&(mp)->m)
#define mutex_enter(mp) mutex_lock(&(mp)->m) #define mutex_enter(mp) \
#define mutex_exit(mp) mutex_unlock(&(mp)->m) ({ \
ASSERT3P(mutex_owner(mp), !=, current); \
mutex_lock(&(mp)->m); \
})
#define mutex_exit(mp) mutex_unlock(&(mp)->m)
#ifdef HAVE_GPL_ONLY_SYMBOLS #ifdef HAVE_GPL_ONLY_SYMBOLS
# define mutex_enter_nested(mp, sc) mutex_lock_nested(&(mp)->m, sc) # 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; \ _rc_ = 0; \
_count_ = 0; \ _count_ = 0; \
_owner_ = mutex_owner(mp); \ _owner_ = mutex_owner(mp); \
ASSERT3P(_owner_, !=, current); \
\ \
while (_owner_ && task_curr(_owner_) && \ while (_owner_ && task_curr(_owner_) && \
_count_ <= spl_mutex_spin_max()) { \ _count_ <= spl_mutex_spin_max()) { \