diff mbox series

[RFC,3/4] arm64/mm: Add pte_preserve_hw_dirty()

Message ID 20230707053331.510041-4-anshuman.khandual@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64/mm: Clean up pte_dirty() state management | expand

Commit Message

Anshuman Khandual July 7, 2023, 5:33 a.m. UTC
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 <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/arm64/include/asm/pgtable.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

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;
 }