]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-patches/0004-Fix-zpl_mount-deadlock.patch
Cherry-pick fix for zpl_mount deadlock
[zfsonlinux.git] / zfs-patches / 0004-Fix-zpl_mount-deadlock.patch
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
5
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.
10
11 -- THREAD A --
12 spa_sync()
13 spa_sync_upgrades()
14 rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG); <- Waiting on B
15
16 -- THREAD B --
17 mount_fs()
18 zpl_mount()
19 zpl_mount_impl()
20 dmu_objset_hold()
21 dmu_objset_hold_flags()
22 dsl_pool_hold()
23 dsl_pool_config_enter()
24 rrw_enter(&dp->dp_config_rwlock, RW_READER, tag);
25 sget()
26 sget_userns()
27 grab_super()
28 down_write(&s->s_umount); <- Waiting on C
29
30 -- THREAD C --
31 cleanup_mnt()
32 deactivate_super()
33 down_write(&s->s_umount);
34 deactivate_locked_super()
35 zpl_kill_sb()
36 kill_anon_super()
37 generic_shutdown_super()
38 sync_filesystem()
39 zpl_sync_fs()
40 zfs_sync()
41 zil_commit()
42 txg_wait_synced() <- Waiting on A
43
44 Reviewed by: Alek Pinchuk <apinchuk@datto.com>
45 Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
46 Closes #7598
47 Closes #7659
48 Closes #7691
49 Closes #7693
50
51 (Cherry-picked from ac09630d8b0bf6c92084a30fdaefd03fd0adbdc1)
52 Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
53 ---
54 include/sys/zfs_vfsops.h | 1 +
55 module/zfs/zpl_super.c | 11 ++++++++++-
56 2 files changed, 11 insertions(+), 1 deletion(-)
57
58 diff --git a/include/sys/zfs_vfsops.h b/include/sys/zfs_vfsops.h
59 index 2326da42..927153b2 100644
60 --- a/include/sys/zfs_vfsops.h
61 +++ b/include/sys/zfs_vfsops.h
62 @@ -32,6 +32,7 @@
63 #include <sys/zil.h>
64 #include <sys/sa.h>
65 #include <sys/rrwlock.h>
66 +#include <sys/dsl_dataset.h>
67 #include <sys/zfs_ioctl.h>
68
69 #ifdef __cplusplus
70 diff --git a/module/zfs/zpl_super.c b/module/zfs/zpl_super.c
71 index fc10271b..5c426b0a 100644
72 --- a/module/zfs/zpl_super.c
73 +++ b/module/zfs/zpl_super.c
74 @@ -271,8 +271,17 @@ zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
75 if (err)
76 return (ERR_PTR(-err));
77
78 + /*
79 + * The dsl pool lock must be released prior to calling sget().
80 + * It is possible sget() may block on the lock in grab_super()
81 + * while deactivate_super() holds that same lock and waits for
82 + * a txg sync. If the dsl_pool lock is held over over sget()
83 + * this can prevent the pool sync and cause a deadlock.
84 + */
85 + dsl_pool_rele(dmu_objset_pool(os), FTAG);
86 s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
87 - dmu_objset_rele(os, FTAG);
88 + dsl_dataset_rele(dmu_objset_ds(os), FTAG);
89 +
90 if (IS_ERR(s))
91 return (ERR_CAST(s));
92