diff mbox series

[kvmtool,08/21] arm: Add support for resetting a vCPU

Message ID 20230526221712.317287-9-oliver.upton@linux.dev (mailing list archive)
State New, archived
Headers show
Series arm64: Handle PSCI calls in userspace | expand

Commit Message

Oliver Upton May 26, 2023, 10:16 p.m. UTC
In order to handle PSCI, we need a way to reset a vCPU. Fortunately, the
KVM_ARM_VCPU_INIT ioctl is said to have the effect of an architectural
reset. Reconfigure features after the INIT ioctl, if necessary (SVE).

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
 arm/include/arm-common/kvm-cpu-arch.h |  2 ++
 arm/kvm-cpu.c                         | 14 +++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/arm/include/arm-common/kvm-cpu-arch.h b/arm/include/arm-common/kvm-cpu-arch.h
index bf5223eaa851..64a4fecd0aee 100644
--- a/arm/include/arm-common/kvm-cpu-arch.h
+++ b/arm/include/arm-common/kvm-cpu-arch.h
@@ -38,6 +38,8 @@  void kvm_cpu__set_kvm_arm_generic_target(struct kvm_arm_target *target);
 
 int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target);
 
+void kvm_cpu__arm_reset(struct kvm_cpu *vcpu);
+
 static inline bool kvm_cpu__emulate_io(struct kvm_cpu *vcpu, u16 port, void *data,
 				       int direction, int size, u32 count)
 {
diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 0ac488a93eef..426fc135f927 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -35,6 +35,15 @@  int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 	return -ENOSPC;
 }
 
+void kvm_cpu__arm_reset(struct kvm_cpu *vcpu)
+{
+	if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu->init))
+		die_perror("KVM_ARM_VCPU_INIT failed");
+
+	if (kvm_cpu__configure_features(vcpu))
+		die("Unable to configure requested vcpu features");
+}
+
 struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 {
 	struct kvm_arm_target *target;
@@ -122,15 +131,14 @@  struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 	if (err || target->init(vcpu))
 		die("Unable to initialise vcpu");
 
+	kvm_cpu__arm_reset(vcpu);
+
 	coalesced_offset = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION,
 				 KVM_CAP_COALESCED_MMIO);
 	if (coalesced_offset)
 		vcpu->ring = (void *)vcpu->kvm_run +
 			     (coalesced_offset * PAGE_SIZE);
 
-	if (kvm_cpu__configure_features(vcpu))
-		die("Unable to configure requested vcpu features");
-
 	return vcpu;
 }