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: 13304440 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 852EFEB64D9 for ; Fri, 7 Jul 2023 05:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i6v7RSAYW1N6yr/2AVoiqmgGyLBgCg9iVasT4Yk02Vo=; b=VWcmt+hnZM4IK+ s+2YQHyf8g9B/E5l8w+aR2sgdIrp4hLjKOIf4uVP6P+yJuovTx/VxA6oxyBD0R+2C2ZQ/KQTt4JN5 IBH0rp27tdBFZ/Qj/X5cFPNWjG2oQ8MTRTcSbOOyqQo0Y9+AnVv/ZYBqNzJbw/I3kcaGUllfymP+q Sb4InHwTCVGqqn55eAi8mHx14uC32D15/xmKu5Hyue60E2b8NX7JWlz1JCQ2535ZTRk70WvmO2nNY sVJwx4sih0N4QP9jOhIASF4zif6kLuDWIC9tLaGz8gSu/Y/ESS8m2lziwGuF75O1dS/r3YZ+xQGCe Ax8FwbJhVDwS6Ut/gs5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHe6W-003dCS-27; Fri, 07 Jul 2023 05:34:04 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHe6T-003dB3-1x for linux-arm-kernel@lists.infradead.org; Fri, 07 Jul 2023 05:34:03 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230706_223401_697107_5D2DDC3A X-CRM114-Status: GOOD ( 11.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }