Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1033743iol; Thu, 9 Jun 2022 21:29:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTyjMeoPdOrh77g/gAGzd2ktbC1k+5UwCsBwlbME9uc0xFGgg3KbwRnWurM+mf4cSD0sC/ X-Received: by 2002:a63:5723:0:b0:3fd:d8b4:c19f with SMTP id l35-20020a635723000000b003fdd8b4c19fmr19146052pgb.137.1654835377838; Thu, 09 Jun 2022 21:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654835377; cv=none; d=google.com; s=arc-20160816; b=GMsFGDzaFWzzd5sMJPu3UTFeGIjeiZRA3Iw81RcZbhiHzgGVKbB92wHmU2aSYOWa1w e2fuom2Hc6ClLabA9NmVvFDUQn9yJgYksTt37UIXAzE3EmAJv5OnVyYY6SJlIicKYTO9 ox64wVyEYSXm7X8LXFJUq/mj/1FSk2YTOgreGSFmu3BF1Gz3yLW2qGqO4X2J7g/j8GW6 YuLmyR5hDbiQ6evMCIKVUsQNo8bxnawA0Kt5GBrv7Kd7pmpuw7DLNlTR5AdL+4wCu9W+ DZ3o+Q/Ct9OipLVG877lmMUD6szr7/xXXO+O8wX/Cz6Di/ce48oi5OBbr6U+3Jn9g7m5 Th7g== 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=JGARqMrfIJfbSf+VmfcHeoTSB5tml7LFM0mDbL6U5+4=; b=s35ooprDmM4GjE+drScBeE3rMOloXQB2FhaAZiD1mtMZEB1z9sOzbvXzUscnrKzdTN czFuUjyhuNxFHq58yQ9z3vGExtvQlqhG1mPy9s3Lw6n4iADlzeB8bgOtWId5pw5U6mrQ gK6IBlBA++T4t0wkWan1KdJIBHIfxFJbicmkBGlLHu8GjP591OrGPF0pn+ABoXleCFCF vBPGn5ZlDe2/QvszhlWBkqbQ0hG8D4nr85uBvuCldDFUjuu1sDj2svHMQ6wuKGijI7z5 ewZJDq53FPsLpIFBfkUVJKNmp1v/ghLSXlHJT+Zn0mpPyvCZ+CsCEnulGADOT06iLfmM CJUw== 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 n11-20020a170902e54b00b0016227572a9bsi37276069plf.513.2022.06.09.21.29.21; Thu, 09 Jun 2022 21:29:37 -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 S231657AbiFJD5v (ORCPT + 99 others); Thu, 9 Jun 2022 23:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbiFJD5t (ORCPT ); Thu, 9 Jun 2022 23:57:49 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 013BB3B284 for ; Thu, 9 Jun 2022 20:57:47 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VFxf77o_1654833464; Received: from 30.0.143.52(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VFxf77o_1654833464) by smtp.aliyun-inc.com; Fri, 10 Jun 2022 11:57:45 +0800 Message-ID: <927ab454-f25d-06d2-5861-a57033f28e00@linux.alibaba.com> Date: Fri, 10 Jun 2022 11:57:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] arm64/hugetlb: Simplify the huge_ptep_set_access_flags() To: Will Deacon Cc: catalin.marinas@arm.com, mike.kravetz@oracle.com, songmuchun@bytedance.com, anshuman.khandual@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220609154438.GA3444@willie-the-truck> From: Baolin Wang In-Reply-To: <20220609154438.GA3444@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 6/9/2022 11:44 PM, Will Deacon wrote: > On Wed, May 25, 2022 at 06:31:09PM +0800, Baolin Wang wrote: >> After commit bc5dfb4fd7bd ("arm64/hugetlb: Implement arm64 specific >> huge_ptep_get()"), the arm64 specific huge_ptep_get() will always >> consider the subpages' dirty and young state for CONT-PTE/PMD hugetlb, >> so there is no need to check them again when setting the access flags >> for CONT-PTE/PMD hugetlb in huge_ptep_set_access_flags(). >> >> Meanwhile this also fixes an issue when users want to make the CONT-PTE/PMD >> hugetlb's pte entry old, which will be failed to make the pte entry old >> since the original code will always consider the subpages' young state >> if the subpages' young state is set. For example, we will make the >> CONT-PTE/PMD hugetlb pte entry old in DAMON to monitoring the accesses, >> but we'll failed to monitoring the actual accesses of the CONT-PTE/PMD >> hugetlb page, due to we can not make its pte old. >> >> Thus remove the code considering the subpages' dirty and young state in >> huge_ptep_set_access_flags() to fix this issue and simplify the function. >> >> Signed-off-by: Baolin Wang >> --- >> arch/arm64/mm/hugetlbpage.c | 10 +--------- >> 1 file changed, 1 insertion(+), 9 deletions(-) >> >> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c >> index e2a5ec9..5c703aa 100644 >> --- a/arch/arm64/mm/hugetlbpage.c >> +++ b/arch/arm64/mm/hugetlbpage.c >> @@ -448,7 +448,6 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, >> size_t pgsize = 0; >> unsigned long pfn = pte_pfn(pte), dpfn; >> pgprot_t hugeprot; >> - pte_t orig_pte; >> >> if (!pte_cont(pte)) >> return ptep_set_access_flags(vma, addr, ptep, pte, dirty); >> @@ -459,14 +458,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, >> if (!__cont_access_flags_changed(ptep, pte, ncontig)) >> return 0; >> >> - orig_pte = get_clear_contig(vma->vm_mm, addr, ptep, pgsize, ncontig); >> - >> - /* Make sure we don't lose the dirty or young state */ >> - if (pte_dirty(orig_pte)) >> - pte = pte_mkdirty(pte); >> - >> - if (pte_young(orig_pte)) >> - pte = pte_mkyoung(pte); >> + clear_flush(vma->vm_mm, addr, ptep, pgsize, ncontig); > > I don't understand what this clear_flush() call is doing here; notably, it > includes TLB invalidation which we don't have for the non-cont case. OK. I can just call a loop of pte_clear() to clear cont-pte to avoid TLB flush. > > Why isn't huge_ptep_set_access_flags() just a loop around > ptep_set_access_flags() if huge_ptep_get() is taking care of collapsing the > dirty/young state? IIUC, according to the comments "Changing some bits of contiguous entries requires us to follow a Break-Before-Make approach, breaking the whole contiguous set before we can change any entries". So we should clear the cont-ptes firstly, then re-set them. Then a loop of ptep_set_access_flags() is not suitable for the cont-pte case, right? Please correct me if I missed something else. Thanks.