From: Chao Yu GC migrates data blocks of post-read and atomic files via meta cache entries, and writes them w/ DATA bios in move_data_block(), however, f2fs_cache_wait_writeback() only submits cached META bio for a meta cache entry, so it may wait forever for a DATA bio which GC has not submitted yet, e.g. an ABBA deadlock found by consistency test w/ atomic write workers and gc_urgent: - lock A: writeback state (F2FS_BLOCK_WRITEBACK) of the meta cache entry of new block B, it's cleared only after the DATA bio cached by GC is submitted and completed - lock B: lock of node cache entry N GC thread atomic commit - do_garbage_collect - gc_data_segment (phase 4) - move_data_block - f2fs_start_cache_writeback(B) (set WRITEBACK of B: lock A) - f2fs_submit_cache_write : B's DATA bio is cached, not submitted until the end of do_garbage_collect - f2fs_commit_atomic_write - __replace_atomic_write_block - f2fs_get_dnode_of_data (lock N: lock B) - f2fs_truncate_data_blocks_range - f2fs_invalidate_blocks(B) - f2fs_truncate_meta_caches - f2fs_cache_wait_writeback - ..._wait_writeback_cond(META) : submits META bio only - wait_on_bit_io(WRITEBACK) (wait for lock A, held by GC) - is_alive (next block) - f2fs_get_node_cache(N) (wait for lock B, held by commit) Then checkpoint, writeback and all syncs hang behind them. Before commit 7a1cf2a76b71 ("f2fs: cache: use meta cache"), GC staged such blocks in META_MAPPING folios, and f2fs_truncate_meta_inode_pages() submitted cached DATA bio of meta inode before waiting on their writeback, the conversion to f2fs_truncate_meta_caches() lost it. Let's submit cached DATA bio as well in f2fs_cache_wait_writeback_cond() when waiting writeback of a meta cache entry w/ META type. Cc: stable@vger.kernel.org Fixes: 7a1cf2a76b71 ("f2fs: cache: use meta cache") Signed-off-by: Chao Yu --- fs/f2fs/cache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/f2fs/cache.c b/fs/f2fs/cache.c index 6cac7662fc1a..f22acf3e51ff 100644 --- a/fs/f2fs/cache.c +++ b/fs/f2fs/cache.c @@ -32,6 +32,12 @@ void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry, /* submit cached bio */ f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, type); + /* + * GC writes meta cache entries w/ DATA bio in move_data_block(), + * submit it as well, or we may wait for a bio cached by GC forever. + */ + if (type == META) + f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, DATA); wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK, TASK_UNINTERRUPTIBLE); -- 2.49.0