Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5580551pxb; Mon, 28 Mar 2022 14:30:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU1xrchIkZeY1B3UfwXIprWZicvBBjb8wUZPIQLBevxZzPugmHDcA+ndoxaY4eMhHJZ0Yj X-Received: by 2002:a63:d23:0:b0:382:70fa:2f0 with SMTP id c35-20020a630d23000000b0038270fa02f0mr11260834pgl.181.1648503049014; Mon, 28 Mar 2022 14:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648503049; cv=none; d=google.com; s=arc-20160816; b=Qs42U0OjMnYMYzM6wo8tfUTPkGBnHxs78JkRX9gbxN1IA2qdQphBxLt5so2hfG15ah UDqOHKpuB5q7+Zuir7GQEeW7MGk6mmGB3VdCN7Z6g2cNoZ89WTnAQ53dWvUk0qGer6oK XSCvP/OcmmWv5m0via9tV8Vr+PJ2gFmXiQbhTmygS9wkBIrM059MHsztmGsEdT4ADyFu Aunz2e8Bp0igbCFVEOJLf3r9fZLnhFsKXa2fy7LtpL5gpghcGyQEWMv0PN1ibXvCLQ1N HdwVE9jQGwMdl8NjeMFcjz1YAuVDUiP31u5doSaoSF8jXa0TgdzPv5EZ9xfSnvFpHY4s EwvQ== 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 :dkim-signature; bh=AWN8AeOEoP32dLV0dKcvNu91oj/yrwUkcTHIUuhPgY8=; b=vDGUDaIfqoZNUhZ7bLBZ1EmNR82kTvWKF+59d628fYhmK7nXFIf+wEyv5AxwxIl5Kz IkCLci9ZZcRwvnv+iAXqjnUhb0myTSyG4iEsSgPCiQxfCAMNaaBKKcWn8UNoHOIYVrnS ZdtljPR5lrPglFcqElds/HzIS9KClOlhznhkR6I4vGMKvPPTkJdV6rBtZ/hI30YCa5Z1 Ud/IBiReS/LmcCTYzYGoAWGtLia8rrRqkXYUc3A+Nq1rHwK1+RJE08YoDzJ5Y42WqL4k dBzd5RM8ZBU8VjQDbOUK7v5tvXSHxV4KWvmqX6YkkOjM+Q9Ok6JuhTY3Jvm/RNtVi5ds KqmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fRvDzdHy; 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=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 8-20020a630f48000000b003983e878483si8186044pgp.609.2022.03.28.14.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:30:49 -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=@kernel.org header.s=k20201202 header.b=fRvDzdHy; 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=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6EBB86B506; Mon, 28 Mar 2022 14:13:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239436AbiC1Tow (ORCPT + 99 others); Mon, 28 Mar 2022 15:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343574AbiC1ToF (ORCPT ); Mon, 28 Mar 2022 15:44:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8225E169; Mon, 28 Mar 2022 12:42:20 -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 3295FB81214; Mon, 28 Mar 2022 19:42:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0537CC36AE5; Mon, 28 Mar 2022 19:42:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648496537; bh=lNpPtBPmupGdvKQXKwMAimjlb9x/Xk2tXHvLiWg62cc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fRvDzdHyAFOnmQHh6mzowG/oGQ4x1R5eUWQ0vXArSjRaAiFcZ4/jzK2IaRjvy6TyH 2OKDOp/5hKtPXbYnmsAtr36c3OtW+LJOl2qhHA0OwpgZ+jMxJwRGfzZmCjZcuC4Z3O iuJvCQfsjAKFuuKoXU8mX9wO+gVeAf5TMFQGZ4I1YUaY/b2NDBecsT1iekQiTEId4f 4mTlZ0Nkm/5n5zBTWn+YjYIQFuxI4IIlcDM/7Uieo12aNEls6hahU/MlP1fwuYzX/R a39u+7hnVz9DxhL1CrgLerxI6otslsbTaOAsM693LV0YM+Wk6/vq1FP3ZI2c+PJZKT IC2n5mxlfG4SQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Josef Bacik , David Sterba , Sasha Levin , clm@fb.com, jbacik@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.17 15/21] btrfs: do not double complete bio on errors during compressed reads Date: Mon, 28 Mar 2022 15:41:50 -0400 Message-Id: <20220328194157.1585642-15-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328194157.1585642-1-sashal@kernel.org> References: <20220328194157.1585642-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: Josef Bacik [ Upstream commit f9f15de85d74e7eef021af059ca53a15f041cdd8 ] I hit some weird panics while fixing up the error handling from btrfs_lookup_bio_sums(). Turns out the compression path will complete the bio we use if we set up any of the compression bios and then return an error, and then btrfs_submit_data_bio() will also call bio_endio() on the bio. Fix this by making btrfs_submit_compressed_read() responsible for calling bio_endio() on the bio if there are any errors. Currently it was only doing it if we created the compression bios, otherwise it was depending on btrfs_submit_data_bio() to do the right thing. This creates the above problem, so fix up btrfs_submit_compressed_read() to always call bio_endio() in case of an error, and then simply return from btrfs_submit_data_bio() if we had to call btrfs_submit_compressed_read(). Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/compression.c | 20 ++++++++++++++------ fs/btrfs/inode.c | 8 +++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 8b3bca269de3..59f50d362db3 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -808,7 +808,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, u64 em_len; u64 em_start; struct extent_map *em; - blk_status_t ret = BLK_STS_RESOURCE; + blk_status_t ret; int faili = 0; u8 *sums; @@ -821,14 +821,18 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, file_offset, fs_info->sectorsize); read_unlock(&em_tree->lock); - if (!em) - return BLK_STS_IOERR; + if (!em) { + ret = BLK_STS_IOERR; + goto out; + } ASSERT(em->compress_type != BTRFS_COMPRESS_NONE); compressed_len = em->block_len; cb = kmalloc(compressed_bio_size(fs_info, compressed_len), GFP_NOFS); - if (!cb) + if (!cb) { + ret = BLK_STS_RESOURCE; goto out; + } refcount_set(&cb->pending_sectors, compressed_len >> fs_info->sectorsize_bits); cb->errors = 0; @@ -851,8 +855,10 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, nr_pages = DIV_ROUND_UP(compressed_len, PAGE_SIZE); cb->compressed_pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); - if (!cb->compressed_pages) + if (!cb->compressed_pages) { + ret = BLK_STS_RESOURCE; goto fail1; + } for (pg_index = 0; pg_index < nr_pages; pg_index++) { cb->compressed_pages[pg_index] = alloc_page(GFP_NOFS); @@ -938,7 +944,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, comp_bio = NULL; } } - return 0; + return BLK_STS_OK; fail2: while (faili >= 0) { @@ -951,6 +957,8 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, kfree(cb); out: free_extent_map(em); + bio->bi_status = ret; + bio_endio(bio); return ret; finish_cb: if (comp_bio) { diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 826f94b2fda5..5aace4c13519 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2538,10 +2538,15 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, goto out; if (bio_flags & EXTENT_BIO_COMPRESSED) { + /* + * btrfs_submit_compressed_read will handle completing + * the bio if there were any errors, so just return + * here. + */ ret = btrfs_submit_compressed_read(inode, bio, mirror_num, bio_flags); - goto out; + goto out_no_endio; } else { /* * Lookup bio sums does extra checks around whether we @@ -2575,6 +2580,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, bio->bi_status = ret; bio_endio(bio); } +out_no_endio: return ret; } -- 2.34.1