From patchwork Thu Jun 29 14:17:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 114318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9679475vqr; Thu, 29 Jun 2023 07:28:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76y58qU2CHH6lQ+yeOI197qTCimT4PS7Z2cMPsnVUS2d8Snorlf/78SnD/U9hdElo/uErw X-Received: by 2002:a17:902:f984:b0:1b8:811:b05a with SMTP id ky4-20020a170902f98400b001b80811b05amr12384644plb.6.1688048909610; Thu, 29 Jun 2023 07:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688048909; cv=none; d=google.com; s=arc-20160816; b=T21Pfg+sq+ua1KfFkeUnAPgjtBI5eag7fzw/7ce0Rg8LHcAXsAu67u89z3Vjt2U5lw EArjJhnLyFz2uuASXNbIP0BNKnqoTYAJ6rt/ws50grVrpNbHb+OyKVwsHjSg3yjsHOI0 3/jaAh7ZvHUjAH+ELTMDHFZQNaTIUqdU/q/9DI2AKYESUtMVMROsKc9/UDWx7/92Ze6R 4n46+BYyzvCuWYswPaz0Wiqew/n4ZrLQMZdzBs+8lx/fvPKN+/mT6UUvQq54dqnI1GhO /yX3pjG/uSdixFwRQg2jJVdiEqTXTxQCzSLY9aGEObgJahbLGYZCzK8D2wF7vxsM5G8c eqUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=/EACAvCkqaq5SWsngoSCmDYPrtH4Wz7SJv4BW6QmdMI=; fh=SGmGsssWH0U0avnEN+LznPu5QDdML/kD+hwJB+00Ip4=; b=T57JGT3xbMEdR1LID86bxHgvhiR39cPz52K6tFTkkt0LO1Uv7qAxpw/xdu3YMxLkCF RRbqLHVG1koAYzPpAvGxoaELbquCrIyxJ/DDaTrAREa0CYl27aBJ4nVqCDmDJekpk8Nc 9J1aCePstSiky0AHkqBsxwn3RsgkBX4u+UBmu5Icfuaa/OP1ATNOAGltEAaGpPpQB458 irnT6Pa8RLrjoNoVjeJaNRCd8ZgT8Wdybu0WZsmAMCu4+JAVpB7mMANPJS+Iedeo/73q rzFcXExzAtQgblwQS2px2wUuflbU6h8hTtbestkHDbWBdtrdgvuPasKTrmUIADoBABPf ueLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=bBbcSEsx; 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 n15-20020a170903110f00b001b041591a5fsi11359003plh.459.2023.06.29.07.28.16; Thu, 29 Jun 2023 07:28:29 -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=bBbcSEsx; 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 S231550AbjF2OSY (ORCPT + 99 others); Thu, 29 Jun 2023 10:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbjF2OSJ (ORCPT ); Thu, 29 Jun 2023 10:18:09 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34DDA1737 for ; Thu, 29 Jun 2023 07:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1688048287; x=1719584287; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=/EACAvCkqaq5SWsngoSCmDYPrtH4Wz7SJv4BW6QmdMI=; b=bBbcSEsxarDnMjaFAdXLmJ7oTwjegItzZ/M7U3u74beXPcGsDYIHb4Zc sdWSQxjmRwlgSOioXtJuD0vvzdEQSLP9raqfyIg81NV76oXmf2BLc7F+O rQBuITpEmfASG+DRmMBZc14gHcXJ94THixkb2NudyWrxSbE3AkFTmfWki Ug2s9eaNojh83qZINUM8yxXj13MGbWLSIWMJwSf88nKs89PgjwN06JQtB 0sgWscodyCeeEATB1gI4B7fScMvfAMqAFtjf38nsF7GptBT6OxwiCT8qP v4ywD5cV9DTr0a3qXHAlvYYBtGXNGyynBvmZTNi8myn/h620TKyZRU911 g==; From: Vincent Whitchurch Date: Thu, 29 Jun 2023 16:17:57 +0200 Subject: [PATCH] squashfs: fix cache race with migration MIME-Version: 1.0 Message-ID: <20230629-squashfs-cache-migration-v1-1-d50ebe55099d@axis.com> X-B4-Tracking: v=1; b=H4sIAJSSnWQC/x2NQQ7CMAwEv1L5jKU0TUHlK4iDG5zGBxKwASFV/ Tspx1lpZlcwVmGDc7eC8kdMamnQHzqImcrCKLfG4J0f3NFPaM83WU6GkWJmvMui9GoS+lM/Bhp dCmGCps9kjLNSiXkPpFqHfX4oJ/n+Hy/XbfsByl3ZJYEAAAA= To: Phillip Lougher , Andrew Morton CC: Christoph Hellwig , , , Vincent Whitchurch 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 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?1770047573271946128?= X-GMAIL-MSGID: =?utf-8?q?1770047573271946128?= Migration replaces the page in the mapping before copying the contents and the flags over from the old page, so check that the page in the page cache is really up to date before using it. Without this, stressing squashfs reads with parallel compaction sometimes results in squashfs reporting data corruption. Fixes: e994f5b677ee ("squashfs: cache partial compressed blocks") Signed-off-by: Vincent Whitchurch --- fs/squashfs/block.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) --- base-commit: 3a8a670eeeaa40d87bd38a587438952741980c18 change-id: 20230629-squashfs-cache-migration-27154a50f449 Best regards, diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index 6aa9c2e1e8ebe..581ce95193390 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -166,6 +166,26 @@ static int squashfs_bio_read_cached(struct bio *fullbio, return 0; } +static struct page *squashfs_get_cache_page(struct address_space *mapping, + pgoff_t index) +{ + struct page *page; + + if (!mapping) + return NULL; + + page = find_get_page(mapping, index); + if (!page) + return NULL; + + if (!PageUptodate(page)) { + put_page(page); + return NULL; + } + + return page; +} + static int squashfs_bio_read(struct super_block *sb, u64 index, int length, struct bio **biop, int *block_offset) { @@ -190,11 +210,10 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length, for (i = 0; i < page_count; ++i) { unsigned int len = min_t(unsigned int, PAGE_SIZE - offset, total_len); - struct page *page = NULL; + pgoff_t index = (read_start >> PAGE_SHIFT) + i; + struct page *page; - if (cache_mapping) - page = find_get_page(cache_mapping, - (read_start >> PAGE_SHIFT) + i); + page = squashfs_get_cache_page(cache_mapping, index); if (!page) page = alloc_page(GFP_NOIO);