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=-8.2 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 F159DC433E0 for ; Thu, 28 May 2020 03:47:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0AD02075A for ; Thu, 28 May 2020 03:47:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jPwRPS2b"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="PL6zETkb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0AD02075A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:Message-ID: In-Reply-To:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pYPqtEPgpPYPjjCTHb/xF/V2BUP5HHmkElhT46Xgk5U=; b=jPwRPS2bc87QFw h0q1qMlyJiagZiT7nrTcgzieOvCEnfm1Z7ZF+UKtEMOo4791zUUugJlL3GJtGPqPVvIKBTcmRKLH7 eTjbFcSO3nyZHL7+Z+9oN+++jWtei6Hkq5oc9XtDrbsPyCLEeuMEF7ZlxC1k7DZQWxFdT/yyvNQeW +fIWwJbuAP5iH/YwypmtwB50m6u7KKXjzjniemuZdgZiuEf/Fm4SoYxs8sOgQxnityovXmzck5Vjb msBNGMhjROljM8yMytkGBPsWSTiQqSE/rUPejOvGEyYdCiIBYoCwL4D6XW6CCE2TmjVnIiiY0cMfa /gcf5f2kAh2XWnwJeQrg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1je9Ve-0006Tk-Os; Thu, 28 May 2020 03:47:10 +0000 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1je9Vc-0006Rv-1r for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2020 03:47:09 +0000 Received: by mail-oi1-x243.google.com with SMTP id w4so23803304oia.1 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=RPG0qFzyvyqUTtIklYg870B9t7bj2xLGa7vM4VXIKS+qRW9icmKJ2Q27bFUfGXS/rV eMVzLtxLTNYQAAXFOjjvMwTXT+A9L/g8E42j6IzvmcXt/aLjOL0qlBdSSS5xhJ4RB3Dl SqkAJUSJcxif2MXH0Fh5oBj8DH4SI38DtWYF2AJrld2IBaPWyg+4PdSG+QLiDtVlVzm7 dzLPikl7ac8BqUUXyArmxpPgEcg+fwSrSw0ni9N7T7kxB06+l8Q72wuJ4t1J7UtdgWM4 9vSPBnoSrRwnnazopcEBRpHacHtfM4OY0Pn8zrOUebAr+74NcCM09WUXgGxxEc7xub/P gc0w== X-Gm-Message-State: AOAM532BOcVwxOvCq15h8VjvL3kcX7jPnSpUnRra4Lz0ryyIokFb3NNb LONkBs7HGf8kErsZgfxfn1potw== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200527_204708_097519_59973E13 X-CRM114-Status: GOOD ( 29.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rich Felker , linux-sh@vger.kernel.org, Catalin Marinas , linux-mips@vger.kernel.org, "James E.J. Bottomley" , linux-mm@kvack.org, Guo Ren , sparclinux@vger.kernel.org, Paul Burton , Helge Deller , Huang Ying , James Hogan , rmk+kernel@arm.linux.org.uk, linux-xtensa@linux-xtensa.org, Steven Capper , Rabin Vincent , Ley Foon Tan , Guan Xuetao , linux-arm-kernel@lists.infradead.org, Chris Zankel , Yoshinori Sato , linux-parisc@vger.kernel.org, Max Filippov , linux-kernel@vger.kernel.org, Ralf Baechle , nios2-dev@lists.rocketboards.org, Andrew Morton , "David S. Miller" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel