Message ID | 20230526-squashfs-cache-fixup-v2-1-6fb7723c3647@axis.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp504293vqr; Fri, 26 May 2023 07:11:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XzR5F5c03e6swTs6gfDRvirhlJQmxrLB5wnVcekXxgjuRspiFU9BfhLGSDUL0tBqwcS1I X-Received: by 2002:a05:6a00:1485:b0:64f:b147:3f3c with SMTP id v5-20020a056a00148500b0064fb1473f3cmr124224pfu.6.1685110265865; Fri, 26 May 2023 07:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685110265; cv=none; d=google.com; s=arc-20160816; b=CCqjmuc9nGc2ALhiofoHZTUwjcZDiNtZo5KjH/xVcm9FvBjUQ56y1Qaap6Zu3hi1Rg Rwdws1CmFdOKJ2AccFCQUyobm3FoxtrZKI4zXE1QeT1K8wSTuKb5Knl7r3BX88Lpnnv7 w2vKOq8SsbUP19op1YNcj/LlFffp/u82jHfRejXTnXb7Ntl1qW69FzPFnbwjctK5CkRD RwoO4Clx/UUSGqZ0mZmGg8NtgAmHHs9fIjMpM+bn4BdHgfbznbn7z+eeVn9ey5Mzmnu3 X+hnrPxuMYgcpohe2FBh6Pve57/mNzn2XHIGW1Rqy7w6Spdw7mVTWGnAF7qtqIMRsh44 YXIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=TLZNcw1d9SH4wI8Zf0nXKgmi5A3y+ZK1ObXJei0thLo=; b=gYL69dQTkybr1GpeFm1357KOFQOpTbpEd8oTIeQnrVwm+SLxLL5HxUYUuCGkW+KKK9 fjStt/63boBolEfQcx2rdL2nr/6PyDic3WZCGuh6du8al+24oDfhMGFSOZEzMTV6u0wf aWNTN0hScgCaGLtI1OD9vLRJi7PasPLeLTTyZ/YaE97vaptnuPj+g73J36yjPsHybraK RSj0VGcIGzR9EfTkEo380A3EW5lNcUWa0wJXfJpw1eDRMmlSDBdk8+LBvt7uyvbdQzxJ 1po6RXrJrDVKlOVpOVHioRTrmNg8mzd2B2iHKH4pA8a8XarTWjNW3BDdykpoiZfLAyC9 k/pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=KIeWF3uC; 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=axis.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020aa7988b000000b0064cf289a327si4080313pfl.129.2023.05.26.07.10.50; Fri, 26 May 2023 07:11:05 -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 (test mode) header.i=@axis.com header.s=axis-central1 header.b=KIeWF3uC; 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=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243787AbjEZN5n (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Fri, 26 May 2023 09:57:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243783AbjEZN5l (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 26 May 2023 09:57:41 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86ECF1A8 for <linux-kernel@vger.kernel.org>; Fri, 26 May 2023 06:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685109460; x=1716645460; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=TLZNcw1d9SH4wI8Zf0nXKgmi5A3y+ZK1ObXJei0thLo=; b=KIeWF3uClVvlsfAMx2vhn4bzptqW0/pgvvIOvLxDrV8IKL46g9myRjha xbKOdYYsgmWvQ5RZLoeyyIddl52ebGi5CthFEPoO70hhKEbEtD5Zoq33S yV2y3zkJ9I/oRCDVnzlL2gurATkhVpKsKQDfwPVqdUMr7unVv2bq/RL0M 5O3c3IccIzS47reo6mTG6fpOWF/8FGCPM37hxibB8zt3eoTKplaDQmIru AOnhKbsCByrhbYkUZJc33FSJLA9kyXqU5/r66EiMIDTjwhfnGyJtzSsJg qa6M7k0SbgyaG7z9iwthtPlmC1rvWec66jbYWgl1vPgsOLbJfvbVV6pPW w==; From: Vincent Whitchurch <vincent.whitchurch@axis.com> Date: Fri, 26 May 2023 15:57:30 +0200 Subject: [PATCH mm-nonmm-unstable v2 1/2] squashfs: fix page update race MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20230526-squashfs-cache-fixup-v2-1-6fb7723c3647@axis.com> References: <20230526-squashfs-cache-fixup-v2-0-6fb7723c3647@axis.com> In-Reply-To: <20230526-squashfs-cache-fixup-v2-0-6fb7723c3647@axis.com> To: Phillip Lougher <phillip@squashfs.org.uk>, Andrew Morton <akpm@linux-foundation.org> CC: <hch@lst.de>, <linux-kernel@vger.kernel.org>, <kernel@axis.com>, "Vincent Whitchurch" <vincent.whitchurch@axis.com> X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766966181752825725?= X-GMAIL-MSGID: =?utf-8?q?1766966181752825725?= |
Series |
squashfs: fixups for caching
|
|
Commit Message
Vincent Whitchurch
May 26, 2023, 1:57 p.m. UTC
We only put the page into the cache after we've read it, so the PageUptodate() check should not be necessary. In fact, it's actively harmful since the check could fail (since we used find_get_page() and not find_lock_page()) and we could end up submitting a page for I/O after it has been read and while it's actively being used, which could lead to corruption depending on what the block driver does with it. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> --- fs/squashfs/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 26/05/2023 14:57, Vincent Whitchurch wrote: > We only put the page into the cache after we've read it, so the > PageUptodate() check should not be necessary. In fact, it's actively > harmful since the check could fail (since we used find_get_page() and > not find_lock_page()) and we could end up submitting a page for I/O > after it has been read and while it's actively being used, which could > lead to corruption depending on what the block driver does with it. > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk>
On Fri, 2023-05-26 at 15:57 +0200, Vincent Whitchurch wrote: > We only put the page into the cache after we've read it, so the > PageUptodate() check should not be necessary. In fact, it's actively > harmful since the check could fail (since we used find_get_page() and > not find_lock_page()) and we could end up submitting a page for I/O > after it has been read and while it's actively being used, which could > lead to corruption depending on what the block driver does with it. It turns out that removing the PageUptodate() check entirely wasn't correct. While it's true that the squashfs code only puts the page into the cache after it's been read as I wrote above, migration on the other hand replaces the page in the mapping _before_ copying the contents over, so a PageUptodate() check is still needed. The original problem can be fixed by moving the PageUptodate() check to squashfs_bio_read() and ignoring the cached page entirely if it's not up to date. I'll post a fix shortly.
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index 6285f5afb6c6..f2412e5fc84b 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -92,7 +92,7 @@ static int squashfs_bio_read_cached(struct bio *fullbio, bio_for_each_segment_all(bv, fullbio, iter_all) { struct page *page = bv->bv_page; - if (page->mapping == cache_mapping && PageUptodate(page)) { + if (page->mapping == cache_mapping) { idx++; continue; }