Skip to contentSkip to conversation

f2fs: fix to access i_size w/ i_size_read()

PATCH Applied Chao Yu 3 participants 5 messages Oct 29, 2025 – Nov 11, 2025

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix to access i_size w/ i_size_read()

It recommends to use i_size_{read,write}() to access and update i_size, otherwise, we may get wrong tearing value due to high 32-bits value and low 32-bits value of i_size field are not updated atomically in 32-bits archicture machine.

---
 include/trace/events/f2fs.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +4 -4
index edbbd869078f..e1fae78d64a5 100644
@@ -204,7 +204,7 @@ DECLARE_EVENT_CLASS(f2fs__inode,
 		__entry->pino	= F2FS_I(inode)->i_pino;
 		__entry->mode	= inode->i_mode;
 		__entry->nlink	= inode->i_nlink;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
 		__entry->blocks	= inode->i_blocks;
 		__entry->advise	= F2FS_I(inode)->i_advise;
 	),
@@ -353,7 +353,7 @@ TRACE_EVENT(f2fs_unlink_enter,
 	TP_fast_assign(
 		__entry->dev	= dir->i_sb->s_dev;
 		__entry->ino	= dir->i_ino;
-		__entry->size	= dir->i_size;
+		__entry->size	= i_size_read(dir);
 		__entry->blocks	= dir->i_blocks;
 		__assign_str(name);
 	),
@@ -433,7 +433,7 @@ DECLARE_EVENT_CLASS(f2fs__truncate_op,
 	TP_fast_assign(
 		__entry->dev	= inode->i_sb->s_dev;
 		__entry->ino	= inode->i_ino;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
 		__entry->blocks	= inode->i_blocks;
 		__entry->from	= from;
 	),
@@ -1006,7 +1006,7 @@ TRACE_EVENT(f2fs_fallocate,
 		__entry->mode	= mode;
 		__entry->offset	= offset;
 		__entry->len	= len;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
 		__entry->blocks = inode->i_blocks;
 		__entry->ret	= ret;
 	),
Signature · 1 line
2.49.0
#1 lore raw
Quoted 42 lines · On 10/29/25 14:31, Chao Yu via Linux-f2fs-devel wrote:

It recommends to use i_size_{read,write}() to access and update i_size, otherwise, we may get wrong tearing value due to high 32-bits value and low 32-bits value of i_size field are not updated atomically in 32-bits archicture machine.

---
  include/trace/events/f2fs.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +3 -3
index edbbd869078f..e1fae78d64a5 100644
@@ -204,7 +204,7 @@ DECLARE_EVENT_CLASS(f2fs__inode,
  		__entry->pino	= F2FS_I(inode)->i_pino;
  		__entry->mode	= inode->i_mode;
  		__entry->nlink	= inode->i_nlink;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
  		__entry->blocks	= inode->i_blocks;
  		__entry->advise	= F2FS_I(inode)->i_advise;
  	),
@@ -353,7 +353,7 @@ TRACE_EVENT(f2fs_unlink_enter,
  	TP_fast_assign(
  		__entry->dev	= dir->i_sb->s_dev;
  		__entry->ino	= dir->i_ino;
-		__entry->size	= dir->i_size;
+		__entry->size	= i_size_read(dir);
  		__entry->blocks	= dir->i_blocks;
  		__assign_str(name);
  	),
@@ -433,7 +433,7 @@ DECLARE_EVENT_CLASS(f2fs__truncate_op,
  	TP_fast_assign(
  		__entry->dev	= inode->i_sb->s_dev;
  		__entry->ino	= inode->i_ino;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
  		__entry->blocks	= inode->i_blocks;
  		__entry->from	= from;
  	),

include/trace/events/f2fs.h TRACE_EVENT(f2fs_fallocate, · line 1012

Quoted 8 lines
include/trace/events/f2fs.h +1 -1
@@ -1006,7 +1006,7 @@ TRACE_EVENT(f2fs_fallocate,
  		__entry->mode	= mode;
  		__entry->offset	= offset;
  		__entry->len	= len;
-		__entry->size	= inode->i_size;
+		__entry->size	= i_size_read(inode);
  		__entry->blocks = inode->i_blocks;
  		__entry->ret	= ret;
  	),

inode->i_size usage in fs/f2fs/ also needs to be updated. For example in f2fs_need_verity(), which may not protected by inode_lock.

Yongpeng,

author maintainer
#2 lore raw
Quoted 45 lines · Yongpeng Yang
Quoted 44 lines · On 10/29/25 14:31, Chao Yu via Linux-f2fs-devel wrote:

It recommends to use i_size_{read,write}() to access and update i_size, otherwise, we may get wrong tearing value due to high 32-bits value and low 32-bits value of i_size field are not updated atomically in 32-bits archicture machine.

---
  include/trace/events/f2fs.h | 8 ++++----

  1 file changed, 4 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +1 -1
index edbbd869078f..e1fae78d64a5 100644
@@ -204,7 +204,7 @@ DECLARE_EVENT_CLASS(f2fs__inode,
           __entry->pino    = F2FS_I(inode)->i_pino;
           __entry->mode    = inode->i_mode;
           __entry->nlink    = inode->i_nlink;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
           __entry->blocks    = inode->i_blocks;
           __entry->advise    = F2FS_I(inode)->i_advise;
       ),
@@ -353,7 +353,7 @@ TRACE_EVENT(f2fs_unlink_enter,

      TP_fast_assign(
          __entry->dev    = dir->i_sb->s_dev;
          __entry->ino    = dir->i_ino;
-        __entry->size    = dir->i_size;
+        __entry->size    = i_size_read(dir);
          __entry->blocks    = dir->i_blocks;
          __assign_str(name);
      ),

include/trace/events/f2fs.h +0 -0
@@ -433,7 +433,7 @@ DECLARE_EVENT_CLASS(f2fs__truncate_op,

      TP_fast_assign(
          __entry->dev    = inode->i_sb->s_dev;
          __entry->ino    = inode->i_ino;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
          __entry->blocks    = inode->i_blocks;
          __entry->from    = from;
      ),

include/trace/events/f2fs.h +0 -0
@@ -1006,7 +1006,7 @@ TRACE_EVENT(f2fs_fallocate,
           __entry->mode    = mode;
           __entry->offset    = offset;
Quoted 8 lines

include/trace/events/f2fs.h TRACE_EVENT(f2fs_fallocate, · line 1012

Quoted 6 lines
include/trace/events/f2fs.h +1 -1
           __entry->len    = len;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
           __entry->blocks = inode->i_blocks;
           __entry->ret    = ret;
       ),

inode->i_size usage in fs/f2fs/ also needs to be updated. For example in f2fs_need_verity(), which may not protected by inode_lock.

Accessing i_size directly in f2fs_need_verity() should be fine? Because fsverity actived inode should be readonly.

Do you see any other cases which are not covered by inode_lock()?

Thanks,

Quoted 2 lines

Yongpeng,

#3 lore raw
Quoted 55 lines · On 10/29/25 17:41, Chao Yu via Linux-f2fs-devel wrote:
Quoted 45 lines · Yongpeng Yang
Quoted 44 lines · On 10/29/25 14:31, Chao Yu via Linux-f2fs-devel wrote:

It recommends to use i_size_{read,write}() to access and update i_size, otherwise, we may get wrong tearing value due to high 32-bits value and low 32-bits value of i_size field are not updated atomically in 32-bits archicture machine.

---
   include/trace/events/f2fs.h | 8 ++++----
   1 file changed, 4 insertions(+), 4 deletions(-)
include/trace/events/f2fs.h +3 -3
index edbbd869078f..e1fae78d64a5 100644
@@ -204,7 +204,7 @@ DECLARE_EVENT_CLASS(f2fs__inode,
           __entry->pino    = F2FS_I(inode)->i_pino;
           __entry->mode    = inode->i_mode;
           __entry->nlink    = inode->i_nlink;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
           __entry->blocks    = inode->i_blocks;
           __entry->advise    = F2FS_I(inode)->i_advise;
       ),
@@ -353,7 +353,7 @@ TRACE_EVENT(f2fs_unlink_enter,
       TP_fast_assign(
           __entry->dev    = dir->i_sb->s_dev;
           __entry->ino    = dir->i_ino;
-        __entry->size    = dir->i_size;
+        __entry->size    = i_size_read(dir);
           __entry->blocks    = dir->i_blocks;
           __assign_str(name);
       ),
@@ -433,7 +433,7 @@ DECLARE_EVENT_CLASS(f2fs__truncate_op,
       TP_fast_assign(
           __entry->dev    = inode->i_sb->s_dev;
           __entry->ino    = inode->i_ino;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
           __entry->blocks    = inode->i_blocks;
           __entry->from    = from;
       ),
@@ -1006,7 +1006,7 @@ TRACE_EVENT(f2fs_fallocate,
           __entry->mode    = mode;
           __entry->offset    = offset;
Quoted 8 lines

include/trace/events/f2fs.h TRACE_EVENT(f2fs_fallocate, · line 1012

Quoted 6 lines
include/trace/events/f2fs.h +1 -1
           __entry->len    = len;
-        __entry->size    = inode->i_size;
+        __entry->size    = i_size_read(inode);
           __entry->blocks = inode->i_blocks;
           __entry->ret    = ret;
       ),

inode->i_size usage in fs/f2fs/ also needs to be updated. For example in f2fs_need_verity(), which may not protected by inode_lock.

Quoted 2 lines

Accessing i_size directly in f2fs_need_verity() should be fine? Because fsverity actived inode should be readonly.

Yes, it's fine.>

Quoted 1 line

Do you see any other cases which are not covered by inode_lock()?

I checked again, no other cases.:)>

Quoted 11 lines

Thanks,

Quoted 2 lines

Yongpeng,

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

#4 lore raw
In reply to Chao Yu
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 8 lines · On Wed, 29 Oct 2025 14:31:04 +0800 you wrote:

It recommends to use i_size_{read,write}() to access and update i_size, otherwise, we may get wrong tearing value due to high 32-bits value and low 32-bits value of i_size field are not updated atomically in 32-bits archicture machine.

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: fix to access i_size w/ i_size_read()

    https://git.kernel.org/jaegeuk/f2fs/c/1797093bfc96

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html