Prevent race on accessing kmutex_t when the mutex is
embedded in a ref counted structure.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Gvozden Neskovic <neskovic@gmail.com>
Closes zfsonlinux/zfs#6401
Closes #637
*/
#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);