git: 81e973eaf95e - stable/14 - arm64: Use the pointer auth register defines

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 15 Jul 2024 12:38:24 UTC
The branch stable/14 has been updated by andrew:

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

commit 81e973eaf95ee62d83129eea83f610ba829229f8
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-05-22 08:19:06 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-07-15 12:27:23 +0000

    arm64: Use the pointer auth register defines
    
    When building with gcc it complains the pointer authentication
    registers aren't valid with the architecture level we are targeting.
    Fix this by using the alternative spelling of these registers accesses
    through MRS_REG_ALT_NAME.
    
    Reviewed by:    jhb
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D45263
    
    (cherry picked from commit 73c200447361a649e00cdb1693a0ae7f3291914e)
---
 sys/arm64/arm64/ptrauth.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/sys/arm64/arm64/ptrauth.c b/sys/arm64/arm64/ptrauth.c
index 03610e9313f5..c7cf47f8a6cd 100644
--- a/sys/arm64/arm64/ptrauth.c
+++ b/sys/arm64/arm64/ptrauth.c
@@ -170,13 +170,11 @@ ptrauth_thread_alloc(struct thread *td)
  * Load the userspace keys. We can't use WRITE_SPECIALREG as we need
  * to set the architecture extension.
  */
-#define	LOAD_KEY(space, name)					\
-__asm __volatile(						\
-	".arch_extension pauth			\n"		\
-	"msr	"#name"keylo_el1, %0		\n"		\
-	"msr	"#name"keyhi_el1, %1		\n"		\
-	".arch_extension nopauth		\n"		\
-	:: "r"(td->td_md.md_ptrauth_##space.name.pa_key_lo),	\
+#define	LOAD_KEY(space, name, reg)					\
+__asm __volatile(							\
+	"msr	"__XSTRING(MRS_REG_ALT_NAME(reg ## KeyLo_EL1))", %0	\n"	\
+	"msr	"__XSTRING(MRS_REG_ALT_NAME(reg ## KeyHi_EL1))", %1	\n"	\
+	:: "r"(td->td_md.md_ptrauth_##space.name.pa_key_lo),		\
 	   "r"(td->td_md.md_ptrauth_##space.name.pa_key_hi))
 
 void
@@ -188,7 +186,7 @@ ptrauth_thread0(struct thread *td)
 	/* TODO: Generate a random number here */
 	memset(&td->td_md.md_ptrauth_kern, 0,
 	    sizeof(td->td_md.md_ptrauth_kern));
-	LOAD_KEY(kern, apia);
+	LOAD_KEY(kern, apia, APIA);
 	/*
 	 * No isb as this is called before ptrauth_start so can rely on
 	 * the instruction barrier there.
@@ -241,8 +239,8 @@ ptrauth_mp_start(uint64_t cpu)
 
 	__asm __volatile(
 	    ".arch_extension pauth		\n"
-	    "msr	apiakeylo_el1, %0	\n"
-	    "msr	apiakeyhi_el1, %1	\n"
+	    "msr	"__XSTRING(APIAKeyLo_EL1_REG)", %0	\n"
+	    "msr	"__XSTRING(APIAKeyHi_EL1_REG)", %1	\n"
 	    ".arch_extension nopauth		\n"
 	    :: "r"(start_key.pa_key_lo), "r"(start_key.pa_key_hi));
 
@@ -258,7 +256,7 @@ struct thread *
 ptrauth_switch(struct thread *td)
 {
 	if (enable_ptrauth) {
-		LOAD_KEY(kern, apia);
+		LOAD_KEY(kern, apia, APIA);
 		isb();
 	}
 
@@ -272,7 +270,7 @@ ptrauth_exit_el0(struct thread *td)
 	if (!enable_ptrauth)
 		return;
 
-	LOAD_KEY(kern, apia);
+	LOAD_KEY(kern, apia, APIA);
 	isb();
 }
 
@@ -283,11 +281,11 @@ ptrauth_enter_el0(struct thread *td)
 	if (!enable_ptrauth)
 		return;
 
-	LOAD_KEY(user, apia);
-	LOAD_KEY(user, apib);
-	LOAD_KEY(user, apda);
-	LOAD_KEY(user, apdb);
-	LOAD_KEY(user, apga);
+	LOAD_KEY(user, apia, APIA);
+	LOAD_KEY(user, apib, APIB);
+	LOAD_KEY(user, apda, APDA);
+	LOAD_KEY(user, apdb, APDB);
+	LOAD_KEY(user, apga, APGA);
 	/*
 	 * No isb as this is called from the exception handler so can rely
 	 * on the eret instruction to be the needed context synchronizing event.