Skip to content

Commit d89616f

Browse files
verygreenbehlendorf
authored andcommitted
Remove misguided HAVE_MUTEX_OWNER check
It is just plain unsafe to peek inside in-kernel mutex structure and make assumptions about what kernel does with those internal fields like owner. Kernel is all too happy to stop doing the expected things like tracing lock owner once you load a tainted module like spl/zfs that is not GPL. As such you will get instant assertion failures like this: VERIFY3(((*(volatile typeof((&((&zo->zo_lock)->m_mutex))->owner) *)& ((&((&zo->zo_lock)->m_mutex))->owner))) == ((void *)0)) failed (ffff88030be28500 == (null)) PANIC at zfs_onexit.c:104:zfs_onexit_destroy() Showing stack for process 3626 CPU: 0 PID: 3626 Comm: mkfs.lustre Tainted: P OE ------------ 3.10.0-debug #1 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 Call Trace: dump_stack+0x19/0x1b spl_dumpstack+0x44/0x50 [spl] spl_panic+0xbf/0xf0 [spl] zfs_onexit_destroy+0x17c/0x280 [zfs] zfsdev_release+0x48/0xd0 [zfs] Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Chunwei Chen <[email protected]> Signed-off-by: Oleg Drokin <[email protected]> Closes openzfs#632 Closes openzfs#633
1 parent eed143d commit d89616f

File tree

2 files changed

+0
-40
lines changed

2 files changed

+0
-40
lines changed

config/spl-build.m4

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
4949
SPL_AC_USLEEP_RANGE
5050
SPL_AC_KMEM_CACHE_ALLOCFLAGS
5151
SPL_AC_WAIT_ON_BIT
52-
SPL_AC_MUTEX_OWNER
5352
SPL_AC_INODE_LOCK
5453
SPL_AC_GROUP_INFO_GID
5554
SPL_AC_KMEM_CACHE_CREATE_USERCOPY
@@ -1562,35 +1561,6 @@ AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
15621561
])
15631562
])
15641563

1565-
dnl #
1566-
dnl # Check whether mutex has owner with task_struct type.
1567-
dnl #
1568-
dnl # Note that before Linux 3.0, mutex owner is of type thread_info.
1569-
dnl #
1570-
dnl # Note that in Linux 3.18, the condition for owner is changed from
1571-
dnl # defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) to
1572-
dnl # defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_MUTEX_SPIN_ON_OWNER)
1573-
dnl #
1574-
AC_DEFUN([SPL_AC_MUTEX_OWNER], [
1575-
AC_MSG_CHECKING([whether mutex has owner])
1576-
tmp_flags="$EXTRA_KCFLAGS"
1577-
EXTRA_KCFLAGS="-Werror"
1578-
SPL_LINUX_TRY_COMPILE([
1579-
#include <linux/mutex.h>
1580-
#include <linux/spinlock.h>
1581-
],[
1582-
DEFINE_MUTEX(m);
1583-
struct task_struct *t __attribute__ ((unused));
1584-
t = m.owner;
1585-
],[
1586-
AC_MSG_RESULT(yes)
1587-
AC_DEFINE(HAVE_MUTEX_OWNER, 1, [yes])
1588-
],[
1589-
AC_MSG_RESULT(no)
1590-
])
1591-
EXTRA_KCFLAGS="$tmp_flags"
1592-
])
1593-
15941564
dnl #
15951565
dnl # 4.7 API change
15961566
dnl # i_mutex is changed to i_rwsem. Instead of directly using

include/sys/mutex.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ typedef enum {
4040
typedef struct {
4141
struct mutex m_mutex;
4242
spinlock_t m_lock; /* used for serializing mutex_exit */
43-
#ifndef HAVE_MUTEX_OWNER
4443
/* only when kernel doesn't have owner */
4544
kthread_t *m_owner;
46-
#endif
4745
#ifdef CONFIG_LOCKDEP
4846
kmutex_type_t m_type;
4947
#endif /* CONFIG_LOCKDEP */
@@ -58,24 +56,16 @@ spl_mutex_set_owner(kmutex_t *mp)
5856
* kernel will handle its owner, so we don't need to do anything if it
5957
* is defined.
6058
*/
61-
#ifndef HAVE_MUTEX_OWNER
6259
mp->m_owner = current;
63-
#endif
6460
}
6561

6662
static inline void
6763
spl_mutex_clear_owner(kmutex_t *mp)
6864
{
69-
#ifndef HAVE_MUTEX_OWNER
7065
mp->m_owner = NULL;
71-
#endif
7266
}
7367

74-
#ifdef HAVE_MUTEX_OWNER
7568
#define mutex_owner(mp) (ACCESS_ONCE(MUTEX(mp)->owner))
76-
#else
77-
#define mutex_owner(mp) (ACCESS_ONCE((mp)->m_owner))
78-
#endif
7969
#define mutex_owned(mp) (mutex_owner(mp) == current)
8070
#define MUTEX_HELD(mp) mutex_owned(mp)
8171
#define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp))

0 commit comments

Comments
 (0)