Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp103383ybm; Wed, 27 May 2020 20:51:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFYuMauPXKCzmIR+RX7ilufeLu6KgU930qIyJiuQ/FLiwjNm9N12vYFBqfjwF1txLeNOHw X-Received: by 2002:a17:906:fa9a:: with SMTP id lt26mr1165853ejb.297.1590637869625; Wed, 27 May 2020 20:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590637869; cv=none; d=google.com; s=arc-20160816; b=X428gaqfbjqM+YzG54LcitqC0vjN2izmaR5fPGwoLdWvlK6GUV9I3E4TKyzq8K+A2l 42rH9GvlE5CcbCv3j9QpDrsuj9nmEcpgsUixLh4q9MHFTctn93XjoWFek8ARL9BjsLG/ KGTzXzr/3cO8v/HLyEsHVKVCdA15b/8+TcT3wFwIa0W2mxURcUGJySeU2s3fLJp0/JFL WuZ+ne3szmeP0xYDhuexSVxgPcBJ2aDLYfJ30C8pjYbfnubepDTsrRfojMV9zQGmux5w LGjmymLHg5vOaRDTuSPiouSYcx2trzDj5+3aw40EmKjeEcDGrjt1bQp57eNlkukVGRQg DmaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=2qx91aVPuFO0vUiP0/I7F3TMnsxZODsCo0wW/nZA/Ek=; b=BAM71dAkHbXTE5R9/hFqs9iy9wyqhWa+e3ttWEHE+zeYqY4idP4JK3AP8S8rcAf01w Y+xC05G4qpd0g/Gv9nUTtitQwswW0l/Oi2Ri9xIeJKHhtmop8FiZxrEw9KmQyric9m93 oUbcJzVaqc40CX0BajQtHBe39a10YwLk3QLIvJqD2D6u2ibWjjOJjlH6t5de0wgmwp1p doB4tjSqr0d4HYL312uLPO+hBXBVE3KZRUon02IzDRR0L69GJrU+Wm+C2NFpG4VIvWcY +MKBXxHQMUHWniv9E2d5EbyagZ8q4yrrt/wb3kS8IvJaX6jKX4S/3XTEMbRI8kLOMzJa G1RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PL6zETkb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si2975312edm.572.2020.05.27.20.50.46; Wed, 27 May 2020 20:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PL6zETkb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbgE1DrB (ORCPT + 99 others); Wed, 27 May 2020 23:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726907AbgE1DrA (ORCPT ); Wed, 27 May 2020 23:47:00 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779C2C08C5C2 for ; Wed, 27 May 2020 20:47:00 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id a137so236571oii.3 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=pXDhAE/llim+ESsa+2sIG3PkdQ9Zz9B2lepsZMFI1/GlHkVnFBfNFj+tyPVmfdpJ7s zQw8ueqqV54FyBD5dCWTxSKg2ktK4gV1LoMTH+Q1m+joPpx5kyLmjE2/J/Q3eS0cYb6Q 9050qAZssRHN0DgMJquiEeWRWr6mx8Q68LGiA3X95L0s5el4+H+LXeXp/lZZRM8MdGUl zhyzguU7nUFsBzcJQBzqRY+yGF6u9zAw/xpTt0lGc4cIui09WyP53fDp2wAJQ+E/a8Nx wMCfxRPENTNdHF9D+nNr1vRgo6tBFHCtPrgnvNO74m2AS1eQy/RmNPS9bqYTRxOeW7Qw EncQ== X-Gm-Message-State: AOAM530VISMGCxLQ27pWfitmiZ+Yb1JQWtmKj9Otd0APbMSIUqLsAV5w V2aIEjpYrijxHF8hUI0+VFDEmQ== 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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