Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1364814pxb; Fri, 21 Jan 2022 16:36:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAW5LYwLD/ZgntAD4EmYQVRB8Kv5sFVNK4oVVd9aVyb8XeogAjmB/s0PJmVx+20hVvDWkq X-Received: by 2002:a17:902:70c6:b0:14a:a396:8691 with SMTP id l6-20020a17090270c600b0014aa3968691mr6080614plt.35.1642811809499; Fri, 21 Jan 2022 16:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642811809; cv=none; d=google.com; s=arc-20160816; b=Ij4Pssz1/FUWeBqUke5qLqaiCoasyQqGbpW+m8LKK2hXtMDP1KrX2dkYkJ+ZWjmcd7 h5VOMsgsBwXd3AHkSjaQPd8r43msmxDuyhh/zOr2xYW7oWi3DWzpcYHNqexzxyD+T0PQ zZe+GTAgkQXZUgBCARiY2eDZ8apLDg0aCMePwboMgLIf7sPaK+lTWq0Plf6BwvcQYpiL /rXRTLCGPTpM7v3Y0ofGdgGM4S7+97awOJHpdF/SFi4jHvpfhhlbKROSgNaZzMsW/2Y8 tb6trGww9Dw/KqCwiJQdgELELk9DXi9VZpysPT3jTlydD9cFjmh387WMAgAkxXyJ2co9 M4/g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SeHulXnRxt1/BdbJImI0BCJU+K+GctUFyqKbKcoVo2M=; b=XV1ita6q6ln3EapwVUeuHm0hOFGIWZd7gbci9+lgdMx3KZeXAwqx9/9y2tAP7ZFv/N pDW0wQOQZfTyXeXfCAQX4n1qteMrp0QidH+wEe+rh/uI5XMf1c5vV2UVRP1+a0hX4gAb Zv+PNPrjuiDSLY0bMJVtLQ9872qc3ctjmaNFOa3wbMV4nMdDAEU4p5UG9zpH0eUTD1C7 u33Ge6GY/PoucCGhSeBgy/m2TNHNSWE9ARO3+nwI4TtblT3DxNfgCnXj22EngocnByc9 EFKFaJgJDM6VrZ9sdZ1vhzZ6BUrbQutuXcJnYc2CYGd1h8wY6oWU1qXfVMOb0OQ3853R Jz0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si7737583pgc.795.2022.01.21.16.36.32; Fri, 21 Jan 2022 16:36:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348854AbiAUHMN (ORCPT + 99 others); Fri, 21 Jan 2022 02:12:13 -0500 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:55789 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378617AbiAUHMK (ORCPT ); Fri, 21 Jan 2022 02:12:10 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0V2QUdB3_1642749127; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0V2QUdB3_1642749127) by smtp.aliyun-inc.com(127.0.0.1); Fri, 21 Jan 2022 15:12:07 +0800 From: Joseph Qi To: akpm@linux-foundation.org, tytso@mit.edu, adilger.kernel@dilger.ca Cc: 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 Date: Fri, 21 Jan 2022 15:12:05 +0800 Message-Id: <20220121071205.100648-3-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220121071205.100648-1-joseph.qi@linux.alibaba.com> References: <20220121071205.100648-1-joseph.qi@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 Fixes: 6f1b228529ae ("ocfs2: fix race between searching chunks and release journal_head from buffer_head") Cc: Signed-off-by: Joseph Qi --- 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