Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp345477pxf; Thu, 8 Apr 2021 04:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxkOTQHWZdBjP1pShYpyuAFEq+3hQ/Uyw9lTXfwbO9c7kkL9hSuaC3FS0ZvRw2GFg6LEzN X-Received: by 2002:a17:906:f9c2:: with SMTP id lj2mr9452772ejb.195.1617881435056; Thu, 08 Apr 2021 04:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617881435; cv=none; d=google.com; s=arc-20160816; b=c+1qFEgic905LGLZiPlZghsVXV6pqkz/5q3uFDPcyxDKLR+MGk/BJIQf//PrvQF9Px TitaGbSaxAeTVGY7hHEkxJHvkE3vHzzD//eg5TMiUJj0XYYljFI76RWdtpnasPhnGgYK 91Vb5CTGQD27/nR7RZpdVVguIhKJgAdJVuyOrNcytqNKGE/6H8ANps0d+FR+bhOPjsdA 483mTGlbR6lUyE6FxXtmAblBN7pmcziDn9Rm/idYY2DFISCRbZGcnfhkhT3gCg0FlC7B UeomfEasaD9XB5eoLjSwVx0Zllt1pSOFTOO6BixanzDJkjXQbE/HZ8sf62JTO+xfn4kU 40eA== 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=v3juxt1OJ3KIF0STAjQ2Zfkb7w/NGs6+VVTB0vZjJ8Q=; b=G3OedYLWQ8GYZUK5aa9XiuDyT9ydFflunKymTomNnmWqo89Bs7w9Hhr+NiUns3A5zS Qll7dEcTSEplJOGY357PgZSEWZPJnHHLTAO/U/4NGfi1VJNV41xj3+3F+3e1KwfnBHfr G+TYfhKXr49RC8u1+4qNOGY+DMPm8uh8ZvTpJO7dVop+sEilCGYyyYNztCEtaUO8bZ6g rA1BHmIIPSdLafHKWRv6btSRRIX+4IMJFTSWLgvJZFmTeSonZKIkKqZXNnOTKtww9PQp 4jti70mq5RbMmw36bPINuHajUczmBozUFvmmQiadRIWwRC287knMRyWVLZdZ796XPJUA 8aPw== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si8536451edx.600.2021.04.08.04.30.11; Thu, 08 Apr 2021 04:30:35 -0700 (PDT) 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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbhDHL2T (ORCPT + 99 others); Thu, 8 Apr 2021 07:28:19 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:16836 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbhDHL2T (ORCPT ); Thu, 8 Apr 2021 07:28:19 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FGJq63mPpz7txW; Thu, 8 Apr 2021 19:25:54 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 19:28:00 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH 1/3] jbd2: protect buffers release with j_checkpoint_mutex Date: Thu, 8 Apr 2021 19:36:16 +0800 Message-ID: <20210408113618.1033785-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210408113618.1033785-1-yi.zhang@huawei.com> References: <20210408113618.1033785-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There is a race between jbd2_journal_try_to_free_buffers() and jbd2_journal_destroy(), so the jbd2_log_do_checkpoint() may still missing to detect the buffer write io error flag and lead to filesystem inconsistency. jbd2_journal_try_to_free_buffers() ext4_put_super() jbd2_journal_destroy() __jbd2_journal_remove_checkpoint() detect buffer write error jbd2_log_do_checkpoint() jbd2_cleanup_journal_tail() <--- lead to inconsistency jbd2_journal_abort() Fix this issue by add j_checkpoint_mutex to protect journal buffer release on jbd2_journal_try_to_free_buffers(). Signed-off-by: Zhang Yi --- fs/jbd2/transaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 9396666b7314..b935b20cbae4 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -2123,6 +2123,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page) J_ASSERT(PageLocked(page)); + mutex_lock(&journal->j_checkpoint_mutex); head = page_buffers(page); bh = head; do { @@ -2163,6 +2164,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page) if (has_write_io_error) jbd2_journal_abort(journal, -EIO); + mutex_unlock(&journal->j_checkpoint_mutex); return ret; } -- 2.25.4