]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.18.6/btrfs-fix-btrfs_write_inode-vs-delayed-iput-deadlock.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.18.6 / btrfs-fix-btrfs_write_inode-vs-delayed-iput-deadlock.patch
1 From 3c4276936f6fbe52884b4ea4e6cc120b890a0f9f Mon Sep 17 00:00:00 2001
2 From: Josef Bacik <jbacik@fb.com>
3 Date: Fri, 20 Jul 2018 11:46:10 -0700
4 Subject: Btrfs: fix btrfs_write_inode vs delayed iput deadlock
5
6 From: Josef Bacik <jbacik@fb.com>
7
8 commit 3c4276936f6fbe52884b4ea4e6cc120b890a0f9f upstream.
9
10 We recently ran into the following deadlock involving
11 btrfs_write_inode():
12
13 [ +0.005066] __schedule+0x38e/0x8c0
14 [ +0.007144] schedule+0x36/0x80
15 [ +0.006447] bit_wait+0x11/0x60
16 [ +0.006446] __wait_on_bit+0xbe/0x110
17 [ +0.007487] ? bit_wait_io+0x60/0x60
18 [ +0.007319] __inode_wait_for_writeback+0x96/0xc0
19 [ +0.009568] ? autoremove_wake_function+0x40/0x40
20 [ +0.009565] inode_wait_for_writeback+0x21/0x30
21 [ +0.009224] evict+0xb0/0x190
22 [ +0.006099] iput+0x1a8/0x210
23 [ +0.006103] btrfs_run_delayed_iputs+0x73/0xc0
24 [ +0.009047] btrfs_commit_transaction+0x799/0x8c0
25 [ +0.009567] btrfs_write_inode+0x81/0xb0
26 [ +0.008008] __writeback_single_inode+0x267/0x320
27 [ +0.009569] writeback_sb_inodes+0x25b/0x4e0
28 [ +0.008702] wb_writeback+0x102/0x2d0
29 [ +0.007487] wb_workfn+0xa4/0x310
30 [ +0.006794] ? wb_workfn+0xa4/0x310
31 [ +0.007143] process_one_work+0x150/0x410
32 [ +0.008179] worker_thread+0x6d/0x520
33 [ +0.007490] kthread+0x12c/0x160
34 [ +0.006620] ? put_pwq_unlocked+0x80/0x80
35 [ +0.008185] ? kthread_park+0xa0/0xa0
36 [ +0.007484] ? do_syscall_64+0x53/0x150
37 [ +0.007837] ret_from_fork+0x29/0x40
38
39 Writeback calls:
40
41 btrfs_write_inode
42 btrfs_commit_transaction
43 btrfs_run_delayed_iputs
44
45 If iput() is called on that same inode, evict() will wait for writeback
46 forever.
47
48 btrfs_write_inode() was originally added way back in 4730a4bc5bf3
49 ("btrfs_dirty_inode") to support O_SYNC writes. However, ->write_inode()
50 hasn't been used for O_SYNC since 148f948ba877 ("vfs: Introduce new
51 helpers for syncing after writing to O_SYNC file or IS_SYNC inode"), so
52 btrfs_write_inode() is actually unnecessary (and leads to a bunch of
53 unnecessary commits). Get rid of it, which also gets rid of the
54 deadlock.
55
56 CC: stable@vger.kernel.org # 3.2+
57 Signed-off-by: Josef Bacik <jbacik@fb.com>
58 [Omar: new commit message]
59 Signed-off-by: Omar Sandoval <osandov@fb.com>
60 Signed-off-by: David Sterba <dsterba@suse.com>
61 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
62
63 ---
64 fs/btrfs/inode.c | 26 --------------------------
65 fs/btrfs/super.c | 1 -
66 2 files changed, 27 deletions(-)
67
68 --- a/fs/btrfs/inode.c
69 +++ b/fs/btrfs/inode.c
70 @@ -6027,32 +6027,6 @@ err:
71 return ret;
72 }
73
74 -int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
75 -{
76 - struct btrfs_root *root = BTRFS_I(inode)->root;
77 - struct btrfs_trans_handle *trans;
78 - int ret = 0;
79 - bool nolock = false;
80 -
81 - if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
82 - return 0;
83 -
84 - if (btrfs_fs_closing(root->fs_info) &&
85 - btrfs_is_free_space_inode(BTRFS_I(inode)))
86 - nolock = true;
87 -
88 - if (wbc->sync_mode == WB_SYNC_ALL) {
89 - if (nolock)
90 - trans = btrfs_join_transaction_nolock(root);
91 - else
92 - trans = btrfs_join_transaction(root);
93 - if (IS_ERR(trans))
94 - return PTR_ERR(trans);
95 - ret = btrfs_commit_transaction(trans);
96 - }
97 - return ret;
98 -}
99 -
100 /*
101 * This is somewhat expensive, updating the tree every time the
102 * inode changes. But, it is most likely to find the inode in cache.
103 --- a/fs/btrfs/super.c
104 +++ b/fs/btrfs/super.c
105 @@ -2331,7 +2331,6 @@ static const struct super_operations btr
106 .sync_fs = btrfs_sync_fs,
107 .show_options = btrfs_show_options,
108 .show_devname = btrfs_show_devname,
109 - .write_inode = btrfs_write_inode,
110 .alloc_inode = btrfs_alloc_inode,
111 .destroy_inode = btrfs_destroy_inode,
112 .statfs = btrfs_statfs,