Skip to contentSkip to conversation

ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock

PATCH Superseded Ivan Pravdin 2 participants 3 messages Jul 5, 2025 – Jul 7, 2025 OCFS2

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock

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.

---
 fs/ocfs2/move_extents.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/move_extents.c +2 -2
index 369c7d27befd..ab460cb2c9c8 100644
@@ -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.
@@ -637,8 +639,6 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
 		goto out_unlock_gb_mutex;
 	}
 
-	inode_lock(tl_inode);
-
 	handle = ocfs2_start_trans(osb, credits);
 	if (IS_ERR(handle)) {
 		ret = PTR_ERR(handle);
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 5 lines · Ivan Pravdin

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.

It's indeed buggy here.

Quoted 21 lines

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.

---
 fs/ocfs2/move_extents.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/move_extents.c +0 -0
index 369c7d27befd..ab460cb2c9c8 100644

fs/ocfs2/move_extents.c static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, · line 621

Quoted 5 lines
fs/ocfs2/move_extents.c +2 -0
@@ -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);
+

The following out_unlock should do the corresponding order changes.

Thanks,
Joseph

Quoted 12 lines
fs/ocfs2/move_extents.c +0 -2
 	/*
 	 * ocfs2_move_extent() didn't reserve any clusters in lock_allocators()
 	 * logic, while we still need to lock the global_bitmap.
@@ -637,8 +639,6 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
 		goto out_unlock_gb_mutex;
 	}
 
-	inode_lock(tl_inode);
-
 	handle = ocfs2_start_trans(osb, credits);
 	if (IS_ERR(handle)) {
 		ret = PTR_ERR(handle);
#2 lore raw
Quoted 5 lines · Joseph Qi

fs/ocfs2/move_extents.c static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, · line 621

Quoted 3 lines
fs/ocfs2/move_extents.c +2 -0
+	inode_lock(tl_inode);
+

The following out_unlock should do the corresponding order changes.

Will fix it in v2, thank you.

Quoted 11 lines

Thanks,
Joseph

Quoted 7 lines
fs/ocfs2/move_extents.c +0 -0
 	/*
 	 * ocfs2_move_extent() didn't reserve any clusters in lock_allocators()
 	 * logic, while we still need to lock the global_bitmap.
@@ -637,8 +639,6 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
 		goto out_unlock_gb_mutex;
 	}
 
Quoted 6 lines

fs/ocfs2/move_extents.c static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, · line 644

Quoted 5 lines
fs/ocfs2/move_extents.c +0 -2
-	inode_lock(tl_inode);
-
 	handle = ocfs2_start_trans(osb, credits);
 	if (IS_ERR(handle)) {
 		ret = PTR_ERR(handle);

Ivan Pravdin