@@ -100,7 +100,7 @@ void activate_traps_vhe_load(struct vcpu_hyp_state *vcpu_hyps);
void deactivate_traps_vhe_put(void);
#endif
-u64 __guest_enter(struct kvm_vcpu *vcpu);
+u64 __guest_enter(struct kvm_cpu_context *guest_ctxt);
bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt);
@@ -18,12 +18,12 @@
.text
/*
- * u64 __guest_enter(struct kvm_vcpu *vcpu);
+ * u64 __guest_enter(struct kvm_cpu_context *guest_ctxt);
*/
SYM_FUNC_START(__guest_enter)
- // x0: vcpu
+ // x0: guest context (input parameter)
// x1-x17: clobbered by macros
- // x29: guest context
+ // x29: guest context (maintained for call duration)
adr_this_cpu x1, kvm_hyp_ctxt, x2
@@ -47,9 +47,7 @@ alternative_else_nop_endif
ret
1:
- set_loaded_vcpu x0, x1, x2
-
- add x29, x0, #VCPU_CONTEXT
+ mov x29, x0
// Macro ptrauth_switch_to_guest format:
// ptrauth_switch_to_guest(guest cxt, tmp1, tmp2, tmp3)
@@ -228,8 +228,11 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
__debug_switch_to_guest(vcpu);
do {
+ struct kvm_cpu_context *hyp_ctxt = this_cpu_ptr(&kvm_hyp_ctxt);
+ set_hyp_running_vcpu(hyp_ctxt, vcpu);
+
/* Jump in the fire! */
- exit_code = __guest_enter(vcpu);
+ exit_code = __guest_enter(guest_ctxt);
/* And we're baaack! */
} while (fixup_guest_exit(vcpu, vgic, &exit_code));
@@ -142,8 +142,11 @@ static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
__debug_switch_to_guest(vcpu);
do {
+ struct kvm_cpu_context *hyp_ctxt = this_cpu_ptr(&kvm_hyp_ctxt);
+ set_hyp_running_vcpu(hyp_ctxt, vcpu);
+
/* Jump in the fire! */
- exit_code = __guest_enter(vcpu);
+ exit_code = __guest_enter(guest_ctxt);
/* And we're baaack! */
} while (fixup_guest_exit(vcpu, vgic, &exit_code));
guest_enter doesn't need the vcpu, only the guest's kvm_cpu_ctxt. Reduce its scope to that. With this commit, the only state in struct vcpu that the hypervisor needs to save locally in future patches is guest context (kvm_cpu_context) and the hypervisor state (vcpu_hyp_state). Signed-off-by: Fuad Tabba <tabba@google.com> --- arch/arm64/include/asm/kvm_hyp.h | 2 +- arch/arm64/kvm/hyp/entry.S | 10 ++++------ arch/arm64/kvm/hyp/nvhe/switch.c | 5 ++++- arch/arm64/kvm/hyp/vhe/switch.c | 5 ++++- 4 files changed, 13 insertions(+), 9 deletions(-)