git: 54f23b015aa6 - main - arm64: Support pmap_fault with a locked pmap

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 17:25:15 UTC
The branch main has been updated by andrew:

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

commit 54f23b015aa6b913fd51c1b5c16e09cc3778fcb8
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-10-14 14:35:56 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-10-15 17:24:42 +0000

    arm64: Support pmap_fault with a locked pmap
    
    When we get a data abort in an EFI runtime service the userspace pmap
    will be locked by the current thread. Skip trying to lock it again as
    it will be in a critical section and the lock may sleep.
    
    Reviewed by:    markj
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D46813
---
 sys/arm64/arm64/pmap.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index 2c8f8b416a9e..10aa7f6bfb5c 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -9178,12 +9178,23 @@ pmap_fault(pmap_t pmap, uint64_t esr, uint64_t far)
 			if (pmap_klookup(far, NULL))
 				rv = KERN_SUCCESS;
 		} else {
-			PMAP_LOCK(pmap);
+			bool owned;
+
+			/*
+			 * In the EFIRT driver we lock the pmap before
+			 * calling into the runtime service. As the lock
+			 * is already owned by the current thread skip
+			 * locking it again.
+			 */
+			owned = PMAP_OWNED(pmap);
+			if (!owned)
+				PMAP_LOCK(pmap);
 			/* Ask the MMU to check the address. */
 			intr = intr_disable();
 			par = arm64_address_translate_s1e0r(far);
 			intr_restore(intr);
-			PMAP_UNLOCK(pmap);
+			if (!owned)
+				PMAP_UNLOCK(pmap);
 
 			/*
 			 * If the translation was successful, then we can