From patchwork Fri Jul 7 05:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 116979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3042738vqx; Thu, 6 Jul 2023 22:45:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlEXdLYKThh8aTxm+A2iZg1+glWJIkx4ydlKa6IBKpYFHXWHRkh2htmq2h6hp/yIyw5r7vNT X-Received: by 2002:a05:6808:d48:b0:3a0:5a6b:25c with SMTP id w8-20020a0568080d4800b003a05a6b025cmr3975341oik.33.1688708739630; Thu, 06 Jul 2023 22:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688708739; cv=none; d=google.com; s=arc-20160816; b=viIUoyZ674xrysBYifS8U3+XLk+NROBqjTHvG1pxtVJqsYxzX3VPFSPl4bosOrISJb cgNr20Gc6BI2fSrPkV0GA51CrQXEspOAZwzTZbHjGJuhNJrLZCuI7lZWLxNMjPdnwBQ4 +WTBsmHLnaaYxBescqjOON/pTQYCw2cbRfeEyDbR4iKEFLDIX3nd0iRRa9nahPac9Te0 Oz6uGVjindahgpwEQq2NFyJCHLRVnxMOfJ3A0H/NlQb3r+l9GHhy2O7xENi5KS8ocrjx AD3Jx+jEFCuq67WPrOfK33b8qFkEbMh52xSRPIjGO5ZfP7qK8kmPEvqw/zFmclH3ccX3 mBXQ== 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=ZQb3yAXZv4KLulngffs/iaEINfHQCq69u+201qbUFUU=; fh=v8WkW07D8QHzh6geYHFbL/t66J83/bx/yAuOgJXvUtg=; b=WK/ZcZiU7s02pQwzzsm0sYOFMij5QSCPqRRBhS9oHnnxXsCKyBZ6NYHw5W4zU3MhOb GnGaNrb31n6Tz7PuGsfAa2/Cpu+mILBeUKSBECILIegCF6zTicTBsazGexzrwpohK7li 9kqIK5FZAzj7KyxHPfC1XXwPHjJrATz4YPSprmiNXd8vdgWhkmnfcrVDo5Ega/2GivF6 rn/W8Bx79YHq1WGm3e1ymySG8IxZIfad+Agj4c49qbYvhYXzqlFnV2QTXpAmdY4X59+f X8RpdqnHzsQNcb0uMQYVXpJHy6MtrlVfKcGV0dtPNGAOy0iUmb/7FDhmiZqe0jdLTNq7 wGSw== 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 l191-20020a6391c8000000b0055ac5fed58dsi3240140pge.363.2023.07.06.22.45.25; Thu, 06 Jul 2023 22:45:39 -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 S232370AbjGGFeI (ORCPT + 99 others); Fri, 7 Jul 2023 01:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232177AbjGGFeE (ORCPT ); Fri, 7 Jul 2023 01:34:04 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5D991FEB; Thu, 6 Jul 2023 22:33:59 -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 4F865D75; Thu, 6 Jul 2023 22:34:41 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.48.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C10AE3F740; Thu, 6 Jul 2023 22:33:55 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , Andrew Morton , David Hildenbrand , Jonathan Corbet , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [RFC 3/4] arm64/mm: Add pte_preserve_hw_dirty() Date: Fri, 7 Jul 2023 11:03:30 +0530 Message-Id: <20230707053331.510041-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230707053331.510041-1-anshuman.khandual@arm.com> References: <20230707053331.510041-1-anshuman.khandual@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?1770739455704206267?= X-GMAIL-MSGID: =?utf-8?q?1770739455704206267?= Preserving the HW dirty state via SW PTE dirty bit, should be made explicit ensuring greater clarity and readability. This adds pte_preserve_hw_dirty() helper for that effect. No functional change is intended. Cc: Catalin Marinas Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index dd20b752ed48..5344e71a58b2 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -237,7 +237,7 @@ static inline pte_t pte_mkdirty(pte_t pte) return pte; } -static inline pte_t pte_wrprotect(pte_t pte) +static inline pte_t pte_preserve_hw_dirty(pte_t pte) { /* * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY @@ -246,6 +246,12 @@ static inline pte_t pte_wrprotect(pte_t pte) if (pte_hw_dirty(pte)) pte = pte_sw_mkdirty(pte); + return pte; +} + +static inline pte_t pte_wrprotect(pte_t pte) +{ + pte = pte_preserve_hw_dirty(pte); pte = clear_pte_bit(pte, __pgprot(PTE_WRITE)); pte = set_pte_bit(pte, __pgprot(PTE_RDONLY)); return pte; @@ -853,9 +859,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY | PTE_PROT_NONE | PTE_VALID | PTE_WRITE | PTE_GP | PTE_ATTRINDX_MASK; - /* preserve the hardware dirty information */ - if (pte_hw_dirty(pte)) - pte = pte_sw_mkdirty(pte); + pte = pte_preserve_hw_dirty(pte); pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask); return pte; }