* [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state
@ 2023-07-13 7:15 Anshuman Khandual
2023-07-13 12:17 ` David Hildenbrand
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Anshuman Khandual @ 2023-07-13 7:15 UTC (permalink / raw)
To: linux-arm-kernel
Cc: david, Anshuman Khandual, Catalin Marinas, Will Deacon,
Mark Rutland, linux-kernel
pte_mkdirty() creates dirty states both in SW and HW bits, which is really
not required, either in pte_wrprotect() or pte_modify() for preserving the
HW dirty state. Because pte_mkdirty() sets PTE_DIRTY and clears PTE_RDONLY
as pte_write() always evaluates to be true - otherwise pte_hw_dirty() will
not test out in the first place. Clearing PTE_RDONLY again is not required
here because the pte is already in pte_hw_dirty() but might soon loose its
dirty state thus requiring preservation in SW dirty bit i.e PTE_DIRTY.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This applies on v6.5-rc1
arch/arm64/include/asm/pgtable.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 0bd18de9fd97..171d6d7f8087 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -212,7 +212,7 @@ static inline pte_t pte_wrprotect(pte_t pte)
* clear), set the PTE_DIRTY bit.
*/
if (pte_hw_dirty(pte))
- pte = pte_mkdirty(pte);
+ pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
pte = clear_pte_bit(pte, __pgprot(PTE_WRITE));
pte = set_pte_bit(pte, __pgprot(PTE_RDONLY));
@@ -823,7 +823,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
PTE_ATTRINDX_MASK;
/* preserve the hardware dirty information */
if (pte_hw_dirty(pte))
- pte = pte_mkdirty(pte);
+ pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
+
pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
return pte;
}
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state
2023-07-13 7:15 [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state Anshuman Khandual
@ 2023-07-13 12:17 ` David Hildenbrand
2023-07-21 18:23 ` Catalin Marinas
2023-07-27 12:22 ` Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2023-07-13 12:17 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: Catalin Marinas, Will Deacon, Mark Rutland, linux-kernel
On 13.07.23 09:15, Anshuman Khandual wrote:
> pte_mkdirty() creates dirty states both in SW and HW bits, which is really
> not required, either in pte_wrprotect() or pte_modify() for preserving the
> HW dirty state. Because pte_mkdirty() sets PTE_DIRTY and clears PTE_RDONLY
> as pte_write() always evaluates to be true - otherwise pte_hw_dirty() will
> not test out in the first place. Clearing PTE_RDONLY again is not required
> here because the pte is already in pte_hw_dirty() but might soon loose its
> dirty state thus requiring preservation in SW dirty bit i.e PTE_DIRTY.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> This applies on v6.5-rc1
>
> arch/arm64/include/asm/pgtable.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 0bd18de9fd97..171d6d7f8087 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -212,7 +212,7 @@ static inline pte_t pte_wrprotect(pte_t pte)
> * clear), set the PTE_DIRTY bit.
> */
> if (pte_hw_dirty(pte))
> - pte = pte_mkdirty(pte);
> + pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
>
> pte = clear_pte_bit(pte, __pgprot(PTE_WRITE));
> pte = set_pte_bit(pte, __pgprot(PTE_RDONLY));
> @@ -823,7 +823,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
> PTE_ATTRINDX_MASK;
> /* preserve the hardware dirty information */
> if (pte_hw_dirty(pte))
> - pte = pte_mkdirty(pte);
> + pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
> +
> pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
> return pte;
> }
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state
2023-07-13 7:15 [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state Anshuman Khandual
2023-07-13 12:17 ` David Hildenbrand
@ 2023-07-21 18:23 ` Catalin Marinas
2023-07-27 12:22 ` Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2023-07-21 18:23 UTC (permalink / raw)
To: Anshuman Khandual
Cc: linux-arm-kernel, david, Will Deacon, Mark Rutland, linux-kernel
On Thu, Jul 13, 2023 at 12:45:18PM +0530, Anshuman Khandual wrote:
> pte_mkdirty() creates dirty states both in SW and HW bits, which is really
> not required, either in pte_wrprotect() or pte_modify() for preserving the
> HW dirty state. Because pte_mkdirty() sets PTE_DIRTY and clears PTE_RDONLY
> as pte_write() always evaluates to be true - otherwise pte_hw_dirty() will
> not test out in the first place. Clearing PTE_RDONLY again is not required
> here because the pte is already in pte_hw_dirty() but might soon loose its
> dirty state thus requiring preservation in SW dirty bit i.e PTE_DIRTY.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state
2023-07-13 7:15 [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state Anshuman Khandual
2023-07-13 12:17 ` David Hildenbrand
2023-07-21 18:23 ` Catalin Marinas
@ 2023-07-27 12:22 ` Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2023-07-27 12:22 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: catalin.marinas, kernel-team, Will Deacon, linux-kernel, david,
Mark Rutland
On Thu, 13 Jul 2023 12:45:18 +0530, Anshuman Khandual wrote:
> pte_mkdirty() creates dirty states both in SW and HW bits, which is really
> not required, either in pte_wrprotect() or pte_modify() for preserving the
> HW dirty state. Because pte_mkdirty() sets PTE_DIRTY and clears PTE_RDONLY
> as pte_write() always evaluates to be true - otherwise pte_hw_dirty() will
> not test out in the first place. Clearing PTE_RDONLY again is not required
> here because the pte is already in pte_hw_dirty() but might soon loose its
> dirty state thus requiring preservation in SW dirty bit i.e PTE_DIRTY.
>
> [...]
Applied to arm64 (for-next/mm), thanks!
[1/1] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state
https://git.kernel.org/arm64/c/6477c3886ae1
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-27 12:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-13 7:15 [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state Anshuman Khandual
2023-07-13 12:17 ` David Hildenbrand
2023-07-21 18:23 ` Catalin Marinas
2023-07-27 12:22 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).