lkml.org 
[lkml]   [2021]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] jffs2: solving deadlock on sync function
Date
Correcting AB-BA deadlock in jffs2_fsync() involving alloc_sem
semaphore and inodes.

The function jffs2_fsync() can't lock the inode because some
process, or even the same process, that call the CG will acquire
alloc_sem semaphore and will try to acquire the inode if it is
inside the Erase Block that is marked to be processed.

Fixes: 02c24a82187d ("fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers")

Signed-off-by: Wagner Popov dos Santos <wpopov@gmail.com>
---
fs/jffs2/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index 7d8654a1472e..7f139704cb8d 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -39,10 +39,14 @@ int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
if (ret)
return ret;

- inode_lock(inode);
- /* Trigger GC to flush any pending writes for this inode */
+ /* Trigger GC to flush any pending writes for this inode
+ *
+ * We need to leave the inode unlocked to avoid a deadlock condition
+ * because the function jffs2_garbage_collect_pass() can try to lock
+ * the same inode if it is inside the erase block that GC is
+ * processing.
+ */
jffs2_flush_wbuf_gc(c, inode->i_ino);
- inode_unlock(inode);

return 0;
}
--
2.20.1
\
 
 \ /
  Last update: 2021-10-27 04:05    [W:0.027 / U:0.676 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site