vmmcp: cut over to virtual apic; fix include mess after upgrade
[akaros.git] / kern / arch / x86 / vmm / vmm.c
index d19593a..142fec9 100644 (file)
@@ -14,8 +14,8 @@
 #include <smp.h>
 #include <kmalloc.h>
 
+#include <ros/vmm.h>
 #include "intel/vmx.h"
-#include "intel/compat.h"
 #include "vmm.h"
 
 /* TODO: have better cpuid info storage and checks */
@@ -57,24 +57,35 @@ void vmm_pcpu_init(void)
        printk("vmm_pcpu_init failed\n");
 }
 
-int vm_run(uint64_t rip, uint64_t rsp, uint64_t cr3)
+int vm_run(struct vmctl *v)
 {
-       struct dune_config d = {rip, rsp, cr3};
-       int vmx_launch(struct dune_config *conf);       
+       int vmx_launch(struct vmctl *v);
        if (current->vmm.amd) {
                return -1;
        } else {
-               return vmx_launch(&d);
+               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)
+int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores, int flags)
 {
        struct vmm *vmm = &p->vmm;
        unsigned int i;
+       if (flags & ~VMM_ALL_FLAGS) {
+               set_errstr("%s: flags is 0x%lx, VMM_ALL_FLAGS is 0x%lx\n", __func__,
+                          flags, VMM_ALL_FLAGS);
+               set_errno(EINVAL);
+               return 0;
+       }
+       vmm->flags = flags;
+
+       if (!x86_supports_vmx) {
+               set_errno(ENODEV);
+               return 0;
+       }
        qlock(&vmm->qlock);
        if (vmm->vmmcp) {
                set_errno(EINVAL);
@@ -83,7 +94,7 @@ int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores)
        }
        /* Set this early, so cleanup checks the gpc array */
        vmm->vmmcp = TRUE;
-       nr_guest_pcores = MIN(nr_guest_pcores, num_cpus);
+       nr_guest_pcores = MIN(nr_guest_pcores, num_cores);
        vmm->amd = 0;
        vmm->guest_pcores = kzmalloc(sizeof(void*) * nr_guest_pcores, KMALLOC_WAIT);
        for (i = 0; i < nr_guest_pcores; i++) {
@@ -112,5 +123,6 @@ void __vmm_struct_cleanup(struct proc *p)
                        vmx_destroy_vcpu(vmm->guest_pcores[i]);
        }
        kfree(vmm->guest_pcores);
+       ept_flush(p->env_pgdir.eptp);
        vmm->vmmcp = FALSE;
 }