git: 6238905c5b25 - main - Only change DMAP props on DMAP covered memory

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 14 Dec 2021 10:44:27 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=6238905c5b253c5b8c6a4b66796819c3a0bed637

commit 6238905c5b253c5b8c6a4b66796819c3a0bed637
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2021-12-14 10:05:15 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2021-12-14 10:38:19 +0000

    Only change DMAP props on DMAP covered memory
    
    When changing memory properties in the arm64 pmap we need to keep both
    the kernel address and DMAP mappings in sync.
    
    To keep the kernel and DMAP memory in sync we recurse when updating the
    former to also update the latter. There was insuffucuent checking around
    this recursion. It would check if the virtual address is not within the
    DMAP region, but not if the physical address is covered.
    
    Add the missing check as without it the recursion may return an error.
    
    Sponsored by:   The FreeBSD Foundation
---
 sys/arm64/arm64/pmap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index 7763e1eabdda..d50c544cc863 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -5970,6 +5970,7 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot,
 {
 	vm_offset_t base, offset, tmpva;
 	vm_size_t pte_size;
+	vm_paddr_t pa;
 	pt_entry_t pte, *ptep, *newpte;
 	pt_entry_t bits, mask;
 	int lvl, rv;
@@ -6083,12 +6084,13 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot,
 			pmap_update_entry(kernel_pmap, ptep, pte, tmpva,
 			    pte_size);
 
-			if (!VIRT_IN_DMAP(tmpva)) {
+			pa = pte & ~ATTR_MASK;
+			if (!VIRT_IN_DMAP(tmpva) && PHYS_IN_DMAP(pa)) {
 				/*
 				 * Keep the DMAP memory in sync.
 				 */
 				rv = pmap_change_props_locked(
-				    PHYS_TO_DMAP(pte & ~ATTR_MASK), pte_size,
+				    PHYS_TO_DMAP(pa), pte_size,
 				    prot, mode);
 				if (rv != 0)
 					return (rv);