]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.34/f2fs-do-not-use-mutex-lock-in-atomic-context.patch
Linux 4.19.34
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / f2fs-do-not-use-mutex-lock-in-atomic-context.patch
CommitLineData
ba172962
SL
1From ae4cfda07e13c6175166efa16edc60b1ea0145c2 Mon Sep 17 00:00:00 2001
2From: Sahitya Tummala <stummala@codeaurora.org>
3Date: Mon, 4 Feb 2019 13:36:53 +0530
4Subject: f2fs: do not use mutex lock in atomic context
5
6[ Upstream commit 9083977dabf3833298ddcd40dee28687f1e6b483 ]
7
8Fix below warning coming because of using mutex lock in atomic context.
9
10BUG: sleeping function called from invalid context at kernel/locking/mutex.c:98
11in_atomic(): 1, irqs_disabled(): 0, pid: 585, name: sh
12Preemption disabled at: __radix_tree_preload+0x28/0x130
13Call trace:
14 dump_backtrace+0x0/0x2b4
15 show_stack+0x20/0x28
16 dump_stack+0xa8/0xe0
17 ___might_sleep+0x144/0x194
18 __might_sleep+0x58/0x8c
19 mutex_lock+0x2c/0x48
20 f2fs_trace_pid+0x88/0x14c
21 f2fs_set_node_page_dirty+0xd0/0x184
22
23Do not use f2fs_radix_tree_insert() to avoid doing cond_resched() with
24spin_lock() acquired.
25
26Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
27Reviewed-by: Chao Yu <yuchao0@huawei.com>
28Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
29Signed-off-by: Sasha Levin <sashal@kernel.org>
30---
31 fs/f2fs/trace.c | 20 +++++++++++++-------
32 1 file changed, 13 insertions(+), 7 deletions(-)
33
34diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c
35index a1fcd00bbb2b..8ac1851a21c0 100644
36--- a/fs/f2fs/trace.c
37+++ b/fs/f2fs/trace.c
38@@ -17,7 +17,7 @@
39 #include "trace.h"
40
41 static RADIX_TREE(pids, GFP_ATOMIC);
42-static struct mutex pids_lock;
43+static spinlock_t pids_lock;
44 static struct last_io_info last_io;
45
46 static inline void __print_last_io(void)
47@@ -61,23 +61,29 @@ void f2fs_trace_pid(struct page *page)
48
49 set_page_private(page, (unsigned long)pid);
50
51+retry:
52 if (radix_tree_preload(GFP_NOFS))
53 return;
54
55- mutex_lock(&pids_lock);
56+ spin_lock(&pids_lock);
57 p = radix_tree_lookup(&pids, pid);
58 if (p == current)
59 goto out;
60 if (p)
61 radix_tree_delete(&pids, pid);
62
63- f2fs_radix_tree_insert(&pids, pid, current);
64+ if (radix_tree_insert(&pids, pid, current)) {
65+ spin_unlock(&pids_lock);
66+ radix_tree_preload_end();
67+ cond_resched();
68+ goto retry;
69+ }
70
71 trace_printk("%3x:%3x %4x %-16s\n",
72 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
73 pid, current->comm);
74 out:
75- mutex_unlock(&pids_lock);
76+ spin_unlock(&pids_lock);
77 radix_tree_preload_end();
78 }
79
80@@ -122,7 +128,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
81
82 void f2fs_build_trace_ios(void)
83 {
84- mutex_init(&pids_lock);
85+ spin_lock_init(&pids_lock);
86 }
87
88 #define PIDVEC_SIZE 128
89@@ -150,7 +156,7 @@ void f2fs_destroy_trace_ios(void)
90 pid_t next_pid = 0;
91 unsigned int found;
92
93- mutex_lock(&pids_lock);
94+ spin_lock(&pids_lock);
95 while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
96 unsigned idx;
97
98@@ -158,5 +164,5 @@ void f2fs_destroy_trace_ios(void)
99 for (idx = 0; idx < found; idx++)
100 radix_tree_delete(&pids, pid[idx]);
101 }
102- mutex_unlock(&pids_lock);
103+ spin_unlock(&pids_lock);
104 }
105--
1062.19.1
107