git: ae43a817d33d - main - Put the arm64 vttbr_el2 register into a state

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 15 Nov 2022 17:32:00 UTC
The branch main has been updated by andrew:

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

commit ae43a817d33db3aa51f6dfce8dd940f06716e2a9
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-11-15 12:53:28 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-11-15 17:26:52 +0000

    Put the arm64 vttbr_el2 register into a state
    
    Zero the vttbr_el2 register on each CPU so we can tell if we are
    running the host or guest kernel from a hypervisor.
    
    Obtained from:  https://github.com/FreeBSD-UPB/freebsd-src (earlier version)
    Sponsored by:   Innovate UK
    Sponsored by:   The FreeBSD Foundation
---
 sys/arm64/arm64/locore.S       | 3 +++
 sys/arm64/include/hypervisor.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S
index 059b6fd0fe1c..3b4f2ccc5353 100644
--- a/sys/arm64/arm64/locore.S
+++ b/sys/arm64/arm64/locore.S
@@ -295,6 +295,9 @@ LENTRY(drop_to_el1)
 	add	x2, x2, :lo12:hyp_vectors
 	msr	vbar_el2, x2
 
+	/* Zero vttbr_el2 so a hypervisor can tell the host and guest apart */
+	msr	vttbr_el2, xzr
+
 	mov	x2, #(PSR_F | PSR_I | PSR_A | PSR_D | PSR_M_EL1h)
 	msr	spsr_el2, x2
 
diff --git a/sys/arm64/include/hypervisor.h b/sys/arm64/include/hypervisor.h
index f209ecde120a..dc6ccbfe20a9 100644
--- a/sys/arm64/include/hypervisor.h
+++ b/sys/arm64/include/hypervisor.h
@@ -199,6 +199,7 @@
 /* VTTBR_EL2 - Virtualization Translation Table Base Register */
 #define	VTTBR_VMID_MASK		0xffff000000000000
 #define	VTTBR_VMID_SHIFT	48
+/* Assumed to be 0 by locore.S */
 #define	VTTBR_HOST		0x0000000000000000
 
 #endif /* !_MACHINE_HYPERVISOR_H_ */