Skip to contentSkip to conversation

f2fs: fix to avoid potential deadloop in f2fs_fsync_node_pages()

PATCH Applied Chao Yu 3 participants 5 messages Aug 24 – Sep 9 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix to avoid potential deadloop in f2fs_fsync_node_pages()

There is potential deadloop in race condition:

Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry

Fixes 608514deba38 ("f2fs: set fsync mark only for the last dnode")
---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/node.c +5 -0
index 968e5ed38816..86c2e67e43b6 100644
@@ -2016,6 +2016,11 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
 		f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx",
 			   ino, last_folio->index);
 		folio_lock(last_folio);
+		if (unlikely(!is_node_folio(last_folio))) {
+			f2fs_folio_put(last_folio, true);
+			ret = -EAGAIN;
+			goto out;
+		}
 		f2fs_folio_wait_writeback(last_folio, NODE, true, true);
 		folio_mark_dirty(last_folio);
 		folio_unlock(last_folio);
Signature · 1 line
2.49.0
#1 lore raw
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 21 lines · On Mon, 24 Aug 2026 21:17:29 +0800 you wrote:

There is potential deadloop in race condition:

Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry

Quoted 1 line

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: fix to avoid potential deadloop in f2fs_fsync_node_pages()

    https://git.kernel.org/jaegeuk/f2fs/c/ce366bfa821e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#2 lore raw
In reply to Chao Yu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 34 lines · 于2026年8月24日周一 21:19写道:

There is potential deadloop in race condition:

Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry

Fixes 608514deba38 ("f2fs: set fsync mark only for the last dnode")
---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/node.c +0 -0
index 968e5ed38816..86c2e67e43b6 100644

fs/f2fs/node.c int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 2019

Quoted 4 lines
fs/f2fs/node.c +1 -0
@@ -2016,6 +2016,11 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
                f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx",
                           ino, last_folio->index);
                folio_lock(last_folio);
+               if (unlikely(!is_node_folio(last_folio))) {

Hi Chao, is_node_folio->NODE_MAPPING(F2FS_F_SB(folio))->F2FS_M_SB(folio->mappping)->F2FS_I_SB(mapping->host) if mapping==NULL, panic will occur here?
just like commit msg in mai: "f2fs: parameterize node helpers and macros"
thanks!

Quoted 16 lines
fs/f2fs/node.c +4 -1
+                       f2fs_folio_put(last_folio, true);
+                       ret = -EAGAIN;
+                       goto out;
+               }
                f2fs_folio_wait_writeback(last_folio, NODE, true, true);
                folio_mark_dirty(last_folio);
                folio_unlock(last_folio);
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#3 lore raw
Quoted 31 lines · Zhiguo Niu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 29 lines · 于2026年8月24日周一 21:19写道:

There is potential deadloop in race condition:

Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry

Fixes 608514deba38 ("f2fs: set fsync mark only for the last dnode")
---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 13 lines

fs/f2fs/node.c int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 2019

Quoted 9 lines
fs/f2fs/node.c +1 -0
index 968e5ed38816..86c2e67e43b6 100644
@@ -2016,6 +2016,11 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
                f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx",
                           ino, last_folio->index);
                folio_lock(last_folio);
+               if (unlikely(!is_node_folio(last_folio))) {

Hi Chao, is_node_folio->NODE_MAPPING(F2FS_F_SB(folio))->F2FS_M_SB(folio->mappping)->F2FS_I_SB(mapping->host) if mapping==NULL, panic will occur here?
just like commit msg in mai: "f2fs: parameterize node helpers and macros"

Hi Zhiguo,

Ah, seems we need to revert ("f2fs: introduce is_{meta,node}_folio") which introduce this bug? IIUC.

Thanks,

Quoted 18 lines

thanks!

Quoted 16 lines
fs/f2fs/node.c +4 -1
+                       f2fs_folio_put(last_folio, true);
+                       ret = -EAGAIN;
+                       goto out;
+               }
                f2fs_folio_wait_writeback(last_folio, NODE, true, true);
                folio_mark_dirty(last_folio);
                folio_unlock(last_folio);
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 47 lines · Chao Yu <[email protected]> 于2026年9月9日周三 10:03写道:
Quoted 31 lines · Zhiguo Niu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 29 lines · 于2026年8月24日周一 21:19写道:

There is potential deadloop in race condition:

Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry

Fixes 608514deba38 ("f2fs: set fsync mark only for the last dnode")
---
 fs/f2fs/node.c | 5 +++++
 1 file changed, 5 insertions(+)
Quoted 13 lines

fs/f2fs/node.c int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 2019

Quoted 9 lines
fs/f2fs/node.c +1 -0
index 968e5ed38816..86c2e67e43b6 100644
@@ -2016,6 +2016,11 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
                f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx",
                           ino, last_folio->index);
                folio_lock(last_folio);
+               if (unlikely(!is_node_folio(last_folio))) {

Hi Chao, is_node_folio->NODE_MAPPING(F2FS_F_SB(folio))->F2FS_M_SB(folio->mappping)->F2FS_I_SB(mapping->host) if mapping==NULL, panic will occur here?
just like commit msg in mai: "f2fs: parameterize node helpers and macros"

Quoted 4 lines

Hi Zhiguo,

Ah, seems we need to revert ("f2fs: introduce is_{meta,node}_folio") which introduce this bug? IIUC.

Hi Chao,
seems yes, we can use sbi directly.
thanks!

Quoted 22 lines

Thanks,

Quoted 18 lines

thanks!

Quoted 16 lines
fs/f2fs/node.c +4 -1
+                       f2fs_folio_put(last_folio, true);
+                       ret = -EAGAIN;
+                       goto out;
+               }
                f2fs_folio_wait_writeback(last_folio, NODE, true, true);
                folio_mark_dirty(last_folio);
                folio_unlock(last_folio);
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel