Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp732909rwd; Wed, 31 May 2023 04:52:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78pWfu4ZeXKHSxAG1sWWC69QFBLX4URSNt83CkyF/L+72ViLCjkecg9SjcAR3HqQNpSfHD X-Received: by 2002:a05:6a00:2450:b0:63f:2f00:c6d with SMTP id d16-20020a056a00245000b0063f2f000c6dmr5134874pfj.2.1685533921882; Wed, 31 May 2023 04:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685533921; cv=none; d=google.com; s=arc-20160816; b=jNYGn0FXohESlQ4kCF8gJhN+o56nhc0TTsKzsH9imlwh3eDJxavrgCFOkZS2NB+xt3 2Fz06ta4CIs4YNUvP4sjgtdyZ5OxCdHm36JcOqdq6nJPcRU1OPLz+4DvbwN9d4yOK1BS ujj60RYEzuowqVhIBGjwvwM9KCwl2Dq5ydoKF0J1Dt7etDbmNPrdOq2l9PPlB3Qkdx9B 4U08NGaoSPAfaaGuVkS1zWn8KEKAW8M74tuox/WcJ9VYiM+lBI/CiH5xWeVdIm7JxDv+ V5oNbhW/o2vck5BKrNy/dJwx0E4lqfheQDwQY5f8vvI8YiTCS+m1KBpWGAw6ULq0bTms 5oTA== 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=ksvTa9hpjuFx2bOjtx6Pigr5XUwKtWnigTi9/mpnz/o=; b=vD8sPmRGiftPezvQMtJwUeOiFpprEkUPCG4VrOJf9jF2T4Z8aCy736oyTYi1tyae38 RUi7s0Bx1qctMjIIocfLiJG9WQ1ONh65CIgLdz2Xr79yE1bWy0oEPv7vpNiCKA0n91Fw Zr0NyY9j/haeNKvi2vhaQ9UGt1KhGmMoayU1jrGhTSsv4Sw0KhDlhzZNkLDdG/4vf7iE Ux6SYxP2yBIYiK2ChiyQ7lmnwWuRHsWYZlaeNeiBM2AecCH4MQS+O7TvWJl9LnF8eVdZ jOfjKlzLCzeJWfzh55DRbz6h4ttApMmlSaaNS1ZworhxtFwZNz/tqd8btmBRPlu6UYc4 clzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a637f52000000b00534842ba603si555866pgn.820.2023.05.31.04.51.43; Wed, 31 May 2023 04:52:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235693AbjEaLvX (ORCPT + 99 others); Wed, 31 May 2023 07:51:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235289AbjEaLvQ (ORCPT ); Wed, 31 May 2023 07:51:16 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B220E13E for ; Wed, 31 May 2023 04:51:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QWSJs2gNFz4f3s5k for ; Wed, 31 May 2023 19:51:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP2 (Coremail) with SMTP id Syh0CgA33eqkNHdkE8UXKg--.13786S8; Wed, 31 May 2023 19:51:09 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, yukuai3@huawei.com, chengzhihao1@huawei.com Subject: [PATCH 4/5] jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint Date: Wed, 31 May 2023 19:50:59 +0800 Message-Id: <20230531115100.2779605-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230531115100.2779605-1-yi.zhang@huaweicloud.com> References: <20230531115100.2779605-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgA33eqkNHdkE8UXKg--.13786S8 X-Coremail-Antispam: 1UD129KBjvJXoWxXrW7Kw48tF1UXw1DuF17KFg_yoW5Kr15pr nag3yaqrWkGr1UZF1SqrWUZ3yjqan8ZrWUGry3GFn2ya1jywsagryakwnFkryjyr93Wayr Xry5Cr93uF40ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-ext4@vger.kernel.org From: Zhihao Cheng Following process, jbd2_journal_commit_transaction // there are several dirty buffer heads in transaction->t_checkpoint_list P1 wb_workfn jbd2_log_do_checkpoint if (buffer_locked(bh)) // false __block_write_full_page trylock_buffer(bh) test_clear_buffer_dirty(bh) if (!buffer_dirty(bh)) __jbd2_journal_remove_checkpoint(jh) if (buffer_write_io_error(bh)) // false >> bh IO error occurs << jbd2_cleanup_journal_tail __jbd2_update_log_tail jbd2_write_superblock // The bh won't be replayed in next mount. , which could corrupt the ext4 image, fetch a reproducer in [Link]. Since writeback process clears buffer dirty after locking buffer head, we can fix it by checking buffer dirty firstly and then checking buffer locked, the buffer head can be removed if it is neither dirty nor locked. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217490 Fixes: 470decc613ab ("[PATCH] jbd2: initial copy of files from jbd") Signed-off-by: Zhihao Cheng Signed-off-by: Zhang Yi --- fs/jbd2/checkpoint.c | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index 3f52560912a9..620f3d345f3d 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -204,20 +204,6 @@ int jbd2_log_do_checkpoint(journal_t *journal) jh = transaction->t_checkpoint_list; bh = jh2bh(jh); - /* - * The buffer may be writing back, or flushing out in the - * last couple of cycles, or re-adding into a new transaction, - * need to check it again until it's unlocked. - */ - if (buffer_locked(bh)) { - get_bh(bh); - spin_unlock(&journal->j_list_lock); - wait_on_buffer(bh); - /* the journal_head may have gone by now */ - BUFFER_TRACE(bh, "brelse"); - __brelse(bh); - goto retry; - } if (jh->b_transaction != NULL) { transaction_t *t = jh->b_transaction; tid_t tid = t->t_tid; @@ -252,16 +238,7 @@ int jbd2_log_do_checkpoint(journal_t *journal) spin_lock(&journal->j_list_lock); goto restart; } - if (!buffer_dirty(bh)) { - BUFFER_TRACE(bh, "remove from checkpoint"); - /* - * If the transaction was released or the checkpoint - * list was empty, we're done. - */ - if (__jbd2_journal_remove_checkpoint(jh) || - !transaction->t_checkpoint_list) - goto out; - } else { + if (buffer_dirty(bh)) { /* * We are about to write the buffer, it could be * raced by some other transaction shrink or buffer @@ -275,6 +252,29 @@ int jbd2_log_do_checkpoint(journal_t *journal) journal->j_chkpt_bhs[batch_count++] = bh; transaction->t_chp_stats.cs_written++; transaction->t_checkpoint_list = jh->b_cpnext; + } else if (buffer_locked(bh)) { + /* + * The buffer may be writing back, or flushing out + * in the last couple of cycles, or re-adding into + * a new transaction, need to check it again until + * it's unlocked. + */ + get_bh(bh); + spin_unlock(&journal->j_list_lock); + wait_on_buffer(bh); + /* the journal_head may have gone by now */ + BUFFER_TRACE(bh, "brelse"); + __brelse(bh); + goto retry; + } else { + BUFFER_TRACE(bh, "remove from checkpoint"); + /* + * If the transaction was released or the checkpoint + * list was empty, we're done. + */ + if (__jbd2_journal_remove_checkpoint(jh) || + !transaction->t_checkpoint_list) + goto out; } if ((batch_count == JBD2_NR_BATCH) || -- 2.31.1