]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Mutex ASSERT on self deadlock
authorBrian Behlendorf <behlendorf1@llnl.gov>
Sun, 19 Aug 2012 19:10:19 +0000 (12:10 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 27 Aug 2012 19:00:55 +0000 (12:00 -0700)
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>
include/sys/mutex.h

index 213bc247786afac742e4e31d3e7afb3d92ddc5ed..905eed50e62e0ead526500ee57bb747ece18da97 100644 (file)
@@ -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()) {                       \