diff mbox

[3/4] KVM: MIPS: Implement EXIT_VM hypercall

Message ID 0cdae923b50fc9ea8355e7520a935b7a6705c095.1486377433.git-series.james.hogan@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

James Hogan Feb. 6, 2017, 10:46 a.m. UTC
Implement the MIPS EXIT_VM hypercall used by paravirtual guest kernels.
When the guest performs this hypercall, the request is passed to
userland in the form of a KVM_EXIT_SYSTEM_EVENT exit reason with system
event type KVM_SYSTEM_EVENT_SHUTDOWN.

We also document the hypercall along with the others as the
documentation was never added.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
Cc: David Daney <david.daney@cavium.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: linux-doc@vger.kernel.org
---
 Documentation/virtual/kvm/hypercalls.txt |  6 ++++++
 arch/mips/kvm/hypcall.c                  |  9 +++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/Documentation/virtual/kvm/hypercalls.txt b/Documentation/virtual/kvm/hypercalls.txt
index e9f1c9d3da98..f8108c84c46b 100644
--- a/Documentation/virtual/kvm/hypercalls.txt
+++ b/Documentation/virtual/kvm/hypercalls.txt
@@ -92,3 +92,9 @@  is used in the hypercall for future use.
 Architecture: mips
 Status: active
 Purpose: Return the frequency of CP0_Count in HZ.
+
+7. KVM_HC_MIPS_EXIT_VM
+------------------------
+Architecture: mips
+Status: active
+Purpose: Shut down the virtual machine.
diff --git a/arch/mips/kvm/hypcall.c b/arch/mips/kvm/hypcall.c
index 7c74ec25f2b9..c3345e5eec02 100644
--- a/arch/mips/kvm/hypcall.c
+++ b/arch/mips/kvm/hypcall.c
@@ -40,6 +40,15 @@  static int kvm_mips_hypercall(struct kvm_vcpu *vcpu, unsigned long num,
 		*hret = (s32)vcpu->arch.count_hz;
 		break;
 
+	case KVM_HC_MIPS_EXIT_VM:
+		/* Pass shutdown system event to userland */
+		memset(&vcpu->run->system_event, 0,
+		       sizeof(vcpu->run->system_event));
+		vcpu->run->system_event.type = KVM_SYSTEM_EVENT_SHUTDOWN;
+		vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+		ret = RESUME_HOST;
+		break;
+
 	default:
 		/* Report unimplemented hypercall to guest */
 		*hret = -KVM_ENOSYS;