From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38811C433E0 for ; Thu, 28 May 2020 03:47:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F40BB2075A for ; Thu, 28 May 2020 03:47:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PL6zETkb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F40BB2075A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E1958001A; Wed, 27 May 2020 23:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4437E80010; Wed, 27 May 2020 23:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30E0F8001A; Wed, 27 May 2020 23:47:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 11EE280010 for ; Wed, 27 May 2020 23:47:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CE429824556B for ; Thu, 28 May 2020 03:47:00 +0000 (UTC) X-FDA: 76864741800.14.kite45_5a49d3c761612 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id AD3B518229818 for ; Thu, 28 May 2020 03:47:00 +0000 (UTC) X-HE-Tag: kite45_5a49d3c761612 X-Filterd-Recvd-Size: 7576 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 May 2020 03:47:00 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id m67so13380085oif.4 for ; Wed, 27 May 2020 20:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=2qx91aVPuFO0vUiP0/I7F3TMnsxZODsCo0wW/nZA/Ek=; b=PL6zETkbGU9mqzrGsocE1HBzwqKl3IMV7yV8wFZbGm4wHOwRBD8OMMG+y5JKGvCgPi vm5n3+sf1eGzsQmqX4L8++JRmCX3DzLApuWLh2lFuHx1IPNt0zVceXBi8JMZm08yMjJi dgTLtqCBs6olHY2rqJsuK9NL5GyMjlA9kP/Cz6nR6Si2xwGFFoE603kc/Dr53G3rQp6S gFBb+PddTEBGiaWOuBvRGs40Im9zVq8VTNmoIb/MzDf19j1pLiqnHKik2BuMsIkBrRbh TYnm6OVvmQUcyWzw/IOjcAS7zNs0Q98eBrYT94efLyjDduG9AxjlXGJtnrsATHUpOImZ HIag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=2qx91aVPuFO0vUiP0/I7F3TMnsxZODsCo0wW/nZA/Ek=; b=N+K4R3JEC9uphJuAD+SAlomUrW4vO59Tk1cjZgNezwto95UWgbH6ytXULtZnM8J063 ODF0gsrW2AvTVT8A2+vL8LC71QZ3M6uiJcZk8HVqlKrcya7YdW4uKlRNxMSljx3Jod60 UvZL6/LHbedWHGb66mX8mU9C6WCOxjWSIomuWhDnxcS7uCKQ2V72dHvyCXVZBdg7HjnD Tug90HmJDHT5DVTSI6qfoFRup50MWJepALx9xVZl2wED6V0y4nB/2pKXeC1Jh1jKj+HK 9wtVHwq1NQAT0RJSPuN+7/C+yrqkyRcNz3ESi9BRijVNLwcLbc/AH6/3pgTxSBJ6oQob oT+A== X-Gm-Message-State: AOAM531SROeAFfFTvHLnROT9IhnBf4QJ9lBZjk5n/G1jLUGMNk0V5pbC ZBd47XuZW3qqC4iNwmhRpdUG0w== X-Google-Smtp-Source: ABdhPJyOlEQNd0DWG0KMQ3iclWevL0B8TV/DHISOzSWHCezO7ksCSIPPniMHO6dFdL8N85bmZfl1CA== X-Received: by 2002:aca:d856:: with SMTP id p83mr958723oig.38.1590637619384; Wed, 27 May 2020 20:46:59 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id v10sm1036334oov.15.2020.05.27.20.46.55 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Wed, 27 May 2020 20:46:58 -0700 (PDT) Date: Wed, 27 May 2020 20:46:22 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Jerome Glisse cc: linux-mm@kvack.org, Andrew Morton , Huang Ying , linux-kernel@vger.kernel.org, Steven Capper , Catalin Marinas , Rabin Vincent , linux-arm-kernel@lists.infradead.org, rmk+kernel@arm.linux.org.uk, Guo Ren , linux-mips@vger.kernel.org, Ralf Baechle , Paul Burton , James Hogan , Ley Foon Tan , nios2-dev@lists.rocketboards.org, linux-parisc@vger.kernel.org, Helge Deller , "James E.J. Bottomley" , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org, Guan Xuetao , linux-xtensa@linux-xtensa.org, Max Filippov , Chris Zankel Subject: Re: Cache flush issue with page_mapping_file() and swap back shmem page ? In-Reply-To: <20200528002033.GB1992500@redhat.com> Message-ID: References: <20200528002033.GB1992500@redhat.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Rspamd-Queue-Id: AD3B518229818 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Jerome, On Wed, 27 May 2020, Jerome Glisse wrote: > So any arch code which uses page_mapping_file() might get the wrong > answer, this function will return NULL for a swap backed page which > can be a shmem pages. But shmem pages can still be shared among > multiple process (and possibly at different virtual addresses if > mremap was use). > > Attached is a patch that changes page_mapping_file() to return the > shmem mapping for swap backed shmem page. I have not tested it (no > way for me to test all those architecture) and i spotted this while > working on something else. So i hope someone can take a closer look. I'm certainly no expert on flush_dcache_page() and friends, but I'd be very surprised if such a problem exists, yet has gone unnoticed for so long. page_mapping_file() itself is fairly new, added when a risk of crashing on a race with swapoff came in: but the previous use of page_mapping() would have suffered equally if there were such a cache flushinhg problem here. And I'm afraid your patch won't do anything to help if there is a problem: very soon after shmem calls add_to_swap_cache(), it calls shmem_delete_from_page_cache(), which sets page->mapping to NULL. But I can assure you that a shmem page (unlike an anon page) is never put into swap cache while it is mapped into userspace, and never mapped into userspace while it is still in swap cache: does that help? Hugh > This might be a shmem page that is in a sense a file that > can be mapped multiple times in different processes at > possibly different virtual addresses (fork + mremap). So > return the shmem mapping that will allow any arch code to > find all mappings of the page. > > Note that even if page is not anonymous then the page might > have a NULL page->mapping field if it is being truncated, > but then it is fine as each pte poiting to the page will be > remove and cache flushing should be handled properly by that > part of the code. > > Signed-off-by: Jerome Glisse > Cc: "Huang, Ying" > Cc: Michal Hocko > Cc: Mel Gorman > Cc: Russell King > Cc: Andrew Morton > Cc: Mike Rapoport > Cc: "David S. Miller" > Cc: "James E.J. Bottomley" > --- > mm/util.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/mm/util.c b/mm/util.c > index 988d11e6c17c..ec8739ab0cc3 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -685,8 +685,24 @@ EXPORT_SYMBOL(page_mapping); > */ > struct address_space *page_mapping_file(struct page *page) > { > - if (unlikely(PageSwapCache(page))) > + if (unlikely(PageSwapCache(page))) { > + /* > + * This might be a shmem page that is in a sense a file that > + * can be mapped multiple times in different processes at > + * possibly different virtual addresses (fork + mremap). So > + * return the shmem mapping that will allow any arch code to > + * find all mappings of the page. > + * > + * Note that even if page is not anonymous then the page might > + * have a NULL page->mapping field if it is being truncated, > + * but then it is fine as each pte poiting to the page will be > + * remove and cache flushing should be handled properly by that > + * part of the code. > + */ > + if (!PageAnon(page)) > + return page->mapping; > return NULL; > + } > return page_mapping(page); > } > > -- > 2.26.2