1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Brian Behlendorf <behlendorf1@llnl.gov>
3 Date: Wed, 11 Jul 2018 15:49:10 -0700
4 Subject: [PATCH] Fix zpl_mount() deadlock
6 Commit 93b43af10 inadvertently introduced the following scenario which
7 can result in a deadlock. This issue was most easily reproduced by
8 LXD containers using a ZFS storage backend but should be reproducible
9 under any workload which is frequently mounting and unmounting.
14 rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG); <- Waiting on B
21 dmu_objset_hold_flags()
23 dsl_pool_config_enter()
24 rrw_enter(&dp->dp_config_rwlock, RW_READER, tag);
28 down_write(&s->s_umount); <- Waiting on C
33 down_write(&s->s_umount);
34 deactivate_locked_super()
37 generic_shutdown_super()
42 txg_wait_synced() <- Waiting on A
44 Reviewed by: Alek Pinchuk <apinchuk@datto.com>
45 Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
51 Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
53 include/sys/zfs_vfsops.h | 1 +
54 module/zfs/zpl_super.c | 11 ++++++++++-
55 2 files changed, 11 insertions(+), 1 deletion(-)
57 diff --git a/include/sys/zfs_vfsops.h b/include/sys/zfs_vfsops.h
58 index 2326da42..927153b2 100644
59 --- a/include/sys/zfs_vfsops.h
60 +++ b/include/sys/zfs_vfsops.h
64 #include <sys/rrwlock.h>
65 +#include <sys/dsl_dataset.h>
66 #include <sys/zfs_ioctl.h>
69 diff --git a/module/zfs/zpl_super.c b/module/zfs/zpl_super.c
70 index fc10271b..5c426b0a 100644
71 --- a/module/zfs/zpl_super.c
72 +++ b/module/zfs/zpl_super.c
73 @@ -271,8 +271,17 @@ zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
75 return (ERR_PTR(-err));
78 + * The dsl pool lock must be released prior to calling sget().
79 + * It is possible sget() may block on the lock in grab_super()
80 + * while deactivate_super() holds that same lock and waits for
81 + * a txg sync. If the dsl_pool lock is held over over sget()
82 + * this can prevent the pool sync and cause a deadlock.
84 + dsl_pool_rele(dmu_objset_pool(os), FTAG);
85 s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
86 - dmu_objset_rele(os, FTAG);
87 + dsl_dataset_rele(dmu_objset_ds(os), FTAG);