Skip to content

Commit fac9cfa

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix false alarm of lockdep on cp_global_sem lock
[ Upstream commit 6a5e3de ] lockdep reported a potential deadlock: a) TCMU device removal context: - call del_gendisk() to get q->q_usage_counter - call start_flush_work() to get work_completion of wb->dwork b) f2fs writeback context: - in wb_workfn(), which holds work_completion of wb->dwork - call f2fs_balance_fs() to get sbi->gc_lock c) f2fs vfs_write context: - call f2fs_gc() to get sbi->gc_lock - call f2fs_write_checkpoint() to get sbi->cp_global_sem d) f2fs mount context: - call recover_fsync_data() to get sbi->cp_global_sem - call f2fs_check_and_fix_write_pointer() to call blkdev_report_zones() that goes down to blk_mq_alloc_request and get q->q_usage_counter Original callstack is in Closes tag. However, I think this is a false alarm due to before mount returns successfully (context d), we can not access file therein via vfs_write (context c). Let's introduce per-sb cp_global_sem_key, and assign the key for cp_global_sem, so that lockdep can recognize cp_global_sem from different super block correctly. A lot of work are done by Shin'ichiro Kawasaki, thanks a lot for the work. Fixes: c426d99 ("f2fs: Check write pointer consistency of open zones") Cc: stable@kernel.org Reported-and-tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Closes: https://lore.kernel.org/linux-f2fs-devel/20260218125237.3340441-1-shinichiro.kawasaki@wdc.com Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> [ adapted context to use plain `init_f2fs_rwsem` instead of mainline's `init_f2fs_rwsem_trace` macro ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a4a0340 commit fac9cfa

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

fs/f2fs/f2fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,9 @@ struct f2fs_sb_info {
19671967
spinlock_t iostat_lat_lock;
19681968
struct iostat_lat_info *iostat_io_lat;
19691969
#endif
1970+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
1971+
struct lock_class_key cp_global_sem_key;
1972+
#endif
19701973
};
19711974

19721975
/* Definitions to access f2fs_sb_info */

fs/f2fs/super.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,6 +4889,11 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
48894889
init_f2fs_rwsem(&sbi->gc_lock);
48904890
mutex_init(&sbi->writepages);
48914891
init_f2fs_rwsem(&sbi->cp_global_sem);
4892+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
4893+
lockdep_register_key(&sbi->cp_global_sem_key);
4894+
lockdep_set_class(&sbi->cp_global_sem.internal_rwsem,
4895+
&sbi->cp_global_sem_key);
4896+
#endif
48924897
init_f2fs_rwsem(&sbi->node_write);
48934898
init_f2fs_rwsem(&sbi->node_change);
48944899
spin_lock_init(&sbi->stat_lock);
@@ -5360,6 +5365,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
53605365
free_sb_buf:
53615366
kfree(raw_super);
53625367
free_sbi:
5368+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
5369+
lockdep_unregister_key(&sbi->cp_global_sem_key);
5370+
#endif
53635371
kfree(sbi);
53645372
sb->s_fs_info = NULL;
53655373

@@ -5441,6 +5449,9 @@ static void kill_f2fs_super(struct super_block *sb)
54415449
/* Release block devices last, after fscrypt_destroy_keyring(). */
54425450
if (sbi) {
54435451
destroy_device_list(sbi);
5452+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
5453+
lockdep_unregister_key(&sbi->cp_global_sem_key);
5454+
#endif
54445455
kfree(sbi);
54455456
sb->s_fs_info = NULL;
54465457
}

0 commit comments

Comments
 (0)