[PATCH 2/2 v2] kvm: set exit_reason to KVM_EXIT_GUEST_PANICED when guest paniced

Wen Congyang
2012-03-07T01:55:01Z

This patch introduces new request bit KVM_REQ_GUEST_PANICED.
If this bit is set, set vcpu's exit_reason to KVM_EXIT_GUEST_PANICED.
And then the user space can know the guest paniced.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
arch/x86/kvm/x86.c | 11 +++++++++++
include/linux/kvm.h | 1 +
include/linux/kvm_host.h | 1 +
3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c9d99e5..978e398 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5013,6 +5013,10 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
case KVM_HC_VAPIC_POLL_IRQ:
ret = 0;
break;
+ case KVM_HC_GUEST_PANICED:
+ ret = 0;
+ kvm_make_request(KVM_REQ_GUEST_PANICED, vcpu);
+ break;
default:
ret = -KVM_ENOSYS;
break;
@@ -5228,6 +5232,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
r = 0;
goto out;
}
+
+ if (kvm_check_request(KVM_REQ_GUEST_PANICED, vcpu)) {
+ vcpu->run->exit_reason = KVM_EXIT_GUEST_PANICED;
+ r = 0;
+ goto out;
+ }
+
if (kvm_check_request(KVM_REQ_DEACTIVATE_FPU, vcpu)) {
vcpu->fpu_active = 0;
kvm_x86_ops->fpu_deactivate(vcpu);
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index acbe429..a46052e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -163,6 +163,7 @@ struct kvm_pit_config {
#define KVM_EXIT_OSI 18
#define KVM_EXIT_PAPR_HCALL 19
#define KVM_EXIT_S390_UCONTROL 20
+#define KVM_EXIT_GUEST_PANICED 21

/* For KVM_EXIT_INTERNAL_ERROR */
#define KVM_INTERNAL_ERROR_EMULATION 1
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 355e445..026bbe5 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -54,6 +54,7 @@
#define KVM_REQ_IMMEDIATE_EXIT 15
#define KVM_REQ_PMU 16
#define KVM_REQ_PMI 17
+#define KVM_REQ_GUEST_PANICED 18

#define KVM_USERSPACE_IRQ_SOURCE_ID 0

--
1.7.1