linux/arch/arm64/kvm
Marc Zyngier 0a216625c3 KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1
The kernel has an awfully complicated boot sequence in order to cope
with the various EL2 configurations, including those that "enhanced"
the architecture. We go from EL2 to EL1, then back to EL2, staying
at EL2 if VHE capable and otherwise go back to EL1.

Here's a paracetamol tablet for you.

The cpu_resume path follows the same logic, because coming up with
two versions of a square wheel is hard.

However, things aren't this straightforward with pKVM, as the host
resume path is always proxied by the hypervisor, which means that
the kernel is always entered at EL1. Which contradicts what the
__boot_cpu_mode[] array contains (it obviously says EL2).

This thus triggers a HVC call from EL1 to EL2 in a vain attempt
to upgrade from EL1 to EL2 VHE, which we are, funnily enough,
reluctant to grant to the host kernel. This is also completely
unexpected, and puzzles your average EL2 hacker.

Address it by fixing up the boot mode at the point the host gets
deprivileged. is_hyp_mode_available() and co already have a static
branch to deal with this, making it pretty safe.

This stable fix doesn't have an upstream version. The entire bootflow
has been reworked from 6.0 and that fixed the boot mode at the same
time, from commit 005e12676a ("arm64: head: record CPU boot mode after
enabling the MMU") to be precise. However, the latter is part of a 20
patches long series and can't be simply cherry-pick'ed.

Link: https://lore.kernel.org/r/20220624150651.1358849-1-ardb@kernel.org/
Link: https://lore.kernel.org/r/20221011165400.1241729-1-maz@kernel.org/
Cc: <stable@vger.kernel.org> # 5.15+
Reported-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vincent Donnefort <vdonnefort@google.com>
[Vincent: Add a paragraph about why this patch is for stable only]
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-12-02 17:41:08 +01:00
..
hyp KVM: arm64: Fix bad dereference on MTE-enabled systems 2022-11-10 18:15:41 +01:00
vgic KVM: arm64: vgic: Fix exit condition in scan_its_table() 2022-10-29 10:12:54 +02:00
arch_timer.c KVM: arm64: timer: Add support for SW-based deactivation 2021-06-01 10:46:00 +01:00
arm.c KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1 2022-12-02 17:41:08 +01:00
debug.c KVM: arm64: MDCR_EL2 is a 64-bit register 2021-08-20 11:12:17 +01:00
fpsimd.c KVM: arm64: Save/restore SVE state for nVHE 2021-03-18 14:23:12 +00:00
guest.c KVM: arm64: Reject 32bit user PSTATE on asymmetric systems 2022-08-25 11:40:29 +02:00
handle_exit.c KVM: arm64: Stop handle_exit() from handling HVC twice when an SError occurs 2022-02-08 18:34:06 +01:00
hypercalls.c KVM: arm64: Allow SMCCC_ARCH_WORKAROUND_3 to be discovered and migrated 2022-03-11 12:22:35 +01:00
inject_fault.c KVM: arm64: Move AArch32 exceptions over to AArch64 sysregs 2020-11-10 11:22:51 +00:00
irq.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 422 2019-06-05 17:37:15 +02:00
Kconfig Merge branch kvm-arm64/generic-entry into kvmarm-master/next 2021-08-20 12:23:09 +01:00
Makefile KVM: stats: Add fd-based API to read binary stats data 2021-06-24 11:47:57 -04:00
mmio.c KVM: arm64: Make kvm_skip_instr() and co private to HYP 2020-11-10 08:34:24 +00:00
mmu.c KVM: arm64: Release mmap_lock when using VM_SHARED with MTE 2021-10-05 13:22:45 +01:00
perf.c KVM: arm64: Fix PMU probe ordering 2021-09-20 12:43:34 +01:00
pmu-emul.c KVM: arm64: Fix PMU probe ordering 2021-09-20 12:43:34 +01:00
pmu.c KVM: arm64: Disable PMU support in protected mode 2021-03-19 12:02:19 +00:00
psci.c KVM: arm64: Allow SMCCC_ARCH_WORKAROUND_3 to be discovered and migrated 2022-03-11 12:22:35 +01:00
pvtime.c KVM: arm64: Use kvm_write_guest_lock when init stolen time 2020-12-03 19:02:18 +00:00
reset.c Merge branch kvm-arm64/psci/cpu_on into kvmarm-master/next 2021-08-20 12:23:02 +01:00
sys_regs.c KVM: arm64: Treat PMCR_EL1.LC as RES1 on asymmetric systems 2022-08-25 11:40:29 +02:00
sys_regs.h KVM: arm64: Refactor sys_regs.h,c for nVHE reuse 2021-08-20 11:12:17 +01:00
trace_arm.h KVM: Move arm64's MMU notifier trace events to generic code 2021-04-17 08:30:56 -04:00
trace_handle_exit.h KVM: arm64: Upgrade trace_kvm_arm_set_dreg32() to 64bit 2021-08-20 11:12:18 +01:00
trace.h KVM: arm64: Move virt/kvm/arm to arch/arm64 2020-05-16 15:03:59 +01:00
trng.c KVM: arm64: Implement the TRNG hypervisor call 2021-01-25 22:19:31 +00:00
va_layout.c KVM: arm64: Generate final CTR_EL0 value when running in Protected mode 2021-03-25 11:00:33 +00:00
vgic-sys-reg-v3.c KVM: arm64: Drop is_aarch32 trap attribute 2020-11-10 11:22:52 +00:00