f2fs: initialize ino_entry_info before checkpoint load
PATCH 1/1 f2fs: initialize ino_entry_info before checkpoint load
When f2fs_get_valid_checkpoint() fails during mount (e.g. due to an invalid checkpoint CRC on a malformed image), f2fs_fill_super() takes an error path that eventually calls iput() on the root inode. This invokes f2fs_drop_inode() -> f2fs_exist_written_data(), which acquires sbi->im[]->ino_lock. However, f2fs_init_ino_entry_info() has not run yet at this point, so the spinlock is uninitialized and lockdep complains:
F2FS-fs (loop0): invalid crc value
F2FS-fs (loop0): Failed to get valid F2FS checkpoint
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use?
...
f2fs_exist_written_data+0x53/0x90 fs/f2fs/checkpoint.c:787 f2fs_drop_inode+0xda/0xbf0 fs/f2fs/super.c:1852 iput+0x651/0xe80 fs/inode.c:2009 f2fs_fill_super+0x6047/0x7850 fs/f2fs/super.c:5461
Move f2fs_init_ino_entry_info() to before f2fs_get_valid_checkpoint() so that sbi->im[] is always fully initialized before any error path can trigger iput() -> f2fs_drop_inode(). The init function only depends on raw superblock fields (BLKS_PER_SEG, F2FS_CP_PACKS, NR_CURSEG_PERSIST_TYPE, __cp_payload), which are populated well before checkpoint load, so the move is safe.
--- fs/f2fs/super.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/f2fs/super.c +7 -2
@@ -5140,6 +5140,13 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) goto free_page_array_cache; } +/* +* Initialize ino entry info early so f2fs_drop_inode -> +* f2fs_exist_written_data can safely take im->ino_lock if mount +* fails after this point and triggers iput on cleanup. +*/ +f2fs_init_ino_entry_info (sbi); + err =f2fs_get_valid_checkpoint (sbi);if (err) {f2fs_err (sbi,"Failed to get valid F2FS checkpoint" );
@@ -5184,8 +5191,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)f2fs_init_extent_cache_info (sbi); -f2fs_init_ino_entry_info (sbi); -f2fs_init_fsync_node_info (sbi);/* setup checkpoint request control and start checkpoint issue thread */
Signature · 1 line
2.43.0
Chao Yu
maintainerQuoted 19 lines · Deepanshu Kartikey
When
f2fs_get_valid_checkpoint()fails during mount (e.g. due to an invalid checkpoint CRC on a malformed image),f2fs_fill_super()takes an error path that eventually callsiput()on the root inode. This invokesf2fs_drop_inode()->f2fs_exist_written_data(), which acquires sbi->im[]->ino_lock. However,f2fs_init_ino_entry_info()has not run yet at this point, so the spinlock is uninitialized and lockdep complains:F2FS-fs (loop0): invalid crc value
F2FS-fs (loop0): Failed to get valid F2FS checkpoint
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use?
...f2fs_exist_written_data+0x53/0x90 fs/f2fs/checkpoint.c:787 f2fs_drop_inode+0xda/0xbf0 fs/f2fs/super.c:1852 iput+0x651/0xe80 fs/inode.c:2009 f2fs_fill_super+0x6047/0x7850 fs/f2fs/super.c:5461
Quoted 7 lines
Move
f2fs_init_ino_entry_info()to beforef2fs_get_valid_checkpoint()so that sbi->im[] is always fully initialized before any error path can triggeriput()->f2fs_drop_inode(). The init function only depends on raw superblock fields (BLKS_PER_SEG,F2FS_CP_PACKS,NR_CURSEG_PERSIST_TYPE,__cp_payload), which are populated well before checkpoint load, so the move is safe.
Otherwise, it looks good to me.
Thanks,
Quoted 35 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/f2fs/super.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/f2fs/super.c +7
-2@@ -5140,6 +5140,13 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) goto free_page_array_cache; } +/* +* Initialize ino entry info early so f2fs_drop_inode -> +* f2fs_exist_written_data can safely take im->ino_lock if mount +* fails after this point and triggers iput on cleanup. +*/ +f2fs_init_ino_entry_info (sbi); + err =f2fs_get_valid_checkpoint (sbi);if (err) {f2fs_err (sbi,"Failed to get valid F2FS checkpoint" );@@ -5184,8 +5191,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)f2fs_init_extent_cache_info (sbi); -f2fs_init_ino_entry_info (sbi); -f2fs_init_fsync_node_info (sbi);/* setup checkpoint request control and start checkpoint issue thread */
Quoted 8 lines · Chao Yu
Fixes xxxOtherwise, it looks good to me.
Thanks,
Thanks for the review. I have sent patch v2.
Thanks
Deepanshu Kartikey