]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ext4: lockdep: handle i_data_sem subclassing for special inodes
authorLi Chen <me@linux.beauty>
Fri, 15 May 2026 09:18:22 +0000 (17:18 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 3 Jun 2026 14:26:35 +0000 (10:26 -0400)
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 <chenl311@chinatelecom.cn>
Link: https://patch.msgid.link/20260515091829.194810-3-me@linux.beauty
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/super.c

index e337a37bb6fb6d75c21db4830466f39fd41d5ea2..115a3c94db16b40b71437243a9b13d1c894a92ec 100644 (file)
@@ -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;
index 4b69e087973112cfc706b92a303d4699c36d27f8..7c484a53c62ef5c24c84885d18eec8179f5fd8c1 100644 (file)
@@ -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;