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 8610FC43334 for ; Fri, 10 Jun 2022 03:57:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68EE48D0072; Thu, 9 Jun 2022 23:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63E6F8D0064; Thu, 9 Jun 2022 23:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 505E38D0072; Thu, 9 Jun 2022 23:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3BAED8D0064 for ; Thu, 9 Jun 2022 23:57:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 0555E81088 for ; Fri, 10 Jun 2022 03:57:51 +0000 (UTC) X-FDA: 79560967542.17.9DB71AC Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 70D3F180038 for ; Fri, 10 Jun 2022 03:57:49 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654833470; a=rsa-sha256; cv=none; b=xTKHWdGs5SUF5JPHKjgApIqAJ6SQNVx7Gy1GxaFeG6GZwoaqYRdKwITxMXLA3chvm0mcFQ SPGGr4ayfXwE5ZV2++UdXnzcoZS+ldBei3Iok6cgBdtYusJfZgwsxzV9ZlW0RhDpFPJ8MV dgHBFvHmaEkpVTn6ZBWG4Wc4AAxXQu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654833470; h=from:from:sender: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: in-reply-to:in-reply-to:references:references; bh=JGARqMrfIJfbSf+VmfcHeoTSB5tml7LFM0mDbL6U5+4=; b=YI0eZ1eGVfR7D3RzlnxWcaQFfGRu/80661LcAcXIMyBkh9NI3uQlyeDtdEzWN7siz5U3Vv 3ZHy8KYLaD2aZtgLeRZ4D38/BSOBTB2hXgDW/tOKVjrqdTO5C5cJ5y6Or9Whn9+WjzvoQ3 T/KCgOOWuoElCTfXMetKG111kWcmkXM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com X-Stat-Signature: 78r77x6icirp5audx5e64pqnbjbduuqy X-Rspamd-Queue-Id: 70D3F180038 X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1654833469-852034 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 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.