From: Li Chen Date: Fri, 15 May 2026 09:18:22 +0000 (+0800) Subject: ext4: lockdep: handle i_data_sem subclassing for special inodes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f473f971382d73a58e386afa7efdaac294b89f0;p=thirdparty%2Fkernel%2Flinux.git ext4: lockdep: handle i_data_sem subclassing for special inodes Fast commit can hold s_fc_lock while writing journal blocks. Mapping the journal inode can take its i_data_sem. Normal inode update paths can take a data inode i_data_sem and then s_fc_lock, which makes lockdep report a circular dependency. lockdep treats all i_data_sem instances as one lock class and cannot distinguish the journal inode i_data_sem from a regular inode i_data_sem. The journal inode is not tracked by fast commit and no FC waiters ever depend on it, so this is not a real ABBA deadlock. Assign the journal inode a dedicated i_data_sem lockdep subclass to avoid the false positive. Inode cache objects can be recycled, so also reset i_data_sem to I_DATA_SEM_NORMAL when allocating an ext4 inode. Otherwise a new inode may inherit an old subclass (journal/quota/ea) and trigger lockdep warnings. Signed-off-by: Li Chen Link: https://patch.msgid.link/20260515091829.194810-3-me@linux.beauty Signed-off-by: Theodore Ts'o --- diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index e337a37bb6fb6..115a3c94db16b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1015,12 +1015,14 @@ do { \ * than the first * I_DATA_SEM_QUOTA - Used for quota inodes only * I_DATA_SEM_EA - Used for ea_inodes only + * I_DATA_SEM_JOURNAL - Used for journal inode only */ enum { I_DATA_SEM_NORMAL = 0, I_DATA_SEM_OTHER, I_DATA_SEM_QUOTA, - I_DATA_SEM_EA + I_DATA_SEM_EA, + I_DATA_SEM_JOURNAL }; struct ext4_fc_inode_snap; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 4b69e08797311..7c484a53c62ef 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1431,6 +1431,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ext4_fc_init_inode(&ei->vfs_inode); spin_lock_init(&ei->i_fc_lock); mmb_init(&ei->i_metadata_bhs, &ei->vfs_inode.i_data); +#ifdef CONFIG_LOCKDEP + lockdep_set_subclass(&ei->i_data_sem, I_DATA_SEM_NORMAL); +#endif return &ei->vfs_inode; } @@ -5910,6 +5913,11 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb, return ERR_PTR(-EFSCORRUPTED); } +#ifdef CONFIG_LOCKDEP + lockdep_set_subclass(&EXT4_I(journal_inode)->i_data_sem, + I_DATA_SEM_JOURNAL); +#endif + ext4_debug("Journal inode found at %p: %lld bytes\n", journal_inode, journal_inode->i_size); return journal_inode;