From patchwork Thu May 28 00:20:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 11574081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16040912 for ; Thu, 28 May 2020 00:20:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC1C420FC3 for ; Thu, 28 May 2020 00:20:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h1jtgxnA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC1C420FC3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA5908001A; Wed, 27 May 2020 20:20:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E54EF80010; Wed, 27 May 2020 20:20:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6A818001A; Wed, 27 May 2020 20:20:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id BF05480010 for ; Wed, 27 May 2020 20:20:53 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6DF29181AEF00 for ; Thu, 28 May 2020 00:20:53 +0000 (UTC) X-FDA: 76864222386.22.vein07_24b8f4d497f46 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 429D318038E6B for ; Thu, 28 May 2020 00:20:53 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jglisse@redhat.com,,RULES_HIT:30006:30012:30054:30064:30090:30091,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: vein07_24b8f4d497f46 X-Filterd-Recvd-Size: 6260 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 May 2020 00:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590625251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3NfM/YRWw8tWtCVntluiCugDqJX5J7Mi6y5RyulO5Co=; b=h1jtgxnAzQph09mJabMY9jcpazYEL6ChAclXRyCVqvk48TUdURDvVLybKR2meXwzlrcDd9 MognWJ/M1FsGJrY4zUKWE4ffh7RjKWYAOjBNXcAf7zvgMgokqj9pOjguI3N62SODbJSRF0 08MFNT7zwUxvvkyf2sbdXlUcg7yXw4k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262--4PlExgtPwKJVseeIiuy9A-1; Wed, 27 May 2020 20:20:44 -0400 X-MC-Unique: -4PlExgtPwKJVseeIiuy9A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D96EC460; Thu, 28 May 2020 00:20:40 +0000 (UTC) Received: from redhat.com (ovpn-119-19.rdu2.redhat.com [10.10.119.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FCE85D9CC; Thu, 28 May 2020 00:20:35 +0000 (UTC) Date: Wed, 27 May 2020 20:20:33 -0400 From: Jerome Glisse To: linux-mm@kvack.org, Andrew Morton , Huang Ying Cc: linux-mm@kvack.org, 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: Cache flush issue with page_mapping_file() and swap back shmem page ? Message-ID: <20200528002033.GB1992500@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Queue-Id: 429D318038E6B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: 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. Cheers, Jérôme From 6c76b9f8baa87ff872f6be5a44805a74c1e07fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= Date: Wed, 27 May 2020 20:18:59 -0400 Subject: [PATCH] mm: fix cache flush for shmem page that are swap backed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Jérôme 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); }