Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Clear guest memory to 0 at init time.
[palacios.git] / palacios / src / palacios / vmm_mem.c
index 64c83c7..dd262c0 100644 (file)
@@ -41,7 +41,8 @@ static int mem_offset_hypercall(struct guest_info * info, uint_t hcall_id, void
 static int unhandled_err(struct guest_info * core, addr_t guest_va, addr_t guest_pa, 
                         struct v3_mem_region * reg, pf_error_t access_info) {
 
-    PrintError("Unhandled memory access error\n");
+    PrintError("Unhandled memory access error (gpa=%p, gva=%p, error_code=%d)\n",
+              (void *)guest_pa, (void *)guest_va, *(uint32_t *)&access_info);
 
     v3_print_mem_map(core->vm_info);
 
@@ -65,12 +66,16 @@ int v3_init_mem_map(struct v3_vm_info * vm) {
     map->base_region.guest_start = 0;
     map->base_region.guest_end = mem_pages * PAGE_SIZE_4KB;
 
-#ifdef CONFIG_ALIGNED_PG_ALLOC
+#ifdef V3_CONFIG_ALIGNED_PG_ALLOC
     map->base_region.host_addr = (addr_t)V3_AllocAlignedPages(mem_pages, vm->mem_align);
 #else
     map->base_region.host_addr = (addr_t)V3_AllocPages(mem_pages);
 #endif
 
+    // Clear the memory...
+    memset(V3_VAddr((void *)map->base_region.host_addr), 0, mem_pages * PAGE_SIZE_4KB);
+
+
     map->base_region.flags.read = 1;
     map->base_region.flags.write = 1;
     map->base_region.flags.exec = 1;
@@ -301,6 +306,10 @@ static struct v3_mem_region * get_next_mem_region( struct v3_vm_info * vm, uint1
     struct v3_mem_region * reg = NULL;
     struct v3_mem_region * parent = NULL;
 
+    if (n == NULL) {
+       return NULL;
+    }
+
     while (n) {
 
        reg = rb_entry(n, struct v3_mem_region, tree_node);
@@ -414,13 +423,13 @@ void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) {
 
     v3_rb_erase(&(reg->tree_node), &(vm->mem_map.mem_regions));
 
-    V3_Free(reg);
 
 
     // If the guest isn't running then there shouldn't be anything to invalidate. 
     // Page tables should __always__ be created on demand during execution
     // NOTE: This is a sanity check, and can be removed if that assumption changes
     if (vm->run_state != VM_RUNNING) {
+       V3_Free(reg);
        return;
     }
 
@@ -457,6 +466,8 @@ void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) {
        }
     }
 
+    V3_Free(reg);
+
     // flush virtual page tables 
     // 3 cases shadow, shadow passthrough, and nested
 
@@ -475,7 +486,7 @@ uint32_t v3_get_max_page_size(struct guest_info * core, addr_t page_addr, v3_cpu
                pg_start = PAGE_ADDR_4MB(page_addr);
                pg_end = (pg_start + PAGE_SIZE_4MB);
 
-               reg = get_overlapping_region(core->vm_info, core->cpu_id, pg_start, pg_end); 
+               reg = get_overlapping_region(core->vm_info, core->vcpu_id, pg_start, pg_end); 
 
                if ((reg) && ((reg->host_addr % PAGE_SIZE_4MB) == 0)) {
                    page_size = PAGE_SIZE_4MB;
@@ -487,7 +498,7 @@ uint32_t v3_get_max_page_size(struct guest_info * core, addr_t page_addr, v3_cpu
                pg_start = PAGE_ADDR_2MB(page_addr);
                pg_end = (pg_start + PAGE_SIZE_2MB);
 
-               reg = get_overlapping_region(core->vm_info, core->cpu_id, pg_start, pg_end);
+               reg = get_overlapping_region(core->vm_info, core->vcpu_id, pg_start, pg_end);
 
                if ((reg) && ((reg->host_addr % PAGE_SIZE_2MB) == 0)) {
                    page_size = PAGE_SIZE_2MB;
@@ -501,7 +512,7 @@ uint32_t v3_get_max_page_size(struct guest_info * core, addr_t page_addr, v3_cpu
                pg_start = PAGE_ADDR_1GB(page_addr);
                pg_end = (pg_start + PAGE_SIZE_1GB);
                
-               reg = get_overlapping_region(core->vm_info, core->cpu_id, pg_start, pg_end);
+               reg = get_overlapping_region(core->vm_info, core->vcpu_id, pg_start, pg_end);
                
                if ((reg) && ((reg->host_addr % PAGE_SIZE_1GB) == 0)) {
                    page_size = PAGE_SIZE_1GB;
@@ -513,7 +524,7 @@ uint32_t v3_get_max_page_size(struct guest_info * core, addr_t page_addr, v3_cpu
                pg_start = PAGE_ADDR_2MB(page_addr);
                pg_end = (pg_start + PAGE_SIZE_2MB);
 
-               reg = get_overlapping_region(core->vm_info, core->cpu_id, pg_start, pg_end);
+               reg = get_overlapping_region(core->vm_info, core->vcpu_id, pg_start, pg_end);
                
                if ((reg) && ((reg->host_addr % PAGE_SIZE_2MB) == 0)) {
                    page_size = PAGE_SIZE_2MB;