]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
x86: Fix error roll-back in vcpu_vendor_cell_init
authorJan Kiszka <jan.kiszka@siemens.com>
Sun, 28 Jun 2015 17:42:47 +0000 (19:42 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Sun, 28 Jun 2015 18:03:03 +0000 (20:03 +0200)
Properly release previous allocations when one of the init steps failed.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/svm.c
hypervisor/arch/x86/vmx.c

index 8c50481b01aec7ce1f74f098057547b068129e11..b8244725fb365a669ee8d356ecd2a0cf2c944833 100644 (file)
@@ -288,19 +288,19 @@ int vcpu_vendor_init(void)
 
 int vcpu_vendor_cell_init(struct cell *cell)
 {
+       int err = -ENOMEM;
        u64 flags;
-       int err;
 
        /* allocate iopm (two 4-K pages + 3 bits) */
        cell->svm.iopm = page_alloc(&mem_pool, 3);
        if (!cell->svm.iopm)
-               return -ENOMEM;
+               return err;
 
        /* build root NPT of cell */
        cell->svm.npt_structs.root_paging = npt_paging;
        cell->svm.npt_structs.root_table = page_alloc(&mem_pool, 1);
        if (!cell->svm.npt_structs.root_table)
-               return -ENOMEM;
+               goto err_free_iopm;
 
        if (!has_avic) {
                /*
@@ -319,6 +319,15 @@ int vcpu_vendor_cell_init(struct cell *cell)
                                    flags,
                                    PAGING_NON_COHERENT);
        }
+       if (err)
+               goto err_free_root_table;
+
+       return 0;
+
+err_free_root_table:
+       page_free(&mem_pool, cell->svm.npt_structs.root_table, 1);
+err_free_iopm:
+       page_free(&mem_pool, cell->svm.iopm, 3);
 
        return err;
 }
index e4797c8101b35c4c61f8b08c941ca330d14a1546..575cc7004472cd8a3c2c5e35bdcafd409af8d582 100644 (file)
@@ -326,22 +326,35 @@ unsigned long arch_paging_gphys2phys(struct per_cpu *cpu_data,
 
 int vcpu_vendor_cell_init(struct cell *cell)
 {
+       int err = -ENOMEM;
+
        /* allocate io_bitmap */
        cell->vmx.io_bitmap = page_alloc(&mem_pool, 2);
        if (!cell->vmx.io_bitmap)
-               return -ENOMEM;
+               return err;
 
        /* build root EPT of cell */
        cell->vmx.ept_structs.root_paging = ept_paging;
        cell->vmx.ept_structs.root_table = page_alloc(&mem_pool, 1);
        if (!cell->vmx.ept_structs.root_table)
-               return -ENOMEM;
+               goto err_free_io_bitmap;
+
+       err = paging_create(&cell->vmx.ept_structs,
+                           paging_hvirt2phys(apic_access_page),
+                           PAGE_SIZE, XAPIC_BASE,
+                           EPT_FLAG_READ | EPT_FLAG_WRITE | EPT_FLAG_WB_TYPE,
+                           PAGING_NON_COHERENT);
+       if (err)
+               goto err_free_root_table;
+
+       return 0;
+
+err_free_root_table:
+       page_free(&mem_pool, cell->vmx.ept_structs.root_table, 1);
+err_free_io_bitmap:
+       page_free(&mem_pool, cell->vmx.io_bitmap, 2);
 
-       return paging_create(&cell->vmx.ept_structs,
-                            paging_hvirt2phys(apic_access_page),
-                            PAGE_SIZE, XAPIC_BASE,
-                            EPT_FLAG_READ|EPT_FLAG_WRITE|EPT_FLAG_WB_TYPE,
-                            PAGING_NON_COHERENT);
+       return err;
 }
 
 int vcpu_map_memory_region(struct cell *cell,