Skip to content

Commit 895a370

Browse files
Ryan Robertswilldeacon
authored andcommitted
arm64: mm: Permit PTE SW bits to change in live mappings
Previously pgattr_change_is_safe() was overly-strict and complained (e.g. "[ 116.262743] __check_safe_pte_update: unsafe attribute change: 0x0560000043768fc3 -> 0x0160000043768fc3") if it saw any SW bits change in a live PTE. There is no such restriction on SW bits in the Arm ARM. Until now, no SW bits have been updated in live mappings via the set_ptes() route. PTE_DIRTY would be updated live, but this is handled by ptep_set_access_flags() which does not call pgattr_change_is_safe(). However, with the introduction of uffd-wp for arm64, there is core-mm code that does ptep_get(); pte_clear_uffd_wp(); set_ptes(); which triggers this false warning. Silence this warning by masking out the SW bits during checks. The bug isn't technically in the highlighted commit below, but that's where bisecting would likely lead as its what made the bug user-visible. Signed-off-by: Ryan Roberts <[email protected]> Fixes: 5b32510 ("arm64/mm: Add uffd write-protect support") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 83a7eef commit 895a370

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

arch/arm64/include/asm/pgtable-hwdef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
#define PTE_CONT (_AT(pteval_t, 1) << 52) /* Contiguous range */
171171
#define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */
172172
#define PTE_UXN (_AT(pteval_t, 1) << 54) /* User XN */
173+
#define PTE_SWBITS_MASK _AT(pteval_t, (BIT(63) | GENMASK(58, 55)))
173174

174175
#define PTE_ADDR_LOW (((_AT(pteval_t, 1) << (50 - PAGE_SHIFT)) - 1) << PAGE_SHIFT)
175176
#ifdef CONFIG_ARM64_PA_BITS_52

arch/arm64/mm/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ bool pgattr_change_is_safe(u64 old, u64 new)
124124
* The following mapping attributes may be updated in live
125125
* kernel mappings without the need for break-before-make.
126126
*/
127-
pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG;
127+
pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG |
128+
PTE_SWBITS_MASK;
128129

129130
/* creating or taking down mappings is always safe */
130131
if (!pte_valid(__pte(old)) || !pte_valid(__pte(new)))

0 commit comments

Comments
 (0)