All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"tytso@mit.edu" <tytso@mit.edu>,
	"adilger.kernel@dilger.ca" <adilger.kernel@dilger.ca>
Cc: "ocfs2-devel@oss.oracle.com" <ocfs2-devel@oss.oracle.com>,
	"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
	Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Subject: Re: [PATCH 2/2] ocfs2: fix a deadlock when commit trans
Date: Mon, 24 Jan 2022 10:37:30 +0800	[thread overview]
Message-ID: <206899ac-c1af-35bb-820a-62a45d93b52a@linux.alibaba.com> (raw)
In-Reply-To: <DS7PR10MB487883FE7025BE9FD4623C39F75D9@DS7PR10MB4878.namprd10.prod.outlook.com>

Sure, will do it in v2.
So could this patch resolve your issue?

Thanks,
Joseph

On 1/23/22 1:31 PM, Gautham Ananthakrishna wrote:
> Hi,
> This deadlock was originally reported by saeed.mirzamohammadi@oracle.com  Could you please add Saeed as the reportedby.
> 
> Thanks,
> Gautham.
> 
> -----Original Message-----
> From: Joseph Qi <joseph.qi@linux.alibaba.com> 
> Sent: Friday, January 21, 2022 12:42 PM
> To: akpm@linux-foundation.org; tytso@mit.edu; adilger.kernel@dilger.ca
> Cc: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>; ocfs2-devel@oss.oracle.com; linux-ext4@vger.kernel.org
> Subject: [PATCH 2/2] ocfs2: fix a deadlock when commit trans
> 
> commit 6f1b228529ae introduces a regression which can deadlock as
> follows:
> 
> Task1:                              Task2:
> jbd2_journal_commit_transaction     ocfs2_test_bg_bit_allocatable
> spin_lock(&jh->b_state_lock)        jbd_lock_bh_journal_head
> __jbd2_journal_remove_checkpoint    spin_lock(&jh->b_state_lock)
> jbd2_journal_put_journal_head
> jbd_lock_bh_journal_head
> 
> Task1 and Task2 lock bh->b_state and jh->b_state_lock in different order, which finally result in a deadlock.
> 
> So use jbd2_journal_[grab|put]_journal_head instead in
> ocfs2_test_bg_bit_allocatable() to fix it.
> 
> Reported-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
> Fixes: 6f1b228529ae ("ocfs2: fix race between searching chunks and release journal_head from buffer_head")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/ocfs2/suballoc.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 481017e1dac5..166c8918c825 100644
> --- a/fs/ocfs2/suballoc.c
> +++ b/fs/ocfs2/suballoc.c
> @@ -1251,26 +1251,23 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,  {
>  	struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
>  	struct journal_head *jh;
> -	int ret = 1;
> +	int ret;
>  
>  	if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
>  		return 0;
>  
> -	if (!buffer_jbd(bg_bh))
> +	jh = jbd2_journal_grab_journal_head(bg_bh);
> +	if (!jh)
>  		return 1;
>  
> -	jbd_lock_bh_journal_head(bg_bh);
> -	if (buffer_jbd(bg_bh)) {
> -		jh = bh2jh(bg_bh);
> -		spin_lock(&jh->b_state_lock);
> -		bg = (struct ocfs2_group_desc *) jh->b_committed_data;
> -		if (bg)
> -			ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
> -		else
> -			ret = 1;
> -		spin_unlock(&jh->b_state_lock);
> -	}
> -	jbd_unlock_bh_journal_head(bg_bh);
> +	spin_lock(&jh->b_state_lock);
> +	bg = (struct ocfs2_group_desc *) jh->b_committed_data;
> +	if (bg)
> +		ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
> +	else
> +		ret = 1;
> +	spin_unlock(&jh->b_state_lock);
> +	jbd2_journal_put_journal_head(jh);
>  
>  	return ret;
>  }
> --
> 2.19.1.6.gb485710b

WARNING: multiple messages have this Message-ID (diff)
From: Joseph Qi via Ocfs2-devel <ocfs2-devel@oss.oracle.com>
To: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"tytso@mit.edu" <tytso@mit.edu>,
	"adilger.kernel@dilger.ca" <adilger.kernel@dilger.ca>
Cc: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>,
	"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
	"ocfs2-devel@oss.oracle.com" <ocfs2-devel@oss.oracle.com>
Subject: Re: [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit	trans
Date: Mon, 24 Jan 2022 10:37:30 +0800	[thread overview]
Message-ID: <206899ac-c1af-35bb-820a-62a45d93b52a@linux.alibaba.com> (raw)
In-Reply-To: <DS7PR10MB487883FE7025BE9FD4623C39F75D9@DS7PR10MB4878.namprd10.prod.outlook.com>

Sure, will do it in v2.
So could this patch resolve your issue?

Thanks,
Joseph

On 1/23/22 1:31 PM, Gautham Ananthakrishna wrote:
> Hi,
> This deadlock was originally reported by saeed.mirzamohammadi@oracle.com  Could you please add Saeed as the reportedby.
> 
> Thanks,
> Gautham.
> 
> -----Original Message-----
> From: Joseph Qi <joseph.qi@linux.alibaba.com> 
> Sent: Friday, January 21, 2022 12:42 PM
> To: akpm@linux-foundation.org; tytso@mit.edu; adilger.kernel@dilger.ca
> Cc: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>; ocfs2-devel@oss.oracle.com; linux-ext4@vger.kernel.org
> Subject: [PATCH 2/2] ocfs2: fix a deadlock when commit trans
> 
> commit 6f1b228529ae introduces a regression which can deadlock as
> follows:
> 
> Task1:                              Task2:
> jbd2_journal_commit_transaction     ocfs2_test_bg_bit_allocatable
> spin_lock(&jh->b_state_lock)        jbd_lock_bh_journal_head
> __jbd2_journal_remove_checkpoint    spin_lock(&jh->b_state_lock)
> jbd2_journal_put_journal_head
> jbd_lock_bh_journal_head
> 
> Task1 and Task2 lock bh->b_state and jh->b_state_lock in different order, which finally result in a deadlock.
> 
> So use jbd2_journal_[grab|put]_journal_head instead in
> ocfs2_test_bg_bit_allocatable() to fix it.
> 
> Reported-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
> Fixes: 6f1b228529ae ("ocfs2: fix race between searching chunks and release journal_head from buffer_head")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/ocfs2/suballoc.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 481017e1dac5..166c8918c825 100644
> --- a/fs/ocfs2/suballoc.c
> +++ b/fs/ocfs2/suballoc.c
> @@ -1251,26 +1251,23 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,  {
>  	struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
>  	struct journal_head *jh;
> -	int ret = 1;
> +	int ret;
>  
>  	if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
>  		return 0;
>  
> -	if (!buffer_jbd(bg_bh))
> +	jh = jbd2_journal_grab_journal_head(bg_bh);
> +	if (!jh)
>  		return 1;
>  
> -	jbd_lock_bh_journal_head(bg_bh);
> -	if (buffer_jbd(bg_bh)) {
> -		jh = bh2jh(bg_bh);
> -		spin_lock(&jh->b_state_lock);
> -		bg = (struct ocfs2_group_desc *) jh->b_committed_data;
> -		if (bg)
> -			ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
> -		else
> -			ret = 1;
> -		spin_unlock(&jh->b_state_lock);
> -	}
> -	jbd_unlock_bh_journal_head(bg_bh);
> +	spin_lock(&jh->b_state_lock);
> +	bg = (struct ocfs2_group_desc *) jh->b_committed_data;
> +	if (bg)
> +		ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
> +	else
> +		ret = 1;
> +	spin_unlock(&jh->b_state_lock);
> +	jbd2_journal_put_journal_head(jh);
>  
>  	return ret;
>  }
> --
> 2.19.1.6.gb485710b

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

  reply	other threads:[~2022-01-24  2:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21  7:12 [PATCH 0/2] ocfs2: fix a deadlock case Joseph Qi
2022-01-21  7:12 ` [Ocfs2-devel] " Joseph Qi via Ocfs2-devel
2022-01-21  7:12 ` [PATCH 1/2] jbd2: export jbd2_journal_[grab|put]_journal_head Joseph Qi
2022-01-21  7:12   ` [Ocfs2-devel] " Joseph Qi via Ocfs2-devel
2022-01-21  7:12 ` [PATCH 2/2] ocfs2: fix a deadlock when commit trans Joseph Qi
2022-01-21  7:12   ` [Ocfs2-devel] " Joseph Qi via Ocfs2-devel
2022-01-23  5:31   ` Gautham Ananthakrishna
2022-01-23  5:31     ` [Ocfs2-devel] " Gautham Ananthakrishna via Ocfs2-devel
2022-01-24  2:37     ` Joseph Qi [this message]
2022-01-24  2:37       ` Joseph Qi via Ocfs2-devel
2022-01-27 12:46       ` Gautham Ananthakrishna
2022-01-27 12:46         ` [Ocfs2-devel] " Gautham Ananthakrishna via Ocfs2-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=206899ac-c1af-35bb-820a-62a45d93b52a@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=akpm@linux-foundation.org \
    --cc=gautham.ananthakrishna@oracle.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=saeed.mirzamohammadi@oracle.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.