git: b5a1f0406b9d - main - arm64_pmap: narrow scope of bti_same test

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Tue, 14 May 2024 04:24:17 UTC
The branch main has been updated by dougm:

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

commit b5a1f0406b9d6bba28e57377dcfc8b83bce987ad
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-05-14 04:22:52 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-05-14 04:22:52 +0000

    arm64_pmap: narrow scope of bti_same test
    
    The pmap_bti_same test in pmap_enter_l3c only happens in the
    !ADDR_IS_KERNEL case; in the other case, a KASSERT fails. So move the
    test into that case to save a bit of time when ADDR_IS_KERNEL.
    
    Reviewed by:    andrew
    Differential Revision:  https://reviews.freebsd.org/D45160
---
 sys/arm64/arm64/pmap.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index 7780c6ec8767..a6056a5edfc2 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -5662,6 +5662,19 @@ retry:
 			}
 		}
 		l3p = (pt_entry_t *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(*ml3p));
+
+have_l3p:
+		/*
+		 * If bti is not the same for the whole L3C range, return
+		 * failure and let vm_fault() cope.  Check after L3 allocation,
+		 * since it could sleep.
+		 */
+		if (!pmap_bti_same(pmap, va, va + L3C_SIZE)) {
+			(*ml3p)->ref_count -= L3C_ENTRIES - 1;
+			pmap_abort_ptp(pmap, va, *ml3p);
+			*ml3p = NULL;
+			return (KERN_PROTECTION_FAILURE);
+		}
 	} else {
 		*ml3p = NULL;
 
@@ -5684,22 +5697,8 @@ retry:
 			    pmap_load(pde)));
 		}
 	}
-have_l3p:
 	l3p = &l3p[pmap_l3_index(va)];
 
-	/*
-	 * If bti is not the same for the whole L3C range, return failure
-	 * and let vm_fault() cope.  Check after L3 allocation, since
-	 * it could sleep.
-	 */
-	if (!pmap_bti_same(pmap, va, va + L3C_SIZE)) {
-		KASSERT(*ml3p != NULL, ("pmap_enter_l3c: missing L3 PTP"));
-		(*ml3p)->ref_count -= L3C_ENTRIES - 1;
-		pmap_abort_ptp(pmap, va, *ml3p);
-		*ml3p = NULL;
-		return (KERN_PROTECTION_FAILURE);
-	}
-
 	/*
 	 * If there are existing mappings, either abort or remove them.
 	 */