* [Ocfs2-devel] [PATCH 0/2] ocfs2: fix a deadlock case
@ 2022-01-21 7:12 Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 1/2] jbd2: export jbd2_journal_[grab|put]_journal_head Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans Joseph Qi via Ocfs2-devel
0 siblings, 2 replies; 6+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2022-01-21 7:12 UTC (permalink / raw)
To: akpm, tytso, adilger.kernel
Cc: linux-ext4, gautham.ananthakrishna, ocfs2-devel
This is trying to fix a deadlock case in ocfs2.
We firstly export jbd2 symbols jbd2_journal_[grab|put]_journal_head as
preparation and later use them in ocfs2 insread of
jbd_[lock|unlock]_bh_journal_head to fix the deadlock.
Joseph Qi (2):
jbd2: export jbd2_journal_[grab|put]_journal_head
ocfs2: fix a deadlock when commit trans
fs/jbd2/journal.c | 2 ++
fs/ocfs2/suballoc.c | 25 +++++++++++--------------
2 files changed, 13 insertions(+), 14 deletions(-)
--
2.19.1.6.gb485710b
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Ocfs2-devel] [PATCH 1/2] jbd2: export jbd2_journal_[grab|put]_journal_head
2022-01-21 7:12 [Ocfs2-devel] [PATCH 0/2] ocfs2: fix a deadlock case Joseph Qi via Ocfs2-devel
@ 2022-01-21 7:12 ` Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans Joseph Qi via Ocfs2-devel
1 sibling, 0 replies; 6+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2022-01-21 7:12 UTC (permalink / raw)
To: akpm, tytso, adilger.kernel
Cc: linux-ext4, gautham.ananthakrishna, ocfs2-devel
This exports symbols jbd2_journal_[grab|put]_journal_head, which will be
used outside modules, e.g. ocfs2.
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
fs/jbd2/journal.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 0b86a4365b66..e9f0c72f6664 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2972,6 +2972,7 @@ struct journal_head *jbd2_journal_grab_journal_head(struct buffer_head *bh)
jbd_unlock_bh_journal_head(bh);
return jh;
}
+EXPORT_SYMBOL(jbd2_journal_grab_journal_head);
static void __journal_remove_journal_head(struct buffer_head *bh)
{
@@ -3024,6 +3025,7 @@ void jbd2_journal_put_journal_head(struct journal_head *jh)
jbd_unlock_bh_journal_head(bh);
}
}
+EXPORT_SYMBOL(jbd2_journal_put_journal_head);
/*
* Initialize jbd inode head
--
2.19.1.6.gb485710b
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans
2022-01-21 7:12 [Ocfs2-devel] [PATCH 0/2] ocfs2: fix a deadlock case Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 1/2] jbd2: export jbd2_journal_[grab|put]_journal_head Joseph Qi via Ocfs2-devel
@ 2022-01-21 7:12 ` Joseph Qi via Ocfs2-devel
2022-01-23 5:31 ` Gautham Ananthakrishna via Ocfs2-devel
1 sibling, 1 reply; 6+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2022-01-21 7:12 UTC (permalink / raw)
To: akpm, tytso, adilger.kernel
Cc: linux-ext4, gautham.ananthakrishna, ocfs2-devel
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans Joseph Qi via Ocfs2-devel
@ 2022-01-23 5:31 ` Gautham Ananthakrishna via Ocfs2-devel
2022-01-24 2:37 ` Joseph Qi via Ocfs2-devel
0 siblings, 1 reply; 6+ messages in thread
From: Gautham Ananthakrishna via Ocfs2-devel @ 2022-01-23 5:31 UTC (permalink / raw)
To: Joseph Qi, akpm, tytso, adilger.kernel
Cc: Saeed Mirzamohammadi, linux-ext4, ocfs2-devel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans
2022-01-23 5:31 ` Gautham Ananthakrishna via Ocfs2-devel
@ 2022-01-24 2:37 ` Joseph Qi via Ocfs2-devel
2022-01-27 12:46 ` Gautham Ananthakrishna via Ocfs2-devel
0 siblings, 1 reply; 6+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2022-01-24 2:37 UTC (permalink / raw)
To: Gautham Ananthakrishna, akpm, tytso, adilger.kernel
Cc: Saeed Mirzamohammadi, linux-ext4, ocfs2-devel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans
2022-01-24 2:37 ` Joseph Qi via Ocfs2-devel
@ 2022-01-27 12:46 ` Gautham Ananthakrishna via Ocfs2-devel
0 siblings, 0 replies; 6+ messages in thread
From: Gautham Ananthakrishna via Ocfs2-devel @ 2022-01-27 12:46 UTC (permalink / raw)
To: Joseph Qi, akpm, tytso, adilger.kernel
Cc: Saeed Mirzamohammadi, linux-ext4, ocfs2-devel
Yes. The patch has resolved the issue.
Thanks,
Gautham.
-----Original Message-----
From: Joseph Qi <joseph.qi@linux.alibaba.com>
Sent: Monday, January 24, 2022 8:08 AM
To: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>; akpm@linux-foundation.org; tytso@mit.edu; adilger.kernel@dilger.ca
Cc: ocfs2-devel@oss.oracle.com; linux-ext4@vger.kernel.org; Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Subject: Re: [PATCH 2/2] ocfs2: fix a deadlock when commit trans
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-01-27 12:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 7:12 [Ocfs2-devel] [PATCH 0/2] ocfs2: fix a deadlock case Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 1/2] jbd2: export jbd2_journal_[grab|put]_journal_head Joseph Qi via Ocfs2-devel
2022-01-21 7:12 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: fix a deadlock when commit trans Joseph Qi via Ocfs2-devel
2022-01-23 5:31 ` Gautham Ananthakrishna via Ocfs2-devel
2022-01-24 2:37 ` Joseph Qi via Ocfs2-devel
2022-01-27 12:46 ` Gautham Ananthakrishna via Ocfs2-devel
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).