VMM: Remove unused code (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Feb 2016 17:20:57 +0000 (12:20 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Feb 2016 22:43:52 +0000 (17:43 -0500)
This removes a lot of the KVM "bag on the side".

For whatever reason, struct vmx_vcpu is in a kernel header, so reinstall
your headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/ros/vmx.h
kern/arch/x86/vmm/intel/vmx.c
kern/arch/x86/vmm/vmm.c
kern/arch/x86/vmm/vmm.h
kern/drivers/dev/cons.c
kern/include/smp.h

index 0f81389..4ed7aa4 100644 (file)
@@ -691,26 +691,13 @@ struct ldttss_desc64 {
 } __attribute__((packed));
 
 struct vmx_vcpu {
-
        int cpu;
-       int launched;
-       struct hw_trapframe regs;
-       uint8_t  fail;
-       uint64_t exit_reason;
-       uint64_t host_rsp;
-
-       uint64_t cr2;
-
-       int shutdown;
-       int ret_code;
        struct proc *proc;
-
        struct msr_autoload {
                unsigned nr;
                struct vmx_msr_entry guest[NR_AUTOLOAD_MSRS];
                struct vmx_msr_entry host[NR_AUTOLOAD_MSRS];
        } msr_autoload;
-
        struct vmcs *vmcs;
 };
 
index 78ba940..9fd0a2f 100644 (file)
 
 #define currentcpu (&per_cpu_info[core_id()])
 
-/* debug stuff == remove later. It's not even multivm safe. */
-uint64_t idtr;
-int debug =0;
-
-// END debug
 static unsigned long *msr_bitmap;
 #define VMX_IO_BITMAP_ORDER            4       /* 64 KB */
 #define VMX_IO_BITMAP_SZ               (1 << (VMX_IO_BITMAP_ORDER + PGSHIFT))
@@ -791,97 +786,6 @@ static void __vmx_setup_pcpu(struct vmx_vcpu *gpc)
         * think about how perf will work with VMs */
 }
 
-/**
- * vmx_get_cpu - called before using a cpu
- * @vcpu: VCPU that will be loaded.
- *
- * Disables preemption. Call vmx_put_cpu() when finished.
- */
-static void
-vmx_get_cpu(struct vmx_vcpu *vcpu)
-{
-       int cur_cpu = core_id();
-       handler_wrapper_t *w;
-
-       if (currentcpu->local_vcpu)
-               panic("get_cpu: currentcpu->localvcpu was non-NULL");
-       if (currentcpu->local_vcpu != vcpu) {
-               currentcpu->local_vcpu = vcpu;
-
-               if (vcpu->cpu != cur_cpu) {
-                       if (vcpu->cpu >= 0) {
-                               panic("vcpu->cpu is not -1, it's %d\n", vcpu->cpu);
-                       } else
-                               vmcs_clear(vcpu->vmcs);
-
-                       ept_sync_context(vcpu_get_eptp(vcpu));
-
-                       vcpu->launched = 0;
-                       vmcs_load(vcpu->vmcs);
-                       __vmx_setup_pcpu(vcpu);
-                       vcpu->cpu = cur_cpu;
-               } else {
-                       vmcs_load(vcpu->vmcs);
-               }
-       }
-}
-
-/**
- * vmx_put_cpu - called after using a cpu
- * @vcpu: VCPU that was loaded.
- */
-static void
-vmx_put_cpu(struct vmx_vcpu *vcpu)
-{
-       if (core_id() != vcpu->cpu)
-               panic("%s: core_id() %d != vcpu->cpu %d\n",
-                         __func__, core_id(), vcpu->cpu);
-
-       if (currentcpu->local_vcpu != vcpu)
-               panic("vmx_put_cpu: asked to clear something not ours");
-
-       ept_sync_context(vcpu_get_eptp(vcpu));
-       vmcs_clear(vcpu->vmcs);
-       vcpu->cpu = -1;
-       currentcpu->local_vcpu = NULL;
-       //put_cpu();
-}
-
-/**
- * vmx_dump_cpu - prints the CPU state
- * @vcpu: VCPU to print
- */
-static void
-vmx_dump_cpu(struct vmx_vcpu *vcpu)
-{
-
-       unsigned long flags;
-
-       vmx_get_cpu(vcpu);
-       printk("GUEST_INTERRUPTIBILITY_INFO: 0x%08x\n",  vmcs_readl(GUEST_INTERRUPTIBILITY_INFO));
-       printk("VM_ENTRY_INTR_INFO_FIELD 0x%08x\n", vmcs_readl(VM_ENTRY_INTR_INFO_FIELD));
-       printk("EXIT_QUALIFICATION 0x%08x\n", vmcs_read32(EXIT_QUALIFICATION));
-       printk("VM_EXIT_REASON 0x%08x\n", vmcs_read32(VM_EXIT_REASON));
-       vcpu->regs.tf_rip = vmcs_readl(GUEST_RIP);
-       vcpu->regs.tf_rsp = vmcs_readl(GUEST_RSP);
-       flags = vmcs_readl(GUEST_RFLAGS);
-       vmx_put_cpu(vcpu);
-
-       printk("--- Begin VCPU Dump ---\n");
-       printk("CPU %d VPID %d\n", vcpu->cpu, 0);
-       printk("RIP 0x%016lx RFLAGS 0x%08lx\n", vcpu->regs.tf_rip, flags);
-       printk("RAX 0x%016lx RCX 0x%016lx\n", vcpu->regs.tf_rax, vcpu->regs.tf_rcx);
-       printk("RDX 0x%016lx RBX 0x%016lx\n", vcpu->regs.tf_rdx, vcpu->regs.tf_rbx);
-       printk("RSP 0x%016lx RBP 0x%016lx\n", vcpu->regs.tf_rsp, vcpu->regs.tf_rbp);
-       printk("RSI 0x%016lx RDI 0x%016lx\n", vcpu->regs.tf_rsi, vcpu->regs.tf_rdi);
-       printk("R8  0x%016lx R9  0x%016lx\n", vcpu->regs.tf_r8, vcpu->regs.tf_r9);
-       printk("R10 0x%016lx R11 0x%016lx\n", vcpu->regs.tf_r10, vcpu->regs.tf_r11);
-       printk("R12 0x%016lx R13 0x%016lx\n", vcpu->regs.tf_r12, vcpu->regs.tf_r13);
-       printk("R14 0x%016lx R15 0x%016lx\n", vcpu->regs.tf_r14, vcpu->regs.tf_r15);
-       printk("--- End VCPU Dump ---\n");
-
-}
-
 uint64_t
 construct_eptp(physaddr_t root_hpa)
 {
@@ -1101,18 +1005,6 @@ static void dumpmsrs(void) {
        printk("core id %d\n", core_id());
 }
 
-static int
-msrio(struct vmx_vcpu *vcpu, uint32_t opcode, uint32_t qual) {
-       int i;
-
-       opcode = (opcode == EXIT_REASON_MSR_READ ? VMM_MSR_EMU_READ :
-                                                  VMM_MSR_EMU_WRITE);
-       if (!vmm_emulate_msr(&vcpu->regs.tf_rcx, &vcpu->regs.tf_rdx,
-                            &vcpu->regs.tf_rax, opcode))
-               return SHUTDOWN_UNHANDLED_EXIT_REASON;
-       return 0;
-}
-
 /* Notes on autoloading.  We can't autoload FS_BASE or GS_BASE, according to the
  * manual, but that's because they are automatically saved and restored when all
  * of the other architectural registers are saved and restored, such as cs, ds,
@@ -1232,10 +1124,10 @@ struct vmx_vcpu *vmx_create_vcpu(struct proc *p, struct vmm_gpcore_init *gpci)
 
        vcpu->cpu = -1;
 
-       vmx_get_cpu(vcpu);
+       vmx_load_guest_pcore(vcpu);
        vmx_setup_vmcs(vcpu);
        ret = vmx_setup_initial_guest_state(p, gpci);
-       vmx_put_cpu(vcpu);
+       vmx_unload_guest_pcore(vcpu);
 
        if (!ret)
                return vcpu;
@@ -1254,496 +1146,21 @@ void vmx_destroy_vcpu(struct vmx_vcpu *vcpu) {
        kfree(vcpu);
 }
 
-/**
- * vmx_current_vcpu - returns a pointer to the vcpu for the current task.
- *
- * In the contexts where this is used the vcpu pointer should never be NULL.
- */
-static inline struct vmx_vcpu *vmx_current_vcpu(void) {
-       struct vmx_vcpu *vcpu = currentcpu->local_vcpu;
-       if (!vcpu)
-               panic("Core has no vcpu!");
-       return vcpu;
-}
-
-/**
- * vmx_run_vcpu - launches the CPU into non-root mode
- * We ONLY support 64-bit guests.
- * @vcpu: the vmx instance to launch
- */
-static int vmx_run_vcpu(struct vmx_vcpu *vcpu)
-{
-       asm(
-               /* Store host registers */
-               "push %%rdx; push %%rbp;"
-               "push %%rcx \n\t" /* placeholder for guest rcx */
-               "push %%rcx \n\t"
-               "cmp %%rsp, %c[host_rsp](%0) \n\t"
-               "je 1f \n\t"
-               "mov %%rsp, %c[host_rsp](%0) \n\t"
-               ASM_VMX_VMWRITE_RSP_RDX "\n\t"
-               "1: \n\t"
-               /* Reload cr2 if changed */
-               "mov %c[cr2](%0), %%rax \n\t"
-               "mov %%cr2, %%rdx \n\t"
-               "cmp %%rax, %%rdx \n\t"
-               "je 2f \n\t"
-               "mov %%rax, %%cr2 \n\t"
-               "2: \n\t"
-               /* Check if vmlaunch of vmresume is needed */
-               "cmpl $0, %c[launched](%0) \n\t"
-               /* Load guest registers.  Don't clobber flags. */
-               "mov %c[rax](%0), %%rax \n\t"
-               "mov %c[rbx](%0), %%rbx \n\t"
-               "mov %c[rdx](%0), %%rdx \n\t"
-               "mov %c[rsi](%0), %%rsi \n\t"
-               "mov %c[rdi](%0), %%rdi \n\t"
-               "mov %c[rbp](%0), %%rbp \n\t"
-               "mov %c[r8](%0),  %%r8  \n\t"
-               "mov %c[r9](%0),  %%r9  \n\t"
-               "mov %c[r10](%0), %%r10 \n\t"
-               "mov %c[r11](%0), %%r11 \n\t"
-               "mov %c[r12](%0), %%r12 \n\t"
-               "mov %c[r13](%0), %%r13 \n\t"
-               "mov %c[r14](%0), %%r14 \n\t"
-               "mov %c[r15](%0), %%r15 \n\t"
-               "mov %c[rcx](%0), %%rcx \n\t" /* kills %0 (ecx) */
-
-               /* Enter guest mode */
-               "jne .Llaunched \n\t"
-               ASM_VMX_VMLAUNCH "\n\t"
-               "jmp .Lkvm_vmx_return \n\t"
-               ".Llaunched: " ASM_VMX_VMRESUME "\n\t"
-               ".Lkvm_vmx_return: "
-               /* Save guest registers, load host registers, keep flags */
-               "mov %0, %c[wordsize](%%rsp) \n\t"
-               "pop %0 \n\t"
-               "mov %%rax, %c[rax](%0) \n\t"
-               "mov %%rbx, %c[rbx](%0) \n\t"
-               "popq %c[rcx](%0) \n\t"
-               "mov %%rdx, %c[rdx](%0) \n\t"
-               "mov %%rsi, %c[rsi](%0) \n\t"
-               "mov %%rdi, %c[rdi](%0) \n\t"
-               "mov %%rbp, %c[rbp](%0) \n\t"
-               "mov %%r8,  %c[r8](%0) \n\t"
-               "mov %%r9,  %c[r9](%0) \n\t"
-               "mov %%r10, %c[r10](%0) \n\t"
-               "mov %%r11, %c[r11](%0) \n\t"
-               "mov %%r12, %c[r12](%0) \n\t"
-               "mov %%r13, %c[r13](%0) \n\t"
-               "mov %%r14, %c[r14](%0) \n\t"
-               "mov %%r15, %c[r15](%0) \n\t"
-               "mov %%rax, %%r10 \n\t"
-               "mov %%rdx, %%r11 \n\t"
-
-               "mov %%cr2, %%rax   \n\t"
-               "mov %%rax, %c[cr2](%0) \n\t"
-
-               "pop  %%rbp; pop  %%rdx \n\t"
-               "setbe %c[fail](%0) \n\t"
-               "mov $" STRINGIFY(GD_UD) ", %%rax \n\t"
-               "mov %%rax, %%ds \n\t"
-               "mov %%rax, %%es \n\t"
-             : : "c"(vcpu), "d"((unsigned long)HOST_RSP),
-               [launched]"i"(offsetof(struct vmx_vcpu, launched)),
-               [fail]"i"(offsetof(struct vmx_vcpu, fail)),
-               [host_rsp]"i"(offsetof(struct vmx_vcpu, host_rsp)),
-               [rax]"i"(offsetof(struct vmx_vcpu, regs.tf_rax)),
-               [rbx]"i"(offsetof(struct vmx_vcpu, regs.tf_rbx)),
-               [rcx]"i"(offsetof(struct vmx_vcpu, regs.tf_rcx)),
-               [rdx]"i"(offsetof(struct vmx_vcpu, regs.tf_rdx)),
-               [rsi]"i"(offsetof(struct vmx_vcpu, regs.tf_rsi)),
-               [rdi]"i"(offsetof(struct vmx_vcpu, regs.tf_rdi)),
-               [rbp]"i"(offsetof(struct vmx_vcpu, regs.tf_rbp)),
-               [r8]"i"(offsetof(struct vmx_vcpu, regs.tf_r8)),
-               [r9]"i"(offsetof(struct vmx_vcpu, regs.tf_r9)),
-               [r10]"i"(offsetof(struct vmx_vcpu, regs.tf_r10)),
-               [r11]"i"(offsetof(struct vmx_vcpu, regs.tf_r11)),
-               [r12]"i"(offsetof(struct vmx_vcpu, regs.tf_r12)),
-               [r13]"i"(offsetof(struct vmx_vcpu, regs.tf_r13)),
-               [r14]"i"(offsetof(struct vmx_vcpu, regs.tf_r14)),
-               [r15]"i"(offsetof(struct vmx_vcpu, regs.tf_r15)),
-               [cr2]"i"(offsetof(struct vmx_vcpu, cr2)),
-               [wordsize]"i"(sizeof(unsigned long))
-             : "cc", "memory"
-               , "rax", "rbx", "rdi", "rsi"
-               , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
-       );
-
-       if (vmcs_readl(GUEST_IDTR_BASE) != idtr){
-               printk("idt changed; old 0x%lx new 0x%lx\n", vmcs_read64(GUEST_IDTR_BASE), idtr);
-               idtr = vmcs_read64(GUEST_IDTR_BASE);
-       }
-       vcpu->regs.tf_rip = vmcs_readl(GUEST_RIP);
-       vcpu->regs.tf_rsp = vmcs_readl(GUEST_RSP);
-       printd("RETURN. ip %016lx sp %016lx cr2 %016lx\n",
-              vcpu->regs.tf_rip, vcpu->regs.tf_rsp, vcpu->cr2);
-       /* FIXME: do we need to set up other flags? */
-       // NO IDEA!
-       vcpu->regs.tf_rflags = vmcs_readl(GUEST_RFLAGS); //& 0xFF) | X86_EFLAGS_IF | 0x2;
-
-       vcpu->regs.tf_cs = GD_UT;
-       vcpu->regs.tf_ss = GD_UD;
-
-       vcpu->launched = 1;
-
-       if (vcpu->fail) {
-               printk("failure detected (err %x)\n",
-                      vmcs_read32(VM_INSTRUCTION_ERROR));
-               return VMX_EXIT_REASONS_FAILED_VMENTRY;
-       }
-
-       return vmcs_read32(VM_EXIT_REASON);
-
-#if 0
-       vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
-       vmx_complete_atomic_exit(vmx);
-       vmx_recover_nmi_blocking(vmx);
-       vmx_complete_interrupts(vmx);
-#endif
-}
-
 static void vmx_step_instruction(void) {
        vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP) +
                    vmcs_read32(VM_EXIT_INSTRUCTION_LEN));
 }
 
-static int vmx_handle_ept_violation(struct vmx_vcpu *vcpu, struct vmctl *v) {
-       unsigned long gva, gpa;
-       int exit_qual, ret = -1;
-       page_t *page;
-
-       vmx_get_cpu(vcpu);
-       exit_qual = vmcs_read32(EXIT_QUALIFICATION);
-       gva = vmcs_readl(GUEST_LINEAR_ADDRESS);
-       gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
-       v->gpa = gpa;
-       v->gva = gva;
-       v->exit_qual = exit_qual;
-       vmx_put_cpu(vcpu);
-
-       int prot = 0;
-       prot |= exit_qual & VMX_EPT_FAULT_READ ? PROT_READ : 0;
-       prot |= exit_qual & VMX_EPT_FAULT_WRITE ? PROT_WRITE : 0;
-       prot |= exit_qual & VMX_EPT_FAULT_INS ? PROT_EXEC : 0;
-       ret = handle_page_fault(current, gpa, prot);
-
-       // Some of these get fixed in the vmm; be less chatty now.
-       if (0 && ret) {
-               printk("EPT page fault failure %d, GPA: %p, GVA: %p\n", ret, gpa,
-                      gva);
-               vmx_dump_cpu(vcpu);
-       }
-
-       /* we let the vmm handle the failure cases. So return
-        * the VMX exit violation, not what handle_page_fault returned.
-        */
-       return EXIT_REASON_EPT_VIOLATION;
-}
-
-static void vmx_handle_cpuid(struct vmx_vcpu *vcpu) {
-       unsigned int eax, ebx, ecx, edx;
-
-       eax = vcpu->regs.tf_rax;
-       ecx = vcpu->regs.tf_rcx;
-       cpuid(eax, ecx, &eax, &ebx, &ecx, &edx);
-       vcpu->regs.tf_rax = eax;
-       vcpu->regs.tf_rbx = ebx;
-       vcpu->regs.tf_rcx = ecx;
-       vcpu->regs.tf_rdx = edx;
-}
-
-static int vmx_handle_nmi_exception(struct vmx_vcpu *vcpu) {
-       uint32_t intr_info;
-
-       vmx_get_cpu(vcpu);
-       intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
-       vmx_put_cpu(vcpu);
-
-       printk("vmx (vcpu %p): got an exception\n", vcpu);
-       printk("vmx (vcpu %p): pid %d\n", vcpu, vcpu->proc->pid);
-       if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR) {
-               return 0;
-       }
-
-       printk("unhandled nmi, intr_info %x\n", intr_info);
-       return -EIO;
-}
-
-static void vmx_hwapic_isr_update(struct vmctl *v, int isr)
-{
-       uint16_t status;
-       uint8_t old;
-
-       status = vmcs_read16(GUEST_INTR_STATUS);
-       old = status >> 8;
-       if (isr != old) {
-               status &= 0xff;
-               status |= isr << 8;
-               vmcs_write16(GUEST_INTR_STATUS, status);
-       }
-}
-
-static void vmx_set_rvi(int vector)
-{
-       uint16_t status;
-       uint8_t old;
-
-       status = vmcs_read16(GUEST_INTR_STATUS);
-       printk("%s: Status is %04x", __func__, status);
-       old = (uint8_t)status & 0xff;
-       if ((uint8_t)vector != old) {
-               status &= ~0xff;
-               status |= (uint8_t)vector;
-               printk("%s: SET 0x%x\n", __func__, status);
-
-               // Clear SVI
-               status &= 0xff;
-               vmcs_write16(GUEST_INTR_STATUS, status);
-       }
-       printk("%s: Status is %04x after RVI", __func__,
-                       vmcs_read16(GUEST_INTR_STATUS));
-}
-
-/*
-static void vmx_set_posted_interrupt(int vector)
-{
-       unsigned long *bit_vec;
-       unsigned long *pir = vmcs_readl(POSTED_INTR_DESC_ADDR_HIGH);
-       pir = pir << 32;
-       pir |= vmcs_readl(POSTED_INTR_DESC_ADDR);
-
-       // Move to the correct location to set our bit.
-       bit_vec = pir + vector/32;
-       test_and_set_bit(vector%32, bit_vec);
-
-       // Set outstanding notification bit
-       bit_vec = pir + 8;
-       test_and_set_bit(0, bit_vec);
-}
-
-*/
-
 int vmx_interrupt_notify(struct vmctl *v)
 {
        /* Assume we want to IPI guest pcore 0 (which vmctl controlled). */
        int vm_core = current->vmm.guest_pcores[0]->cpu;
 
        send_ipi(vm_core, I_VMMCP_POSTED);
-       if(debug) printk("Posting Interrupt\n");
        return 0;
 }
 
 /**
- * vmx_launch - the main loop for a VMX Dune process
- * @conf: the launch configuration
- */
-int vmx_launch(struct vmctl *v) {
-       int ret;
-       struct vmx_vcpu *vcpu;
-       int errors = 0;
-       int advance;
-       int interrupting = 0;
-       uintptr_t pir_kva, vapic_kva, apic_kva;
-       uint64_t pir_physical, vapic_physical, apic_physical;
-       struct proc * current_proc = current;
-
-       /* TODO: dirty hack til we have VMM contexts */
-       vcpu = current->vmm.guest_pcores[0];
-       if (!vcpu) {
-               printk("Failed to get a CPU!\n");
-               return -ENOMEM;
-       }
-
-       v->core = core_id();
-       printd("Core Id: %d\n", v->core);
-       /* We need to prep the host's autoload region for our current core.  Right
-        * now, the only autoloaded MSR that varies at runtime (in this case per
-        * core is the KERN_GS_BASE). */
-       rdmsrl(MSR_KERNEL_GS_BASE, vcpu->msr_autoload.host[0].value);
-       /* if cr3 is set, means 'set everything', else means 'start where you left off' */
-       vmx_get_cpu(vcpu);
-       switch(v->command) {
-       case REG_ALL:
-               printd("REG_ALL\n");
-               // fallthrough
-               vcpu->regs = v->regs;
-               vmcs_writel(GUEST_RSP, v->regs.tf_rsp);
-               vmcs_writel(GUEST_RIP, v->regs.tf_rip);
-               break;
-       case REG_RSP_RIP_CR3:
-               printd("REG_RSP_RIP_CR3\n");
-               vmcs_writel(GUEST_RSP, v->regs.tf_rsp);
-               vmcs_writel(GUEST_CR3, v->cr3);
-               vcpu->regs = v->regs;
-               // fallthrough
-       case REG_RIP:
-               printd("REG_RIP %p\n", v->regs.tf_rip);
-               vmcs_writel(GUEST_RIP, v->regs.tf_rip);
-               break;
-       case RESUME:
-               /* If v->interrupt is non-zero, set it in the vmcs and
-                * zero it in the vmctl. Else set RIP.
-                * We used to check RFLAGS.IF and such here but we'll let the VMM
-                * do it. If the VMM screws up we can always fix it. Note to people
-                * who know about security: could this be an issue?
-                * I don't see how: it will mainly just break your guest vm AFAICT.
-                */
-               if (v->interrupt) {
-                       if(debug) printk("Set VM_ENTRY_INFTR_INFO_FIELD to 0x%x\n", v->interrupt);
-                       vmcs_writel(VM_ENTRY_INTR_INFO_FIELD, v->interrupt);
-
-                       v->interrupt = 0;
-                       interrupting = 1;
-               }
-               printd("RESUME\n");
-               break;
-       default:
-               error(EINVAL, "Bad command in vmx_launch");
-       }
-       vcpu->shutdown = 0;
-       vmx_put_cpu(vcpu);
-       if (interrupting) {
-               if(debug) printk("BEFORE INTERRUPT: ");
-               if(debug) vmx_dump_cpu(vcpu);
-       }
-       vcpu->ret_code = -1;
-
-       while (1) {
-               advance = 0;
-               vmx_get_cpu(vcpu);
-
-               // TODO: manage the fpu when we restart.
-
-               // TODO: see if we need to exit before we go much further.
-               disable_irq();
-               //dumpmsrs();
-               ret = vmx_run_vcpu(vcpu);
-
-               //dumpmsrs();
-               enable_irq();
-
-               // Update the core the vm is running on in case it has changed.
-               v->core = core_id();
-               current_proc->vmm.vmexits[ret] += 1;
-
-               v->intrinfo1 = vmcs_readl(GUEST_INTERRUPTIBILITY_INFO);
-               v->intrinfo2 = vmcs_readl(VM_EXIT_INTR_INFO);
-               vmx_put_cpu(vcpu);
-
-               if (interrupting) {
-                       if(debug) printk("POST INTERRUPT: \n");
-                       unsigned long cr8val;
-                       asm volatile("mov %%cr8,%0" : "=r" (cr8val));
-                       if(debug) printk("CR8 Value: 0x%08x", cr8val);
-
-                       if(debug) printk("%s: Status is %04x\n", __func__,
-                                       vmcs_read16(GUEST_INTR_STATUS));
-                       if(debug) vmx_dump_cpu(vcpu);
-               }
-
-               if (ret == EXIT_REASON_VMCALL) {
-                       if (current->vmm.flags & VMM_VMCALL_PRINTF) {
-                               uint8_t byte = vcpu->regs.tf_rdi;
-                               printd("System call\n");
-#ifdef DEBUG
-                               vmx_dump_cpu(vcpu);
-#endif
-                               advance = 3;
-                               printk("%c", byte);
-                               // adjust the RIP
-                       } else {
-                               vcpu->shutdown = SHUTDOWN_UNHANDLED_EXIT_REASON;
-#ifdef DEBUG
-                               vmx_dump_cpu(vcpu);
-                               printd("system call! WTF\n");
-#endif
-                       }
-               } else if (ret == EXIT_REASON_CR_ACCESS) {
-                       show_cr_access(vmcs_read32(EXIT_QUALIFICATION));
-                       vmx_dump_cpu(vcpu);
-                       vcpu->shutdown = SHUTDOWN_UNHANDLED_EXIT_REASON;
-               } else if (ret == EXIT_REASON_CPUID) {
-                       printd("CPUID EXIT RIP: %p\n", vcpu->regs.tf_rip);
-                       vmx_handle_cpuid(vcpu);
-                       vmx_get_cpu(vcpu);
-                       vmcs_writel(GUEST_RIP, vcpu->regs.tf_rip + 2);
-                       vmx_put_cpu(vcpu);
-               } else if (ret == EXIT_REASON_EPT_VIOLATION) {
-                       if (vmx_handle_ept_violation(vcpu, v))
-                               vcpu->shutdown = SHUTDOWN_EPT_VIOLATION;
-               } else if (ret == EXIT_REASON_EXCEPTION_NMI) {
-                       if (vmx_handle_nmi_exception(vcpu))
-                               vcpu->shutdown = SHUTDOWN_NMI_EXCEPTION;
-               } else if (ret == EXIT_REASON_EXTERNAL_INTERRUPT) {
-                       printk("External interrupt\n");
-                       vmx_dump_cpu(vcpu);
-                       printk("GUEST_INTERRUPTIBILITY_INFO: 0x%08x,",  v->intrinfo1);
-                       printk("VM_EXIT_INFO_FIELD 0x%08x,", v->intrinfo2);
-                       printk("rflags 0x%x\n", vcpu->regs.tf_rflags);
-                       vcpu->shutdown = SHUTDOWN_UNHANDLED_EXIT_REASON;
-               } else if (ret == EXIT_REASON_MSR_READ) {
-                       printd("msr read\n");
-                       vmx_dump_cpu(vcpu);
-                       vcpu->shutdown =
-                               msrio(vcpu, ret, vmcs_read32(EXIT_QUALIFICATION));
-                       advance = 2;
-               } else if (ret == EXIT_REASON_MSR_WRITE) {
-                       printd("msr write\n");
-                       vmx_dump_cpu(vcpu);
-                       vcpu->shutdown =
-                               msrio(vcpu, ret, vmcs_read32(EXIT_QUALIFICATION));
-                       advance = 2;
-               } else if (ret == EXIT_REASON_IO_INSTRUCTION) {
-                       vcpu->shutdown = SHUTDOWN_UNHANDLED_EXIT_REASON;
-               } else if (ret == EXIT_REASON_APIC_WRITE) {
-                       printk("BEGIN APIC WRITE EXIT DUMP\n");
-                       vmx_dump_cpu(vcpu);
-                       printk("END APIC WRITE EXIT DUMP\n");
-               //} else if (ret == EXIT_REASON_APIC_ACCESS) {
-                       //vmx_dump_cpu(vcpu);
-               } else {
-                       printk("unhandled exit: reason 0x%x, exit qualification 0x%x\n",
-                              ret, vmcs_read32(EXIT_QUALIFICATION));
-                       if (ret & 0x80000000) {
-                               printk("entry failed.\n");
-                               vmx_dump_cpu(vcpu);
-                       }
-                       vcpu->shutdown = SHUTDOWN_UNHANDLED_EXIT_REASON;
-               }
-
-               interrupting = 0;
-               /* TODO: we can't just return and relaunch the VMCS, in case we blocked.
-                * similar to how proc_restartcore/smp_idle only restart the pcpui
-                * cur_ctx, we need to do the same, via the VMCS resume business. */
-               if (vcpu->shutdown)
-                       break;
-
-               if (advance) {
-                       vmx_get_cpu(vcpu);
-                       vmcs_writel(GUEST_RIP, vcpu->regs.tf_rip + advance);
-                       vmx_put_cpu(vcpu);
-               }
-       }
-
-       printd("RETURN. ip %016lx sp %016lx, shutdown 0x%lx ret 0x%lx\n",
-              vcpu->regs.tf_rip, vcpu->regs.tf_rsp, vcpu->shutdown, vcpu->shutdown);
-       v->regs = vcpu->regs;
-       v->shutdown = vcpu->shutdown;
-       v->ret_code = ret;
-//  hexdump((void *)vcpu->regs.tf_rsp, 128 * 8);
-       /*
-        * Return both the reason for the shutdown and a status value.
-        * The exit() and exit_group() system calls only need 8 bits for
-        * the status but we allow 16 bits in case we might want to
-        * return more information for one of the other shutdown reasons.
-        */
-       ret = (vcpu->shutdown << 16) | (vcpu->ret_code & 0xffff);
-
-       return ret;
-}
-
-/**
  * __vmx_enable - low-level enable of VMX mode on the current CPU
  * @vmxon_buf: an opaque buffer for use as the VMXON region
  */
index d5fc6f8..36c2750 100644 (file)
@@ -84,17 +84,6 @@ int vm_post_interrupt(struct vmctl *v)
        return -1;
 }
 
-int vm_run(struct vmctl *v)
-{
-       int vmx_launch(struct vmctl *v);
-       if (current->vmm.amd) {
-               return -1;
-       } else {
-               return vmx_launch(v);
-       }
-       return -1;
-}
-
 /* Initializes a process to run virtual machine contexts, returning the number
  * initialized, optionally setting errno */
 int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores,
index be9584c..48e3df9 100644 (file)
@@ -52,7 +52,6 @@ int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores,
 void __vmm_struct_cleanup(struct proc *p);
 
 int vm_post_interrupt(struct vmctl *v);
-int vm_run(struct vmctl *);
 int intel_vmx_start(int id);
 int intel_vmx_setup(int nvmcs);
 
index e1782f2..99bf93b 100644 (file)
@@ -91,7 +91,6 @@ static int writetime(char *, int);
 static int writebintime(char *, int);
 
 enum {
-       CMV,
        CMbroken,
        CMconsole,
        CMhalt,
@@ -102,7 +101,6 @@ enum {
 
 
 struct cmdtab rebootmsg[] = {
-       {CMV, "V", 4},
        {CMbroken, "broken", 0},
        {CMconsole, "console", 1},
        {CMhalt, "halt", 1},
@@ -1113,12 +1111,8 @@ static long conswrite(struct chan *c, void *va, long n, int64_t off)
                                ret = vm_post_interrupt(&vmctl);
                                n = ret;
                                //printk("vm_interrupt_notify returns %d\n", ret);
-                       }
-                       else {
-                               ret = vm_run(&vmctl);
-                               printd("vm_run returns %d\n", ret);
-                               n = ret;
-                               memmove(a, &vmctl, sizeof(vmctl));
+                       } else {
+                               error(EINVAL, "Bad vmctl command");
                        }
                        break;
                case Qsysctl:
@@ -1147,26 +1141,6 @@ static long conswrite(struct chan *c, void *va, long n, int64_t off)
                                case CMnobroken:
                                        keepbroken = 0;
                                        break;
-                               case CMV:
-                                       /* it's ok to throw away this struct each time;
-                                        * this is stateless and going away soon anyway.
-                                        * we only kept it here until we can rewrite all the
-                                        * tests
-                                        */
-                                       rip =  strtoul(cb->f[1], NULL, 0);
-                                       rsp =  strtoul(cb->f[2], NULL, 0);
-                                       cr3 =  strtoul(cb->f[3], NULL, 0);
-                                       if (cr3) {
-                                               vmctl.command = REG_RSP_RIP_CR3;
-                                               vmctl.cr3 = cr3;
-                                               vmctl.regs.tf_rip = rip;
-                                               vmctl.regs.tf_rsp = rsp;
-                                       } else {
-                                               vmctl.command = RESUME;
-                                       }
-                                       ret = vm_run(&vmctl);
-                                       printd("vm_run returns %d\n", ret);
-                                       n = ret;
                                case CMreboot:
                                        reboot();
                                        break;
index 15d84ef..77b1165 100644 (file)
@@ -39,7 +39,6 @@ struct per_cpu_info {
        int coreid;                                     /* must be second */
        struct vmcs *vmxarea;
        int vmx_enabled;
-       void *local_vcpu;
        int guest_pcoreid;
 #endif
        spinlock_t lock;