From 2f76797ad9b630751fad9b10aa7aa4a1737c4300 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 28 Feb 2023 20:27:20 -0500 Subject: [PATCH] Linux: Assert mutex is held in mutex_exit() A spurious mutex_exit() in a development branch caused weird issues until I identified it. An assertion prior to mutex_exit() would have caught it. Rather than adding assertions before invocations of mutex_exit() in the code, let us simply add an assertion to mutex_exit(). It is cheap and will likely improve developer productivity. Reviewed-by: Brian Behlendorf Reviewed-by: Brian Atkinson Signed-off-by: Richard Yao Sponsored-By: Wasabi Technology, Inc. Closes #14541 --- include/os/linux/spl/sys/mutex.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/os/linux/spl/sys/mutex.h b/include/os/linux/spl/sys/mutex.h index 677076a0f..6b61c59c4 100644 --- a/include/os/linux/spl/sys/mutex.h +++ b/include/os/linux/spl/sys/mutex.h @@ -171,6 +171,7 @@ spl_mutex_lockdep_on_maybe(kmutex_t *mp) \ */ #define mutex_exit(mp) \ { \ + ASSERT3P(mutex_owner(mp), ==, current); \ spl_mutex_clear_owner(mp); \ spin_lock(&(mp)->m_lock); \ spl_mutex_lockdep_off_maybe(mp); \