Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp357145rdb; Mon, 18 Sep 2023 18:32:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAX3z8CpRg19SV2Mk5Ef7AoTxzpFTFZVI1+LL5iaJXS/8BKInSBYLCybSLyJxTAT7jNYdy X-Received: by 2002:a05:6870:e2d4:b0:1c0:fe16:90f9 with SMTP id w20-20020a056870e2d400b001c0fe1690f9mr13213529oad.51.1695087157841; Mon, 18 Sep 2023 18:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695087157; cv=none; d=google.com; s=arc-20160816; b=LDW7zWivoYLXNo2nbIIJtxqLItIEMTyOH3laVcHK+L1HlVodJtaT/Uw9YTZTJPfslx KpfjIRlY2R+hYHY1GkcDNxhMKIPaeDaLGyv47M/c8nYT8d9o4uiyy7Q6a9iUQ2wCVNiK nBpXO/Cx23DqQl2dirNRBKFC8iLAHCZrtgRebxqUYj03LQynx32qxBYeMvywM99Ya0QY /1epYJzH6P6QT/D2mS1Y0Hp4TKzQwvZgQSVtjx2IqCGiD1SA25uAcaYr6qGWF2LP7itX IC6FNlsWO92LtbZAgZkcTSONrQ3pBvzkPqNKgB3QP+ypPwZ3BoJlVDyjKOBljaJr9mx2 Fiog== 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 :message-id:date:subject:cc:to:from; bh=9FKCDywk3PfOGGEoO8mMmE+TTcnUwedfyGmOJpGBCc8=; fh=aCPesFXtiotw8J5f6WLQRIus1aexICE2r1Wx2Btxekk=; b=LD/vSESWgVCFv7VsTZfu8CJ2zXmZ8w4OPxxOfnW0n7n3Azv85phKl1fXYng397Z5QE 2Ll4IkUCjd3LN/zXEkos6PD73ULkc8bfsCL8jc0pcnSdxlPMZXe99PXNk8E1DEErs1WU 2PTsLe7SUiV/ywoV9ZU+fxNWE6MJpux0tH/qfI96FU7GuU2z5d1eXjNRLzvOQA3JpvcI 4m/B5AupWC3HwtDuE3Y89SIE1UVRnIeO/t6wOrMvM7xSnrO7QJOYV0cO1qg5NoXgMalI VG0FQE1hJBDmdqN8QsWv0GhpixEL9oRyIl+dftpCGUvq68+tdW+JDL/MFvIuSlux+SzE /TCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k11-20020a637b4b000000b00578a7f5a0b1si862080pgn.393.2023.09.18.18.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 18:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 04CC1811EDB1; Mon, 18 Sep 2023 18:31:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbjISBb0 (ORCPT + 99 others); Mon, 18 Sep 2023 21:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjISBbZ (ORCPT ); Mon, 18 Sep 2023 21:31:25 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8775094; Mon, 18 Sep 2023 18:31:17 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RqPCS4Km4ztSq2; Tue, 19 Sep 2023 09:27:00 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 19 Sep 2023 09:31:12 +0800 From: Zhihao Cheng To: , CC: , , , Subject: [PATCH v3] jbd2: Fix potential data lost in recovering journal raced with synchronizing fs bdev Date: Tue, 19 Sep 2023 09:25:25 +0800 Message-ID: <20230919012525.1783108-1-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.67] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 18 Sep 2023 18:31:32 -0700 (PDT) JBD2 makes sure journal data is fallen on fs device by sync_blockdev(), however, other process could intercept the EIO information from bdev's mapping, which leads journal recovering successful even EIO occurs during data written back to fs device. We found this problem in our product, iscsi + multipath is chosen for block device of ext4. Unstable network may trigger kpartx to rescan partitions in device mapper layer. Detailed process is shown as following: mount kpartx irq jbd2_journal_recover do_one_pass memcpy(nbh->b_data, obh->b_data) // copy data to fs dev from journal mark_buffer_dirty // mark bh dirty vfs_read generic_file_read_iter // dio filemap_write_and_wait_range __filemap_fdatawrite_range do_writepages block_write_full_folio submit_bh_wbc >> EIO occurs in disk << end_buffer_async_write mark_buffer_write_io_error mapping_set_error set_bit(AS_EIO, &mapping->flags) // set! filemap_check_errors test_and_clear_bit(AS_EIO, &mapping->flags) // clear! err2 = sync_blockdev filemap_write_and_wait filemap_check_errors test_and_clear_bit(AS_EIO, &mapping->flags) // false err2 = 0 Filesystem is mounted successfully even data from journal is failed written into disk, and ext4/ocfs2 could become corrupted. Fix it by comparing the wb_err state in fs block device before recovering and after recovering. Fetch a reproducer in [Link]. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217888 Cc: stable@vger.kernel.org Signed-off-by: Zhihao Cheng Signed-off-by: Zhang Yi --- v1->v3: Initialize wb_err. Untialized wb_err could be same with mapping->wb_err(eg. EIO without ERRSEQ_SEEN). When EIO occurs again, mapping->wb_err won't be changed, and wb_err is still same with mapping->wb_err. fs/jbd2/recovery.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index c269a7d29a46..5b771a3d8d9a 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -289,6 +289,8 @@ int jbd2_journal_recover(journal_t *journal) journal_superblock_t * sb; struct recovery_info info; + errseq_t wb_err; + struct address_space *mapping; memset(&info, 0, sizeof(info)); sb = journal->j_superblock; @@ -306,6 +308,9 @@ int jbd2_journal_recover(journal_t *journal) return 0; } + wb_err = 0; + mapping = journal->j_fs_dev->bd_inode->i_mapping; + errseq_check_and_advance(&mapping->wb_err, &wb_err); err = do_one_pass(journal, &info, PASS_SCAN); if (!err) err = do_one_pass(journal, &info, PASS_REVOKE); @@ -327,6 +332,9 @@ int jbd2_journal_recover(journal_t *journal) jbd2_journal_clear_revoke(journal); err2 = sync_blockdev(journal->j_fs_dev); + if (!err) + err = err2; + err2 = errseq_check_and_advance(&mapping->wb_err, &wb_err); if (!err) err = err2; /* Make sure all replayed data is on permanent storage */ -- 2.39.2