]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
f2fs: fix to avoid potential deadlock
authorChao Yu <chao@kernel.org>
Thu, 27 Jan 2022 05:44:49 +0000 (13:44 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:57:03 +0000 (11:57 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit 344150999b7fc88502a65bbb147a47503eca2033 ]

Quoted from Jing Xia's report, there is a potential deadlock may happen
between kworker and checkpoint as below:

[T:writeback] [T:checkpoint]
- wb_writeback
 - blk_start_plug
bio contains NodeA was plugged in writeback threads
- do_writepages  -- sync write inodeB, inc wb_sync_req[DATA]
 - f2fs_write_data_pages
  - f2fs_write_single_data_page -- write last dirty page
   - f2fs_do_write_data_page
    - set_page_writeback  -- clear page dirty flag and
    PAGECACHE_TAG_DIRTY tag in radix tree
    - f2fs_outplace_write_data
     - f2fs_update_data_blkaddr
      - f2fs_wait_on_page_writeback -- wait NodeA to writeback here
   - inode_dec_dirty_pages
 - writeback_sb_inodes
  - writeback_single_inode
   - do_writepages
    - f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
     - wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
  - requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped
 - blk_finish_plug

Let's try to avoid deadlock condition by forcing unplugging previous bio via
blk_finish_plug(current->plug) once we'v skipped writeback in writepages()
due to valid sbi->wb_sync_req[DATA/NODE].

Fixes: 687de7f1010c ("f2fs: avoid IO split due to mixed WB_SYNC_ALL and WB_SYNC_NONE")
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Jing Xia <jing.xia@unisoc.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 2911ad0249c5ab50afc640982811f11896233b65)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
fs/f2fs/data.c
fs/f2fs/node.c

index e662355cf8c9b824cfbb2018fd215112ead2b683..f6e9fc36b8376b70404e8a85c2a0a56b9387d20d 100644 (file)
@@ -3214,8 +3214,12 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
        /* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */
        if (wbc->sync_mode == WB_SYNC_ALL)
                atomic_inc(&sbi->wb_sync_req[DATA]);
-       else if (atomic_read(&sbi->wb_sync_req[DATA]))
+       else if (atomic_read(&sbi->wb_sync_req[DATA])) {
+               /* to avoid potential deadlock */
+               if (current->plug)
+                       blk_finish_plug(current->plug);
                goto skip_write;
+       }
 
        if (__should_serialize_io(inode, wbc)) {
                mutex_lock(&sbi->writepages);
index 556fcd8457f3f26d3564842eeef0714106769661..69c6bcaf5aae8c27530382b85e4366b5488519da 100644 (file)
@@ -2106,8 +2106,12 @@ static int f2fs_write_node_pages(struct address_space *mapping,
 
        if (wbc->sync_mode == WB_SYNC_ALL)
                atomic_inc(&sbi->wb_sync_req[NODE]);
-       else if (atomic_read(&sbi->wb_sync_req[NODE]))
+       else if (atomic_read(&sbi->wb_sync_req[NODE])) {
+               /* to avoid potential deadlock */
+               if (current->plug)
+                       blk_finish_plug(current->plug);
                goto skip_write;
+       }
 
        trace_f2fs_writepages(mapping->host, wbc, NODE);