summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGvozden Neskovic <[email protected]>2017-08-03 05:42:58 +0200
committerBrian Behlendorf <[email protected]>2017-08-02 20:42:58 -0700
commit261a3151e16851304eb3e36af2681d1d1579b08f (patch)
treee7862bd56808c2591737ff6eed319dc345f65c24 /include
parent549423c0d4b8176110283a5cf90c6393b2a537d4 (diff)
spl-mutex: fix race in mutex_exit
Prevent race on accessing kmutex_t when the mutex is embedded in a ref counted structure. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Chunwei Chen <[email protected]> Signed-off-by: Gvozden Neskovic <[email protected]> Closes zfsonlinux/zfs#6401 Closes #637
Diffstat (limited to 'include')
-rw-r--r--include/sys/mutex.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/include/sys/mutex.h b/include/sys/mutex.h
index 319235223..8a98a9213 100644
--- a/include/sys/mutex.h
+++ b/include/sys/mutex.h
@@ -183,12 +183,13 @@ spl_mutex_lockdep_on_maybe(kmutex_t *mp) \
*/
#define mutex_exit(mp) \
{ \
- spl_mutex_lockdep_off_maybe(mp); \
- spin_lock(&(mp)->m_lock); \
spl_mutex_clear_owner(mp); \
+ spin_lock(&(mp)->m_lock); \
+ spl_mutex_lockdep_off_maybe(mp); \
mutex_unlock(MUTEX(mp)); \
- spin_unlock(&(mp)->m_lock); \
spl_mutex_lockdep_on_maybe(mp); \
+ spin_unlock(&(mp)->m_lock); \
+ /* NOTE: do not dereference mp after this point */ \
}
int spl_mutex_init(void);