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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0E95C433F5 for ; Wed, 4 May 2022 02:49:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45DD56B0071; Tue, 3 May 2022 22:49:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40C266B0073; Tue, 3 May 2022 22:49:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D54A6B0074; Tue, 3 May 2022 22:49:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1EF546B0071 for ; Tue, 3 May 2022 22:49:54 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E927028C37 for ; Wed, 4 May 2022 02:49:53 +0000 (UTC) X-FDA: 79426530666.19.6A9F1CD Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 6E713A007D for ; Wed, 4 May 2022 02:49:44 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R521e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VC9zWyy_1651632588; Received: from 30.32.81.226(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VC9zWyy_1651632588) by smtp.aliyun-inc.com(127.0.0.1); Wed, 04 May 2022 10:49:49 +0800 Message-ID: <33af56f6-3ab9-0859-013a-598e46dd8da2@linux.alibaba.com> Date: Wed, 4 May 2022 10:50:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v2 2/3] mm: rmap: Move the cache flushing to the correct place for hugetlb PMD sharing To: Mike Kravetz , Muchun Song Cc: akpm@linux-foundation.org, almasrymina@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <4f7ae6dfdc838ab71e1655188b657c032ff1f28f.1651056365.git.baolin.wang@linux.alibaba.com> <16644a23-e7df-a330-fba0-a9cd5da4800e@oracle.com> From: Baolin Wang In-Reply-To: <16644a23-e7df-a330-fba0-a9cd5da4800e@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6E713A007D X-Stat-Signature: mp9x4a55e5dn5imcao3bhbmtggtp7yx3 Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com X-HE-Tag: 1651632584-373179 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: On 5/4/2022 2:42 AM, Mike Kravetz wrote: > On 4/27/22 22:55, Muchun Song wrote: >> On Wed, Apr 27, 2022 at 06:52:06PM +0800, Baolin Wang wrote: >>> The cache level flush will always be first when changing an existing >>> virtual–>physical mapping to a new value, since this allows us to >>> properly handle systems whose caches are strict and require a >>> virtual–>physical translation to exist for a virtual address. So we >>> should move the cache flushing before huge_pmd_unshare(). >>> >> >> Right. >> >>> As Muchun pointed out[1], now the architectures whose supporting hugetlb >>> PMD sharing have no cache flush issues in practice. But I think we >>> should still follow the cache/TLB flushing rules when changing a valid >>> virtual address mapping in case of potential issues in future. >> >> Right. One point i need to clarify. I do not object this change but >> want you to clarify this (not an issue in practice) in commit log >> to let others know they do not need to bp this. >> >>> >>> [1] https://lore.kernel.org/all/YmT%2F%2FhuUbFX+KHcy@FVFYT0MHHV2J.usts.net/ >>> Signed-off-by: Baolin Wang >>> --- >>> mm/rmap.c | 40 ++++++++++++++++++++++------------------ >>> 1 file changed, 22 insertions(+), 18 deletions(-) >>> >>> diff --git a/mm/rmap.c b/mm/rmap.c >>> index 61e63db..4f0d115 100644 >>> --- a/mm/rmap.c >>> +++ b/mm/rmap.c >>> @@ -1535,15 +1535,16 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >>> * do this outside rmap routines. >>> */ >>> VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); >>> + /* >>> + * huge_pmd_unshare may unmap an entire PMD page. >>> + * There is no way of knowing exactly which PMDs may >>> + * be cached for this mm, so we must flush them all. >>> + * start/end were already adjusted above to cover this >>> + * range. >>> + */ >>> + flush_cache_range(vma, range.start, range.end); >>> + >> >> flush_cache_range() is always called even if we do not need to flush. >> How about introducing a new helper like hugetlb_pmd_shared() which >> returns true for shared PMD? Then: >> >> if (hugetlb_pmd_shared(mm, vma, pvmw.pte)) { >> flush_cache_range(vma, range.start, range.end); >> huge_pmd_unshare(mm, vma, &address, pvmw.pte); >> flush_tlb_range(vma, range.start, range.end); >> } >> >> The code could be a little simpler. Right? >> >> Thanks. >> > > I thought about adding a 'hugetlb_pmd_shared()' interface for another use. > I believe it could even be used earlier in this call sequence. Since we > hold i_mmap_rwsem, we would even test for shared BEFORE calling > adjust_range_if_pmd_sharing_possible. We can not make an authoritative test > in adjust range... because not all callers will be holding i_mmap_rwsem. > > I think we COULD optimize to minimize the flush range. However, I think > that would complicate this code even more, and it is difficult enough to > follow. > > My preference would be to over flush as is done here for correctness and > simplification. We can optimize later if desired. OK. Agree. > > With Muchun's comment that this is not an issue in practice today, > Reviewed-by: Mike Kravetz Thanks.