Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp635690iob; Wed, 4 May 2022 05:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/Xe3V7uCQdxlEPkJcQedlCUFyOEvhylKFXDd/EOunRNkC4nwW4BRaLkY+EA5C48nhB2dI X-Received: by 2002:a05:6638:2413:b0:32b:805e:eb7d with SMTP id z19-20020a056638241300b0032b805eeb7dmr3168064jat.306.1651665793146; Wed, 04 May 2022 05:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651665793; cv=none; d=google.com; s=arc-20160816; b=OW6xGI/KKJUzfPM0d7T727fQ/IvqhQmk4KpS8Q9+mtR5AQFCTyBKx58jfIPucwi18D UD0oINz117U+/NtdSYaisCKzOitRtGZlLEfsO1EhDXWnhi28qgXOx+WxKjZOC9F5RpmI 0jXhlEm5gX5Ta2BZn6zbyyKij19rsAXWeuCCqTNnhIDqerwGPI5UC4wghEyzKst0xbvX KoaTmXh7twn/SJ6w3ygnGh6jQS8MW+5f/G7mvEkb/fOMsd1reo+z0DhmtpqOSVuGEDx+ CGuxhhI+9EeXCPA6bN3ysBz0mT1cIfa4P90Xe28tLaz4ChcjDdA4JPeKIqoKmFBTBJCe T+tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=bKOSg/0kDJsBUXy9Ogc8tN8o1GzrSIvH0pzXzUovIUM=; b=GVvCsncOOi0hJ07oUBY5/ST7uhRkfBlzj755KmeiHYZv+J31OB4BrNgaW9DymyK/q7 w0vtav7dbeo7E34vQrRfR2ibVBgq5yCcrZa4SSjvw879eJZ0zmjwLW5T4DRPSvewAnq1 T/6UySkxs98Dri0zkVJt7MHHM4cgR45U0fOg1CJvhEGJjvzkOEWewbtG6IliIdYItPd6 /lHkbtwx/U5Tpwq0Onys81cR3eZyjfXmFVWFvBb8YFADnUMyatn4SIRgqLKi3LcDxoOp 1nhSKCllydLKdexQoK/3EBEa5RSXQ1fGbFVpvrRY7mtWHTx+cIpIoLxIPb1F45up0ggi kzsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h32-20020a05663833a000b0032aefbc4bb9si3609221jav.101.2022.05.04.05.02.56; Wed, 04 May 2022 05:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344106AbiEDCxa (ORCPT + 99 others); Tue, 3 May 2022 22:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbiEDCx3 (ORCPT ); Tue, 3 May 2022 22:53:29 -0400 Received: from out199-15.us.a.mail.aliyun.com (out199-15.us.a.mail.aliyun.com [47.90.199.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7254120BFE for ; Tue, 3 May 2022 19:49:54 -0700 (PDT) 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-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.