From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Cen Zhang <zzzccc427@gmail.com>, jaegeuk@kernel.org
Cc: gality369@gmail.com, zhenghaoran154@gmail.com,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, baijiaju1990@gmail.com,
ziyuzhang201@gmail.com, r33s3n6@gmail.com,
hanguidong02@gmail.com
Subject: Re: [f2fs-dev] [PATCH] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
Date: Wed, 18 Mar 2026 13:56:42 +0800 [thread overview]
Message-ID: <e4c34148-e667-4e36-a1cf-57aaada22dd9@kernel.org> (raw)
In-Reply-To: <20260317114225.3017089-1-zzzccc427@gmail.com>
On 2026/3/17 19:42, 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.
>
Need a Fixes line and Cc stable@kernel.org?
Otherwise, it looks good to me.
Thanks,
> 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))
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: Cen Zhang <zzzccc427@gmail.com>, jaegeuk@kernel.org
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
r33s3n6@gmail.com, gality369@gmail.com, zhenghaoran154@gmail.com,
hanguidong02@gmail.com, ziyuzhang201@gmail.com
Subject: Re: [PATCH] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()
Date: Wed, 18 Mar 2026 13:56:42 +0800 [thread overview]
Message-ID: <e4c34148-e667-4e36-a1cf-57aaada22dd9@kernel.org> (raw)
In-Reply-To: <20260317114225.3017089-1-zzzccc427@gmail.com>
On 2026/3/17 19:42, 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.
>
Need a Fixes line and Cc stable@kernel.org?
Otherwise, it looks good to me.
Thanks,
> 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))
next prev parent reply other threads:[~2026-03-18 5:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 11:42 [f2fs-dev] [PATCH] f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode() Cen Zhang
2026-03-17 11:42 ` Cen Zhang
2026-03-18 5:56 ` Chao Yu via Linux-f2fs-devel [this message]
2026-03-18 5:56 ` Chao Yu
2026-03-18 7:50 ` [f2fs-dev] " Cen Zhang
2026-03-18 7:50 ` Cen Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e4c34148-e667-4e36-a1cf-57aaada22dd9@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=baijiaju1990@gmail.com \
--cc=chao@kernel.org \
--cc=gality369@gmail.com \
--cc=hanguidong02@gmail.com \
--cc=jaegeuk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=r33s3n6@gmail.com \
--cc=zhenghaoran154@gmail.com \
--cc=ziyuzhang201@gmail.com \
--cc=zzzccc427@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.