]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Linux: Assert mutex is held in mutex_exit()
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Wed, 1 Mar 2023 01:27:20 +0000 (20:27 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Mar 2023 01:27:20 +0000 (17:27 -0800)
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 <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Richard Yao <richard.yao@klarasystems.com>
Sponsored-By: Wasabi Technology, Inc.
Closes #14541

include/os/linux/spl/sys/mutex.h

index 677076a0f1341d92b9a68264e3e9c14d2cbe5026..6b61c59c48e202bf3db4931cdfa4a2d7badac3fd 100644 (file)
@@ -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);                        \