aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-03-04 07:17:08 -0500
committerAvi Kivity <avi@qumranet.com>2007-05-03 03:52:24 -0400
commit8eb7d334bd8e693340ee198280f7d45035cdab8c (patch)
tree438ec0b6b6c7714e436884576a3fdce84507813f
parentb4e63f560beb187cffdaf706e534a1e2f9effb66 (diff)
KVM: Fold kvm_run::exit_type into kvm_run::exit_reason
Currently, userspace is told about the nature of the last exit from the guest using two fields, exit_type and exit_reason, where exit_type has just two enumerations (and no need for more). So fold exit_type into exit_reason, reducing the complexity of determining what really happened. Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--drivers/kvm/kvm_main.c3
-rw-r--r--drivers/kvm/svm.c7
-rw-r--r--drivers/kvm/vmx.c7
-rw-r--r--include/linux/kvm.h15
4 files changed, 15 insertions, 17 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index de93117f1e97..ac44df551aa8 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1608,8 +1608,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1608 1608
1609 vcpu->mmio_needed = 0; 1609 vcpu->mmio_needed = 0;
1610 1610
1611 if (kvm_run->exit_type == KVM_EXIT_TYPE_VM_EXIT 1611 if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
1612 && kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
1613 kvm_arch_ops->cache_regs(vcpu); 1612 kvm_arch_ops->cache_regs(vcpu);
1614 vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret; 1613 vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret;
1615 kvm_arch_ops->decache_regs(vcpu); 1614 kvm_arch_ops->decache_regs(vcpu);
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index d4b2936479d9..b09928f14219 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1298,8 +1298,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1298{ 1298{
1299 u32 exit_code = vcpu->svm->vmcb->control.exit_code; 1299 u32 exit_code = vcpu->svm->vmcb->control.exit_code;
1300 1300
1301 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
1302
1303 if (is_external_interrupt(vcpu->svm->vmcb->control.exit_int_info) && 1301 if (is_external_interrupt(vcpu->svm->vmcb->control.exit_int_info) &&
1304 exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR) 1302 exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
1305 printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x " 1303 printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
@@ -1609,8 +1607,9 @@ again:
1609 vcpu->svm->next_rip = 0; 1607 vcpu->svm->next_rip = 0;
1610 1608
1611 if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) { 1609 if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
1612 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY; 1610 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
1613 kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code; 1611 kvm_run->fail_entry.hardware_entry_failure_reason
1612 = vcpu->svm->vmcb->control.exit_code;
1614 post_kvm_run_save(vcpu, kvm_run); 1613 post_kvm_run_save(vcpu, kvm_run);
1615 return 0; 1614 return 0;
1616 } 1615 }
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 71410a65bb90..cf9568fbe8a5 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1922,10 +1922,10 @@ again:
1922 1922
1923 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); 1923 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
1924 1924
1925 kvm_run->exit_type = 0;
1926 if (fail) { 1925 if (fail) {
1927 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY; 1926 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
1928 kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR); 1927 kvm_run->fail_entry.hardware_entry_failure_reason
1928 = vmcs_read32(VM_INSTRUCTION_ERROR);
1929 r = 0; 1929 r = 0;
1930 } else { 1930 } else {
1931 /* 1931 /*
@@ -1935,7 +1935,6 @@ again:
1935 profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP)); 1935 profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
1936 1936
1937 vcpu->launched = 1; 1937 vcpu->launched = 1;
1938 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
1939 r = kvm_handle_exit(kvm_run, vcpu); 1938 r = kvm_handle_exit(kvm_run, vcpu);
1940 if (r > 0) { 1939 if (r > 0) {
1941 /* Give scheduler a change to reschedule. */ 1940 /* Give scheduler a change to reschedule. */
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 9151ebfa22e9..57f47ef93829 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -11,7 +11,7 @@
11#include <asm/types.h> 11#include <asm/types.h>
12#include <linux/ioctl.h> 12#include <linux/ioctl.h>
13 13
14#define KVM_API_VERSION 7 14#define KVM_API_VERSION 8
15 15
16/* 16/*
17 * Architectural interrupt line count, and the size of the bitmap needed 17 * Architectural interrupt line count, and the size of the bitmap needed
@@ -34,9 +34,6 @@ struct kvm_memory_region {
34#define KVM_MEM_LOG_DIRTY_PAGES 1UL 34#define KVM_MEM_LOG_DIRTY_PAGES 1UL
35 35
36 36
37#define KVM_EXIT_TYPE_FAIL_ENTRY 1
38#define KVM_EXIT_TYPE_VM_EXIT 2
39
40enum kvm_exit_reason { 37enum kvm_exit_reason {
41 KVM_EXIT_UNKNOWN = 0, 38 KVM_EXIT_UNKNOWN = 0,
42 KVM_EXIT_EXCEPTION = 1, 39 KVM_EXIT_EXCEPTION = 1,
@@ -47,6 +44,7 @@ enum kvm_exit_reason {
47 KVM_EXIT_MMIO = 6, 44 KVM_EXIT_MMIO = 6,
48 KVM_EXIT_IRQ_WINDOW_OPEN = 7, 45 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
49 KVM_EXIT_SHUTDOWN = 8, 46 KVM_EXIT_SHUTDOWN = 8,
47 KVM_EXIT_FAIL_ENTRY = 9,
50}; 48};
51 49
52/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ 50/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
@@ -57,12 +55,11 @@ struct kvm_run {
57 __u8 padding1[3]; 55 __u8 padding1[3];
58 56
59 /* out */ 57 /* out */
60 __u32 exit_type;
61 __u32 exit_reason; 58 __u32 exit_reason;
62 __u32 instruction_length; 59 __u32 instruction_length;
63 __u8 ready_for_interrupt_injection; 60 __u8 ready_for_interrupt_injection;
64 __u8 if_flag; 61 __u8 if_flag;
65 __u16 padding2; 62 __u8 padding2[6];
66 63
67 /* in (pre_kvm_run), out (post_kvm_run) */ 64 /* in (pre_kvm_run), out (post_kvm_run) */
68 __u64 cr8; 65 __u64 cr8;
@@ -71,8 +68,12 @@ struct kvm_run {
71 union { 68 union {
72 /* KVM_EXIT_UNKNOWN */ 69 /* KVM_EXIT_UNKNOWN */
73 struct { 70 struct {
74 __u32 hardware_exit_reason; 71 __u64 hardware_exit_reason;
75 } hw; 72 } hw;
73 /* KVM_EXIT_FAIL_ENTRY */
74 struct {
75 __u64 hardware_entry_failure_reason;
76 } fail_entry;
76 /* KVM_EXIT_EXCEPTION */ 77 /* KVM_EXIT_EXCEPTION */
77 struct { 78 struct {
78 __u32 exception; 79 __u32 exception;