Skip to content

Commit 3855a7b

Browse files
Ahmed GenidiMarc Zyngier
Ahmed Genidi
authored and
Marc Zyngier
committed
KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu()
When KVM is in protected mode, host calls to PSCI are proxied via EL2, and cold entries from CPU_ON, CPU_SUSPEND, and SYSTEM_SUSPEND bounce through __kvm_hyp_init_cpu() at EL2 before entering the host kernel's entry point at EL1. While __kvm_hyp_init_cpu() initializes SPSR_EL2 for the exception return to EL1, it does not initialize SCTLR_EL1. Due to this, it's possible to enter EL1 with SCTLR_EL1 in an UNKNOWN state. In practice this has been seen to result in kernel crashes after CPU_ON as a result of SCTLR_EL1.M being 1 in violation of the initial core configuration specified by PSCI. Fix this by initializing SCTLR_EL1 for cold entry to the host kernel. As it's necessary to write to SCTLR_EL12 in VHE mode, this initialization is moved into __kvm_host_psci_cpu_entry() where we can use write_sysreg_el1(). The remnants of the '__init_el2_nvhe_prepare_eret' macro are folded into its only caller, as this is clearer than having the macro. Fixes: cdf3671 ("KVM: arm64: Intercept host's CPU_ON SMCs") Reported-by: Leo Yan <[email protected]> Signed-off-by: Ahmed Genidi <[email protected]> [ Mark: clarify commit message, handle E2H, move to C, remove macro ] Signed-off-by: Mark Rutland <[email protected]> Cc: Ahmed Genidi <[email protected]> Cc: Ben Horgan <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Leo Yan <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Leo Yan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 7a68b55 commit 3855a7b

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

arch/arm64/include/asm/el2_setup.h

-5
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@
270270
.Lskip_gcs_\@:
271271
.endm
272272

273-
.macro __init_el2_nvhe_prepare_eret
274-
mov x0, #INIT_PSTATE_EL1
275-
msr spsr_el2, x0
276-
.endm
277-
278273
.macro __init_el2_mpam
279274
/* Memory Partitioning And Monitoring: disable EL2 traps */
280275
mrs x1, id_aa64pfr0_el1

arch/arm64/kernel/head.S

+2-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
322322
msr sctlr_el1, x1
323323
mov x2, xzr
324324
3:
325-
__init_el2_nvhe_prepare_eret
325+
mov x0, #INIT_PSTATE_EL1
326+
msr spsr_el2, x0
326327

327328
mov w0, #BOOT_CPU_MODE_EL2
328329
orr x0, x0, x2

arch/arm64/kvm/hyp/nvhe/hyp-init.S

-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ SYM_CODE_START_LOCAL(__kvm_hyp_init_cpu)
214214

215215
bl __kvm_init_el2_state
216216

217-
__init_el2_nvhe_prepare_eret
218-
219217
/* Enable MMU, set vectors and stack. */
220218
mov x0, x28
221219
bl ___kvm_hyp_init // Clobbers x0..x2

arch/arm64/kvm/hyp/nvhe/psci-relay.c

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bool is_cpu_on)
218218
if (is_cpu_on)
219219
release_boot_args(boot_args);
220220

221+
write_sysreg_el1(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR);
222+
write_sysreg(INIT_PSTATE_EL1, SPSR_EL2);
223+
221224
__host_enter(host_ctxt);
222225
}
223226

0 commit comments

Comments
 (0)