KVM: arm64: Load the stage-2 MMU context in kvm_vcpu_load_vhe()
authorOliver Upton <oliver.upton@linux.dev>
Wed, 18 Oct 2023 23:32:12 +0000 (23:32 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Fri, 20 Oct 2023 17:52:01 +0000 (17:52 +0000)
commit934bf871f0113e1e57cfa262dcbc9aad5fa0a252
tree7ce30e9dcc50fd4014f9dbf73647612297994c7b
parent27cde4c0fe28eab228d1fc9d84c68a109219887d
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/20231018233212.2888027-6-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/hyp/vhe/switch.c