VMM: Add custom exit reasons (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Feb 2016 15:38:20 +0000 (10:38 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Feb 2016 22:43:52 +0000 (17:43 -0500)
We'll need these types for when the kernel fails to pop a VM context.  In
that case, we'll reflect the context back to the 2LS, and we'll need exit
reasons to explain what went wrong.

I also cleaned up the #defines a little.  We had multiple copies of the
exit reasons throughout the codebase.

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/ros/vmx.h
user/vmm/vmx.c
user/vmm/vmx.h [deleted file]

index 8e1a0fd..0f81389 100644 (file)
@@ -346,43 +346,48 @@ enum vmcs_field {
 #define EXIT_REASON_RDSEED              61
 #define EXIT_REASON_XSAVES              63
 #define EXIT_REASON_XRSTORS             64
+/* Non-standard exit reasons */
+#define EXIT_REASON_GUEST_IN_USE        257
+#define EXIT_REASON_VMENTER_FAILED      258
 
 #define VMX_EXIT_REASONS \
-       { EXIT_REASON_EXCEPTION_NMI,         "EXCEPTION_NMI" }, \
-       { EXIT_REASON_EXTERNAL_INTERRUPT,    "EXTERNAL_INTERRUPT" }, \
-       { EXIT_REASON_TRIPLE_FAULT,          "TRIPLE_FAULT" }, \
-       { EXIT_REASON_PENDING_INTERRUPT,     "PENDING_INTERRUPT" }, \
-       { EXIT_REASON_NMI_WINDOW,            "NMI_WINDOW" }, \
-       { EXIT_REASON_TASK_SWITCH,           "TASK_SWITCH" }, \
-       { EXIT_REASON_CPUID,                 "CPUID" }, \
-       { EXIT_REASON_HLT,                   "HLT" }, \
-       { EXIT_REASON_INVLPG,                "INVLPG" }, \
-       { EXIT_REASON_RDPMC,                 "RDPMC" }, \
-       { EXIT_REASON_RDTSC,                 "RDTSC" }, \
-       { EXIT_REASON_VMCALL,                "VMCALL" }, \
-       { EXIT_REASON_VMCLEAR,               "VMCLEAR" }, \
-       { EXIT_REASON_VMLAUNCH,              "VMLAUNCH" }, \
-       { EXIT_REASON_VMPTRLD,               "VMPTRLD" }, \
-       { EXIT_REASON_VMPTRST,               "VMPTRST" }, \
-       { EXIT_REASON_VMREAD,                "VMREAD" }, \
-       { EXIT_REASON_VMRESUME,              "VMRESUME" }, \
-       { EXIT_REASON_VMWRITE,               "VMWRITE" }, \
-       { EXIT_REASON_VMOFF,                 "VMOFF" }, \
-       { EXIT_REASON_VMON,                  "VMON" }, \
-       { EXIT_REASON_CR_ACCESS,             "CR_ACCESS" }, \
-       { EXIT_REASON_DR_ACCESS,             "DR_ACCESS" }, \
-       { EXIT_REASON_IO_INSTRUCTION,        "IO_INSTRUCTION" }, \
-       { EXIT_REASON_MSR_READ,              "MSR_READ" }, \
-       { EXIT_REASON_MSR_WRITE,             "MSR_WRITE" }, \
-       { EXIT_REASON_MWAIT_INSTRUCTION,     "MWAIT_INSTRUCTION" }, \
-       { EXIT_REASON_MONITOR_INSTRUCTION,   "MONITOR_INSTRUCTION" }, \
-       { EXIT_REASON_PAUSE_INSTRUCTION,     "PAUSE_INSTRUCTION" }, \
-       { EXIT_REASON_MCE_DURING_VMENTRY,    "MCE_DURING_VMENTRY" }, \
-       { EXIT_REASON_TPR_BELOW_THRESHOLD,   "TPR_BELOW_THRESHOLD" }, \
-       { EXIT_REASON_APIC_ACCESS,           "APIC_ACCESS" }, \
-       { EXIT_REASON_EPT_VIOLATION,         "EPT_VIOLATION" }, \
-       { EXIT_REASON_EPT_MISCONFIG,         "EPT_MISCONFIG" }, \
-       { EXIT_REASON_WBINVD,                "WBINVD" }
+       [EXIT_REASON_EXCEPTION_NMI]         "EXCEPTION_NMI", \
+       [EXIT_REASON_EXTERNAL_INTERRUPT]    "EXTERNAL_INTERRUPT", \
+       [EXIT_REASON_TRIPLE_FAULT]          "TRIPLE_FAULT", \
+       [EXIT_REASON_PENDING_INTERRUPT]     "PENDING_INTERRUPT", \
+       [EXIT_REASON_NMI_WINDOW]            "NMI_WINDOW", \
+       [EXIT_REASON_TASK_SWITCH]           "TASK_SWITCH", \
+       [EXIT_REASON_CPUID]                 "CPUID", \
+       [EXIT_REASON_HLT]                   "HLT", \
+       [EXIT_REASON_INVLPG]                "INVLPG", \
+       [EXIT_REASON_RDPMC]                 "RDPMC", \
+       [EXIT_REASON_RDTSC]                 "RDTSC", \
+       [EXIT_REASON_VMCALL]                "VMCALL", \
+       [EXIT_REASON_VMCLEAR]               "VMCLEAR", \
+       [EXIT_REASON_VMLAUNCH]              "VMLAUNCH", \
+       [EXIT_REASON_VMPTRLD]               "VMPTRLD", \
+       [EXIT_REASON_VMPTRST]               "VMPTRST", \
+       [EXIT_REASON_VMREAD]                "VMREAD", \
+       [EXIT_REASON_VMRESUME]              "VMRESUME", \
+       [EXIT_REASON_VMWRITE]               "VMWRITE", \
+       [EXIT_REASON_VMOFF]                 "VMOFF", \
+       [EXIT_REASON_VMON]                  "VMON", \
+       [EXIT_REASON_CR_ACCESS]             "CR_ACCESS", \
+       [EXIT_REASON_DR_ACCESS]             "DR_ACCESS", \
+       [EXIT_REASON_IO_INSTRUCTION]        "IO_INSTRUCTION", \
+       [EXIT_REASON_MSR_READ]              "MSR_READ", \
+       [EXIT_REASON_MSR_WRITE]             "MSR_WRITE", \
+       [EXIT_REASON_MWAIT_INSTRUCTION]     "MWAIT_INSTRUCTION", \
+       [EXIT_REASON_MONITOR_INSTRUCTION]   "MONITOR_INSTRUCTION", \
+       [EXIT_REASON_PAUSE_INSTRUCTION]     "PAUSE_INSTRUCTION", \
+       [EXIT_REASON_MCE_DURING_VMENTRY]    "MCE_DURING_VMENTRY", \
+       [EXIT_REASON_TPR_BELOW_THRESHOLD]   "TPR_BELOW_THRESHOLD", \
+       [EXIT_REASON_APIC_ACCESS]           "APIC_ACCESS", \
+       [EXIT_REASON_EPT_VIOLATION]         "EPT_VIOLATION", \
+       [EXIT_REASON_EPT_MISCONFIG]         "EPT_MISCONFIG", \
+       [EXIT_REASON_WBINVD]                "WBINVD", \
+       [EXIT_REASON_GUEST_IN_USE]          "GUEST_IN_USE", \
+       [EXIT_REASON_VMENTER_FAILED]        "VMENTER_FAILED"
 
 /*
  * Interruption-information format
@@ -711,16 +716,5 @@ struct vmx_vcpu {
 
 
 static char * const VMX_EXIT_REASON_NAMES[] = {
-       "EXCEPTION_NMI", "EXTERNAL_INTERRUPT", "TRIPLE_FAULT",
-       "INIT_SIGNAL", "START_UP_IPI", "IO_SM_INTERRUPT", "OTHER_SMI",
-       "INTERRUPT_WINDOW", "NMI_WINDOW", "TASK_SWITCH", "CPUID", "GETSEC", "HLT", "INVD",
-       "INVLPG", "RDPMC", "RDTSC", "RSM", "VMCALL", "VMCLEAR", "VMLAUNCH", "VMPTRLD",
-       "VMPTRST", "VMREAD", "VMRESUME", "VMWRITE", "VMOFF", "VMON", "CR_ACCESS",
-       "DR_ACCESS", "IO_INSTRUCTION", "MSR_READ", "MSR_WRITE", "INVALID_STATE",
-       "ENTRY_MSR_LOADING", "35", "MWAIT_INSTRUCTION", "MONITOR_TRAP_FLAG", "38",
-       "MONITOR_INSTRUCTION", "PAUSE_INSTRUCTION", "MCE_DURING_VMENTRY", "42",
-       "TPR_BELOW_THRESHOLD", "APIC_ACCESS", "VIRTUALIZED_EOI", "GDTR_IDTR_ACCESS",
-       "LDTR_TR_ACCESS", "EPT_VIOLATION", "EPT_MISCONFIG", "INVEPT", "RDTSCP",
-       "VMX_TIMER_EXPIRED", "INVVPID", "WBINVD", "XSETBV", "APIC_WRITE", "RDRAND",
-       "INVPCID", "VMFUNC", "60", "RDSEED", "62", "XSAVES", "XRSTORS"
+       VMX_EXIT_REASONS
 };
index c35882e..80a8d19 100644 (file)
 #include <vmm/virtio.h>
 #include <vmm/virtio_mmio.h>
 #include <vmm/virtio_ids.h>
-
-// TODO: put this some common place for user and kernel mode. Once
-// we know we need to. Not sure we want to expose this outside
-// vmrunkernel anyway. Users may claim they want to write a vmm, but ...
-#define VMX_EXIT_REASONS_FAILED_VMENTRY         0x80000000
-
-#define EXIT_REASON_EXCEPTION_NMI       0
-#define EXIT_REASON_EXTERNAL_INTERRUPT  1
-#define EXIT_REASON_TRIPLE_FAULT        2
-
-#define EXIT_REASON_INTERRUPT_WINDOW    7
-#define EXIT_REASON_NMI_WINDOW          8
-#define EXIT_REASON_TASK_SWITCH         9
-#define EXIT_REASON_CPUID               10
-#define EXIT_REASON_HLT                 12
-#define EXIT_REASON_INVD                13
-#define EXIT_REASON_INVLPG              14
-#define EXIT_REASON_RDPMC               15
-#define EXIT_REASON_RDTSC               16
-#define EXIT_REASON_VMCALL              18
-#define EXIT_REASON_VMCLEAR             19
-#define EXIT_REASON_VMLAUNCH            20
-#define EXIT_REASON_VMPTRLD             21
-#define EXIT_REASON_VMPTRST             22
-#define EXIT_REASON_VMREAD              23
-#define EXIT_REASON_VMRESUME            24
-#define EXIT_REASON_VMWRITE             25
-#define EXIT_REASON_VMOFF               26
-#define EXIT_REASON_VMON                27
-#define EXIT_REASON_CR_ACCESS           28
-#define EXIT_REASON_DR_ACCESS           29
-#define EXIT_REASON_IO_INSTRUCTION      30
-#define EXIT_REASON_MSR_READ            31
-#define EXIT_REASON_MSR_WRITE           32
-#define EXIT_REASON_INVALID_STATE       33
-#define EXIT_REASON_MWAIT_INSTRUCTION   36
-#define EXIT_REASON_MONITOR_INSTRUCTION 39
-#define EXIT_REASON_PAUSE_INSTRUCTION   40
-#define EXIT_REASON_MCE_DURING_VMENTRY  41
-#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
-#define EXIT_REASON_APIC_ACCESS         44
-#define EXIT_REASON_EPT_VIOLATION       48
-#define EXIT_REASON_EPT_MISCONFIG       49
-#define EXIT_REASON_WBINVD              54
-#define EXIT_REASON_XSETBV              55
-#define EXIT_REASON_INVPCID             58
+#include <ros/arch/vmx.h>
 
 /* nowhere on my linux system. */
 #define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
 
 char *vmxexit[] = {
-       [EXIT_REASON_EXCEPTION_NMI]        "EXCEPTION_NMI",
-       [EXIT_REASON_EXTERNAL_INTERRUPT]   "EXTERNAL_INTERRUPT",
-       [EXIT_REASON_TRIPLE_FAULT]         "TRIPLE_FAULT",
-       [EXIT_REASON_INTERRUPT_WINDOW]    "INTERRUPT WINDOW (i.e. ok to send interrupts",
-       [EXIT_REASON_NMI_WINDOW]           "NMI_WINDOW",
-       [EXIT_REASON_TASK_SWITCH]          "TASK_SWITCH",
-       [EXIT_REASON_CPUID]                "CPUID",
-       [EXIT_REASON_HLT]                  "HLT",
-       [EXIT_REASON_INVLPG]               "INVLPG",
-       [EXIT_REASON_RDPMC]                "RDPMC",
-       [EXIT_REASON_RDTSC]                "RDTSC",
-       [EXIT_REASON_VMCALL]               "VMCALL",
-       [EXIT_REASON_VMCLEAR]              "VMCLEAR",
-       [EXIT_REASON_VMLAUNCH]             "VMLAUNCH",
-       [EXIT_REASON_VMPTRLD]              "VMPTRLD",
-       [EXIT_REASON_VMPTRST]              "VMPTRST",
-       [EXIT_REASON_VMREAD]               "VMREAD",
-       [EXIT_REASON_VMRESUME]             "VMRESUME",
-       [EXIT_REASON_VMWRITE]              "VMWRITE",
-       [EXIT_REASON_VMOFF]                "VMOFF",
-       [EXIT_REASON_VMON]                 "VMON",
-       [EXIT_REASON_CR_ACCESS]            "CR_ACCESS",
-       [EXIT_REASON_DR_ACCESS]            "DR_ACCESS",
-       [EXIT_REASON_IO_INSTRUCTION]       "IO_INSTRUCTION",
-       [EXIT_REASON_MSR_READ]             "MSR_READ",
-       [EXIT_REASON_MSR_WRITE]            "MSR_WRITE",
-       [EXIT_REASON_MWAIT_INSTRUCTION]    "MWAIT_INSTRUCTION",
-       [EXIT_REASON_MONITOR_INSTRUCTION]  "MONITOR_INSTRUCTION",
-       [EXIT_REASON_PAUSE_INSTRUCTION]    "PAUSE_INSTRUCTION",
-       [EXIT_REASON_MCE_DURING_VMENTRY]   "MCE_DURING_VMENTRY",
-       [EXIT_REASON_TPR_BELOW_THRESHOLD]  "TPR_BELOW_THRESHOLD",
-       [EXIT_REASON_APIC_ACCESS]          "APIC_ACCESS",
-       [EXIT_REASON_EPT_VIOLATION]        "EPT_VIOLATION",
-       [EXIT_REASON_EPT_MISCONFIG]        "EPT_MISCONFIG",
-       [EXIT_REASON_WBINVD]               "WBINVD"
+       VMX_EXIT_REASONS
 };
 
 void showstatus(FILE *f, struct vmctl *v)
 {
        int shutdown = v->ret_code;
        char *when = shutdown & VMX_EXIT_REASONS_FAILED_VMENTRY ? "entry" : "exit";
-       shutdown &= 0xff;
+       shutdown &= ~VMX_EXIT_REASONS_FAILED_VMENTRY;
        char *reason = "UNKNOWN";
        if (shutdown < ARRAY_SIZE(vmxexit) && vmxexit[shutdown])
                reason = vmxexit[shutdown];
diff --git a/user/vmm/vmx.h b/user/vmm/vmx.h
deleted file mode 100644 (file)
index cee7258..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// TODO: put this some common place for user and kernel mode. Once
-// we know we need to. Not sure we want to expose this outside
-// vmrunkernel anyway. Users may claim they want to write a vmm, but ...
-#define VMX_EXIT_REASONS_FAILED_VMENTRY         0x80000000
-
-#define EXIT_REASON_EXCEPTION_NMI       0
-#define EXIT_REASON_EXTERNAL_INTERRUPT  1
-#define EXIT_REASON_TRIPLE_FAULT        2
-
-#define EXIT_REASON_PENDING_INTERRUPT   7
-#define EXIT_REASON_INTERRUPT_WINDOW    7
-#define EXIT_REASON_NMI_WINDOW          8
-#define EXIT_REASON_TASK_SWITCH         9
-#define EXIT_REASON_CPUID               10
-#define EXIT_REASON_HLT                 12
-#define EXIT_REASON_INVD                13
-#define EXIT_REASON_INVLPG              14
-#define EXIT_REASON_RDPMC               15
-#define EXIT_REASON_RDTSC               16
-#define EXIT_REASON_VMCALL              18
-#define EXIT_REASON_VMCLEAR             19
-#define EXIT_REASON_VMLAUNCH            20
-#define EXIT_REASON_VMPTRLD             21
-#define EXIT_REASON_VMPTRST             22
-#define EXIT_REASON_VMREAD              23
-#define EXIT_REASON_VMRESUME            24
-#define EXIT_REASON_VMWRITE             25
-#define EXIT_REASON_VMOFF               26
-#define EXIT_REASON_VMON                27
-#define EXIT_REASON_CR_ACCESS           28
-#define EXIT_REASON_DR_ACCESS           29
-#define EXIT_REASON_IO_INSTRUCTION      30
-#define EXIT_REASON_MSR_READ            31
-#define EXIT_REASON_MSR_WRITE           32
-#define EXIT_REASON_INVALID_STATE       33
-#define EXIT_REASON_MWAIT_INSTRUCTION   36
-#define EXIT_REASON_MONITOR_INSTRUCTION 39
-#define EXIT_REASON_PAUSE_INSTRUCTION   40
-#define EXIT_REASON_MCE_DURING_VMENTRY  41
-#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
-#define EXIT_REASON_APIC_ACCESS         44
-#define EXIT_REASON_EPT_VIOLATION       48
-#define EXIT_REASON_EPT_MISCONFIG       49
-#define EXIT_REASON_WBINVD              54
-#define EXIT_REASON_XSETBV              55
-#define EXIT_REASON_INVPCID             58