From patchwork Wed Oct 19 08:23:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp298965wrs; Wed, 19 Oct 2022 05:31:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51PyDy/vFA8L+pRo53iDzb2D48TnijdMgeJkmHYlrc77jqWABrjhL302+iVs8WvNkkVrVP X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr7290491edb.123.1666182679103; Wed, 19 Oct 2022 05:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182679; cv=none; d=google.com; s=arc-20160816; b=eoPICY137gkjewaDY0d7KQphSNp8zQurTNGTjGf+BL8cCLdIx5vXETjCm8yG51zo1A 5AI+mDEtAK0SbrWeC4Lidrb8IkyEvJDbwHKQ5jvfyH9/uaoZW0qRHLSi7B0okJCn44Tn 0hr6n4/2G/HOz48/S/074L2gSZpNyNxDFjd5VwsVZCd5cZyYdc443hSLur8QFwXXVTUd GNLT6vjP1OiTp0eS1tqbA9XtsdrW5X7OzfjgnQqELq27bAMmOw4a21Buf/MXG0H0zPFl W3KXmK3jzt8dVZfI7hTrXMiFp8jL+SOYwzhEL+zQv3O2eoYyjRG23yRIgRIpB1Bu5X7c W+9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m1Cr7vcu731OL4wOHQ4O7l3nifR6B1yafldWCW63Njs=; b=LB0KlOT1d+dp/fKUQ8eaX5qnSBGdawGKVCevdDxvs6QoWnrsQYX2lWCYIjCUz/axAV xOfGAk1OHEv1GTkfJsuZ/4olsVy6IrD5+D58ZdAKZnW1fZsFKMce+xeSwyADmCgQgzoR K0QZzuif4aX0NZScXfzzbDR+yUq4Ryj6IEi8z1D8uAcD1/Txwm7loh7/yA+R5+6rxGck zleAuqQG1Nu4QIqLrIn+eSwO1ygWMJH/qdIjDeLi2+AG6lVocPlXMzARQ/onNcbKjHGp 3+BJED71xcENGEUtLKKqJoStqdvmzPjGXyEs+sd4z+RqhVehveAcszdKayCVg1CYnFNk KdSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qqcwACNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb11-20020a1709076d8b00b0078d450cbb02si14431532ejc.452.2022.10.19.05.30.49; Wed, 19 Oct 2022 05:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qqcwACNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231436AbiJSMTr (ORCPT + 99 others); Wed, 19 Oct 2022 08:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbiJSMS7 (ORCPT ); Wed, 19 Oct 2022 08:18:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 233AFB56; Wed, 19 Oct 2022 04:54:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B055CB822F3; Wed, 19 Oct 2022 08:44:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA801C433C1; Wed, 19 Oct 2022 08:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169052; bh=nUERqgW9u3L3Gmp0YEDns3/KS90y3rmvkG6wOm5wYsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qqcwACNfdv8ioKlc1kJncRwfqZHaT/6UjbqDYSWFzE1vMpbnKtAzlM87LgSVC6iet zI3jHgn3idqvyTeUyk1eugXExXJbxQ96V8dDEUdLVCBTRPCnMu2BnVZCTACdmPbpKw vTensmLcj+iIyGlnsMUMWwJ5HRC82t0ZpzzOvpfg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Zhang Yi , Jan Kara , Theodore Tso Subject: [PATCH 6.0 141/862] ext4: ext4_read_bh_lock() should submit IO if the buffer isnt uptodate Date: Wed, 19 Oct 2022 10:23:48 +0200 Message-Id: <20221019083256.225377856@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747119169367474700?= X-GMAIL-MSGID: =?utf-8?q?1747119169367474700?= From: Zhang Yi commit 0b73284c564d3ae4feef4bc920292f004acf4980 upstream. Recently we notice that ext4 filesystem would occasionally fail to read metadata from disk and report error message, but the disk and block layer looks fine. After analyse, we lockon commit 88dbcbb3a484 ("blkdev: avoid migration stalls for blkdev pages"). It provide a migration method for the bdev, we could move page that has buffers without extra users now, but it lock the buffers on the page, which breaks the fragile metadata read operation on ext4 filesystem, ext4_read_bh_lock() was copied from ll_rw_block(), it depends on the assumption of that locked buffer means it is under IO. So it just trylock the buffer and skip submit IO if it lock failed, after wait_on_buffer() we conclude IO error because the buffer is not uptodate. This issue could be easily reproduced by add some delay just after buffer_migrate_lock_buffers() in __buffer_migrate_folio() and do fsstress on ext4 filesystem. EXT4-fs error (device pmem1): __ext4_find_entry:1658: inode #73193: comm fsstress: reading directory lblock 0 EXT4-fs error (device pmem1): __ext4_find_entry:1658: inode #75334: comm fsstress: reading directory lblock 0 Fix it by removing the trylock logic in ext4_read_bh_lock(), just lock the buffer and submit IO if it's not uptodate, and also leave over readahead helper. Cc: stable@kernel.org Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220831074629.3755110-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -205,19 +205,12 @@ int ext4_read_bh(struct buffer_head *bh, int ext4_read_bh_lock(struct buffer_head *bh, blk_opf_t op_flags, bool wait) { - if (trylock_buffer(bh)) { - if (wait) - return ext4_read_bh(bh, op_flags, NULL); + lock_buffer(bh); + if (!wait) { ext4_read_bh_nowait(bh, op_flags, NULL); return 0; } - if (wait) { - wait_on_buffer(bh); - if (buffer_uptodate(bh)) - return 0; - return -EIO; - } - return 0; + return ext4_read_bh(bh, op_flags, NULL); } /* @@ -264,7 +257,8 @@ void ext4_sb_breadahead_unmovable(struct struct buffer_head *bh = sb_getblk_gfp(sb, block, 0); if (likely(bh)) { - ext4_read_bh_lock(bh, REQ_RAHEAD, false); + if (trylock_buffer(bh)) + ext4_read_bh_nowait(bh, REQ_RAHEAD, NULL); brelse(bh); } }