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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 D5D8FC433E0 for ; Thu, 28 May 2020 00:23:23 +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 91E88207CB for ; Thu, 28 May 2020 00:23:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZqFXG1rf"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DtC9ez39" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91E88207CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Subject:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=MoDp61WoGDoXfGN1naQOJpCHxFS5LyHnwfZXqb9FRjY=; b=ZqFXG1rf2lgvxS nGKsdhrN7BekbqgjhpgkODIv5O+DaI2+XRDcn90P4wwdm0ZL2kJQXLt4V7Gi7rf/MWAhVoppyE9MX CrkY3670GoOj6jN9IBbXSgz9Th3JxshPQAZ2Me+lg8SaiONpHS7ljrkIqfaxBCJ48K5mZDoOMHmSZ ndpIh9x67x364EUpFb2rm4pauw/iBwG4xfsRnulDLOA34jfBsSnficOWrCdhFwJCEL8O0RoHVtNPj ZACY04z0EWND196+fr0oZq7sbyPxfQuyuRj6I/oK7Lim6KsPy2zLBp6vFqCuUQmvuJ22du1zvYRar Y2bcj1KMYWOw2peJ5H8A==; 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 1je6KC-0005yc-Q2; Thu, 28 May 2020 00:23:08 +0000 Received: from us-smtp-1.mimecast.com ([207.211.31.81] helo=us-smtp-delivery-1.mimecast.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1je6K8-0005xe-S7 for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2020 00:23:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590625381; 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=DtC9ez39MIRaRkHUY0UQA794jqsVcW7kxaLCrUXsPs86TOSWcskoUyvPOReoQ1k0mSvVmD ry6D6mQI2T7LNNrBUJb0bRds9FkyQblbQnkLWiyAMEGgsntgY2fswh0QnuVjRNAOas+R1V UEGCsiRCAmPlilvPMbbf5dqx11PEoVA= 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 Subject: Cache flush issue with page_mapping_file() and swap back shmem page ? Message-ID: <20200528002033.GB1992500@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200527_172305_115518_36BD1A71 X-CRM114-Status: GOOD ( 17.41 ) 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 , 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, "David S. Miller" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org --/04w6evG8XlLl3ft Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 --/04w6evG8XlLl3ft Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="0001-mm-fix-cache-flush-for-shmem-page-that-are-swap-back.patch" Content-Transfer-Encoding: 8bit >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); } -- 2.26.2 --/04w6evG8XlLl3ft Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --/04w6evG8XlLl3ft--