6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yongpeng Yang [ Upstream commit c3e238bd1f56993f205ef83889d406dfeaf717a8 ] During FGGC node block migration, fsck may incorrectly treat the migrated node block as fsync-written data. The reproduction scenario: root@vm:/mnt/f2fs# seq 1 2048 | xargs -n 1 ./test_sync // write inline inode and sync root@vm:/mnt/f2fs# rm -f 1 root@vm:/mnt/f2fs# sync root@vm:/mnt/f2fs# f2fs_io gc_range // move data block in sync mode and not write CP SPO, "fsck --dry-run" find inode has already checkpointed but still with DENT_BIT_SHIFT set The root cause is that GC does not clear the dentry mark and fsync mark during node block migration, leading fsck to misinterpret them as user-issued fsync writes. In BGGC mode, node block migration is handled by f2fs_sync_node_pages(), which guarantees the dentry and fsync marks are cleared before writing. This patch move the set/clear of the fsync|dentry marks into __write_node_folio to make the logic clearer, and ensures the fsync|dentry mark is cleared in FGGC. Cc: stable@kernel.org Fixes: da011cc0da8c ("f2fs: move node pages only in victim section during GC") Signed-off-by: Yongpeng Yang Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/node.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 0898ce801f281..9709a212e6a03 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1643,9 +1643,10 @@ static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino) return last_page; } -static int __write_node_page(struct page *page, bool atomic, bool *submitted, - struct writeback_control *wbc, bool do_balance, - enum iostat_type io_type, unsigned int *seq_id) +static int __write_node_page(struct page *page, bool atomic, bool do_fsync, + bool *submitted, struct writeback_control *wbc, + bool do_balance, enum iostat_type io_type, + unsigned int *seq_id) { struct f2fs_sb_info *sbi = F2FS_P_SB(page); struct folio *folio = page_folio(page); @@ -1715,13 +1716,14 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, goto redirty_out; } - if (atomic) { - if (!test_opt(sbi, NOBARRIER)) - fio.op_flags |= REQ_PREFLUSH | REQ_FUA; - if (IS_INODE(page)) - set_dentry_mark(page, + if (atomic && !test_opt(sbi, NOBARRIER)) + fio.op_flags |= REQ_PREFLUSH | REQ_FUA; + + set_dentry_mark(page, false); + set_fsync_mark(page, do_fsync); + if (IS_INODE(page) && (atomic || is_fsync_dnode(page))) + set_dentry_mark(page, f2fs_need_dentry_mark(sbi, ino_of_node(page))); - } /* should add to global list before clearing PAGECACHE status */ if (f2fs_in_warm_node_list(sbi, page)) { @@ -1781,7 +1783,7 @@ int f2fs_move_node_page(struct page *node_page, int gc_type) goto out_page; } - if (__write_node_page(node_page, false, NULL, + if (__write_node_page(node_page, false, false, NULL, &wbc, false, FS_GC_NODE_IO, NULL)) { err = -EAGAIN; unlock_page(node_page); @@ -1802,7 +1804,7 @@ int f2fs_move_node_page(struct page *node_page, int gc_type) static int f2fs_write_node_page(struct page *page, struct writeback_control *wbc) { - return __write_node_page(page, false, NULL, wbc, false, + return __write_node_page(page, false, false, NULL, wbc, false, FS_NODE_IO, NULL); } @@ -1836,6 +1838,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, for (i = 0; i < nr_folios; i++) { struct page *page = &fbatch.folios[i]->page; bool submitted = false; + bool do_fsync = false; if (unlikely(f2fs_cp_error(sbi))) { f2fs_put_page(last_page, 0); @@ -1866,11 +1869,8 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, f2fs_wait_on_page_writeback(page, NODE, true, true); - set_fsync_mark(page, 0); - set_dentry_mark(page, 0); - if (!atomic || page == last_page) { - set_fsync_mark(page, 1); + do_fsync = true; percpu_counter_inc(&sbi->rf_node_block_count); if (IS_INODE(page)) { if (is_inode_flag_set(inode, @@ -1890,8 +1890,9 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, ret = __write_node_page(page, atomic && page == last_page, - &submitted, wbc, true, - FS_NODE_IO, seq_id); + do_fsync, &submitted, + wbc, true, FS_NODE_IO, + seq_id); if (ret) { unlock_page(page); f2fs_put_page(last_page, 0); @@ -2098,10 +2099,7 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, if (!clear_page_dirty_for_io(page)) goto continue_unlock; - set_fsync_mark(page, 0); - set_dentry_mark(page, 0); - - ret = __write_node_page(page, false, &submitted, + ret = __write_node_page(page, false, false, &submitted, wbc, do_balance, io_type, NULL); if (ret) unlock_page(page); -- 2.53.0