Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp121031imn; Tue, 2 Aug 2022 20:20:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR5lczsKryE6A8FTeO8pCx84cUsKhcLI/t+0JCqJUbPEdg8qX71O6OeKA3ZudbuW8Jv/ORGU X-Received: by 2002:a63:90c1:0:b0:41b:d351:f338 with SMTP id a184-20020a6390c1000000b0041bd351f338mr13895325pge.228.1659496804115; Tue, 02 Aug 2022 20:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659496804; cv=none; d=google.com; s=arc-20160816; b=WEXkhtWMiH55Qwh0W5VWZE0b7/XT/YuaLwgdblOZtZnAYIi6jxGIgA1zzDuh9rFEQa Pp2fEZkV2mxr7aw1aUMoJLEJVK2kHtxAQC2xMObMMSTEy2jBwfehCDBeIwNgiMrRxlD8 XYEfK5DucKNLB47ZBkqgze+t3hZupsdLT6qTuwkPWOxYKXkVH+yd9M+E+8kCkOG/yZ97 Sm6sRI5teZcKXVqYVSzELQBhORPs3qLIchqWCCu8QZjVqXV51jrM+oUAZKDdsFklpDgy SmKxqTcK4TTqq9rUCkKVmJXGXdvW56kN5FIXXgqxwzK1O1P04DmRssARxALBBdG29Gsz qjJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5RRVQl4J+7WXKkaGNwelJxyZ6SmgqBWySND67zzTwmQ=; b=gOwC2BnDfgjT0FH4ulMGXrEeV86yOhWjS1oIFyzgkF+IQa1EOfff0JTxwfIu0yRoxp HSfZu7+QcdWk6GFdf9pnHS/QJFW3yWhUh+tUeOUlNpQuZfQxbrtcytKfKHM8Lyfb6R7T LbfRq+4rBv4JHvo0jG+qm2Hhg4e6RL83aFXjzSdUoAjAH3XjTl/BC1JArtBL8KPbNLMJ PcW20Shfr5SNNh/Dy6D8hSqKdGtpb9HstbUvoVD8He0A+OZtapAZUk2iB26qoIo2PgVf +ukKGIrbDzBmnw6iTjlK6W+S3iH2aLTPfUpSu+DF7bb5mKdOx5BHMpAQyn5CqvM6R6HC TlPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WbnMhlm0; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp6-20020a170902e78600b0016ef52451aasi1072685plb.99.2022.08.02.20.19.47; Tue, 02 Aug 2022 20:20:04 -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 header.i=@infradead.org header.s=casper.20170209 header.b=WbnMhlm0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbiHCDSA (ORCPT + 99 others); Tue, 2 Aug 2022 23:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbiHCDR6 (ORCPT ); Tue, 2 Aug 2022 23:17:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB67932D8E for ; Tue, 2 Aug 2022 20:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5RRVQl4J+7WXKkaGNwelJxyZ6SmgqBWySND67zzTwmQ=; b=WbnMhlm0UwFM0Dewke3HjZ/48z Uyw4PHUlinyN876MkcaaNskBIdOLY5gBEWAgtMEZX4bw08pW2pwYF3N4Gkb/wqWdZWdyU6XxTcN1v 5Jm0I8ugS09D623Lyt6uQGql+5w2Tb9zcYuI8CxpCH0SVHv0Ov8HlEQZlJpg0wXkQG3hs6vJpn+Dn pVli00qM/OOk4O3RE2yjPduiQol2d4DTz7scKAlkcc3bLwICr7I3gx4iI3uuci0l3Pg040ZlqyZiq 1EDgTHuEJOwSiYiMwntBqRRZDcn76Ib8sU34kA5Pa/7jwTadOeXWsvBxMO4D2hLluXDBCdKYGhias JUcoBCGQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJ4tK-008vai-QL; Wed, 03 Aug 2022 03:17:50 +0000 Date: Wed, 3 Aug 2022 04:17:50 +0100 From: Matthew Wilcox To: Andrew Morton Cc: Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] shmem: Update folio if shmem_replace_page() updates the page Message-ID: References: <20220730042518.1264767-1-willy@infradead.org> <20220802174637.3bd3478d137b52ef3b67c3b3@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220802174637.3bd3478d137b52ef3b67c3b3@linux-foundation.org> 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_NONE, SPF_NONE 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 On Tue, Aug 02, 2022 at 05:46:37PM -0700, Andrew Morton wrote: > On Sat, 30 Jul 2022 05:25:18 +0100 "Matthew Wilcox (Oracle)" wrote: > > > If we allocate a new page, we need to make sure that our folio matches > > that new page. This will be solved by changing shmem_replace_page() > > to shmem_replace_folio(), but this is the minimal fix. > > > > ... > > > > --- a/mm/shmem.c > > +++ b/mm/shmem.c > > @@ -1771,6 +1771,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, > > > > if (shmem_should_replace_folio(folio, gfp)) { > > error = shmem_replace_page(&page, gfp, info, index); > > + folio = page_folio(page); > > if (error) > > goto failed; > > } > > What are the user-visible runtime effects of the bug? > > Should we backport this into 5.19.X? Definitely should be backported. The next line not visible in this patch context says: error = shmem_add_to_page_cache(folio, mapping, index, swp_to_radix_entry(swap), gfp, charge_mm); so if we do end up in this path, we store the wrong page in the shmem inode's page cache, and I would rather imagine that data corruption ensues.