Centos-kernel-stream-9/arch/arm64/kvm/hyp
Gavin Shan 75aeb442da KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu()
JIRA: https://issues.redhat.com/browse/RHEL-82298

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>
(cherry picked from commit 3855a7b91d42ebf3513b7ccffc44807274978b3d)
Signed-off-by: Gavin Shan <gshan@redhat.com>
Conflicts:
	arch/arm64/include/asm/el2_setup.h
	Contextual conflicts due to missed upstream commits ff5181d8a2a82
	("arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0
	and EL1") and 23b33d1e168cf ("arm64: head.S: Initialise MPAM EL2
	registers and disable traps")
2025-03-19 11:00:14 +10:00
..
include KVM: arm64: Eagerly switch ZCR_EL{1,2} 2025-03-19 11:00:14 +10:00
nvhe KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu() 2025-03-19 11:00:14 +10:00
vhe KVM: arm64: Eagerly switch ZCR_EL{1,2} 2025-03-19 11:00:14 +10:00
Makefile
aarch32.c KVM: arm64: AArch32: Fix spurious trapping of conditional instructions 2024-06-27 08:25:48 -04:00
entry.S KVM: arm64: Eagerly switch ZCR_EL{1,2} 2025-03-19 11:00:14 +10:00
exception.c
fpsimd.S KVM: arm64: Reintroduce __sve_save_state 2024-06-27 08:25:49 -04:00
hyp-constants.c
hyp-entry.S
pgtable.c arm64/kvm: Avoid invalid physical addresses to signal owner updates 2025-03-19 11:00:13 +10:00
vgic-v2-cpuif-proxy.c
vgic-v3-sr.c KVM: arm64: Just advertise SEIS as 0 when emulating ICC_CTLR_EL1 2024-12-12 21:57:19 -05:00