All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: adilger.kernel@dilger.ca, akpm@linux-foundation.org,
	gautham.ananthakrishna@oracle.com, gechangwei@live.cn,
	ghe@suse.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com,
	junxiao.bi@oracle.com, linux-mm@kvack.org, mark@fasheh.com,
	mm-commits@vger.kernel.org, piaojun@huawei.com,
	saeed.mirzamohammadi@oracle.com, stable@vger.kernel.org,
	torvalds@linux-foundation.org, tytso@mit.edu
Subject: [patch 12/12] ocfs2: fix a deadlock when commit trans
Date: Sat, 29 Jan 2022 13:41:27 -0800	[thread overview]
Message-ID: <20220129214127.zeeGfdF7V%akpm@linux-foundation.org> (raw)
In-Reply-To: <20220129134026.8ccf701012f26eb2c2c269c9@linux-foundation.org>

From: Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: 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.

Link: https://lkml.kernel.org/r/20220121071205.100648-3-joseph.qi@linux.alibaba.com
Fixes: 6f1b228529ae ("ocfs2: fix race between searching chunks and release journal_head from buffer_head")
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reported-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
Tested-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com>
Reported-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/ocfs2/suballoc.c |   25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

--- a/fs/ocfs2/suballoc.c~ocfs2-fix-a-deadlock-when-commit-trans
+++ a/fs/ocfs2/suballoc.c
@@ -1251,26 +1251,23 @@ static int ocfs2_test_bg_bit_allocatable
 {
 	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;
 }
_


      parent reply	other threads:[~2022-01-29 21:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29 21:40 incoming Andrew Morton
2022-01-29 21:40 ` [patch 01/12] include/linux/sysctl.h: fix register_sysctl_mount_point() return type Andrew Morton
2022-01-29 21:40 ` [patch 02/12] binfmt_misc: fix crash when load/unload module Andrew Morton
2022-01-29 21:40 ` [patch 03/12] ia64: make IA64_MCA_RECOVERY bool instead of tristate Andrew Morton
2022-01-29 21:41 ` [patch 04/12] memory-failure: fetch compound_head after pgmap_pfn_valid() Andrew Morton
2022-01-29 21:41 ` [patch 05/12] mm: page->mapping folio->mapping should have the same offset Andrew Morton
2022-01-29 21:41 ` [patch 06/12] tools/testing/scatterlist: add missing defines Andrew Morton
2022-01-29 21:41 ` [patch 07/12] kasan: test: fix compatibility with FORTIFY_SOURCE Andrew Morton
2022-01-29 21:41 ` [patch 08/12] mm, kasan: use compare-exchange operation to set KASAN page tag Andrew Morton
2022-01-29 21:41 ` [patch 09/12] psi: fix "no previous prototype" warnings when CONFIG_CGROUPS=n Andrew Morton
2022-01-29 21:41 ` [patch 10/12] psi: fix "defined but not used" warnings when CONFIG_PROC_FS=n Andrew Morton
2022-01-29 21:41 ` [patch 11/12] jbd2: export jbd2_journal_[grab|put]_journal_head Andrew Morton
2022-01-29 21:41 ` Andrew Morton [this message]

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=20220129214127.zeeGfdF7V%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=gautham.ananthakrishna@oracle.com \
    --cc=gechangwei@live.cn \
    --cc=ghe@suse.com \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=junxiao.bi@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=mark@fasheh.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=piaojun@huawei.com \
    --cc=saeed.mirzamohammadi@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --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.