From patchwork Fri May 26 13:25:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 99491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp480651vqr; Fri, 26 May 2023 06:38:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DiAD4x3YVxuLyTKJN7sd5p7TEuIcYInPWSB0kCiofNKXNAOlBbIiUjUsJPMH416aRr5K2 X-Received: by 2002:a05:6a20:3944:b0:10c:4a13:a5cf with SMTP id r4-20020a056a20394400b0010c4a13a5cfmr2226050pzg.6.1685108336199; Fri, 26 May 2023 06:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685108336; cv=none; d=google.com; s=arc-20160816; b=phI7+xE/LCBazNLCoZ9/cQ8pKnBLGRd9Q97ORBXiNcBQN32jnNHNGm6aRhm45D8fIi Syg/x70bCwj/txTo7puAJofls+maIsmJqWrY8VJr/qywqyb6Ag6XoN+natAD9QKKIH0+ pV7vP4ljyM9kxEeOzkBFFW9DfZuF39iekQlECeurPcx7QvJ4i8Ugf8j1espz1DZHUiEq c9jFHyDTCyjSPRb0rsMJ8caL/xj1pG3ou3f2Pv0BPyzFVnB7rmSIBhCmZ6XaOPzzkLKe R6j8+61p3aA1qir2LEPXeDhAVVPnxo9ANwmG5TrgPDYCNLf2k2+WORdo7pSCrYIkt9gD Q/ww== 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=vQ6s9WHOVRERw63K8NCydHFioykHH4Lnjaq5pXtH6Qw=; b=wxsW1lIoqeKswY1du5L7kCu7dn4SQZVt3nAFNJu4IJi5yoDRe3iFRwMh4Cga5OmYSJ Y2WiJK1dJFzo6czGyUuhr5tXrcAVMRKJV/GhlD330IlZZAeOWk/l633Js39hGqteMSUr 39+Qz1YyheMCDgWv9tVqqXp+UfyWEGSZ9j1MqftYGTeMZX9XOOMYwwvUvqLydREQNall GgOxtqfGfYb5GRABt/nFmSoLHDlHK3XPX+iXQNYAJeiHgGxJkpWJx1Kwu47oF/UZsC+U nCGrOLj9An2jPv3etA2Qy9GJiHktelDmZ0AWIO3fEYqReWu8tpN9pZb0euZD52HOQr9h xvoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=BYQME4zL; 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 y22-20020a637d16000000b00534266e33d9si3501916pgc.269.2023.05.26.06.38.43; Fri, 26 May 2023 06:38:56 -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=BYQME4zL; 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 S243518AbjEZN0I (ORCPT + 99 others); Fri, 26 May 2023 09:26:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237139AbjEZN0G (ORCPT ); Fri, 26 May 2023 09:26:06 -0400 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF8995 for ; Fri, 26 May 2023 06:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685107561; x=1716643561; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=vQ6s9WHOVRERw63K8NCydHFioykHH4Lnjaq5pXtH6Qw=; b=BYQME4zL2VDlIAMPa3qQaGjq+liFxdWz55rihtik6M/neJ77i32R4rkT riL/Uu93cQq9EiWy9zDqcjgGaszkayZ2eu29HA11suW/pZIFbEOnied67 KP39r9f1c/rd8BrxuyCMOUcX0fjvbvld195Vy+Ao79Clgx4J5YBlhyhu1 lqEZkDsr1v0lPQKZR9xIXYjGnmrRtkSuwBmuFoJmaSk5LDjJWRRToPYa3 wK8LAMSJhgc9diZ3Prlcm8Zws4tgBFMMQbhGV1r9TVFLT4FnSanT4XsJV +Yl5RTxmHo3qvc8NWaduUTfVq0JErP3epHXP69Sdh0ajWDdP+b3w9jxkG Q==; From: Vincent Whitchurch Date: Fri, 26 May 2023 15:25:45 +0200 Subject: [PATCH mm-nonmm-unstable 1/2] squashfs: fix page update race MIME-Version: 1.0 Message-ID: <20230526-squashfs-cache-fixup-v1-1-d54a7fa23e7b@axis.com> References: <20230526-squashfs-cache-fixup-v1-0-d54a7fa23e7b@axis.com> In-Reply-To: <20230526-squashfs-cache-fixup-v1-0-d54a7fa23e7b@axis.com> To: Phillip Lougher , Andrew Morton CC: , , , "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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766964158820308674?= X-GMAIL-MSGID: =?utf-8?q?1766964158820308674?= 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. Signed-off-by: Vincent Whitchurch Reviewed-by: Christoph Hellwig --- 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 = bv->bv_page; - if (page->mapping == cache_mapping && PageUptodate(page)) { + if (page->mapping == cache_mapping) { idx++; continue; } From patchwork Fri May 26 13:25:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 99495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp488283vqr; Fri, 26 May 2023 06:51:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ODuZHZUR44Hpy0ejfTMVhdv/qlhwgNbWEUSV61JmT2gF8Knsws0Jje7TQ6qb0CJWBeqGL X-Received: by 2002:a17:902:cece:b0:1ae:8bd9:e015 with SMTP id d14-20020a170902cece00b001ae8bd9e015mr3523182plg.5.1685109084654; Fri, 26 May 2023 06:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685109084; cv=none; d=google.com; s=arc-20160816; b=d/N3kslyyofZsdpcJ84CXts6MrcWYTAh4LH8e7pGGBFuEs8yHKzrgcn+4FrkzJJRGb EgNRumM61JtlPpY+L4LsfWSUp4bjVNDzFIx+3HQ1VpD+ks/y3WWOOm8K667MS4uSiYkR dHSj7TVvr/ec1N5w3WBYfzFowa9u7X8lnZlEjJu4mY5BvzkUtExmg+YlcjEuZfDI0T8h ijzhmjkuLw3BbZ3+WvG803pztXApfh2tOMeq/Bux2pIx8+5gYYeK1eVt7DPu8qrKcrCX Ibbik6EfSx1vTgLDICPABPn/4ZsYbWIJD/qBfu9kdjllMWDcSjfOVm1pLLvsJHj/VdJl 2sWw== 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=kGcEORmcjqsDDRn5OZ/5Wb++WiIzuQvNjLEwUt1X/v0=; b=NsTAajDdGGGdiACKFaUzX+6d4/PFB72fAyXcJwcvXR4M9rCiVybYsh5J5+HVmj830Z bqmOvl+7zyLjqpxDWcMRATeqiJm9893+KnJhWSId9qq22bjFEtNTjKSMuEWNRJeNdSy+ GpCHU9kL/1jIMUBdPTkZ5o0nFJEBRMalgfjlHMYqYvhB46jfG9HuiL7LsDDcZPa7/LsI cQEU9eU/vEHqMI8WkSUwXKoyX1+BDGKJRWzmzP0bx3fTd8av7YwRzd9DpFJ8TWdaG9TR YNS9f7NAGkUh12oSP3jlxoKdB3hb6hcqF1ctf7RyQ/LaZrm9NvWZ4QLATP4f66zpepX4 HP7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=U2fu9L9r; 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 z10-20020a170903018a00b001ac59bc1c20si4442570plg.47.2023.05.26.06.51.11; Fri, 26 May 2023 06:51:24 -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=U2fu9L9r; 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 S243694AbjEZN0L (ORCPT + 99 others); Fri, 26 May 2023 09:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237139AbjEZN0J (ORCPT ); Fri, 26 May 2023 09:26:09 -0400 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B434198 for ; Fri, 26 May 2023 06:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685107567; x=1716643567; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=kGcEORmcjqsDDRn5OZ/5Wb++WiIzuQvNjLEwUt1X/v0=; b=U2fu9L9r7bpc9dUPuKYddjM+Gx75LNY0uyuVzjR7bd+OVv9r0d3NqdHh ERkryOqhnXXznDSBUI3xCpYhC9QjA4kIMOFKCr3JtgbNAM6C8eKu5yI06 MtDXem4OqufNrboivXNZiuR+B8eH7CX8b3spyEp/bIctBj9we/PFab29G Yv4dfCnPwzmwxVseVZqBU9rbxZJyDeLWgPvvODJJdGZC/iIr6X8LpmAyj FGNJbrItp2pa0T3Fr1v7SEFfEGjKIFs7A45C2p8G3C+D+zqFlYXJuvvPA myk0PqbTSYqv+r9fRHWo8sPfEjSRU4SEFiaZRPHNUbWdRkgGVadaMZ4Fe Q==; From: Vincent Whitchurch Date: Fri, 26 May 2023 15:25:46 +0200 Subject: [PATCH mm-nonmm-unstable 2/2] squashfs: fix page indices MIME-Version: 1.0 Message-ID: <20230526-squashfs-cache-fixup-v1-2-d54a7fa23e7b@axis.com> References: <20230526-squashfs-cache-fixup-v1-0-d54a7fa23e7b@axis.com> In-Reply-To: <20230526-squashfs-cache-fixup-v1-0-d54a7fa23e7b@axis.com> To: Phillip Lougher , Andrew Morton CC: , , , "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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766964943472351331?= X-GMAIL-MSGID: =?utf-8?q?1766964943472351331?= 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 --- fs/squashfs/block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index f2412e5fc84b..447fb04f2b61 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -142,7 +142,7 @@ static int squashfs_bio_read_cached(struct bio *fullbio, if (head_to_cache) { int ret = add_to_page_cache_lru(head_to_cache, cache_mapping, - read_start, GFP_NOIO); + read_start >> PAGE_SHIFT, GFP_NOIO); if (!ret) { SetPageUptodate(head_to_cache); @@ -153,7 +153,7 @@ static int squashfs_bio_read_cached(struct bio *fullbio, if (tail_to_cache) { int ret = add_to_page_cache_lru(tail_to_cache, cache_mapping, - read_end - PAGE_SIZE, GFP_NOIO); + (read_end >> PAGE_SHIFT) - 1, GFP_NOIO); if (!ret) { SetPageUptodate(tail_to_cache); @@ -192,7 +192,7 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length, if (cache_mapping) page = find_get_page(cache_mapping, - read_start + i * PAGE_SIZE); + (read_start >> PAGE_SHIFT) + i); if (!page) page = alloc_page(GFP_NOIO);