Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

f2fs: fix false alarm of lockdep on cp_global_sem lock

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: c426d99127b1 ("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>

authored by

Chao Yu and committed by
Jaegeuk Kim
6a5e3de9 238e14eb

+14
+3
fs/f2fs/f2fs.h
··· 2042 2042 spinlock_t iostat_lat_lock; 2043 2043 struct iostat_lat_info *iostat_io_lat; 2044 2044 #endif 2045 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 2046 + struct lock_class_key cp_global_sem_key; 2047 + #endif 2045 2048 }; 2046 2049 2047 2050 /* Definitions to access f2fs_sb_info */
+11
fs/f2fs/super.c
··· 4964 4964 init_f2fs_rwsem_trace(&sbi->gc_lock, sbi, LOCK_NAME_GC_LOCK); 4965 4965 mutex_init(&sbi->writepages); 4966 4966 init_f2fs_rwsem_trace(&sbi->cp_global_sem, sbi, LOCK_NAME_CP_GLOBAL); 4967 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 4968 + lockdep_register_key(&sbi->cp_global_sem_key); 4969 + lockdep_set_class(&sbi->cp_global_sem.internal_rwsem, 4970 + &sbi->cp_global_sem_key); 4971 + #endif 4967 4972 init_f2fs_rwsem_trace(&sbi->node_write, sbi, LOCK_NAME_NODE_WRITE); 4968 4973 init_f2fs_rwsem_trace(&sbi->node_change, sbi, LOCK_NAME_NODE_CHANGE); 4969 4974 spin_lock_init(&sbi->stat_lock); ··· 5440 5435 free_sb_buf: 5441 5436 kfree(raw_super); 5442 5437 free_sbi: 5438 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 5439 + lockdep_unregister_key(&sbi->cp_global_sem_key); 5440 + #endif 5443 5441 kfree(sbi); 5444 5442 sb->s_fs_info = NULL; 5445 5443 ··· 5524 5516 /* Release block devices last, after fscrypt_destroy_keyring(). */ 5525 5517 if (sbi) { 5526 5518 destroy_device_list(sbi); 5519 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 5520 + lockdep_unregister_key(&sbi->cp_global_sem_key); 5521 + #endif 5527 5522 kfree(sbi); 5528 5523 sb->s_fs_info = NULL; 5529 5524 }