KVM: arm64: initialize HCRX_EL2
authorKristina Martsenko <kristina.martsenko@arm.com>
Tue, 9 May 2023 14:22:25 +0000 (15:22 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Mon, 5 Jun 2023 16:05:05 +0000 (17:05 +0100)
ARMv8.7/9.2 adds a new hypervisor configuration register HCRX_EL2.
Initialize the register to a safe value (all fields 0), to be robust
against firmware that has not initialized it. This is also needed to
ensure that the register is reinitialized after a kexec by a future
kernel.

In addition, move SMPME setup over to the new flags, as it would
otherwise get overridden. It is safe to set the bit even if SME is not
(uniformly) supported, as it will write to a RES0 bit (having no
effect), and SME will be disabled by the cpufeature framework.
(Similar to how e.g. the API bit is handled in HCR_HOST_NVHE_FLAGS.)

Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20230509142235.3284028-2-kristina.martsenko@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/el2_setup.h
arch/arm64/include/asm/kvm_arm.h

index 037724b19c5c84d391dcc92d175a2c30559206e8..0201577863ca462b9eeab4fa31f336616c1c8b93 100644 (file)
        isb
 .endm
 
+.macro __init_el2_hcrx
+       mrs     x0, id_aa64mmfr1_el1
+       ubfx    x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
+       cbz     x0, .Lskip_hcrx_\@
+       mov_q   x0, HCRX_HOST_FLAGS
+       msr_s   SYS_HCRX_EL2, x0
+.Lskip_hcrx_\@:
+.endm
+
 /*
  * Allow Non-secure EL1 and EL0 to access physical timer and counter.
  * This is not necessary for VHE, since the host kernel runs in EL2,
  */
 .macro init_el2_state
        __init_el2_sctlr
+       __init_el2_hcrx
        __init_el2_timers
        __init_el2_debug
        __init_el2_lor
        cbz     x1, .Lskip_sme_\@
 
        msr_s   SYS_SMPRIMAP_EL2, xzr           // Make all priorities equal
-
-       mrs     x1, id_aa64mmfr1_el1            // HCRX_EL2 present?
-       ubfx    x1, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
-       cbz     x1, .Lskip_sme_\@
-
-       mrs_s   x1, SYS_HCRX_EL2
-       orr     x1, x1, #HCRX_EL2_SMPME_MASK    // Enable priority mapping
-       msr_s   SYS_HCRX_EL2, x1
 .Lskip_sme_\@:
 .endm
 
index baef29fcbeeedc9a978a8ee2aa2346ad7382f314..fb7fe28b8eb8f02e4ae158b417b32bd332c14345 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <asm/esr.h>
 #include <asm/memory.h>
+#include <asm/sysreg.h>
 #include <asm/types.h>
 
 /* Hyp Configuration Register (HCR) bits */
@@ -92,6 +93,8 @@
 #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
 
+#define HCRX_HOST_FLAGS (HCRX_EL2_SMPME)
+
 /* TCR_EL2 Registers bits */
 #define TCR_EL2_RES1           ((1U << 31) | (1 << 23))
 #define TCR_EL2_TBI            (1 << 20)