From: Hugh Dickins <hughd@google.com>
To: Jerome Glisse <jglisse@redhat.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Huang Ying <ying.huang@intel.com>,
linux-kernel@vger.kernel.org,
Steven Capper <steve.capper@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Rabin Vincent <rabinv@axis.com>,
linux-arm-kernel@lists.infradead.org,
rmk+kernel@arm.linux.org.uk, Guo Ren <guoren@kernel.org>,
linux-mips@vger.kernel.org, Ralf Baechle <ralf@linux-mips.org>,
Paul Burton <paulburton@kernel.org>,
James Hogan <jhogan@kernel.org>, Ley Foon Tan <lftan@altera.com>,
nios2-dev@lists.rocketboards.org, linux-parisc@vger.kernel.org,
Helge Deller <deller@gmx.de>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
linux-sh@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
sparclinux@vger.kernel.org, Guan Xuetao <gxt@pku.edu.cn>,
linux-xtensa@linux-xtensa.org, Max Filippov <jcmvbkbc@gmail.com>,
Chris Zankel <chris@zankel.net>
Subject: Re: Cache flush issue with page_mapping_file() and swap back shmem page ?
Date: Wed, 27 May 2020 20:46:22 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.11.2005272021220.3857@eggly.anvils> (raw)
In-Reply-To: <20200528002033.GB1992500@redhat.com>
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 <jglisse@redhat.com>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
> ---
> 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
next prev parent reply other threads:[~2020-05-28 3:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 0:20 Cache flush issue with page_mapping_file() and swap back shmem page ? Jerome Glisse
2020-05-28 3:46 ` Hugh Dickins [this message]
2020-05-28 11:20 ` Jerome Glisse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.2.11.2005272021220.3857@eggly.anvils \
--to=hughd@google.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=chris@zankel.net \
--cc=dalias@libc.org \
--cc=davem@davemloft.net \
--cc=deller@gmx.de \
--cc=guoren@kernel.org \
--cc=gxt@pku.edu.cn \
--cc=jcmvbkbc@gmail.com \
--cc=jglisse@redhat.com \
--cc=jhogan@kernel.org \
--cc=lftan@altera.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=nios2-dev@lists.rocketboards.org \
--cc=paulburton@kernel.org \
--cc=rabinv@axis.com \
--cc=ralf@linux-mips.org \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=sparclinux@vger.kernel.org \
--cc=steve.capper@linaro.org \
--cc=ying.huang@intel.com \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).