Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Expose HVM state to host + Linux host /proc additions for it
[palacios.git] / palacios / src / palacios / vmx_handler.c
index 247422a..f8a183e 100644 (file)
  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
  */
 
-static int PanicUnhandledVMExit(struct VM *vm)
-{
-  PrintInfo("Panicking due to VMExit with reason %u\n", vm->vmcs.exitInfoFields.reason);
-  PrintTrace("Panicking due to VMExit with reason %u\n", vm->vmcs.exitInfoFields.reason);
-  PrintTrace_VMCS_ALL();
-  PrintTrace_VMX_Regs(&(vm->registers));
-  VMXPanic();
-  return 0;
-}
-
-
-
+#include <palacios/vmx_handler.h>
+#include <palacios/vmm_types.h>
+#include <palacios/vmm.h>
+#include <palacios/vmcs.h>
+#include <palacios/vmx_lowlevel.h>
+#include <palacios/vmx_io.h>
+#include <palacios/vmm_cpuid.h>
+#include <palacios/vmm_debug.h>
+
+#include <palacios/vmx.h>
+#include <palacios/vmm_ctrl_regs.h>
+#include <palacios/vmm_lowlevel.h>
+#include <palacios/vmx_ctrl_regs.h>
+#include <palacios/vmx_assist.h>
+#include <palacios/vmm_halt.h>
+#include <palacios/vmm_mwait.h>
+#include <palacios/vmx_ept.h>
+
+
+#ifndef V3_CONFIG_DEBUG_VMX
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
+
+#ifdef V3_CONFIG_TELEMETRY
+#include <palacios/vmm_telemetry.h>
+#endif
+
+/* At this point the GPRs are already copied into the guest_info state */
+int v3_handle_vmx_exit(struct guest_info * info, struct vmx_exit_info * exit_info) {
+    struct vmx_basic_exit_info * basic_info = (struct vmx_basic_exit_info *)&(exit_info->exit_reason);
+
+    /*
+      PrintError(info->vm_info, info, "Handling VMX_EXIT: %s (%u), %lu (0x%lx)\n", 
+      v3_vmx_exit_code_to_str(exit_info->exit_reason),
+      exit_info->exit_reason, 
+      exit_info->exit_qual, exit_info->exit_qual);
+      
+      v3_print_vmcs();
+    */
+
+
+    if (basic_info->entry_error == 1) {
+       switch (basic_info->reason) {
+           case VMX_EXIT_INVALID_GUEST_STATE:
+               PrintError(info->vm_info, info, "VM Entry failed due to invalid guest state\n");
+               PrintError(info->vm_info, info, "Printing VMCS: (NOTE: This VMCS may not belong to the correct guest)\n");
+               v3_print_vmcs();
+               break;
+           case VMX_EXIT_INVALID_MSR_LOAD:
+               PrintError(info->vm_info, info, "VM Entry failed due to error loading MSRs\n");
+               break;
+           default:
+               PrintError(info->vm_info, info, "Entry failed for unknown reason (%d)\n", basic_info->reason);
+               break;
+       }
+       
+       return -1;
+    }
 
 
-static int HandleVMPrintsAndPanics(struct VM *vm, uint_t port, uint_t data)
-{
-  if (port==VMXASSIST_INFO_PORT &&
-      (vm->state == VM_VMXASSIST_STARTUP || 
-       vm->state == VM_VMXASSIST_V8086_BIOS ||
-       vm->state == VM_VMXASSIST_V8086)) { 
-    // Communication channel from VMXAssist
-    PrintTrace("VMXASSIST Output Port\n");
-    PrintDebug("%c",data&0xff);
-    return 1;
-  } 
-
-  if ((port==ROMBIOS_PANIC_PORT || 
-       port==ROMBIOS_PANIC_PORT2 || 
-       port==ROMBIOS_DEBUG_PORT ||
-       port==ROMBIOS_INFO_PORT) &&
-      (vm->state==VM_VMXASSIST_V8086_BIOS)) {
-    // rombios is communicating
-    PrintTrace("ROMBIOS Output Port\n");
-    //    PrintDebug("%c",data&0xff);
-    return 1;
-  }
-
-  if (port==BOOT_STATE_CARD_PORT && vm->state==VM_VMXASSIST_V8086_BIOS) { 
-    // rombios is sending something to the display card
-    PrintTrace("Hex Display: 0x%x\n",data&0xff);
-    return 1;
-  }
-  return 0;
-}
 
-static int HandleInOutExit(struct VM *vm)
-{
-  uint_t address;
-
-  struct VMCSExitInfoFields *exitinfo = &(vm->vmcs.exitInfoFields);
-  struct VMExitIOQual * qual = (struct VMExitIOQual *)&(vm->vmcs.exitInfoFields.qualification);
-  struct VMXRegs *regs = &(vm->registers);
-
-  address=GetLinearIP(vm);
-
-  PrintTrace("Handling Input/Output Instruction Exit\n");
-
-  PrintTrace_VMX_Regs(regs);
-
-  PrintTrace("Qualifications=0x%x\n", exitinfo->qualification);
-  PrintTrace("Reason=0x%x\n", exitinfo->reason);
-  PrintTrace("IO Port: 0x%x (%d)\n", qual->port, qual->port);
-  PrintTrace("Instruction Info=%x\n", exitinfo->instrInfo);
-  PrintTrace("%x : %s %s %s instruction of length %d for %d bytes from/to port 0x%x\n",
-                  address,
-                  qual->dir == 0 ? "output" : "input",
-                  qual->string ==0 ? "nonstring" : "STRING",
-                  qual->REP == 0 ? "with no rep" : "WITH REP",
-                  exitinfo->instrLength, 
-                  qual->accessSize==0 ? 1 : qual->accessSize==1 ? 2 : 4,
-                  qual->port);
-
-  if ((qual->port == PIC_MASTER_CMD_ISR_PORT) ||
-      (qual->port == PIC_MASTER_IMR_PORT)     ||
-      (qual->port == PIC_SLAVE_CMD_ISR_PORT)  ||
-      (qual->port == PIC_SLAVE_IMR_PORT)) {
-    PrintTrace( "PIC Access\n");
-  }
-                  
-
-  if ((qual->dir == 1) && (qual->REP == 0) && (qual->string == 0)) { 
-    char byte = In_Byte(qual->port);
-
-    vm->vmcs.guestStateArea.rip += exitinfo->instrLength;
-    regs->eax = (regs->eax & 0xffffff00) | byte;
-    PrintTrace("Returning 0x%x in eax\n", (regs->eax));
-  }
-
-  if (qual->dir==0 && qual->REP==0 && qual->string==0) { 
-    // See if we need to handle the outb as a signal or
-    // print from the VM
-    if (HandleVMPrintsAndPanics(vm,qual->port,regs->eax)) {
-    } else {
-      // If not, just go ahead and do the outb
-      Out_Byte(qual->port,regs->eax);
-      PrintTrace("Wrote 0x%x to port\n",(regs->eax));
+#ifdef V3_CONFIG_TELEMETRY
+    if (info->vm_info->enable_telemetry) {
+       v3_telemetry_start_exit(info);
+    }
+#endif
+
+    switch (basic_info->reason) {
+        case VMX_EXIT_INFO_EXCEPTION_OR_NMI: {
+            pf_error_t error_code = *(pf_error_t *)&(exit_info->int_err);
+
+
+            // JRL: Change "0x0e" to a macro value
+            if ((uint8_t)exit_info->int_info == 14) {
+#ifdef V3_CONFIG_DEBUG_SHADOW_PAGING
+                PrintDebug(info->vm_info, info, "Page Fault at %p error_code=%x\n", (void *)exit_info->exit_qual, *(uint32_t *)&error_code);
+#endif
+
+                if (info->shdw_pg_mode == SHADOW_PAGING) {
+                    if (v3_handle_shadow_pagefault(info, (addr_t)exit_info->exit_qual, error_code) == -1) {
+                        PrintError(info->vm_info, info, "Error handling shadow page fault\n");
+                        return -1;
+                    }
+           
+                } else {
+                    PrintError(info->vm_info, info, "Page fault in unimplemented paging mode\n");
+                    return -1;
+                }
+           } else if ((uint8_t)exit_info->int_info == 2) {
+               // NMI. Don't do anything
+            } else {
+                PrintError(info->vm_info, info, "Unknown exception: 0x%x\n", (uint8_t)exit_info->int_info);
+                v3_print_GPRs(info);
+                return -1;
+            }
+            break;
+        }
+
+       case VMX_EXIT_EPT_VIOLATION: {
+           struct ept_exit_qual * ept_qual = (struct ept_exit_qual *)&(exit_info->exit_qual);
+
+           if (v3_handle_nested_pagefault(info, exit_info->ept_fault_addr, ept_qual,NULL,NULL) == -1) {
+               PrintError(info->vm_info, info, "Error handling EPT fault\n");
+               return -1;
+           }
+
+           break;
+       }
+        case VMX_EXIT_INVLPG:
+            if (info->shdw_pg_mode == SHADOW_PAGING) {
+                if (v3_handle_shadow_invlpg(info) == -1) {
+                   PrintError(info->vm_info, info, "Error handling INVLPG\n");
+                    return -1;
+                }
+            }
+
+            break;
+
+        case VMX_EXIT_RDTSC:
+#ifdef V3_CONFIG_DEBUG_TIME
+           PrintDebug(info->vm_info, info, "RDTSC\n");
+#endif 
+           if (v3_handle_rdtsc(info) == -1) {
+               PrintError(info->vm_info, info, "Error Handling RDTSC instruction\n");
+               return -1;
+           }
+           
+           break;
+
+        case VMX_EXIT_CPUID:
+           if (v3_handle_cpuid(info) == -1) {
+               PrintError(info->vm_info, info, "Error Handling CPUID instruction\n");
+               return -1;
+           }
+
+            break;
+        case VMX_EXIT_RDMSR: 
+            if (v3_handle_msr_read(info) == -1) {
+               PrintError(info->vm_info, info, "Error handling MSR Read\n");
+                return -1;
+           }
+
+            break;
+        case VMX_EXIT_WRMSR:
+            if (v3_handle_msr_write(info) == -1) {
+               PrintError(info->vm_info, info, "Error handling MSR Write\n");
+                return -1;
+           }
+
+            break;
+       case VMX_EXIT_VMCALL:
+           /* 
+            * Hypercall 
+            */
+
+           // VMCALL is a 3 byte op
+           // We do this early because some hypercalls can change the rip...
+           info->rip += 3;         
+
+           if (v3_handle_hypercall(info) == -1) {
+               return -1;
+           }
+           break;
+        case VMX_EXIT_IO_INSTR: {
+           struct vmx_exit_io_qual * io_qual = (struct vmx_exit_io_qual *)&(exit_info->exit_qual);
+
+            if (io_qual->dir == 0) {
+                if (io_qual->string) {
+                    if (v3_handle_vmx_io_outs(info, exit_info) == -1) {
+                        PrintError(info->vm_info, info, "Error in outs IO handler\n");
+                        return -1;
+                    }
+                } else {
+                    if (v3_handle_vmx_io_out(info, exit_info) == -1) {
+                        PrintError(info->vm_info, info, "Error in out IO handler\n");
+                        return -1;
+                    }
+                }
+            } else {
+                if (io_qual->string) {
+                    if(v3_handle_vmx_io_ins(info, exit_info) == -1) {
+                        PrintError(info->vm_info, info, "Error in ins IO handler\n");
+                        return -1;
+                    }
+                } else {
+                    if (v3_handle_vmx_io_in(info, exit_info) == -1) {
+                        PrintError(info->vm_info, info, "Error in in IO handler\n");
+                        return -1;
+                    }
+                }
+            }
+            break;
+       }
+        case VMX_EXIT_CR_REG_ACCESSES: {
+           struct vmx_exit_cr_qual * cr_qual = (struct vmx_exit_cr_qual *)&(exit_info->exit_qual);
+           
+           // PrintDebug(info->vm_info, info, "Control register: %d\n", cr_qual->access_type);
+           switch(cr_qual->cr_id) {
+               case 0:
+                   //PrintDebug(info->vm_info, info, "Handling CR0 Access\n");
+                   if (v3_vmx_handle_cr0_access(info, cr_qual, exit_info) == -1) {
+                       PrintError(info->vm_info, info, "Error in CR0 access handler\n");
+                       return -1;
+                   }
+                   break;
+               case 3:
+                   //PrintDebug(info->vm_info, info, "Handling CR3 Access\n");
+                   if (v3_vmx_handle_cr3_access(info, cr_qual) == -1) {
+                       PrintError(info->vm_info, info, "Error in CR3 access handler\n");
+                       return -1;
+                   }
+                   break;
+               case 4:
+                   //PrintDebug(info->vm_info, info, "Handling CR4 Access\n");
+                   if (v3_vmx_handle_cr4_access(info, cr_qual) == -1) {
+                       PrintError(info->vm_info, info, "Error in CR4 access handler\n");
+                       return -1;
+                   }
+                   break;
+               case 8:
+                   if (v3_vmx_handle_cr8_access(info, cr_qual) == -1) {
+                       PrintError(info->vm_info, info, "Error in CR8 access handler\n");
+                       return -1;
+                   }
+                   break;
+               default:
+                   PrintError(info->vm_info, info, "Unhandled CR access: %d\n", cr_qual->cr_id);
+                   return -1;
+           }
+           
+           // TODO: move RIP increment into all of the above individual CR
+           //       handlers, not just v3_vmx_handle_cr4_access()
+           if (cr_qual->cr_id != 4)
+               info->rip += exit_info->instr_len;
+
+           break;
+       }
+        case VMX_EXIT_HLT:
+            PrintDebug(info->vm_info, info, "Guest halted\n");
+
+            if (v3_handle_halt(info) == -1) {
+               PrintError(info->vm_info, info, "Error handling halt instruction\n");
+                return -1;
+            }
+
+            break;
+
+        case VMX_EXIT_MONITOR:
+            PrintDebug(info->vm_info, info, "Guest Executing monitor\n");
+
+            if (v3_handle_monitor(info) == -1) {
+               PrintError(info->vm_info, info, "Error handling monitor instruction\n");
+                return -1;
+            }
+
+            break;
+
+        case VMX_EXIT_MWAIT:
+            PrintDebug(info->vm_info, info, "Guest Executing mwait\n");
+
+            if (v3_handle_mwait(info) == -1) {
+               PrintError(info->vm_info, info, "Error handling mwait instruction\n");
+                return -1;
+            }
+
+            break;
+
+
+        case VMX_EXIT_PAUSE:
+            // Handled as NOP
+            info->rip += 2;
+
+            break;
+        case VMX_EXIT_EXTERNAL_INTR:
+            // Interrupts are handled outside switch
+            break;
+        case VMX_EXIT_INTR_WINDOW:
+           // This is handled in the atomic part of the vmx code,
+           // not in the generic (interruptable) vmx handler
+            break;
+        case VMX_EXIT_EXPIRED_PREEMPT_TIMER:
+           V3_Print(info->vm_info, info, "VMX Preempt Timer Expired.\n");
+           // This just forces an exit and is handled outside the switch
+           break;
+           
+        default:
+            PrintError(info->vm_info, info, "Unhandled VMX_EXIT: %s (%u), %lu (0x%lx)\n", 
+                      v3_vmx_exit_code_to_str(basic_info->reason),
+                      basic_info->reason, 
+                      exit_info->exit_qual, exit_info->exit_qual);
+            return -1;
     }
-    vm->vmcs.guestStateArea.rip += exitinfo->instrLength;
-  }
-
-  return 0;
-}  
-
 
-static int HandleExternalIRQExit(struct VM *vm)
-{
-  struct VMCSExitInfoFields * exitinfo = &(vm->vmcs.exitInfoFields);
-  struct VMExitIntInfo * intInfo  = (struct VMExitIntInfo *)&(vm->vmcs.exitInfoFields.intInfo);
 
-  PrintTrace("External Interrupt captured\n");
-  PrintTrace("IntInfo: %x\n", exitinfo->intInfo);
+#ifdef V3_CONFIG_TELEMETRY
+    if (info->vm_info->enable_telemetry) {
+        v3_telemetry_end_exit(info, exit_info->exit_reason);
+    }
+#endif
 
 
-  if (!intInfo->valid) {
-     // interrupts are off, but this interrupt is not acknoledged (still pending)
-     // so we turn on interrupts to deliver appropriately in the
-     // host
-    PrintTrace("External Interrupt is invald.  Turning Interrupts back on\n");
-    asm("sti");
     return 0;
-  } 
-
-  // At this point, interrupts are off and the interrupt has been 
-  // acknowledged.  We will now handle the interrupt ourselves 
-  // and turn interrupts  back on in the host
-
-  PrintTrace("type: %d\n", intInfo->type);
-  PrintTrace("number: %d\n", intInfo->nr);
-
-  PrintTrace("Interrupt %d occuring now and handled by HandleExternalIRQExit\n",intInfo->nr);
-
-  switch (intInfo->type) {
-  case 0:  {  // ext. IRQ
-    // In the following, we construct an "int x" instruction
-    // where x is the specific interrupt number that is raised
-    // then we execute that instruciton
-    // because we are in host context, that means it is delivered as normal
-    // through the host IDT
-     
-     ((char*)(&&ext_int_seq_start))[1] = intInfo->nr;
-     PrintTrace("Interrupt instruction setup done %x\n", *((ushort_t *)(&&ext_int_seq_start)));
-     
-ext_int_seq_start:
-     asm("int $0");
-  }
-
-    break;
-  case 2: // NMI
-    PrintTrace("Type: NMI\n");
-    break;
-  case 3: // hw exception
-    PrintTrace("Type: HW Exception\n");
-    break;
-  case 4: // sw exception
-    PrintTrace("Type: SW Exception\n");
-    break;
-  default:
-    PrintTrace("Invalid Interrupt Type\n");
-    return -1;
-  }
-  
-  if (intInfo->valid && intInfo->errorCode) {
-    PrintTrace("IntError: %x\n", exitinfo->intErrorCode);
-  }
-
-
-  return 0;
-
-}
-
-
-
-
-
-
-
-static int HandleExceptionOrNMI(struct VM *vm)
-{
-  struct Instruction inst;
-  uint_t num;
-  uint_t type;
-  uint_t errorvalid;
-  uint_t error;
-  uint_t ext=0;
-  uint_t idt=0;
-  uint_t ti=0;
-  uint_t selectorindex=0;
-
-  PrintTrace("Exception or NMI occurred\n");
-  
-  num=vm->vmcs.exitInfoFields.intInfo & 0xff;
-  type=(vm->vmcs.exitInfoFields.intInfo & 0x700)>>8;
-  errorvalid=(vm->vmcs.exitInfoFields.intInfo & 0x800)>>11;
-  if (errorvalid) { 
-    error=vm->vmcs.exitInfoFields.intErrorCode;
-    ext=error&0x1;
-    idt=(error&0x2)>>1;
-    ti=(error&0x4)>>2;
-    selectorindex=(error>>3)&0xffff;
-  }
-  
-  PrintTrace("Exception %d now - handled by HandleExceptionOrNMI\n",num);
-
-  PrintTrace("Exception Number %u : %s\n", num, exception_names[num]);
-  PrintTrace("Exception Type %u : %s\n", type, exception_type_names[type]);
-  if (errorvalid) { 
-    if (ext) { 
-      PrintTrace("External\n");
-    } else {
-      PrintTrace("%s - Selector Index is %u\n", idt ? "IDT" : ti ? "LDT" : "GDT", selectorindex);
-    }
-  }
-
-  DecodeCurrentInstruction(vm,&inst);
-
-  if (inst.type==VM_MOV_TO_CR0) {
-    PrintTrace("MOV TO CR0, oldvalue=0x%x, newvalue=0x%x\n",inst.input2, inst.input1);
-    if ((inst.input2 & CR0_PE) && !(inst.input1 & CR0_PE) && vm->state==VM_VMXASSIST_STARTUP) {
-      // This is VMXAssist signalling for us to turn on V8086 mode and
-      // jump into the bios
-      PrintTrace("VMXAssist is signaling us for switch to V8086 mode and jump to 0xf000:fff0\n");
-      SetupV8086ModeForBoot(vm);
-      goto leave;
-    } else {
-      PrintTrace("Instruction is a write to CR0, but we don't understand it so we'll just exec it\n");
-    } 
-  } 
-
-
-  PrintTrace("Trying to execute the faulting instruction in VMM context now\n");
-  ExecFaultingInstructionInVMM(vm);
-
-    leave:
-  //
-  //PanicUnhandledVMExit(vmcs,regs);
-  //VMXPanic();
-  return 0;
 }
 
-
-
-
-
-int Do_VMM(struct VMXRegs regs) 
+static const char VMX_EXIT_INFO_EXCEPTION_OR_NMI_STR[] = "VMX_EXIT_INFO_EXCEPTION_OR_NMI";
+static const char VMX_EXIT_EXTERNAL_INTR_STR[] = "VMX_EXIT_EXTERNAL_INTR";
+static const char VMX_EXIT_TRIPLE_FAULT_STR[] = "VMX_EXIT_TRIPLE_FAULT";
+static const char VMX_EXIT_INIT_SIGNAL_STR[] = "VMX_EXIT_INIT_SIGNAL";
+static const char VMX_EXIT_STARTUP_IPI_STR[] = "VMX_EXIT_STARTUP_IPI";
+static const char VMX_EXIT_IO_SMI_STR[] = "VMX_EXIT_IO_SMI";
+static const char VMX_EXIT_OTHER_SMI_STR[] = "VMX_EXIT_OTHER_SMI";
+static const char VMX_EXIT_INTR_WINDOW_STR[] = "VMX_EXIT_INTR_WINDOW";
+static const char VMX_EXIT_NMI_WINDOW_STR[] = "VMX_EXIT_NMI_WINDOW";
+static const char VMX_EXIT_TASK_SWITCH_STR[] = "VMX_EXIT_TASK_SWITCH";
+static const char VMX_EXIT_CPUID_STR[] = "VMX_EXIT_CPUID";
+static const char VMX_EXIT_HLT_STR[] = "VMX_EXIT_HLT";
+static const char VMX_EXIT_INVD_STR[] = "VMX_EXIT_INVD";
+static const char VMX_EXIT_INVLPG_STR[] = "VMX_EXIT_INVLPG";
+static const char VMX_EXIT_RDPMC_STR[] = "VMX_EXIT_RDPMC";
+static const char VMX_EXIT_RDTSC_STR[] = "VMX_EXIT_RDTSC";
+static const char VMX_EXIT_RSM_STR[] = "VMX_EXIT_RSM";
+static const char VMX_EXIT_VMCALL_STR[] = "VMX_EXIT_VMCALL";
+static const char VMX_EXIT_VMCLEAR_STR[] = "VMX_EXIT_VMCLEAR";
+static const char VMX_EXIT_VMLAUNCH_STR[] = "VMX_EXIT_VMLAUNCH";
+static const char VMX_EXIT_VMPTRLD_STR[] = "VMX_EXIT_VMPTRLD";
+static const char VMX_EXIT_VMPTRST_STR[] = "VMX_EXIT_VMPTRST";
+static const char VMX_EXIT_VMREAD_STR[] = "VMX_EXIT_VMREAD";
+static const char VMX_EXIT_VMRESUME_STR[] = "VMX_EXIT_VMRESUME";
+static const char VMX_EXIT_VMWRITE_STR[] = "VMX_EXIT_VMWRITE";
+static const char VMX_EXIT_VMXOFF_STR[] = "VMX_EXIT_VMXOFF";
+static const char VMX_EXIT_VMXON_STR[] = "VMX_EXIT_VMXON";
+static const char VMX_EXIT_CR_REG_ACCESSES_STR[] = "VMX_EXIT_CR_REG_ACCESSES";
+static const char VMX_EXIT_MOV_DR_STR[] = "VMX_EXIT_MOV_DR";
+static const char VMX_EXIT_IO_INSTR_STR[] = "VMX_EXIT_IO_INSTR";
+static const char VMX_EXIT_RDMSR_STR[] = "VMX_EXIT_RDMSR";
+static const char VMX_EXIT_WRMSR_STR[] = "VMX_EXIT_WRMSR";
+static const char VMX_EXIT_INVALID_GUEST_STATE_STR[] = "VMX_EXIT_INVALID_GUEST_STATE";
+static const char VMX_EXIT_INVALID_MSR_LOAD_STR[] = "VMX_EXIT_INVALID_MSR_LOAD";
+static const char VMX_EXIT_MWAIT_STR[] = "VMX_EXIT_MWAIT";
+static const char VMX_EXIT_MONITOR_STR[] = "VMX_EXIT_MONITOR";
+static const char VMX_EXIT_PAUSE_STR[] = "VMX_EXIT_PAUSE";
+static const char VMX_EXIT_INVALID_MACHINE_CHECK_STR[] = "VMX_EXIT_INVALIDE_MACHINE_CHECK";
+static const char VMX_EXIT_TPR_BELOW_THRESHOLD_STR[] = "VMX_EXIT_TPR_BELOW_THRESHOLD";
+static const char VMX_EXIT_APIC_STR[] = "VMX_EXIT_APIC";
+static const char VMX_EXIT_GDTR_IDTR_STR[] = "VMX_EXIT_GDTR_IDTR";
+static const char VMX_EXIT_LDTR_TR_STR[] = "VMX_EXIT_LDTR_TR";
+static const char VMX_EXIT_EPT_VIOLATION_STR[] = "VMX_EXIT_EPT_VIOLATION";
+static const char VMX_EXIT_EPT_CONFIG_STR[] = "VMX_EXIT_EPT_CONFIG";
+static const char VMX_EXIT_INVEPT_STR[] = "VMX_EXIT_INVEPT";
+static const char VMX_EXIT_RDTSCP_STR[] = "VMX_EXIT_RDTSCP";
+static const char VMX_EXIT_EXPIRED_PREEMPT_TIMER_STR[] = "VMX_EXIT_EXPIRED_PREEMPT_TIMER";
+static const char VMX_EXIT_INVVPID_STR[] = "VMX_EXIT_INVVPID";
+static const char VMX_EXIT_WBINVD_STR[] = "VMX_EXIT_WBINVD";
+static const char VMX_EXIT_XSETBV_STR[] = "VMX_EXIT_XSETBV";
+
+const char * v3_vmx_exit_code_to_str(vmx_exit_t exit)
 {
-
-  ullong_t vmcs_ptr = 0;
-  uint_t vmcs_ptr_low = 0;
-  int ret = 0;
-  uint_t vmx_abort = 0;
-
-
-  
-  PrintTrace("Vm Exit\n");
-  ret = VMCS_STORE(&vmcs_ptr);
-  vmcs_ptr &= 0xffffffff;
-  vmcs_ptr_low +=  vmcs_ptr;
-
-
-
-
-  PrintTrace("ret=%d\n", ret);
-  PrintTrace("Revision: %x\n", *(uint_t *)(vmcs_ptr_low));
-  vmx_abort = *(uint_t*)(((char *)vmcs_ptr_low)+4);
-    
-  struct VM *vm = FindVM();
-
-  if (vmx_abort != 0) {
-    PrintTrace("VM ABORTED w/ code: %x\n", vmx_abort);
-    return -1;
-  }
-
-  vm->registers = regs;
-
-  if (CopyOutVMCSData(&(vm->vmcs)) != 0) {
-    PrintTrace("Could not copy out VMCS\n");
-    return -1;
-  }
-
-
-  PrintTrace("Guest esp: 0x%x (%u)\n", vm->vmcs.guestStateArea.rsp, vm->vmcs.guestStateArea.rsp);
-
-  PrintTrace("VM Exit for reason: %d (%x)\n", 
-             vm->vmcs.exitInfoFields.reason & 0x00000fff,
-             vm->vmcs.exitInfoFields.reason);  
-
-  if (vm->vmcs.exitInfoFields.reason & (0x1<<29) ) { 
-    PrintTrace("VM Exit is from VMX root operation.  Panicking\n");
-    VMXPanic();
-  }
-
-  if (vm->vmcs.exitInfoFields.reason & (0x1<<31) ) { 
-    PrintTrace("VM Exit is due to a VM entry failure.  Shouldn't happen here. Panicking\n");
-    PrintTrace_VMCSData(&(vm->vmcs));
-    VMXPanic();
-  }
-
-  switch (vm->vmcs.exitInfoFields.reason) {
-  case VM_EXIT_REASON_INFO_EXCEPTION_OR_NMI:
-    ret = HandleExceptionOrNMI(vm);
-    break;
-  case VM_EXIT_REASON_EXTERNAL_INTR:
-    ret = HandleExternalIRQExit(vm);
-    break;
-  case VM_EXIT_REASON_TRIPLE_FAULT:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_INIT_SIGNAL:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_STARTUP_IPI:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_IO_SMI:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_OTHER_SMI:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_INTR_WINDOW:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_NMI_WINDOW:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_TASK_SWITCH:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_CPUID:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_INVD:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_INVLPG:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_RDPMC:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_RDTSC:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_RSM:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMCALL:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMCLEAR:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMLAUNCH:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMPTRLD:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMPTRST:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMREAD:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMRESUME:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMWRITE:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMXOFF:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_VMXON:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_CR_REG_ACCESSES:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_MOV_DR:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_IO_INSTR:
-    ret = HandleInOutExit(vm);
-    break;
-  case VM_EXIT_REASON_RDMSR:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_WRMSR:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_ENTRY_FAIL_INVALID_GUEST_STATE:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_ENTRY_FAIL_MSR_LOAD:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_MWAIT:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_MONITOR:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_PAUSE:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_ENTRY_FAILURE_MACHINE_CHECK:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  case VM_EXIT_REASON_TPR_BELOW_THRESHOLD:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  default:
-    ret = PanicUnhandledVMExit(vm);
-    break;
-  }
-  
-  
-  regs = vm->registers;
-  CopyInVMCSData(&(vm->vmcs));
-
-  /*
-    {
-    VMCS_CLEAR(vmcs_ptr);
+    switch (exit) {
+        case VMX_EXIT_INFO_EXCEPTION_OR_NMI:
+            return VMX_EXIT_INFO_EXCEPTION_OR_NMI_STR;
+        case VMX_EXIT_EXTERNAL_INTR:
+            return VMX_EXIT_EXTERNAL_INTR_STR;
+        case VMX_EXIT_TRIPLE_FAULT:
+            return VMX_EXIT_TRIPLE_FAULT_STR;
+        case VMX_EXIT_INIT_SIGNAL:
+            return VMX_EXIT_INIT_SIGNAL_STR;
+        case VMX_EXIT_STARTUP_IPI:
+            return VMX_EXIT_STARTUP_IPI_STR;
+        case VMX_EXIT_IO_SMI:
+            return VMX_EXIT_IO_SMI_STR;
+        case VMX_EXIT_OTHER_SMI:
+            return VMX_EXIT_OTHER_SMI_STR;
+        case VMX_EXIT_INTR_WINDOW:
+            return VMX_EXIT_INTR_WINDOW_STR;
+        case VMX_EXIT_NMI_WINDOW:
+            return VMX_EXIT_NMI_WINDOW_STR;
+        case VMX_EXIT_TASK_SWITCH:
+            return VMX_EXIT_TASK_SWITCH_STR;
+        case VMX_EXIT_CPUID:
+            return VMX_EXIT_CPUID_STR;
+        case VMX_EXIT_HLT:
+            return VMX_EXIT_HLT_STR;
+        case VMX_EXIT_INVD:
+            return VMX_EXIT_INVD_STR;
+        case VMX_EXIT_INVLPG:
+            return VMX_EXIT_INVLPG_STR;
+        case VMX_EXIT_RDPMC:
+            return VMX_EXIT_RDPMC_STR;
+        case VMX_EXIT_RDTSC:
+            return VMX_EXIT_RDTSC_STR;
+        case VMX_EXIT_RSM:
+            return VMX_EXIT_RSM_STR;
+        case VMX_EXIT_VMCALL:
+            return VMX_EXIT_VMCALL_STR;
+        case VMX_EXIT_VMCLEAR:
+            return VMX_EXIT_VMCLEAR_STR;
+        case VMX_EXIT_VMLAUNCH:
+            return VMX_EXIT_VMLAUNCH_STR;
+        case VMX_EXIT_VMPTRLD:
+            return VMX_EXIT_VMPTRLD_STR;
+        case VMX_EXIT_VMPTRST:
+            return VMX_EXIT_VMPTRST_STR;
+        case VMX_EXIT_VMREAD:
+            return VMX_EXIT_VMREAD_STR;
+        case VMX_EXIT_VMRESUME:
+            return VMX_EXIT_VMRESUME_STR;
+        case VMX_EXIT_VMWRITE:
+            return VMX_EXIT_VMWRITE_STR;
+        case VMX_EXIT_VMXOFF:
+            return VMX_EXIT_VMXOFF_STR;
+        case VMX_EXIT_VMXON:
+            return VMX_EXIT_VMXON_STR;
+        case VMX_EXIT_CR_REG_ACCESSES:
+            return VMX_EXIT_CR_REG_ACCESSES_STR;
+        case VMX_EXIT_MOV_DR:
+            return VMX_EXIT_MOV_DR_STR;
+        case VMX_EXIT_IO_INSTR:
+            return VMX_EXIT_IO_INSTR_STR;
+        case VMX_EXIT_RDMSR:
+            return VMX_EXIT_RDMSR_STR;
+        case VMX_EXIT_WRMSR:
+            return VMX_EXIT_WRMSR_STR;
+        case VMX_EXIT_INVALID_GUEST_STATE:
+            return VMX_EXIT_INVALID_GUEST_STATE_STR;
+        case VMX_EXIT_INVALID_MSR_LOAD:
+            return VMX_EXIT_INVALID_MSR_LOAD_STR;
+        case VMX_EXIT_MWAIT:
+            return VMX_EXIT_MWAIT_STR;
+        case VMX_EXIT_MONITOR:
+            return VMX_EXIT_MONITOR_STR;
+        case VMX_EXIT_PAUSE:
+            return VMX_EXIT_PAUSE_STR;
+        case VMX_EXIT_INVALID_MACHINE_CHECK:
+            return VMX_EXIT_INVALID_MACHINE_CHECK_STR;
+        case VMX_EXIT_TPR_BELOW_THRESHOLD:
+            return VMX_EXIT_TPR_BELOW_THRESHOLD_STR;
+        case VMX_EXIT_APIC:
+            return VMX_EXIT_APIC_STR;
+        case VMX_EXIT_GDTR_IDTR:
+            return VMX_EXIT_GDTR_IDTR_STR;
+        case VMX_EXIT_LDTR_TR:
+            return VMX_EXIT_LDTR_TR_STR;
+        case VMX_EXIT_EPT_VIOLATION:
+            return VMX_EXIT_EPT_VIOLATION_STR;
+        case VMX_EXIT_EPT_CONFIG:
+            return VMX_EXIT_EPT_CONFIG_STR;
+        case VMX_EXIT_INVEPT:
+            return VMX_EXIT_INVEPT_STR;
+        case VMX_EXIT_RDTSCP:
+            return VMX_EXIT_RDTSCP_STR;
+        case VMX_EXIT_EXPIRED_PREEMPT_TIMER:
+            return VMX_EXIT_EXPIRED_PREEMPT_TIMER_STR;
+        case VMX_EXIT_INVVPID:
+            return VMX_EXIT_INVVPID_STR;
+        case VMX_EXIT_WBINVD:
+            return VMX_EXIT_WBINVD_STR;
+        case VMX_EXIT_XSETBV:
+            return VMX_EXIT_XSETBV_STR;
     }
-  */
-
-  PrintTrace("Returning from Do_VMM: %d\n", ret);
-  return ret;
-}
-
-
-
-
-
-
-// simply execute the instruction that is faulting and return
-static int ExecFaultingInstructionInVMM(struct VM *vm)
-{
-  uint_t address = GetLinearIP(vm);
-  myregs = (uint_t)&(vm->registers);
-  
-
-  PrintTrace("About the execute faulting instruction!\n");
-  PrintTrace("Instruction is:\n");
-  PrintTraceMemDump((void*)(address),vm->vmcs.exitInfoFields.instrLength);
-  
-
-  PrintTrace("The template code is:\n");
-  PrintTraceMemDump(&&template_code,TEMPLATE_CODE_LEN);
-
-  // clone the template code
-  //memcpy(&&template_code,code,MAX_CODE);
-  
-  // clean up the nop field
-  memset(&&template_code+INSTR_OFFSET_START,*((uchar_t *)(&&template_code+0)),NOP_SEQ_LEN);
-  // overwrite the nops with the faulting instruction
-  memcpy(&&template_code+INSTR_OFFSET_START, (void*)(address),vm->vmcs.exitInfoFields.instrLength);
-  
-  PrintTrace("Finished modifying the template code, which now is:\n");
-  PrintTraceMemDump(&&template_code,TEMPLATE_CODE_LEN);
-
-  PrintTrace("Now entering modified template code\n");
-
-
- template_code:
-  // Template code stores current registers,
-  // restores registers, has a landing pad of noops 
-  // that will be modified, restores current regs, and then returns
-  //
-  // Note that this currently ignores cr0, cr3, cr4, dr7, rsp, rip, and rflags
-  // it also blythly assumes it can exec the instruction in protected mode
-  //
-  __asm__ __volatile__ ("nop\n"               // for cloning purposes                          (1 byte)
-                       "pusha\n"             // push our current regs onto the current stack  (1 byte)
-                       "movl %0, %%eax\n"    // Get oldesp location                           (5 bytes)
-                       "movl %%esp, (%%eax)\n"  // store the current stack pointer in oldesp       (2 bytes)
-                        "movl %1, %%eax\n"    // Get regs location                             (5 bytes)
-                       "movl (%%eax), %%esp\n"  // point esp at regs                               (2 bytes)
-                       "popa\n"              // now we have the VM registers restored            (1 byte)
-                       "nop\n"               // now we execute the actual instruction         (1 byte x 10)
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       "nop\n"               // now we execute the actual instruction
-                       // need to copy back to the VM registers!
-                        "movl %0, %%eax\n"     // recapture oldesp location                     (5 bytes)
-                       "movl (%%eax), %%esp\n"   // now we'll get our esp back from oldesp       (2 bytes)
-                       "popa\n"              // and restore our GP regs and we're done       (1 byte)
-                       : "=m"(oldesp)
-                       : "m"(myregs)
-                       );
-  
-  PrintTrace("Survived executing the faulting instruction and returning.\n");
-
-  vm->vmcs.guestStateArea.rip += vm->vmcs.exitInfoFields.instrLength;
-
-  return 0;
-
+    return NULL;
 }