Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7161993rwd; Tue, 6 Jun 2023 07:10:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ec012YIzOdWpnzmvi6Y0vUDP9rGSdOI9x7TRULHakQovi53bbAi5ArWXuQetXSAsUAsDx X-Received: by 2002:a05:620a:8b83:b0:75e:d53b:8d9f with SMTP id qx3-20020a05620a8b8300b0075ed53b8d9fmr1213763qkn.29.1686060636143; Tue, 06 Jun 2023 07:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686060636; cv=none; d=google.com; s=arc-20160816; b=NQP9SzwT/vos3KlmECljfjmE+rWWr1GaR1jruWroX4wC98HfNzobEefeOtqnbkDz2P hWrXBdNlqSOPhLvbDV+M/cylyR7vJv27DbgrNOKZwuR/TYwSlk9ML6aAC+K1eBuX2WY4 l/LGA9pklBJ/gV5UFyYkkclkJM54Dtn+pMZFtXq4jfOlM5JZTJVzrD3+ZTG7Kx6gVS5r BbJXy8fqAbPwS7P2cjuKmfE4YvwcOfzYCt/6gI2FzVVMRE2C1+wqbHN/YuBxSoeCzLnF 72UyPHEqOzVTMtgXBr97jt7kyClLHKxHOWPSPnLW5lhYtYdOszGJ3F1Rj5weZvSLghFQ QLjQ== 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=KotwXjMumGXkFLp70tCmMBCOZEXWdcOEl5RRtkuVcBI=; b=mh/HgYJgnnwwcit6yxBh12wiIy0BXIlBy8yS6wa21/brHCigPk+N1mc0NqDDDCfVQl 2xCiPkNSGkRoM3khZEgSB6Yq/6wc1esTI0sYLBi/3wKmu4Q8pbqGdNbOUrtwScr56c+j o/J1LqzuYmRzx0JGCHZV+qqoDES+CxIy7Erz1A6KiO1qQw4FoHkOcL/OB/HxpmgBV39a uMlawmGw7lvbMt6Rjk+lwGilLXokUeEesRAe/JxYDX5Q/cP6Wtm1PmF1YNHHMHTnk7+I 2qj6EzzCIbxFAviDFZpQvDmV387z9AjC7FFgOhwS5Xchq5wiU4oDLqqZQBkPdlQodLew fglw== 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 f18-20020a05620a069200b0074a5ff89c2fsi6050122qkh.333.2023.06.06.07.10.18; Tue, 06 Jun 2023 07:10:36 -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 S237445AbjFFOAQ (ORCPT + 99 others); Tue, 6 Jun 2023 10:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237507AbjFFN7r (ORCPT ); Tue, 6 Jun 2023 09:59:47 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 017FF10DF for ; Tue, 6 Jun 2023 06:59:42 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QbBtK5m4Dz4f3wRZ for ; Tue, 6 Jun 2023 21:59:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP2 (Coremail) with SMTP id Syh0CgAXB+XBO39kUFbyKw--.11143S8; Tue, 06 Jun 2023 21:59:37 +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 v3 4/6] jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint Date: Tue, 6 Jun 2023 21:59:26 +0800 Message-Id: <20230606135928.434610-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230606135928.434610-1-yi.zhang@huaweicloud.com> References: <20230606135928.434610-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgAXB+XBO39kUFbyKw--.11143S8 X-Coremail-Antispam: 1UD129KBjvJXoWxXrW7Kw48tF1UWFWxZr4Utwb_yoW5CrWxpr 4Sg34agr4kWr1UuFnaqFW5X3y0qa1DZrWUGr43K3Wvya1jywsagryayrn2yry5tr93Wayr Zr15Cr97CF10ka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMx C20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAF wI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20x vE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v2 0xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxV W8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= 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 try locking buffer and check dirtiness while buffer is 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 Reviewed-by: Jan Kara --- fs/jbd2/checkpoint.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index b94f847960c2..42b34cab64fb 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,7 +238,22 @@ int jbd2_log_do_checkpoint(journal_t *journal) spin_lock(&journal->j_list_lock); goto restart; } - if (!buffer_dirty(bh)) { + if (!trylock_buffer(bh)) { + /* + * The buffer is locked, it 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 if (!buffer_dirty(bh)) { + unlock_buffer(bh); BUFFER_TRACE(bh, "remove from checkpoint"); /* * If the transaction was released or the checkpoint @@ -262,6 +263,7 @@ int jbd2_log_do_checkpoint(journal_t *journal) !transaction->t_checkpoint_list) goto out; } else { + unlock_buffer(bh); /* * We are about to write the buffer, it could be * raced by some other transaction shrink or buffer -- 2.31.1