Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp860872pxb; Tue, 1 Feb 2022 11:58:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxR8tujn6rB5OkFvxh8pD8sP1zu6Sj8MvoCg7huQV7IM9O9rN5ki1sY49ibueXfItR05Eqc X-Received: by 2002:a17:907:9614:: with SMTP id gb20mr21433149ejc.412.1643745502835; Tue, 01 Feb 2022 11:58:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745502; cv=none; d=google.com; s=arc-20160816; b=aPC/b016C++bIExAHfkteGc29ZDPjT5lj5ova2bLjVG+g3L0nzoHIe87QT3Osoi5RC Mzd4IPuDxv4kfYZmIRcOOkVbT+UDAbpNVITPbDOudjdg9+I/AHaWl6N5NCJGrQvjscV5 ADYWZjWcW+w+ZdRwDt8FUlyyWc2NxNAKb5wWrC2lWIzPq3ElHV3oEwBemx2rr5hHKyG5 OvwVGM7riFyVtC1ODN/Zcgaf/hrzBb2cIqng1eJNVKCbvW/4BHHTg8YZrtLBCICMFdPJ 9nJwjerhVQafpVhJjpv23K/rJFOPAJMLWt4YtJnMT9tkKb2aiWmBC7kiZHFfUuwDFcGA qIyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BCfk53UrIttjMOaUOBJIqS7Iu+bTL6yWrchat5hKpM0=; b=wWiUYdZrO9jwsW0mvL4gEH38IAl1OVdRs4XxVw9Xve7l4v6fRhn/enxSdpYGzPxvDr k5895ugO82XITsFYhNxRWyj/4bZjeeT26Vxi2/HwK3A6aGv/heEarNsPVq8zZqXmhHQ8 25RDD8cm44KYeahm2r0fjHgOFPcYf7bjpJFDnBxafpqqyFxmAipXkjlaFdQONw1zKQlL OaDDtmVByOA+fs338Tt3SI+dC005eMaUxOoJ3U2qiZ5RqfVjUKQofIAAJVmcA2Dhc2dU F0C1ZIfNrCer2+fstx4Un/T1/DTf205qAmQjU8vZ5PpfSFkhIVXGtrEvA077QG/5l9bR nMSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yZ1iW3TZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr21si9980760ejc.150.2022.02.01.11.57.57; Tue, 01 Feb 2022 11:58:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yZ1iW3TZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359792AbiAaLH5 (ORCPT + 99 others); Mon, 31 Jan 2022 06:07:57 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:52344 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359139AbiAaLE0 (ORCPT ); Mon, 31 Jan 2022 06:04:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0C64CB82A66; Mon, 31 Jan 2022 11:04:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3DB6C340E8; Mon, 31 Jan 2022 11:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627063; bh=vyg+4TvZoYeDggdG1JwpcL5LTHe6BlggCSP8GiUcu2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yZ1iW3TZw1Xzic6TNXsGXRMMhQogk6YsekQyG9NOgAxbrj3G6mOkoAUAdITsWXVD4 Ia/4Ux/7Zv6SOJZV00Cia8v4CgGK8odAdSjsnMhh8IXpaqvE2fI6cv+wn67cpLQUQL bkdyBy6QGSaStv4uaoArMQQZWvNPzTNQyGEh3d3E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joseph Qi , Gautham Ananthakrishna , Saeed Mirzamohammadi , "Theodore Tso" , Andreas Dilger , Changwei Ge , Gang He , Joel Becker , Jun Piao , Junxiao Bi , Mark Fasheh , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 036/100] ocfs2: fix a deadlock when commit trans Date: Mon, 31 Jan 2022 11:55:57 +0100 Message-Id: <20220131105221.661935365@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joseph Qi commit ddf4b773aa40790dfa936bd845c18e735a49c61c upstream. 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 Reported-by: Gautham Ananthakrishna Tested-by: Gautham Ananthakrishna Reported-by: Saeed Mirzamohammadi Cc: "Theodore Ts'o" Cc: Andreas Dilger Cc: Changwei Ge Cc: Gang He Cc: Joel Becker Cc: Jun Piao Cc: Junxiao Bi Cc: Mark Fasheh Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/suballoc.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -1253,26 +1253,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; }