Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp573441rdb; Tue, 19 Sep 2023 04:20:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3NJ7SsOceEWzy+gtJEWalw4J5d83J/NspEZQe3aWFBH2JPq7fkzhwUIUe0ugBmX2RQ0v6 X-Received: by 2002:a9d:68da:0:b0:6bc:88da:af44 with SMTP id i26-20020a9d68da000000b006bc88daaf44mr11831391oto.6.1695122458869; Tue, 19 Sep 2023 04:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695122458; cv=none; d=google.com; s=arc-20160816; b=IKK6AqUQcbMRm27qkMLdt38V49okXd6rX4CUJixt5fzMtEi+l2kgSemHOylKDOWCX5 VgzLx2BWhJYMBn+sMDGF9FPXsETxk+6tXCDhE/jlQchsEPTSxR9fB3MQihJ7gyzwTeIG wsTT+Vx2TWp5fazPuZ7Ap2XBzK5HN0Lg/bY4/obbcKbtrLF7bPK7fx8pPw2VohhxBrgZ AedlPuRRVXWe1ZE1EnY4eWD1QipDooNQIsFCPVzm7IlrUd+idyYh7swrW24c+lmMNPdX 32lkKPwyJWgC1059l1RkLIcFsC4jeGd/Yi2SBRiAomefaK9vejKTu8sKM428FdK8eIoB +omw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=BqMbcEnQ6os/yIzidgiwTsnnSh4DkvSm5AJWdUsULfE=; fh=FOV5yBmfNhEBE5fYxyl0sDT9UQMwGJ/R1W+6FZHEea0=; b=hm/KFsL6v79cQD0k/Mx/3Vo0WEpTDNwBRwsMvdBLSiQ+6raZudu4dHjOHS7czhu4Ot savezY+rXFrxEvz3KT7RcAsCK2KZS2RxkWyPgybsmo330IEuzE8NKvisWPHAaTFtd1Jc FcJsM2kPvx3WUajay2You7rBVJkSjXZSxkUYa/rdsgxRq9lnuLCI9jloxPjBlJV5uJya q1aKll20/H55wdhxoi1M/lazx7q6i8z/r+rk65fu5o67De9Ik6KoQ/BOXH7m/GY3B/lt ym54WuV/hzOZDvuHQpWyGEVhf+lIoNSmxpkJJHj6HbRGtShIayk1BJRBs5s8ftkPEAYF wlFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Fp7OOz3L; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bu15-20020a63294f000000b00574166b7d34si9643812pgb.881.2023.09.19.04.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:20:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Fp7OOz3L; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2510380A21BD; Tue, 19 Sep 2023 03:14:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231657AbjISKO7 (ORCPT + 99 others); Tue, 19 Sep 2023 06:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbjISKOz (ORCPT ); Tue, 19 Sep 2023 06:14:55 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6645FED; Tue, 19 Sep 2023 03:14:40 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EE1461FE31; Tue, 19 Sep 2023 10:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1695118478; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BqMbcEnQ6os/yIzidgiwTsnnSh4DkvSm5AJWdUsULfE=; b=Fp7OOz3L93luSmwVfhBCp68Y20TYaHVbKgP6lCIjwGRzEMd+Gc2PM1a+AX79JNKOP+qm/Z yVyNRADOSl3nUis7Df3OTJ2jZVbWDdaX6/G+YRlf7QPx9jEBFlL1kVncQYXVbYKaS/e1BH qviGDotKFrCVuguDTOHhAoZVKQ7Wd7c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1695118478; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BqMbcEnQ6os/yIzidgiwTsnnSh4DkvSm5AJWdUsULfE=; b=Z5Eo2NGRMZGb7i/dOdfMTwT4lw+u68vIhb8Kte0KDpOSdDOfWXSlykBzJBkUeIs4s6rS3g SEs2Su87ZNrlZgAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D960A13458; Tue, 19 Sep 2023 10:14:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lUXtNI50CWUbQwAAMHmgww (envelope-from ); Tue, 19 Sep 2023 10:14:38 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 5D08FA0759; Tue, 19 Sep 2023 12:14:38 +0200 (CEST) Date: Tue, 19 Sep 2023 12:14:38 +0200 From: Jan Kara To: Zhihao Cheng Cc: tytso@mit.edu, jack@suse.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Subject: Re: [PATCH v3] jbd2: Fix potential data lost in recovering journal raced with synchronizing fs bdev Message-ID: <20230919101438.rjmxut6l2d6ufwnj@quack3> References: <20230919012525.1783108-1-chengzhihao1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919012525.1783108-1-chengzhihao1@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 03:14:58 -0700 (PDT) On Tue 19-09-23 09:25:25, Zhihao Cheng wrote: > 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. Yeah, good catch. The patch still looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > 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 > -- Jan Kara SUSE Labs, CR