[RFC,3/4] arm64/mm: Add pte_preserve_hw_dirty()
Commit Message
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(-)
@@ -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;
}