FROMLIST: 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. 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> Bug: 258157858 Link: https://lore.kernel.org/all/20221108100138.3887862-1-vdonnefort@google.com/ Change-Id: I4a2269402ececa0ec47cab88343c3c623b4b2e3d
This commit is contained in:
committed by
Vincent Donnefort
parent
b72960ae91
commit
7266895825
@@ -2162,6 +2162,17 @@ static int pkvm_drop_host_privileges(void)
|
||||
* once the host stage 2 is installed.
|
||||
*/
|
||||
static_branch_enable(&kvm_protected_mode_initialized);
|
||||
|
||||
/*
|
||||
* Fixup the boot mode so that we don't take spurious round
|
||||
* trips via EL2 on cpu_resume. Flush to the PoC for a good
|
||||
* measure, so that it can be observed by a CPU coming out of
|
||||
* suspend with the MMU off.
|
||||
*/
|
||||
__boot_cpu_mode[0] = __boot_cpu_mode[1] = BOOT_CPU_MODE_EL1;
|
||||
dcache_clean_poc((unsigned long)__boot_cpu_mode,
|
||||
(unsigned long)(__boot_cpu_mode + 2));
|
||||
|
||||
on_each_cpu(_kvm_host_prot_finalize, &ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user