From nobody Sun Feb 8 02:56:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7234CC77B73 for ; Fri, 26 May 2023 13:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243790AbjEZN5o (ORCPT ); Fri, 26 May 2023 09:57:44 -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 ); 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 ; 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 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: quoted-printable 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 , Andrew Morton CC: , , , "Vincent Whitchurch" X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Vincent Whitchurch Reviewed-by: Phillip Lougher --- fs/squashfs/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 =3D bv->bv_page; =20 - if (page->mapping =3D=3D cache_mapping && PageUptodate(page)) { + if (page->mapping =3D=3D cache_mapping) { idx++; continue; } --=20 2.34.1 From nobody Sun Feb 8 02:56:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85586C7EE2C for ; Fri, 26 May 2023 13:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243781AbjEZN5m (ORCPT ); Fri, 26 May 2023 09:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243780AbjEZN5k (ORCPT ); Fri, 26 May 2023 09:57:40 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4740EF3 for ; Fri, 26 May 2023 06:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685109459; x=1716645459; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=4n8uWwoKijuf7hNq7pa6eDg5K8Opr8XjUEd1CHMUr5Q=; b=Z4Qhd1HaPyBYT/3hKcPykXUdMHlRUjMoitobLFnFMNVvzG20o+wtN/1k qz5+VYMu0ENl107lr1jXK/I72S+rKiJLsN3lbCZu1922d5AuN9PlYF4K/ PVdxD5jWc/SOyYz8NK35Mllq7FStFKEn9txAH6RroiGQsqJ2Zo+slRAuQ O2aKgxMyRgfUmcu6HjV6n9T8yZbDdtKL6hiQ16VqhioJn9iBXvKCxCVUI e3BAvnzrJEKxr+8kbS0EwIOXDuxsqzDMyEElkzMZnf2mQTu+5+8meR1oO 78XsKHb9jmHW2Z9SEr/TwfsKjah7v3zPHOZSLYp+/0h11Sv5hcI2WKrk9 w==; From: Vincent Whitchurch Date: Fri, 26 May 2023 15:57:31 +0200 Subject: [PATCH mm-nonmm-unstable v2 2/2] squashfs: fix page indices MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20230526-squashfs-cache-fixup-v2-2-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 , Andrew Morton CC: , , , "Vincent Whitchurch" X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The page cache functions want the page index as an argument but we're currently passing in the byte address. Signed-off-by: Vincent Whitchurch Reviewed-by: Christoph Hellwig Reviewed-by: Phillip Lougher --- fs/squashfs/block.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index f2412e5fc84b..6aa9c2e1e8eb 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -142,7 +142,8 @@ static int squashfs_bio_read_cached(struct bio *fullbio, =20 if (head_to_cache) { int ret =3D add_to_page_cache_lru(head_to_cache, cache_mapping, - read_start, GFP_NOIO); + read_start >> PAGE_SHIFT, + GFP_NOIO); =20 if (!ret) { SetPageUptodate(head_to_cache); @@ -153,7 +154,8 @@ static int squashfs_bio_read_cached(struct bio *fullbio, =20 if (tail_to_cache) { int ret =3D add_to_page_cache_lru(tail_to_cache, cache_mapping, - read_end - PAGE_SIZE, GFP_NOIO); + (read_end >> PAGE_SHIFT) - 1, + GFP_NOIO); =20 if (!ret) { SetPageUptodate(tail_to_cache); @@ -192,7 +194,7 @@ static int squashfs_bio_read(struct super_block *sb, u6= 4 index, int length, =20 if (cache_mapping) page =3D find_get_page(cache_mapping, - read_start + i * PAGE_SIZE); + (read_start >> PAGE_SHIFT) + i); if (!page) page =3D alloc_page(GFP_NOIO); =20 --=20 2.34.1