From patchwork Thu Jun 22 14:42:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 111737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5150772vqr; Thu, 22 Jun 2023 08:25:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5X0EWyTLkTxt8o7YKp+EMAnwb5VufVUug9Fu2j/gICgia7XJnTUqedCKGg4swKMzzibyrV X-Received: by 2002:aa7:8894:0:b0:651:ce88:27f5 with SMTP id z20-20020aa78894000000b00651ce8827f5mr23843328pfe.13.1687447552575; Thu, 22 Jun 2023 08:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687447552; cv=none; d=google.com; s=arc-20160816; b=kUizLSr8WbKNG6CL4sGwVF5+/ctI+38RAEqYREHnr6491Mq+TW6xfWeQBy+8ZN2xzj Sm7ZbIyKxDsncgmGVMz7oHF2NLeKQNZzCnqEHOkNmYEUmlmWpnQ14dkmX9KVAVTACffo H+bSrcXqDVUDrq+1eKxkFMiD8vT8Bdne63egGoqobepcGuWTvQIXQSU7PbhMfTcvg6gu RFDLzE956RphK5FweEZyXZ8scSPgKfE/Gp5SBGMCq7L7OkoYjd6kZSX9fm5nn8jLfh1Y H7YvwQXTH0zwbJ5t2e7isom8YCY05Z1GFtdQCrxa01KTSDc7EIUT0h0QP1o1lVrgNbr5 b9UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8+4aKe5InG/sT9ahgDIcgoSk7tRyyrQ1fi5c8NU1sPo=; b=MCOvv4Ok/4vPxXH7pWp/kKLUUCofbJSXyJ1flmntxxIzGMvwx024iEvvnMy5h7dScu U3r70ykwINk3bwy+bGgYzs+CF/WfccU2RNlfzmN33xpwUlig9p6silrL4uusLPCRcD8j ydZpbdGofNql7o5FwIFOHgeLDs5jWy21wKvqvSbtSRT1LTaYzpG5kVv4uX1ewbt5gjh1 65HYTHv1qWuf64ZsA1QjS8TC1ImWsKbPe6fSKPp5ucza9mUt5hRbk4sVGXsmrDInda5c byATGvg0hOWF8gSk1OINLdRN1vdHcUNws01UENtM2l0197Nh+e0MjQQojUpe9Va+SNRz Nq2w== 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=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020aa7950d000000b0063b8f0a6f51si5208327pfp.117.2023.06.22.08.25.40; Thu, 22 Jun 2023 08:25:52 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231754AbjFVOnX (ORCPT + 99 others); Thu, 22 Jun 2023 10:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbjFVOnG (ORCPT ); Thu, 22 Jun 2023 10:43:06 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE4D52134 for ; Thu, 22 Jun 2023 07:42:50 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A4C61042; Thu, 22 Jun 2023 07:43:34 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAAD23F663; Thu, 22 Jun 2023 07:42:47 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Anshuman Khandual , Matthew Wilcox , Yu Zhao , Mark Rutland Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 08/14] arm64/mm: ptep_set_access_flags(): New layer to manage contig bit Date: Thu, 22 Jun 2023 15:42:03 +0100 Message-Id: <20230622144210.2623299-9-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230622144210.2623299-1-ryan.roberts@arm.com> References: <20230622144210.2623299-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769417005176517899?= X-GMAIL-MSGID: =?utf-8?q?1769417005176517899?= Create a new layer for the in-table PTE manipulation APIs. For now, The existing API is prefixed with double underscore to become the arch-private API and the public API is just a simple wrapper that calls the private API. The public API implementation will subsequently be used to transparently manipulate the contiguous bit where appropriate. But since there are already some contig-aware users (e.g. hugetlb, kernel mapper), we must first ensure those users use the private API directly so that the future contig-bit manipulations in the public API do not interfere with those existing uses. No behavioural changes intended. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 16 ++++++++++++---- arch/arm64/mm/fault.c | 6 +++--- arch/arm64/mm/hugetlbpage.c | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 2fcc3b19c873..ff79578fd806 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -311,7 +311,7 @@ static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, /* * Check for potential race with hardware updates of the pte - * (ptep_set_access_flags safely changes valid ptes without going + * (__ptep_set_access_flags safely changes valid ptes without going * through an invalid entry). */ VM_WARN_ONCE(!pte_young(pte), @@ -842,8 +842,7 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) return pte_pmd(pte_modify(pmd_pte(pmd), newprot)); } -#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS -extern int ptep_set_access_flags(struct vm_area_struct *vma, +extern int __ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t entry, int dirty); @@ -853,7 +852,8 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp, pmd_t entry, int dirty) { - return ptep_set_access_flags(vma, address, (pte_t *)pmdp, pmd_pte(entry), dirty); + return __ptep_set_access_flags(vma, address, (pte_t *)pmdp, + pmd_pte(entry), dirty); } static inline int pud_devmap(pud_t pud) @@ -1166,6 +1166,14 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, __ptep_set_wrprotect(mm, addr, ptep); } +#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS +static inline int ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t entry, int dirty) +{ + return __ptep_set_access_flags(vma, addr, ptep, entry, dirty); +} + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_PGTABLE_H */ diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index d3a64624ed88..f5a7a5ff6814 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -195,9 +195,9 @@ static void show_pte(unsigned long addr) * * Returns whether or not the PTE actually changed. */ -int ptep_set_access_flags(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep, - pte_t entry, int dirty) +int __ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, + pte_t entry, int dirty) { pteval_t old_pteval, pteval; pte_t pte = READ_ONCE(*ptep); diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 7d5eb71db396..9a87b1c5661a 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -477,7 +477,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, pte_t orig_pte; if (!pte_cont(pte)) - return ptep_set_access_flags(vma, addr, ptep, pte, dirty); + return __ptep_set_access_flags(vma, addr, ptep, pte, dirty); ncontig = find_num_contig(mm, addr, ptep, &pgsize); dpfn = pgsize >> PAGE_SHIFT;