VMM: Free VMCSs when appropriate
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 Aug 2016 17:16:03 +0000 (10:16 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 Aug 2016 17:35:11 +0000 (10:35 -0700)
Previously we weren't freeing them at all.  Additionally, if we failed
part of the way through a create_guest_pcore, we'd leak the VMCS we
allocated.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/vmm/intel/vmx.c

index 485bb27..2608e82 100644 (file)
@@ -720,7 +720,7 @@ vmx_alloc_vmcs(void)
 static void
 vmx_free_vmcs(struct vmcs *vmcs)
 {
-       //free_pages((unsigned long)vmcs, vmcs_config.order);
+       free_cont_pages(vmcs, vmcs_config.order);
 }
 
 /*
@@ -1124,7 +1124,7 @@ static void vmx_setup_vmcs(struct guest_pcore *gpc)
 struct guest_pcore *create_guest_pcore(struct proc *p,
                                        struct vmm_gpcore_init *gpci)
 {
-       ERRSTACK(1);
+       ERRSTACK(2);
        struct guest_pcore *gpc = kmalloc(sizeof(struct guest_pcore), MEM_WAIT);
 
        if (!gpc)
@@ -1140,8 +1140,11 @@ struct guest_pcore *create_guest_pcore(struct proc *p,
        /* Warning: p here is uncounted (weak) reference */
        gpc->proc = p;
        gpc->vmcs = vmx_alloc_vmcs();
+       if (waserror()) {
+               vmx_free_vmcs(gpc->vmcs);
+               nexterror();
+       }
        printd("%d: gpc->vmcs is %p\n", core_id(), gpc->vmcs);
-
        gpc->cpu = -1;
 
        vmx_load_guest_pcore(gpc);
@@ -1152,6 +1155,7 @@ struct guest_pcore *create_guest_pcore(struct proc *p,
 
        gpc->posted_irq_desc = gpci->posted_irq_desc;
        poperror();
+       poperror();
        return gpc;
 }