]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ocfs2: kill osb->system_file_mutex lock
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Mon, 18 May 2026 04:23:40 +0000 (13:23 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:24:57 +0000 (21:24 -0700)
Commit 43b10a20372d ("ocfs2: avoid system inode ref confusion by adding
mutex lock") tried to avoid a refcount leak caused by allowing multiple
threads to call igrab(inode).  But addition of osb->system_file_mutex made
locking dependency complicated and is causing lockdep to warn about
possibility of AB-BA deadlock.

Since _ocfs2_get_system_file_inode() returns the same inode for the same
input arguments, we don't need to serialize
_ocfs2_get_system_file_inode().  What we need to make sure is that
igrab(inode) is called for only once().  Therefore, replace
osb->system_file_mutex with cmpxchg()-based locking.

Link: https://lore.kernel.org/fea8d1fd-afb0-4302-a560-c202e2ef7afd@I-love.SAKURA.ne.jp
Fixes: 43b10a20372d ("ocfs2: avoid system inode ref confusion by adding mutex lock")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Heming Zhao <heming.zhao@suse.com>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/ocfs2.h
fs/ocfs2/super.c
fs/ocfs2/sysfile.c

index 7b50e03dfa664a2b69eadc7e5230bc38963d0a85..62cad6522c7a31b7ab60a2e07ecef5b0aa96239d 100644 (file)
@@ -494,8 +494,6 @@ struct ocfs2_super
        struct rb_root  osb_rf_lock_tree;
        struct ocfs2_refcount_tree *osb_ref_tree_lru;
 
-       struct mutex system_file_mutex;
-
        /*
         * OCFS2 needs to schedule several different types of work which
         * require cluster locking, disk I/O, recovery waits, etc. Since these
index b875f01c97564def7a198e5ed6bd25a096bee70c..6dd45c2153f88eb75153b2c15e24277a3fa4391d 100644 (file)
@@ -1997,8 +1997,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
        spin_lock_init(&osb->osb_xattr_lock);
        ocfs2_init_steal_slots(osb);
 
-       mutex_init(&osb->system_file_mutex);
-
        atomic_set(&osb->alloc_stats.moves, 0);
        atomic_set(&osb->alloc_stats.local_data, 0);
        atomic_set(&osb->alloc_stats.bitmap_data, 0);
index d53a6cc866bef627f4ca5a986eb326ea9a7c7f7c..67e492f4b828b64396a0184efa9ceca406fe95c6 100644 (file)
@@ -98,11 +98,9 @@ struct inode *ocfs2_get_system_file_inode(struct ocfs2_super *osb,
        } else
                arr = get_local_system_inode(osb, type, slot);
 
-       mutex_lock(&osb->system_file_mutex);
        if (arr && ((inode = *arr) != NULL)) {
                /* get a ref in addition to the array ref */
                inode = igrab(inode);
-               mutex_unlock(&osb->system_file_mutex);
                BUG_ON(!inode);
 
                return inode;
@@ -112,11 +110,10 @@ struct inode *ocfs2_get_system_file_inode(struct ocfs2_super *osb,
        inode = _ocfs2_get_system_file_inode(osb, type, slot);
 
        /* add one more if putting into array for first time */
-       if (arr && inode) {
-               *arr = igrab(inode);
-               BUG_ON(!*arr);
+       if (inode && arr && !*arr && !cmpxchg(&(*arr), NULL, inode)) {
+               inode = igrab(inode);
+               BUG_ON(!inode);
        }
-       mutex_unlock(&osb->system_file_mutex);
        return inode;
 }