Skip to content

Commit 934bf87

Browse files
committed
KVM: arm64: Load the stage-2 MMU context in kvm_vcpu_load_vhe()
To date the VHE code has aggressively reloaded the stage-2 MMU context on every guest entry, despite the fact that this isn't necessary. This was probably done for consistency with the nVHE code, which needs to switch in/out the stage-2 MMU context as both the host and guest run at EL1. Hoist __load_stage2() into kvm_vcpu_load_vhe(), thus avoiding a reload on every guest entry/exit. This is likely to be beneficial to systems with one of the speculative AT errata, as there is now one fewer context synchronization event on the guest entry path. Additionally, it is possible that implementations have hitched correctness mitigations on writes to VTTBR_EL2, which are now elided on guest re-entry. Note that __tlb_switch_to_guest() is deliberately left untouched as it can be called outside the context of a running vCPU. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 27cde4c commit 934bf87

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void kvm_vcpu_load_vhe(struct kvm_vcpu *vcpu)
120120
{
121121
__vcpu_load_switch_sysregs(vcpu);
122122
__vcpu_load_activate_traps(vcpu);
123+
__load_stage2(vcpu->arch.hw_mmu, vcpu->arch.hw_mmu->arch);
123124
}
124125

125126
void kvm_vcpu_put_vhe(struct kvm_vcpu *vcpu)
@@ -182,17 +183,11 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
182183
sysreg_save_host_state_vhe(host_ctxt);
183184

184185
/*
185-
* ARM erratum 1165522 requires us to configure both stage 1 and
186-
* stage 2 translation for the guest context before we clear
187-
* HCR_EL2.TGE.
188-
*
189-
* We have already configured the guest's stage 1 translation in
190-
* kvm_vcpu_load_sysregs_vhe above. We must now call
191-
* __load_stage2 before __activate_traps, because
192-
* __load_stage2 configures stage 2 translation, and
193-
* __activate_traps clear HCR_EL2.TGE (among other things).
186+
* Note that ARM erratum 1165522 requires us to configure both stage 1
187+
* and stage 2 translation for the guest context before we clear
188+
* HCR_EL2.TGE. The stage 1 and stage 2 guest context has already been
189+
* loaded on the CPU in kvm_vcpu_load_vhe().
194190
*/
195-
__load_stage2(vcpu->arch.hw_mmu, vcpu->arch.hw_mmu->arch);
196191
__activate_traps(vcpu);
197192

198193
__kvm_adjust_pc(vcpu);

0 commit comments

Comments
 (0)