From 58de79153622145cb6fc57bc92c4de678876992f Mon Sep 17 00:00:00 2001 From: Harry Moulton Date: Mon, 13 Apr 2026 12:54:38 +0100 Subject: [PATCH] arm64: mte: configure initial state for system registers The fields in SCTLR_EL1 and HCR_EL2 for enabling MTE are set, and if the ID_AA64PFR1_EL1 register shows MTE is present, the GCR_EL1 register is also configured, and the two TFSR registers which hold pending tag check faults are cleared. Reviewed by: andrew Sponsored by: Arm Ltd Signed-off-by: Harry Moulton Differential Revision: https://reviews.freebsd.org/D55946 --- sys/arm64/arm64/locore.S | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index f1228235dfe..4c8e0c68032 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -398,7 +398,7 @@ LENTRY(enter_kernel_el) */ /* Configure the Hypervisor */ - ldr x2, =(HCR_RW | HCR_APK | HCR_API) + ldr x2, =(HCR_RW | HCR_APK | HCR_API | HCR_ATA) msr hcr_el2, x2 /* Stash value of HCR_EL2 for later */ @@ -1063,6 +1063,21 @@ LENTRY(start_mmu) isb ldr x2, mair + + /* + * If MTE is supported, configure GCR_EL1 and clear the TFSR registers of + * any pending tag check faults + */ + CHECK_CPU_FEAT(x3, ID_AA64PFR1, MTE, MTE, 1f) + + /* Set GCR_EL1, non-zero tags excluded by default */ + mov x3, #(GCR_Exclude_MASK | GCR_RRND) + msr GCR_EL1_REG, x3 + + /* Clear any pending tag check faults */ + msr TFSR_EL1_REG, xzr + msr TFSRE0_EL1_REG, xzr +1: msr mair_el1, x2 /*