Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
spl-mutex: fix race in mutex_exit
Browse files Browse the repository at this point in the history
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 openzfs/zfs#6401
Closes #637
  • Loading branch information
ironMann authored and behlendorf committed Aug 3, 2017
1 parent 549423c commit 261a315
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/sys/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 261a315

Please sign in to comment.