KVM: arm64: Move management of __hyp_running_vcpu to load/put on VHE
authorMarc Zyngier <maz@kernel.org>
Thu, 2 May 2024 15:40:30 +0000 (16:40 +0100)
committerMarc Zyngier <maz@kernel.org>
Fri, 3 May 2024 10:36:24 +0000 (11:36 +0100)
commit9a39359903fea9c354d89dce81ffd952859c90dc
tree6cf1d90d3b13ce61166002926329989d5bc0c0f9
parent5294afdbf45aced5295fe5941c58b40c41c23800
KVM: arm64: Move management of __hyp_running_vcpu to load/put on VHE

The per-CPU host context structure contains a __hyp_running_vcpu that
serves as a replacement for kvm_get_current_vcpu() in contexts where
we cannot make direct use of it (such as in the nVHE hypervisor).
Since there is a lot of common code between nVHE and VHE, the latter
also populates this field even if kvm_get_running_vcpu() always works.

We currently pretty inconsistent when populating __hyp_running_vcpu
to point to the currently running vcpu:

- on {n,h}VHE, we set __hyp_running_vcpu on entry to __kvm_vcpu_run
  and clear it on exit.

- on VHE, we set __hyp_running_vcpu on entry to __kvm_vcpu_run_vhe
  and never clear it, effectively leaving a dangling pointer...

VHE is obviously the odd one here. Although we could make it behave
just like nVHE, this wouldn't match the behaviour of KVM with VHE,
where the load phase is where most of the context-switch gets done.

So move all the __hyp_running_vcpu management to the VHE-specific
load/put phases, giving us a bit more sanity and matching the
behaviour of kvm_get_running_vcpu().

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20240502154030.3011995-1-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/vhe/switch.c