* [PATCH v4] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
@ 2025-07-08 2:06 Ivan Pravdin
2025-07-08 2:13 ` Joseph Qi
0 siblings, 1 reply; 2+ messages in thread
From: Ivan Pravdin @ 2025-07-08 2:06 UTC (permalink / raw)
To: mark, jlbec, joseph.qi, ocfs2-devel, linux-kernel
Cc: Ivan Pravdin, syzbot+6bf948e47f9bac7aacfa
In ocfs2_move_extent(), tl_inode is currently locked after the global
bitmap inode. However, in ocfs2_flush_truncate_log(), the lock order
is reversed: tl_inode is locked first, followed by the global bitmap
inode.
This creates a classic ABBA deadlock scenario if two threads attempt
these operations concurrently and acquire the locks in different orders.
To prevent this, move the tl_inode locking earlier in
ocfs2_move_extent(), so that it always precedes the global bitmap
inode lock.
No functional changes beyond lock ordering.
Reported-by: syzbot+6bf948e47f9bac7aacfa@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/67d5645c.050a0220.1dc86f.0004.GAE@google.com/
Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
---
v1 -> v2: Fixed unlocking order in ocfs2_move_extent.
v2 -> v3: Added missing out_unlock_tl_inode and renamed out_unlock_gb_mutex to
out_unlock_gb_inode and out_unlock_gb_inode to out_unlock.
v3 -> v4: Rearranged gb_inode cleanup.
fs/ocfs2/move_extents.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
index 369c7d27befd..cbe2f8ed8897 100644
--- a/fs/ocfs2/move_extents.c
+++ b/fs/ocfs2/move_extents.c
@@ -617,6 +617,8 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
*/
credits += OCFS2_INODE_UPDATE_CREDITS + 1;
+ inode_lock(tl_inode);
+
/*
* ocfs2_move_extent() didn't reserve any clusters in lock_allocators()
* logic, while we still need to lock the global_bitmap.
@@ -626,7 +628,7 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
if (!gb_inode) {
mlog(ML_ERROR, "unable to get global_bitmap inode\n");
ret = -EIO;
- goto out;
+ goto out_unlock_tl_inode;
}
inode_lock(gb_inode);
@@ -634,16 +636,14 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
ret = ocfs2_inode_lock(gb_inode, &gb_bh, 1);
if (ret) {
mlog_errno(ret);
- goto out_unlock_gb_mutex;
+ goto out_unlock_gb_inode;
}
- inode_lock(tl_inode);
-
handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
mlog_errno(ret);
- goto out_unlock_tl_inode;
+ goto out_unlock;
}
new_phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, *new_phys_cpos);
@@ -703,15 +703,14 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
out_commit:
ocfs2_commit_trans(osb, handle);
brelse(gd_bh);
-
-out_unlock_tl_inode:
- inode_unlock(tl_inode);
-
+out_unlock:
ocfs2_inode_unlock(gb_inode, 1);
-out_unlock_gb_mutex:
+out_unlock_gb_inode:
inode_unlock(gb_inode);
brelse(gb_bh);
iput(gb_inode);
+out_unlock_tl_inode:
+ inode_unlock(tl_inode);
out:
if (context->meta_ac) {
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
2025-07-08 2:06 [PATCH v4] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock Ivan Pravdin
@ 2025-07-08 2:13 ` Joseph Qi
0 siblings, 0 replies; 2+ messages in thread
From: Joseph Qi @ 2025-07-08 2:13 UTC (permalink / raw)
To: Ivan Pravdin, mark, jlbec, ocfs2-devel, linux-kernel, akpm
Cc: syzbot+6bf948e47f9bac7aacfa
On 2025/7/8 10:06, Ivan Pravdin wrote:
> In ocfs2_move_extent(), tl_inode is currently locked after the global
> bitmap inode. However, in ocfs2_flush_truncate_log(), the lock order
> is reversed: tl_inode is locked first, followed by the global bitmap
> inode.
>
> This creates a classic ABBA deadlock scenario if two threads attempt
> these operations concurrently and acquire the locks in different orders.
>
> To prevent this, move the tl_inode locking earlier in
> ocfs2_move_extent(), so that it always precedes the global bitmap
> inode lock.
>
> No functional changes beyond lock ordering.
>
> Reported-by: syzbot+6bf948e47f9bac7aacfa@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/67d5645c.050a0220.1dc86f.0004.GAE@google.com/
> Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
Looks fine.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> v1 -> v2: Fixed unlocking order in ocfs2_move_extent.
> v2 -> v3: Added missing out_unlock_tl_inode and renamed out_unlock_gb_mutex to
> out_unlock_gb_inode and out_unlock_gb_inode to out_unlock.
> v3 -> v4: Rearranged gb_inode cleanup.
>
> fs/ocfs2/move_extents.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
> index 369c7d27befd..cbe2f8ed8897 100644
> --- a/fs/ocfs2/move_extents.c
> +++ b/fs/ocfs2/move_extents.c
> @@ -617,6 +617,8 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
> */
> credits += OCFS2_INODE_UPDATE_CREDITS + 1;
>
> + inode_lock(tl_inode);
> +
> /*
> * ocfs2_move_extent() didn't reserve any clusters in lock_allocators()
> * logic, while we still need to lock the global_bitmap.
> @@ -626,7 +628,7 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
> if (!gb_inode) {
> mlog(ML_ERROR, "unable to get global_bitmap inode\n");
> ret = -EIO;
> - goto out;
> + goto out_unlock_tl_inode;
> }
>
> inode_lock(gb_inode);
> @@ -634,16 +636,14 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
> ret = ocfs2_inode_lock(gb_inode, &gb_bh, 1);
> if (ret) {
> mlog_errno(ret);
> - goto out_unlock_gb_mutex;
> + goto out_unlock_gb_inode;
> }
>
> - inode_lock(tl_inode);
> -
> handle = ocfs2_start_trans(osb, credits);
> if (IS_ERR(handle)) {
> ret = PTR_ERR(handle);
> mlog_errno(ret);
> - goto out_unlock_tl_inode;
> + goto out_unlock;
> }
>
> new_phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, *new_phys_cpos);
> @@ -703,15 +703,14 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
> out_commit:
> ocfs2_commit_trans(osb, handle);
> brelse(gd_bh);
> -
> -out_unlock_tl_inode:
> - inode_unlock(tl_inode);
> -
> +out_unlock:
> ocfs2_inode_unlock(gb_inode, 1);
> -out_unlock_gb_mutex:
> +out_unlock_gb_inode:
> inode_unlock(gb_inode);
> brelse(gb_bh);
> iput(gb_inode);
> +out_unlock_tl_inode:
> + inode_unlock(tl_inode);
>
> out:
> if (context->meta_ac) {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-08 2:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08 2:06 [PATCH v4] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock Ivan Pravdin
2025-07-08 2:13 ` Joseph Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).