Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2153809iof; Tue, 7 Jun 2022 21:33:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYA6XmFMB/xjWw1bFh2WiDY5ugQzOocnsdkCOMvBTX3D+s0XSMF0kHLR0LBMaAVlT8nKWf X-Received: by 2002:a05:6a00:a10:b0:51b:fbe1:cedb with SMTP id p16-20020a056a000a1000b0051bfbe1cedbmr19379370pfh.68.1654662789309; Tue, 07 Jun 2022 21:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654662789; cv=none; d=google.com; s=arc-20160816; b=YX51bqyGebem2hZucHm0fMkNLV06Zi5/mFW6wXEeSJRmTS0aCoiGGiFz88H8Z6Nr9v ERCM/wt+8cqptvDJ++vjRezziAQ73Htzlp0hbR2diWzTEOMETqPvkFEAODZZlwgbQ4cq BP5d7mKzNLZSdpJIu3u067BgPzL0aZ8DMNdu9DyLJrms3aUAg24FXdcFh7In8MZKbIF9 QHql+ReqjOpEnHBnXUgsRloWSTQqPDiw8LufQL/FlPhBQyawEpaneK73gKiL9qL5Eifo bkrqoitabkCSrRyFfCpCxgMhSRU2OrC6XvM/d+N2bjOvQ29KXL5DEW2mTyvJphUoTXso d4+w== 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=bcbF1f+hYhSILJIQV2kivUFQ/+Symh8/IPZKAA16zOc=; b=h6RGTJEY+vgkUWsRYXxHG63dGTb1pg3+pCILsEpshqLREroylG+z+saKSPyMgyCxGI FS8LweMHW+/ZOFdbpwfl5UbrjAJzZnTLXiZG1X+JtUkHh9FuI7JJEO8+fiG3zgwugNsw r3qaki2Q+92YrWuBQvvpYo9Vykk1NJ4PvTOP9s8b2G8FCxrQWV4wrJTOlLHg0fs1MLPe e7R6TAr9fFtlT0f2DiXbohVTDQVRwsziD8RpSzCRVLWx8UTv6Z6nXhQYUmTI+gJkQdev 81zrqVZaTQk4TXpAN8OyO5mhkZzN01xt7g1+8I2wtRHoAkZfhLo4rpeVKd6EpSJ3p6ax vMZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=awFM3ti9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c10-20020a170903234a00b00158b259cf77si28875623plh.169.2022.06.07.21.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=awFM3ti9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 237B6260659; Tue, 7 Jun 2022 21:01:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358810AbiFGUVs (ORCPT + 99 others); Tue, 7 Jun 2022 16:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355438AbiFGT3v (ORCPT ); Tue, 7 Jun 2022 15:29:51 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA9E41A43E8; Tue, 7 Jun 2022 11:11:58 -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 sin.source.kernel.org (Postfix) with ESMTPS id 23266CE2443; Tue, 7 Jun 2022 18:11:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38B50C34115; Tue, 7 Jun 2022 18:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654625510; bh=5/0HLBIHwIsm8UNga4LbUSZ3eBdbnNrZstFRE28f+uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awFM3ti9V0d0MsJn1aMpbb7bRD7pcOuKz47SH+bHU1fZRBriZiuxhKGrqYCtNiI8C 7QC5xm3XUNct0EPiJQeicc5+PxQiob39kG5uFjWIM3PRxdtK/4ICrCp8paBW+6Hhlc EE9DrQagLAYt4DC0LZmSVcYTMZageR6wZnHln4Ik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 5.17 045/772] btrfs: fix the error handling for submit_extent_page() for btrfs_do_readpage() Date: Tue, 7 Jun 2022 18:53:57 +0200 Message-Id: <20220607164950.360048766@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Qu Wenruo commit 10f7f6f879c28f8368d6516ab1ccf3517a1f5d3d upstream. [BUG] Test case generic/475 have a very high chance (almost 100%) to hit a fs hang, where a data page will never be unlocked and hang all later operations. [CAUSE] In btrfs_do_readpage(), if we hit an error from submit_extent_page() we will try to do the cleanup for our current io range, and exit. This works fine for PAGE_SIZE == sectorsize cases, but not for subpage. For subpage btrfs_do_readpage() will lock the full page first, which can contain several different sectors and extents: btrfs_do_readpage() |- begin_page_read() | |- btrfs_subpage_start_reader(); | Now the page will have PAGE_SIZE / sectorsize reader pending, | and the page is locked. | |- end_page_read() for different branches | This function will reduce subpage readers, and when readers | reach 0, it will unlock the page. But when submit_extent_page() failed, we only cleanup the current io range, while the remaining io range will never be cleaned up, and the page remains locked forever. [FIX] Update the error handling of submit_extent_page() to cleanup all the remaining subpage range before exiting the loop. Please note that, now submit_extent_page() can only fail due to sanity check in alloc_new_bio(). Thus regular IO errors are impossible to trigger the error path. CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent_io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3721,8 +3721,12 @@ int btrfs_do_readpage(struct page *page, this_bio_flag, force_bio_submit); if (ret) { - unlock_extent(tree, cur, cur + iosize - 1); - end_page_read(page, false, cur, iosize); + /* + * We have to unlock the remaining range, or the page + * will never be unlocked. + */ + unlock_extent(tree, cur, end); + end_page_read(page, false, cur, end + 1 - cur); goto out; } cur = cur + iosize;