vmmcp: cut over to virtual apic; fix include mess after upgrade
[akaros.git] / kern / arch / x86 / vmm / vmm.c
index ca0fba5..142fec9 100644 (file)
@@ -14,6 +14,7 @@
 #include <smp.h>
 #include <kmalloc.h>
 
 #include <smp.h>
 #include <kmalloc.h>
 
+#include <ros/vmm.h>
 #include "intel/vmx.h"
 #include "vmm.h"
 
 #include "intel/vmx.h"
 #include "vmm.h"
 
@@ -56,24 +57,31 @@ void vmm_pcpu_init(void)
        printk("vmm_pcpu_init failed\n");
 }
 
        printk("vmm_pcpu_init failed\n");
 }
 
-int vm_run(uint64_t rip, uint64_t rsp, uint64_t cr3)
+int vm_run(struct vmctl *v)
 {
 {
-       int vmx_launch(uint64_t rip, uint64_t rsp, uint64_t cr3);
+       int vmx_launch(struct vmctl *v);
        if (current->vmm.amd) {
                return -1;
        } else {
        if (current->vmm.amd) {
                return -1;
        } else {
-               return vmx_launch(rip, rsp, cr3);
+               return vmx_launch(v);
        }
        return -1;
 }
 
 /* Initializes a process to run virtual machine contexts, returning the number
  * initialized, optionally setting errno */
        }
        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;
 {
        struct vmm *vmm = &p->vmm;
        unsigned int i;
-       epte_t *ept_pml4;
+       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;
        if (!x86_supports_vmx) {
                set_errno(ENODEV);
                return 0;
@@ -86,14 +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;
        }
        /* Set this early, so cleanup checks the gpc array */
        vmm->vmmcp = TRUE;
-       ept_pml4 = kpage_zalloc_addr();
-       if (!ept_pml4) {
-               set_errno(ENOMEM);
-               return 0;
-       }
-       p->env_pgdir.epte = ept_pml4;
-       p->env_pgdir.eptp = construct_eptp(PADDR(ept_pml4));
-       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++) {
        vmm->amd = 0;
        vmm->guest_pcores = kzmalloc(sizeof(void*) * nr_guest_pcores, KMALLOC_WAIT);
        for (i = 0; i < nr_guest_pcores; i++) {
@@ -123,6 +124,5 @@ void __vmm_struct_cleanup(struct proc *p)
        }
        kfree(vmm->guest_pcores);
        ept_flush(p->env_pgdir.eptp);
        }
        kfree(vmm->guest_pcores);
        ept_flush(p->env_pgdir.eptp);
-       page_decref(kva2page(p->env_pgdir.epte));
        vmm->vmmcp = FALSE;
 }
        vmm->vmmcp = FALSE;
 }