Skip to content

Commit 9083977

Browse files
Sahitya TummalaJaegeuk Kim
authored andcommitted
f2fs: do not use mutex lock in atomic context
Fix below warning coming because of using mutex lock in atomic context. BUG: sleeping function called from invalid context at kernel/locking/mutex.c:98 in_atomic(): 1, irqs_disabled(): 0, pid: 585, name: sh Preemption disabled at: __radix_tree_preload+0x28/0x130 Call trace: dump_backtrace+0x0/0x2b4 show_stack+0x20/0x28 dump_stack+0xa8/0xe0 ___might_sleep+0x144/0x194 __might_sleep+0x58/0x8c mutex_lock+0x2c/0x48 f2fs_trace_pid+0x88/0x14c f2fs_set_node_page_dirty+0xd0/0x184 Do not use f2fs_radix_tree_insert() to avoid doing cond_resched() with spin_lock() acquired. Signed-off-by: Sahitya Tummala <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent c42d28c commit 9083977

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

fs/f2fs/trace.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "trace.h"
1515

1616
static RADIX_TREE(pids, GFP_ATOMIC);
17-
static struct mutex pids_lock;
17+
static spinlock_t pids_lock;
1818
static struct last_io_info last_io;
1919

2020
static inline void __print_last_io(void)
@@ -58,23 +58,29 @@ void f2fs_trace_pid(struct page *page)
5858

5959
set_page_private(page, (unsigned long)pid);
6060

61+
retry:
6162
if (radix_tree_preload(GFP_NOFS))
6263
return;
6364

64-
mutex_lock(&pids_lock);
65+
spin_lock(&pids_lock);
6566
p = radix_tree_lookup(&pids, pid);
6667
if (p == current)
6768
goto out;
6869
if (p)
6970
radix_tree_delete(&pids, pid);
7071

71-
f2fs_radix_tree_insert(&pids, pid, current);
72+
if (radix_tree_insert(&pids, pid, current)) {
73+
spin_unlock(&pids_lock);
74+
radix_tree_preload_end();
75+
cond_resched();
76+
goto retry;
77+
}
7278

7379
trace_printk("%3x:%3x %4x %-16s\n",
7480
MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
7581
pid, current->comm);
7682
out:
77-
mutex_unlock(&pids_lock);
83+
spin_unlock(&pids_lock);
7884
radix_tree_preload_end();
7985
}
8086

@@ -119,7 +125,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
119125

120126
void f2fs_build_trace_ios(void)
121127
{
122-
mutex_init(&pids_lock);
128+
spin_lock_init(&pids_lock);
123129
}
124130

125131
#define PIDVEC_SIZE 128
@@ -147,13 +153,13 @@ void f2fs_destroy_trace_ios(void)
147153
pid_t next_pid = 0;
148154
unsigned int found;
149155

150-
mutex_lock(&pids_lock);
156+
spin_lock(&pids_lock);
151157
while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
152158
unsigned idx;
153159

154160
next_pid = pid[found - 1] + 1;
155161
for (idx = 0; idx < found; idx++)
156162
radix_tree_delete(&pids, pid[idx]);
157163
}
158-
mutex_unlock(&pids_lock);
164+
spin_unlock(&pids_lock);
159165
}

0 commit comments

Comments
 (0)