mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
@ 2025-07-05 17:53 Ivan Pravdin
  2025-07-07  1:32 ` Joseph Qi
  0 siblings, 1 reply; 3+ messages in thread
From: Ivan Pravdin @ 2025-07-05 17:53 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>
---
 fs/ocfs2/move_extents.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
index 369c7d27befd..ab460cb2c9c8 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.
@@ -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.45.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
  2025-07-05 17:53 [PATCH] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock Ivan Pravdin
@ 2025-07-07  1:32 ` Joseph Qi
  2025-07-07  3:11   ` Ivan Pravdin
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2025-07-07  1:32 UTC (permalink / raw)
  To: Ivan Pravdin, mark, jlbec, ocfs2-devel, linux-kernel
  Cc: syzbot+6bf948e47f9bac7aacfa



On 2025/7/6 01:53, 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.
> 
It's indeed buggy here.

> 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>
> ---
>  fs/ocfs2/move_extents.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
> index 369c7d27befd..ab460cb2c9c8 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);
> +

The following out_unlock should do the corresponding order changes.

Thanks,
Joseph

>  	/*
>  	 * 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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
  2025-07-07  1:32 ` Joseph Qi
@ 2025-07-07  3:11   ` Ivan Pravdin
  0 siblings, 0 replies; 3+ messages in thread
From: Ivan Pravdin @ 2025-07-07  3:11 UTC (permalink / raw)
  To: Joseph Qi, mark, jlbec, ocfs2-devel, linux-kernel
  Cc: syzbot+6bf948e47f9bac7aacfa

On Mon, Jul 07, 2025 at 09:32:52AM GMT, Joseph Qi wrote:
> >  
> > +	inode_lock(tl_inode);
> > +
> 
> The following out_unlock should do the corresponding order changes.

Will fix it in v2, thank you.

> 
> Thanks,
> Joseph
> 
> >  	/*
> >  	 * 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);
> 
	Ivan Pravdin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-07  3:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-05 17:53 [PATCH] ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock Ivan Pravdin
2025-07-07  1:32 ` Joseph Qi
2025-07-07  3:11   ` Ivan Pravdin

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®