Skip to content

Commit af94aad

Browse files
kristina-martsenkoctmarinas
authored andcommitted
KVM: arm64: initialize HCRX_EL2
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 <[email protected]> Acked-by: Marc Zyngier <[email protected]> Acked-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 44c026a commit af94aad

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

arch/arm64/include/asm/el2_setup.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
isb
2323
.endm
2424

25+
.macro __init_el2_hcrx
26+
mrs x0, id_aa64mmfr1_el1
27+
ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
28+
cbz x0, .Lskip_hcrx_\@
29+
mov_q x0, HCRX_HOST_FLAGS
30+
msr_s SYS_HCRX_EL2, x0
31+
.Lskip_hcrx_\@:
32+
.endm
33+
2534
/*
2635
* Allow Non-secure EL1 and EL0 to access physical timer and counter.
2736
* This is not necessary for VHE, since the host kernel runs in EL2,
@@ -184,6 +193,7 @@
184193
*/
185194
.macro init_el2_state
186195
__init_el2_sctlr
196+
__init_el2_hcrx
187197
__init_el2_timers
188198
__init_el2_debug
189199
__init_el2_lor
@@ -284,14 +294,6 @@
284294
cbz x1, .Lskip_sme_\@
285295

286296
msr_s SYS_SMPRIMAP_EL2, xzr // Make all priorities equal
287-
288-
mrs x1, id_aa64mmfr1_el1 // HCRX_EL2 present?
289-
ubfx x1, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
290-
cbz x1, .Lskip_sme_\@
291-
292-
mrs_s x1, SYS_HCRX_EL2
293-
orr x1, x1, #HCRX_EL2_SMPME_MASK // Enable priority mapping
294-
msr_s SYS_HCRX_EL2, x1
295297
.Lskip_sme_\@:
296298
.endm
297299

arch/arm64/include/asm/kvm_arm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <asm/esr.h>
1111
#include <asm/memory.h>
12+
#include <asm/sysreg.h>
1213
#include <asm/types.h>
1314

1415
/* Hyp Configuration Register (HCR) bits */
@@ -92,6 +93,8 @@
9293
#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
9394
#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
9495

96+
#define HCRX_HOST_FLAGS (HCRX_EL2_SMPME)
97+
9598
/* TCR_EL2 Registers bits */
9699
#define TCR_EL2_RES1 ((1U << 31) | (1 << 23))
97100
#define TCR_EL2_TBI (1 << 20)

0 commit comments

Comments
 (0)