f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
Subsystems (2)
PATCH v2 1/1 f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
f2fs_update_inode() reads inode->i_blocks without holding i_lock to serialize it to the on-disk inode, while concurrent truncate or allocation paths may modify i_blocks under i_lock. Since blkcnt_t is u64, this risks torn reads on 32-bit architectures.
Following the approach in ext4_inode_blocks_set(), add READ_ONCE() to prevent potential compiler-induced tearing.
--- fs/f2fs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/inode.c +1 -1
@@ -694,7 +694,7 @@ void f2fs_update_inode(struct inode *inode, struct folio *node_folio) ri->i_uid =cpu_to_le32 (i_uid_read (inode)); ri->i_gid =cpu_to_le32 (i_gid_read (inode)); ri->i_links =cpu_to_le32 (inode->i_nlink); - ri->i_blocks =cpu_to_le64 (SECTOR_TO_BLOCK (inode->i_blocks) +1 ); + ri->i_blocks =cpu_to_le64 (SECTOR_TO_BLOCK (READ_ONCE (inode->i_blocks)) +1 );if (!f2fs_is_atomic_file (inode) ||is_inode_flag_set (inode,FI_ATOMIC_COMMITTED ))
Signature · 1 line
2.34.1
Quoted 11 lines · Cen Zhang
f2fs_update_inode()readsinode->i_blockswithout holdingi_lockto serialize it to the on-disk inode, while concurrent truncate or allocation paths may modifyi_blocksunderi_lock. Sinceblkcnt_tis u64, this risks torn reads on 32-bit architectures.Following the approach in
ext4_inode_blocks_set(), addREAD_ONCE()to prevent potential compiler-induced tearing.Fixes 19f99cee206c ("f2fs: add core inode operations")Signed-off-by Cen Zhang <[email protected]>
Thanks,
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 9 lines · On Wed, 18 Mar 2026 15:32:53 +0800 you wrote:
f2fs_update_inode()readsinode->i_blockswithout holdingi_lockto serialize it to the on-disk inode, while concurrent truncate or allocation paths may modifyi_blocksunderi_lock. Sinceblkcnt_tis u64, this risks torn reads on 32-bit architectures.Following the approach in
ext4_inode_blocks_set(), addREAD_ONCE()to prevent potential compiler-induced tearing.[...]
Here is the summary with links:
- [f2fs-dev,v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
https://git.kernel.org/jaegeuk/f2fs/c/5471834a96fb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html