* [PATCH] ocfs2: fix lock acquisition order in refcounttree
@ 2025-07-14 22:15 Diogo Jahchan Koike
2025-07-15 2:51 ` Tetsuo Handa
2026-04-25 21:26 ` Andrew Morton
0 siblings, 2 replies; 6+ messages in thread
From: Diogo Jahchan Koike @ 2025-07-14 22:15 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi
Cc: Diogo Jahchan Koike, syzbot+1fed2de07d8e11a3ec1b, Tetsuo Handa,
ocfs2-devel, linux-kernel
Acquiring the locks in refcounttree should follow
the ip_alloc --> ip_xattr ordering, as done by multiple
code paths in ocfs2; otherwise, we risk an ABBA deadlock
(i.e in the start transaction path).
Reported-by: syzbot+1fed2de07d8e11a3ec1b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1fed2de07d8e11a3ec1b
Tested-by: syzbot+1fed2de07d8e11a3ec1b@syzkaller.appspotmail.com
Reviewed-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Diogo Jahchan Koike <djahchankoike@gmail.com>
---
fs/ocfs2/refcounttree.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 8f732742b26e..c8467b92b64e 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -928,8 +928,8 @@ int ocfs2_try_remove_refcount_tree(struct inode *inode,
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
- down_write(&oi->ip_xattr_sem);
down_write(&oi->ip_alloc_sem);
+ down_write(&oi->ip_xattr_sem);
if (oi->ip_clusters)
goto out;
@@ -945,8 +945,8 @@ int ocfs2_try_remove_refcount_tree(struct inode *inode,
if (ret)
mlog_errno(ret);
out:
- up_write(&oi->ip_alloc_sem);
up_write(&oi->ip_xattr_sem);
+ up_write(&oi->ip_alloc_sem);
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
2025-07-14 22:15 [PATCH] ocfs2: fix lock acquisition order in refcounttree Diogo Jahchan Koike
@ 2025-07-15 2:51 ` Tetsuo Handa
2025-07-18 13:54 ` Tetsuo Handa
2026-04-25 21:26 ` Andrew Morton
1 sibling, 1 reply; 6+ messages in thread
From: Tetsuo Handa @ 2025-07-15 2:51 UTC (permalink / raw)
To: Diogo Jahchan Koike, Mark Fasheh, Joel Becker, Joseph Qi
Cc: syzbot+1fed2de07d8e11a3ec1b, ocfs2-devel, linux-kernel
On 2025/07/15 7:15, Diogo Jahchan Koike wrote:
> Acquiring the locks in refcounttree should follow
> the ip_alloc --> ip_xattr ordering, as done by multiple
> code paths in ocfs2; otherwise, we risk an ABBA deadlock
> (i.e in the start transaction path).
I noticed that ocfs2_reflink() in the same file wants similar change.
down_write(&OCFS2_I(inode)->ip_xattr_sem);
down_write(&OCFS2_I(inode)->ip_alloc_sem);
error = __ocfs2_reflink(old_dentry, old_bh,
new_orphan_inode, preserve);
up_write(&OCFS2_I(inode)->ip_alloc_sem);
up_write(&OCFS2_I(inode)->ip_xattr_sem);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
2025-07-15 2:51 ` Tetsuo Handa
@ 2025-07-18 13:54 ` Tetsuo Handa
2025-07-21 10:40 ` Tetsuo Handa
0 siblings, 1 reply; 6+ messages in thread
From: Tetsuo Handa @ 2025-07-18 13:54 UTC (permalink / raw)
To: Diogo Jahchan Koike, Mark Fasheh, Joel Becker, Joseph Qi
Cc: syzbot+1fed2de07d8e11a3ec1b, ocfs2-devel, linux-kernel
On 2025/07/15 11:51, Tetsuo Handa wrote:
> On 2025/07/15 7:15, Diogo Jahchan Koike wrote:
>> Acquiring the locks in refcounttree should follow
>> the ip_alloc --> ip_xattr ordering, as done by multiple
>> code paths in ocfs2; otherwise, we risk an ABBA deadlock
>> (i.e in the start transaction path).
>
> I noticed that ocfs2_reflink() in the same file wants similar change.
>
> down_write(&OCFS2_I(inode)->ip_xattr_sem);
> down_write(&OCFS2_I(inode)->ip_alloc_sem);
> error = __ocfs2_reflink(old_dentry, old_bh,
> new_orphan_inode, preserve);
> up_write(&OCFS2_I(inode)->ip_alloc_sem);
> up_write(&OCFS2_I(inode)->ip_xattr_sem);
>
Moreover, I noticed that e.g. ocfs2_xattr_set_handle() firstly acquires
ip_xatr_sem and then ocfs2_xattr_ibody_find() might acquire ip_alloc_sem.
Diogo, where do you see the ip_alloc --> ip_xattr ordering?
Unless we unify to either ip_alloc --> ip_xattr ordering or
ip_xattr --> ip_alloc ordering (or replace ip_xattr with ip_alloc),
this patch simply changes the location of lockdep warning?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
2025-07-18 13:54 ` Tetsuo Handa
@ 2025-07-21 10:40 ` Tetsuo Handa
0 siblings, 0 replies; 6+ messages in thread
From: Tetsuo Handa @ 2025-07-21 10:40 UTC (permalink / raw)
To: Diogo Jahchan Koike, Mark Fasheh, Joel Becker, Joseph Qi, ocfs2-devel
Cc: syzbot+1fed2de07d8e11a3ec1b, linux-kernel
On 2025/07/18 22:54, Tetsuo Handa wrote:
> On 2025/07/15 11:51, Tetsuo Handa wrote:
>> On 2025/07/15 7:15, Diogo Jahchan Koike wrote:
>>> Acquiring the locks in refcounttree should follow
>>> the ip_alloc --> ip_xattr ordering, as done by multiple
>>> code paths in ocfs2; otherwise, we risk an ABBA deadlock
>>> (i.e in the start transaction path).
>>
>> I noticed that ocfs2_reflink() in the same file wants similar change.
>>
>> down_write(&OCFS2_I(inode)->ip_xattr_sem);
>> down_write(&OCFS2_I(inode)->ip_alloc_sem);
>> error = __ocfs2_reflink(old_dentry, old_bh,
>> new_orphan_inode, preserve);
>> up_write(&OCFS2_I(inode)->ip_alloc_sem);
>> up_write(&OCFS2_I(inode)->ip_xattr_sem);
>>
>
> Moreover, I noticed that e.g. ocfs2_xattr_set_handle() firstly acquires
> ip_xatr_sem and then ocfs2_xattr_ibody_find() might acquire ip_alloc_sem.
>
> Diogo, where do you see the ip_alloc --> ip_xattr ordering?
>
> Unless we unify to either ip_alloc --> ip_xattr ordering or
> ip_xattr --> ip_alloc ordering (or replace ip_xattr with ip_alloc),
> this patch simply changes the location of lockdep warning?
>
Since I couldn't find direct ip_alloc --> ip_xattr ordering,
I tried effectively replacing ip_xattr with ip_alloc at
https://lkml.kernel.org/r/687be24a.a70a0220.693ce.0092.GAE@google.com
and got sb_internal --> ip_alloc v.s. ip_alloc --> sb_internal
ordering problem, as with other lockdep reports in ocfs2 subsystem
at https://syzkaller.appspot.com/upstream/s/ocfs2 .
In the team network driver, this kind of ordering issues has been
addressed by simplifying locking dependency at
https://lkml.kernel.org/r/20250623153147.3413631-1-sdf@fomichev.me .
ocfs2 developers, can you simplify locking dependency in ocfs2, by
killing several locks and reordering the locks?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
2025-07-14 22:15 [PATCH] ocfs2: fix lock acquisition order in refcounttree Diogo Jahchan Koike
2025-07-15 2:51 ` Tetsuo Handa
@ 2026-04-25 21:26 ` Andrew Morton
2026-04-25 22:30 ` Tetsuo Handa
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2026-04-25 21:26 UTC (permalink / raw)
To: Diogo Jahchan Koike
Cc: Mark Fasheh, Joel Becker, Joseph Qi, syzbot+1fed2de07d8e11a3ec1b,
Tetsuo Handa, ocfs2-devel, linux-kernel
On Mon, 14 Jul 2025 19:15:32 -0300 Diogo Jahchan Koike <djahchankoike@gmail.com> wrote:
> Acquiring the locks in refcounttree should follow
> the ip_alloc --> ip_xattr ordering, as done by multiple
> code paths in ocfs2; otherwise, we risk an ABBA deadlock
> (i.e in the start transaction path).
>
> Reported-by: syzbot+1fed2de07d8e11a3ec1b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=1fed2de07d8e11a3ec1b
But ocfs2_reflink() does
down_write(&OCFS2_I(inode)->ip_xattr_sem);
down_write(&OCFS2_I(inode)->ip_alloc_sem);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
2026-04-25 21:26 ` Andrew Morton
@ 2026-04-25 22:30 ` Tetsuo Handa
0 siblings, 0 replies; 6+ messages in thread
From: Tetsuo Handa @ 2026-04-25 22:30 UTC (permalink / raw)
To: Andrew Morton, Diogo Jahchan Koike, ocfs2-devel, Mark Fasheh,
Joel Becker, Joseph Qi
Cc: syzbot+1fed2de07d8e11a3ec1b, linux-kernel
On 2026/04/26 6:26, Andrew Morton wrote:
> But ocfs2_reflink() does
>
> down_write(&OCFS2_I(inode)->ip_xattr_sem);
> down_write(&OCFS2_I(inode)->ip_alloc_sem);
>
>
Yes, we know. We are waiting for response from OCFS2 people on the below message.
-------- Forwarded Message --------
Message-ID: <dee1a0fe-7846-466a-a08b-4967929b5f6e@I-love.SAKURA.ne.jp>
Date: Mon, 21 Jul 2025 19:40:58 +0900
Subject: Re: [PATCH] ocfs2: fix lock acquisition order in refcounttree
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Diogo Jahchan Koike <djahchankoike@gmail.com>, Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>, Joseph Qi <joseph.qi@linux.alibaba.com>, ocfs2-devel@lists.linux.dev
Cc: syzbot+1fed2de07d8e11a3ec1b@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org
References: <20250714221552.4853-1-djahchankoike@gmail.com> <5957f94d-2521-43d4-ba0b-7b98576167a4@I-love.SAKURA.ne.jp> <6e49d04a-4069-4cce-9f49-fd63983ae658@I-love.SAKURA.ne.jp>
In-Reply-To: <6e49d04a-4069-4cce-9f49-fd63983ae658@I-love.SAKURA.ne.jp>
On 2025/07/18 22:54, Tetsuo Handa wrote:
> On 2025/07/15 11:51, Tetsuo Handa wrote:
>> On 2025/07/15 7:15, Diogo Jahchan Koike wrote:
>>> Acquiring the locks in refcounttree should follow
>>> the ip_alloc --> ip_xattr ordering, as done by multiple
>>> code paths in ocfs2; otherwise, we risk an ABBA deadlock
>>> (i.e in the start transaction path).
>>
>> I noticed that ocfs2_reflink() in the same file wants similar change.
>>
>> down_write(&OCFS2_I(inode)->ip_xattr_sem);
>> down_write(&OCFS2_I(inode)->ip_alloc_sem);
>> error = __ocfs2_reflink(old_dentry, old_bh,
>> new_orphan_inode, preserve);
>> up_write(&OCFS2_I(inode)->ip_alloc_sem);
>> up_write(&OCFS2_I(inode)->ip_xattr_sem);
>>
>
> Moreover, I noticed that e.g. ocfs2_xattr_set_handle() firstly acquires
> ip_xatr_sem and then ocfs2_xattr_ibody_find() might acquire ip_alloc_sem.
>
> Diogo, where do you see the ip_alloc --> ip_xattr ordering?
>
> Unless we unify to either ip_alloc --> ip_xattr ordering or
> ip_xattr --> ip_alloc ordering (or replace ip_xattr with ip_alloc),
> this patch simply changes the location of lockdep warning?
>
Since I couldn't find direct ip_alloc --> ip_xattr ordering,
I tried effectively replacing ip_xattr with ip_alloc at
https://lkml.kernel.org/r/687be24a.a70a0220.693ce.0092.GAE@google.com
and got sb_internal --> ip_alloc v.s. ip_alloc --> sb_internal
ordering problem, as with other lockdep reports in ocfs2 subsystem
at https://syzkaller.appspot.com/upstream/s/ocfs2 .
In the team network driver, this kind of ordering issues has been
addressed by simplifying locking dependency at
https://lkml.kernel.org/r/20250623153147.3413631-1-sdf@fomichev.me .
ocfs2 developers, can you simplify locking dependency in ocfs2, by
killing several locks and reordering the locks?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-25 22:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-14 22:15 [PATCH] ocfs2: fix lock acquisition order in refcounttree Diogo Jahchan Koike
2025-07-15 2:51 ` Tetsuo Handa
2025-07-18 13:54 ` Tetsuo Handa
2025-07-21 10:40 ` Tetsuo Handa
2026-04-25 21:26 ` Andrew Morton
2026-04-25 22:30 ` Tetsuo Handa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®