Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp869831pxb; Tue, 1 Feb 2022 12:07:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyawOgAeVHDijsLJ9Uh3ksXVLy3b8QGSOvmbjWSUbkzcblCKBHk+2QS0RSl2xpJdsgPSzKW X-Received: by 2002:aa7:cdd9:: with SMTP id h25mr26765855edw.95.1643746020189; Tue, 01 Feb 2022 12:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643746020; cv=none; d=google.com; s=arc-20160816; b=Nd8V8lZ0IVoTCrCYiHiIKGTySsP7DTe0VEb1CA5WNZH46VtRysReTWzBA1Dhd7ytJC DTlT6RJhOq4OLc2LrsDBsYkbFp5E0cYEtix7UcVKmdLJoJW6ttn/j6VI53CjqV5zOPc4 y/2KMYWWyqODQH625wPLFLylNkBHyBBzoB/AzQ3aGXfdpTeZRcO/1rWaQloueP9RJ+n4 0qohZO4FqyVR83Oj5R5mDy9OOxVmlPCqPqCn1jBb0hMb4uwLSsC/tsWPkkBQd4g9phLC fgqQhQ5qsvgSGYcNEBOEllUJI6Xlhk4qWvhOURfDS9HsUYJ+mIdOPUy52ofgrQVwZctl iL0w== 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=xq4MEio2szmxzzEjwXC6KfkyeNbTjdP6fQ1x4l3oQbQ=; b=fE8NwU/zF4Hum7N73JX4ixUH1vg8g2me/3M0C9KwDtMiZYiCIvAcb6mOnZB5r1EZ0C S/fkM/O5XemyqN9wHylAUJarOkUP9K1kalEgCpKiwzURLjTqOIb6HqvVOntqgFwLGwcV VjafD0AZmSuSCJc9ib6foxiWyiSNPPKKOKcZDv4WvB9NzZGlqaiofI+K0MWHlTtgItSM U8DthNC+NpyO5x2feP4Q/NamGMJsMdpovuN2XkItQ1Ys2xOO+rg6JWaJnYK4VcZkwkpE VUFuLpk0R8xoBoV5FC+2Yw6S/Ij5BrVwJMHjYXu8hnR0QHjn6LMIJbMtzs3XTUyin57b Vxjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EgFATjTB; 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 du8si9592090ejc.413.2022.02.01.12.06.34; Tue, 01 Feb 2022 12:07:00 -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=EgFATjTB; 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 S1377134AbiAaLZz (ORCPT + 99 others); Mon, 31 Jan 2022 06:25:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359805AbiAaLRN (ORCPT ); Mon, 31 Jan 2022 06:17:13 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2494C0617A6; Mon, 31 Jan 2022 03:11:31 -0800 (PST) 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 7F544B82A61; Mon, 31 Jan 2022 11:11:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A9EEC340E8; Mon, 31 Jan 2022 11:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627489; bh=X0VcEdGakIz6rEue8sRTEPf3AQkU+2J1McCJq0WJgpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EgFATjTB4QvE5aJNazF34CZCLuqvkhBwda6psgSsZbctJmzPRBoTx5HqpIDhFwAMH xuJg51rYA6fp0I88ZNvnqdjtolNTy2qMGrRW34XTVe8zjbl5tsDNimD+Z4kSmPXx4M XaESXsIjAkJwQLpTVQrmPixyWQtCHSBxOGYRbljY= 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.15 067/171] ocfs2: fix a deadlock when commit trans Date: Mon, 31 Jan 2022 11:55:32 +0100 Message-Id: <20220131105232.307231263@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105229.959216821@linuxfoundation.org> References: <20220131105229.959216821@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 @@ -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; }