mirror-linux/arch/arm64/kernel
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>
2025-03-02 08:36:52 +00:00
..
pi arm64/mm: Override PARange for !LPA2 and use it consistently 2024-12-19 17:23:52 +00:00
probes - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
vdso arm64: Handle .ARM.attributes section in linker scripts 2025-02-07 09:56:57 +00:00
vdso32 arm64: vdso: Drop LBASE_VDSO 2024-11-02 12:37:33 +01:00
.gitignore
Makefile arm64: Detect if in a realm and set RIPAS RAM 2024-10-23 10:19:32 +01:00
Makefile.syscalls syscalls: fix syscall macros for newfstat/newfstatat 2024-08-02 15:20:47 +02:00
acpi.c Merge branch 'for-next/vcpu-hotplug' into for-next/core 2024-07-11 19:10:02 +01:00
acpi_numa.c arm64: ACPI: NUMA: initialize all values of acpi_early_node_map to NUMA_NO_NODE 2024-08-14 17:51:39 +01:00
acpi_parking_protocol.c arm64: smp: Remove dedicated wakeup IPI 2023-09-25 17:15:28 +01:00
alternative.c Merge branches 'for-next/kpti', 'for-next/missing-proto-warn', 'for-next/iss2-decode', 'for-next/kselftest', 'for-next/misc', 'for-next/feat_mops', 'for-next/module-alloc', 'for-next/sysreg', 'for-next/cpucap', 'for-next/acpi', 'for-next/kdump', 'for-next/acpi-doc', 'for-next/doc' and 'for-next/tpidr2-fix', remote-tracking branch 'arm64/for-next/perf' into for-next/core 2023-06-23 18:32:20 +01:00
armv8_deprecated.c sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00
asm-offsets.c fgraph: Replace fgraph_ret_regs with ftrace_regs 2024-12-26 10:50:02 -05:00
cacheinfo.c arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array 2025-02-07 09:57:56 +00:00
compat_alignment.c
cpu-reset.S arm64: kernel: remove SHF_WRITE|SHF_EXECINSTR from .idmap.text 2023-05-02 12:42:22 +01:00
cpu_errata.c KVM: arm64: Work around x1e's CNTVOFF_EL2 bogosity 2025-01-02 19:19:10 +00:00
cpu_ops.c
cpufeature.c arm64: Add missing registrations of hwcaps 2025-02-13 11:13:09 +00:00
cpuinfo.c arm64/hwcap: Describe 2024 dpISA extensions to userspace 2025-01-08 13:41:06 +00:00
crash_dump.c
debug-monitors.c Merge branch 'for-next/mops' into for-next/core 2024-11-14 12:07:28 +00:00
efi-header.S arm64: efi: Enable BTI codegen and add PE/COFF annotation 2023-04-20 15:43:45 +02:00
efi-rt-wrapper.S
efi.c efi: arm64: Map Device with Prot Shared 2024-10-23 10:19:32 +01:00
elfcore.c
entry-common.c Merge branch 'for-next/mops' into for-next/core 2024-11-14 12:07:28 +00:00
entry-fpsimd.S
entry-ftrace.S fgraph: Replace fgraph_ret_regs with ftrace_regs 2024-12-26 10:50:02 -05:00
entry.S arm64: stacktrace: unwind exception boundaries 2024-10-17 18:06:25 +01:00
fpsimd.c KVM/arm64 fixes for 6.14, take #2 2025-02-14 18:32:47 -05:00
ftrace.c ftrace: Add ftrace_get_symaddr to convert fentry_ip to symaddr 2024-12-26 10:50:07 -05:00
head.S KVM: arm64: Initialize SCTLR_EL1 in __kvm_hyp_init_cpu() 2025-03-02 08:36:52 +00:00
hibernate-asm.S
hibernate.c hugetlb: arm64: add mte support 2024-10-16 14:50:47 +01:00
hw_breakpoint.c perf/bpf: Remove unneeded uses_default_overflow_handler() 2024-04-12 11:49:50 +02:00
hyp-stub.S arm64: Fix usage of new shifted MDCR_EL2 values 2024-11-26 06:31:36 -08:00
idle.c arm64: idle: Tag the arm64 idle functions as __cpuidle 2023-09-25 17:15:28 +01:00
image-vars.h KVM: arm64: Work around x1e's CNTVOFF_EL2 bogosity 2025-01-02 19:19:10 +00:00
image.h
io.c arm64: Use new fallback IO memcpy/memset 2024-10-28 21:44:29 +00:00
irq.c arm64: irq: set the correct node for shadow call stack 2023-12-13 12:09:00 +00:00
jump_label.c asm-generic: introduce text-patching.h 2024-11-07 14:25:15 -08:00
kaslr.c arm64: kaslr: Use feature override instead of parsing the cmdline again 2024-02-16 12:42:31 +00:00
kexec_image.c kexec_file, arm64: print out debugging message if required 2023-12-20 15:02:57 -08:00
kgdb.c asm-generic: introduce text-patching.h 2024-11-07 14:25:15 -08:00
kuser32.S arm64: Update Documentation/arm references 2023-06-12 06:33:48 -06:00
machine_kexec.c kexec: Consolidate machine_kexec_mask_interrupts() implementation 2024-12-11 20:32:34 +01:00
machine_kexec_file.c arm64, crash: wrap crash dumping code into crash related ifdefs 2024-02-23 17:48:23 -08:00
module-plts.c Merge branch 'for-next/cpus_have_const_cap' into for-next/core 2023-10-26 17:10:18 +01:00
module.c arm64/scs: Fix handling of DWARF augmentation data in CIE/FDE frames 2024-11-08 16:37:55 +00:00
mte.c hugetlb: arm64: add mte support 2024-10-16 14:50:47 +01:00
paravirt.c
patching.c arm64: patching: avoid early page_to_phys() 2024-12-03 18:05:42 +00:00
pci.c arm64: PCI: Migrate ACPI related functions to pci-acpi.c 2024-08-27 15:48:34 +02:00
perf_callchain.c perf/core: Correct perf sampling with guest VMs 2024-11-14 10:40:01 +01:00
perf_regs.c
pointer_auth.c
process.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
proton-pack.c arm64: errata: Unify speculative SSBS errata logic 2024-06-12 16:07:21 +01:00
psci.c arm64: psci: Ignore DENIED CPUs 2024-06-28 18:38:31 +01:00
ptrace.c arm64: ptrace: fix partial SETREGSET for NT_ARM_GCS 2024-12-05 18:05:51 +00:00
reloc_test_core.c ARM64: reloc_test: add missing MODULE_DESCRIPTION() macro 2024-06-13 10:23:54 +01:00
reloc_test_syms.S
relocate_kernel.S
return_address.c
rsi.c arm64: rsi: Add automatic arm-cca-guest module loading 2025-01-08 13:58:49 +00:00
sdei.c arm64: sdei: abort running SDEI handlers during crash 2023-08-04 17:35:33 +01:00
setup.c mm/memblock: add memblock_alloc_or_panic interface 2025-01-25 20:22:38 -08:00
signal.c arm64/signal: Silence sparse warning storing GCSPR_EL0 2024-12-20 14:12:04 +00:00
signal32.c arm64: rework compat syscall macros 2024-07-10 14:23:38 +02:00
sigreturn32.S arm64: rework compat syscall macros 2024-07-10 14:23:38 +02:00
sleep.S arm64: mm: Handle LVA support as a CPU feature 2024-02-16 12:42:36 +00:00
smccc-call.S arm64: smccc: Remove broken support for SMCCCv1.3 SVE discard hint 2024-11-07 11:18:52 +00:00
smp.c arm64 updates for 6.12 2024-09-16 06:55:07 +02:00
smp_spin_table.c
stacktrace.c arm64: stacktrace: Don't WARN when unwinding other tasks 2024-12-12 16:23:15 +00:00
suspend.c arm64/sme: Restore SME registers on exit from suspend 2024-02-20 12:19:15 +00:00
sys.c arm64: generate 64-bit syscall.tbl 2024-07-10 14:23:38 +02:00
sys32.c arm64: convert unistd_32.h to syscall.tbl format 2024-07-10 14:23:38 +02:00
sys_compat.c arm64: Avoid cpus_have_const_cap() for ARM64_WORKAROUND_1542419 2023-10-16 14:17:06 +01:00
syscall.c arm64: convert unistd_32.h to syscall.tbl format 2024-07-10 14:23:38 +02:00
time.c
topology.c arm64: amu: Delay allocating cpumask for AMU FIE support 2025-02-13 11:06:22 +00:00
trace-events-emulation.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
traps.c - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
vdso-wrap.S
vdso.c arm64: vdso: Use only one single vvar mapping 2024-11-02 12:37:33 +01:00
vdso32-wrap.S
vmcore_info.c crash: split vmcoreinfo exporting code out from crash_core.c 2024-02-23 17:48:22 -08:00
vmlinux.lds.S arm64: Handle .ARM.attributes section in linker scripts 2025-02-07 09:56:57 +00:00
watchdog_hld.c arm64: enable perf events based hard lockup detector 2023-06-09 17:44:22 -07:00