Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b508af62 authored by Sayali Lokhande's avatar Sayali Lokhande
Browse files

f2fs: Avoid double lock for cp_rwsem during checkpoint



There could be a scenario where f2fs_sync_node_pages gets
called during checkpoint, which in turn tries to flush
inline data and calls iput(). This results in deadlock as
iput() tries to hold cp_rwsem, which is already held at the
beginning by checkpoint->block_operations().

Call stack :

Thread A		Thread B
f2fs_write_checkpoint()
- block_operations(sbi)
 - f2fs_lock_all(sbi);
  - down_write(&sbi->cp_rwsem);

                        - open()
                         - igrab()
                        - write() write inline data
                        - unlink()
- f2fs_sync_node_pages()
 - if (is_inline_node(page))
  - flush_inline_data()
   - ilookup()
     page = f2fs_pagecache_get_page()
     if (!page)
      goto iput_out;
     iput_out:
			-close()
			-iput()
       iput(inode);
       - f2fs_evict_inode()
        - f2fs_truncate_blocks()
         - f2fs_lock_op()
           - down_read(&sbi->cp_rwsem);

Change-Id: If9ee25ce1839df75540c5cc0b4e80b579b3bd067
Signed-off-by: default avatarSayali Lokhande <sayalil@codeaurora.org>
parent 4e1c68c5
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -1216,21 +1216,19 @@ static int block_operations(struct f2fs_sb_info *sbi)
		goto retry_flush_quotas;
	}

retry_flush_nodes:
	down_write(&sbi->node_write);

	if (get_pages(sbi, F2FS_DIRTY_NODES)) {
		up_write(&sbi->node_write);
		up_write(&sbi->node_change);
		f2fs_unlock_all(sbi);
		atomic_inc(&sbi->wb_sync_req[NODE]);
		err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
		atomic_dec(&sbi->wb_sync_req[NODE]);
		if (err) {
			up_write(&sbi->node_change);
			f2fs_unlock_all(sbi);
		if (err)
			goto out;
		}
		cond_resched();
		goto retry_flush_nodes;
		goto retry_flush_quotas;
	}

	/*