linux/arch/arm64/kvm
Ahmed Genidi 3855a7b91d 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: cdf3671927 ("KVM: arm64: Intercept host's CPU_ON SMCs")
Reported-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Ahmed Genidi <ahmed.genidi@arm.com>
[ Mark: clarify commit message, handle E2H, move to C, remove macro ]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ahmed Genidi <ahmed.genidi@arm.com>
Cc: Ben Horgan <ben.horgan@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Leo Yan <leo.yan@arm.com>
Link: https://lore.kernel.org/r/20250227180526.1204723-3-mark.rutland@arm.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
History 2025-03-02 08:36:52 +00:00
..
hyp KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu() 2025-03-02 08:36:52 +00:00
vgic KVM: arm64: vgic: Hoist SGI/PPI alloc from vgic_init() to kvm_create_vgic() 2025-02-13 18:03:54 +00:00
.gitignore KVM: arm64: Generate hyp_constants.h for the host 2021-12-06 08:37:03 +00:00
arch_timer.c KVM: arm64: timer: Drop warning on failed interrupt signalling 2025-02-13 18:03:54 +00:00
arm.c KVM: arm64: Ensure a VMID is allocated before programming VTTBR_EL2 2025-02-20 16:29:28 +00:00
at.c arm64 updates for 6.14 2025-01-20 21:21:49 -08:00
debug.c KVM: arm64: Support trace filtering for guests 2025-01-12 12:50:11 +00:00
emulate-nested.c Merge branch kvm-arm64/nv-timers into kvmarm-master/next 2025-01-17 11:04:53 +00:00
fpsimd.c KVM: arm64: Simplify warning in kvm_arch_vcpu_load_fp() 2025-02-13 17:55:13 +00:00
guest.c KVM: arm64: Manage software step state at load/put 2024-12-20 09:04:06 +00:00
handle_exit.c KVM: arm64: nv: Honor MDCR_EL2.TDE routing for debug exceptions 2024-12-20 09:04:11 +00:00
hypercalls.c Merge branch kvm-arm64/psci-1.3 into kvmarm/next 2024-11-11 18:36:46 +00:00
inject_fault.c KVM: arm64: Fix typos 2024-02-24 09:13:33 +00:00
Kconfig Merge branch kvm-arm64/s2-ptdump into kvmarm-master/next 2024-09-12 08:38:02 +01:00
Makefile Merge branch kvm-arm64/s2-ptdump into kvmarm-master/next 2024-09-12 08:38:02 +01:00
mmio.c KVM: arm64: Don't retire aborted MMIO instruction 2024-10-26 14:37:49 +00:00
mmu.c Merge branch kvm-arm64/misc-6.14 into kvmarm-master/next 2025-01-17 11:06:50 +00:00
nested.c KVM: arm64: Fix nested S2 MMU structures reallocation 2025-02-04 15:02:16 +00:00
pauth.c KVM: arm64: nv: Work around lack of pauth support in old toolchains 2024-04-23 19:27:11 +01:00
pkvm.c KVM: arm64: Introduce the EL1 pKVM MMU 2024-12-20 09:44:00 +00:00
pmu-emul.c KVM: arm64: Only apply PMCR_EL0.P to the guest range of counters 2024-12-18 13:22:25 -08:00
pmu.c perf: arm_pmuv3: Add support for Armv9.4 PMU instruction counter 2024-08-16 13:09:12 +01:00
psci.c KVM: arm64: Add support for PSCI v1.2 and v1.3 2024-10-24 16:38:07 -07:00
ptdump.c KVM: arm64: Register ptdump with debugfs on guest creation 2024-09-10 21:32:51 +01:00
pvtime.c KVM: MMU: Make the definition of 'INVALID_GPA' common 2023-01-19 21:48:38 +00:00
reset.c KVM: arm64: Convert the SVE guest vcpu flag to a vm flag 2024-12-20 13:54:09 +00:00
stacktrace.c arm64: kvm: Introduce nvhe stack size constants 2025-01-08 11:25:28 +00:00
sys_regs.c KVM/arm64 fixes for 6.14, take #1 2025-02-04 11:14:53 -05:00
sys_regs.h Merge branch kvm-arm64/visibility-cleanups into kvmarm-master/next 2024-09-12 08:38:17 +01:00
trace.h KVM: arm64: Move virt/kvm/arm to arch/arm64 2020-05-16 15:03:59 +01:00
trace_arm.h KVM: arm64: Add tracepoint for MMIO accesses where ISV==0 2023-10-30 20:17:22 +00:00
trace_handle_exit.h KVM: arm64: Remove debug tracepoints 2024-12-20 09:01:25 +00:00
trng.c KVM: arm64: Implement the TRNG hypervisor call 2021-01-25 22:19:31 +00:00
va_layout.c arm64: alternatives: kvm: prepare for cap changes 2022-09-16 17:15:02 +01:00
vgic-sys-reg-v3.c KVM: arm64: vgic-v3: Convert userspace accessors over to FIELD_GET/FIELD_PREP 2022-07-17 11:55:33 +01:00
vmid.c KVM: arm64: Ensure a VMID is allocated before programming VTTBR_EL2 2025-02-20 16:29:28 +00:00