KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1
Subsystems (3)
PATCH 1/1 KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1
From: Marc Zyngier <[email protected]>
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 patch doesn't have an upstream version. It's been fixed by the side effect of another upstream patch. see conversation [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/arm.c +11 -0
@@ -2000,6 +2000,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; }
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Quoted 63 lines · Vincent Donnefort
From: Marc Zyngier <[email protected]>
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_resumepath 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 <[email protected]> # 5.15+Reported-by Vincent Donnefort <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Tested-by Vincent Donnefort <[email protected]>---
This patch doesn't have an upstream version. It's been fixed by the side effect of another upstream patch. see conversation [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/arm.c +11
-0@@ -2000,6 +2000,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; }Signature · 1 line
2.38.1.431.g37b22c650d-goog
Hi Greg,
Any chance to pick this fix for 5.15?
Thanks!
Signature · 1 line
Vincent.
Quoted 67 lines · Vincent Donnefort
Quoted 63 lines · Vincent Donnefort
From: Marc Zyngier <[email protected]>
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_resumepath 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 <[email protected]> # 5.15+Reported-by Vincent Donnefort <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Tested-by Vincent Donnefort <[email protected]>---
This patch doesn't have an upstream version. It's been fixed by the side effect of another upstream patch. see conversation [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/arm.c +11
-0@@ -2000,6 +2000,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; }Signature · 1 line
2.38.1.431.g37b22c650d-googHi Greg,
Quoted 1 line
Any chance to pick this fix for 5.15?
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
Quoted 70 lines · Greg KH
Quoted 67 lines · Vincent Donnefort
Quoted 63 lines · Vincent Donnefort
From: Marc Zyngier <[email protected]>
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_resumepath 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 <[email protected]> # 5.15+Reported-by Vincent Donnefort <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Tested-by Vincent Donnefort <[email protected]>---
This patch doesn't have an upstream version. It's been fixed by the side effect of another upstream patch. see conversation [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/arm.c +11
-0@@ -2000,6 +2000,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; }Signature · 1 line
2.38.1.431.g37b22c650d-googHi Greg,
Quoted 1 line
Any chance to pick this fix for 5.15?
Quoted 8 lines
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.</formletter>
Sadly this patch doesn't have an upstream version equivalent. The reason is it's been fixed as a side effect of another feature introduction, hence the stable-only fix made by Marc. [1]
Not sure how to handle that case.
Quoted 78 lines · Vincent Donnefort
Quoted 77 lines · Greg KH
Quoted 67 lines · Vincent Donnefort
Quoted 63 lines · Vincent Donnefort
From: Marc Zyngier <[email protected]>
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_resumepath 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 <[email protected]> # 5.15+Reported-by Vincent Donnefort <[email protected]>Signed-off-by Marc Zyngier <[email protected]>Tested-by Vincent Donnefort <[email protected]>---
This patch doesn't have an upstream version. It's been fixed by the side effect of another upstream patch. see conversation [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/arm.c +11
-0@@ -2000,6 +2000,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; }Signature · 1 line
2.38.1.431.g37b22c650d-googHi Greg,
Quoted 1 line
Any chance to pick this fix for 5.15?
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
Quoted 7 lines
Quoted 1 line
</formletter>
Sadly this patch doesn't have an upstream version equivalent. The reason is it's been fixed as a side effect of another feature introduction, hence the stable-only fix made by Marc. [1]
Not sure how to handle that case.
It needs to really really really document why this is not relevant for newer kernels and what commit fixed this instead and why this is all happening in the changelog text, AND give us a clue in maybe the subject line [PATCH 5.15] to show that this is only for a specific tree.
it was not obvious here at all, sorry, I missed the --- comments in the normal flood of other patches.
thanks,
gre gk-h