public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
@ 2026-03-18  7:32 Cen Zhang
  2026-03-19 11:00 ` Chao Yu
  2026-03-24 17:32 ` [f2fs-dev] " patchwork-bot+f2fs
  0 siblings, 2 replies; 3+ messages in thread
From: Cen Zhang @ 2026-03-18  7:32 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, baijiaju1990, Cen Zhang, stable

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.

Fixes: 19f99cee206c ("f2fs: add core inode operations")
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
 fs/f2fs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 078874db918c..73b913dbe02a 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -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))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
  2026-03-18  7:32 [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode() Cen Zhang
@ 2026-03-19 11:00 ` Chao Yu
  2026-03-24 17:32 ` [f2fs-dev] " patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2026-03-19 11:00 UTC (permalink / raw)
  To: Cen Zhang, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, baijiaju1990, stable

On 2026/3/18 15:32, Cen Zhang wrote:
> 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.
> 
> Fixes: 19f99cee206c ("f2fs: add core inode operations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
  2026-03-18  7:32 [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode() Cen Zhang
  2026-03-19 11:00 ` Chao Yu
@ 2026-03-24 17:32 ` patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2026-03-24 17:32 UTC (permalink / raw)
  To: Cen Zhang
  Cc: jaegeuk, chao, baijiaju1990, linux-kernel, stable,
	linux-f2fs-devel

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Wed, 18 Mar 2026 15:32:53 +0800 you wrote:
> 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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-24 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18  7:32 [PATCH v2] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode() Cen Zhang
2026-03-19 11:00 ` Chao Yu
2026-03-24 17:32 ` [f2fs-dev] " patchwork-bot+f2fs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox