diff mbox series

[RFC,v1,22/30] KVM: arm64: reduce scope of __guest_enter to depend only on kvm_cpu_ctxt

Message ID 20210924125359.2587041-23-tabba@google.com (mailing list archive)
State New, archived
Headers show
Series Reduce scope of vcpu state at hyp by refactoring out state hyp needs | expand

Commit Message

Fuad Tabba Sept. 24, 2021, 12:53 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index b379c2b96f33..c5206e958136 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -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);
 
diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S
index 8e7033aa5770..f553f184e402 100644
--- a/arch/arm64/kvm/hyp/entry.S
+++ b/arch/arm64/kvm/hyp/entry.S
@@ -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)
diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 483df8fe052e..d9a69e66158c 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -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));
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 64de9f0d7636..5039910a7c80 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -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));