X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_mem.c;h=29579e5ae4bc662f8fdee9f801ebdea57903d0fe;hb=03b23f614f0a00d3e23d5579f9abb87684af9ec8;hp=390de616db8317747748076d328930281ca948b4;hpb=b7093fd3602ef2c796a1f8a0daded9d6aad0b756;p=palacios.releases.git diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 390de61..29579e5 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -31,7 +31,7 @@ static int mem_offset_hypercall(struct guest_info * info, uint_t hcall_id, void * private_data) { - PrintDebug("V3Vee: Memory offset hypercall (offset=%p)\n", + PrintDebug(info->vm_info, info,"V3Vee: Memory offset hypercall (offset=%p)\n", (void *)(info->vm_info->mem_map.base_region.host_addr)); info->vm_regs.rbx = info->vm_info->mem_map.base_region.host_addr; @@ -42,7 +42,7 @@ 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 (gpa=%p, gva=%p, error_code=%d)\n", + PrintError(core->vm_info, core, "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); @@ -61,7 +61,7 @@ int v3_init_mem_map(struct v3_vm_info * vm) { map->mem_regions.rb_node = NULL; // There is an underlying region that contains all of the guest memory - // PrintDebug("Mapping %d pages of memory (%u bytes)\n", (int)mem_pages, (uint_t)info->mem_size); + // PrintDebug(info->vm_info, info, "Mapping %d pages of memory (%u bytes)\n", (int)mem_pages, (uint_t)info->mem_size); // 2MB page alignment needed for 2MB hardware nested paging map->base_region.guest_start = 0; @@ -74,7 +74,7 @@ int v3_init_mem_map(struct v3_vm_info * vm) { #endif if ((void*)map->base_region.host_addr == NULL) { - PrintError("Could not allocate guest memory\n"); + PrintError(vm, VCORE_NONE,"Could not allocate guest memory\n"); return -1; } @@ -119,14 +119,14 @@ struct v3_mem_region * v3_create_mem_region(struct v3_vm_info * vm, uint16_t cor struct v3_mem_region * entry = NULL; if (guest_addr_start >= guest_addr_end) { - PrintError("Region start is after region end\n"); + PrintError(vm, VCORE_NONE, "Region start is after region end\n"); return NULL; } entry = (struct v3_mem_region *)V3_Malloc(sizeof(struct v3_mem_region)); if (!entry) { - PrintError("Cannot allocate in creating a memory region\n"); + PrintError(vm, VCORE_NONE, "Cannot allocate in creating a memory region\n"); return NULL; } @@ -189,9 +189,10 @@ struct v3_mem_region * __insert_mem_region(struct v3_vm_info * vm, } else { if ((region->guest_end != tmp_region->guest_end) || (region->guest_start != tmp_region->guest_start)) { - PrintError("Trying to map a partial overlapped core specific page...\n"); + PrintError(vm, VCORE_NONE, "Trying to map a partial overlapped core specific page...\n"); return tmp_region; // This is ugly... } else if (region->core_id == tmp_region->core_id) { + PrintError(vm, VCORE_NONE, "Trying to map a core-overlapping page\n"); return tmp_region; } else if (region->core_id < tmp_region->core_id) { p = &(*p)->rb_left; @@ -211,14 +212,17 @@ struct v3_mem_region * __insert_mem_region(struct v3_vm_info * vm, int v3_insert_mem_region(struct v3_vm_info * vm, struct v3_mem_region * region) { struct v3_mem_region * ret; int i = 0; + int rc; if ((ret = __insert_mem_region(vm, region))) { + PrintError(vm, VCORE_NONE, "Internal insert failed returned region is from 0x%p to 0x%p on vcore %d\n", (void*)(ret->guest_start), (void*)(ret->guest_end), ret->core_id); return -1; } v3_rb_insert_color(&(region->tree_node), &(vm->mem_map.mem_regions)); + rc = 0; for (i = 0; i < vm->num_cores; i++) { struct guest_info * info = &(vm->cores[i]); @@ -230,30 +234,17 @@ int v3_insert_mem_region(struct v3_vm_info * vm, struct v3_mem_region * region) v3_mem_mode_t mem_mode = v3_get_vm_mem_mode(info); if (mem_mode == PHYSICAL_MEM) { - addr_t cur_addr; - - for (cur_addr = region->guest_start; - cur_addr < region->guest_end; - cur_addr += PAGE_SIZE_4KB) { - v3_invalidate_passthrough_addr(info, cur_addr); - } + rc |= v3_invalidate_passthrough_addr_range(info, region->guest_start, region->guest_end-1); } else { - v3_invalidate_shadow_pts(info); + rc |= v3_invalidate_shadow_pts(info); } } else if (info->shdw_pg_mode == NESTED_PAGING) { - addr_t cur_addr; - - for (cur_addr = region->guest_start; - cur_addr < region->guest_end; - cur_addr += PAGE_SIZE_4KB) { - - v3_invalidate_nested_addr(info, cur_addr); - } + rc |= v3_invalidate_nested_addr_range(info, region->guest_start, region->guest_end-1); } } - return 0; + return rc; } @@ -285,7 +276,7 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i // go right, core too small n = n->rb_right; } else { - PrintDebug("v3_get_mem_region: Impossible!\n"); + PrintDebug(vm, VCORE_NONE, "v3_get_mem_region: Impossible!\n"); return NULL; } } @@ -295,7 +286,7 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i // There is not registered region, so we check if its a valid address in the base region if (guest_addr > vm->mem_map.base_region.guest_end) { - PrintError("Guest Address Exceeds Base Memory Size (ga=0x%p), (limit=0x%p) (core=0x%x)\n", + PrintError(vm, VCORE_NONE, "Guest Address Exceeds Base Memory Size (ga=0x%p), (limit=0x%p) (core=0x%x)\n", (void *)guest_addr, (void *)vm->mem_map.base_region.guest_end, core_id); v3_print_mem_map(vm); @@ -343,7 +334,7 @@ static struct v3_mem_region * get_next_mem_region( struct v3_vm_info * vm, uint1 // go right, core too small n = n->rb_right; } else { - PrintError("v3_get_mem_region: Impossible!\n"); + PrintError(vm, VCORE_NONE, "v3_get_mem_region: Impossible!\n"); return NULL; } } @@ -389,7 +380,7 @@ static struct v3_mem_region * get_overlapping_region(struct v3_vm_info * vm, uin struct v3_mem_region * start_region = v3_get_mem_region(vm, core_id, start_gpa); if (start_region == NULL) { - PrintError("Invalid memory region\n"); + PrintError(vm, VCORE_NONE, "Invalid memory region\n"); return NULL; } @@ -426,6 +417,7 @@ static struct v3_mem_region * get_overlapping_region(struct v3_vm_info * vm, uin void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) { int i = 0; + int rc; if (reg == NULL) { return; @@ -444,6 +436,8 @@ void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) { return; } + rc = 0; + for (i = 0; i < vm->num_cores; i++) { struct guest_info * info = &(vm->cores[i]); @@ -454,26 +448,13 @@ void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) { v3_mem_mode_t mem_mode = v3_get_vm_mem_mode(info); if (mem_mode == PHYSICAL_MEM) { - addr_t cur_addr; - - for (cur_addr = reg->guest_start; - cur_addr < reg->guest_end; - cur_addr += PAGE_SIZE_4KB) { - v3_invalidate_passthrough_addr(info, cur_addr); - } + rc |= v3_invalidate_passthrough_addr_range(info,reg->guest_start, reg->guest_end-1); } else { - v3_invalidate_shadow_pts(info); + rc |= v3_invalidate_shadow_pts(info); } } else if (info->shdw_pg_mode == NESTED_PAGING) { - addr_t cur_addr; - - for (cur_addr = reg->guest_start; - cur_addr < reg->guest_end; - cur_addr += PAGE_SIZE_4KB) { - - v3_invalidate_nested_addr(info, cur_addr); - } + rc |= v3_invalidate_nested_addr_range(info,reg->guest_start, reg->guest_end-1); } } @@ -482,6 +463,7 @@ void v3_delete_mem_region(struct v3_vm_info * vm, struct v3_mem_region * reg) { // flush virtual page tables // 3 cases shadow, shadow passthrough, and nested + if (rc) { PrintError(vm, VCORE_NONE, "Error in deleting memory region\n"); } } // Determine if a given address can be handled by a large page of the requested size @@ -543,7 +525,7 @@ uint32_t v3_get_max_page_size(struct guest_info * core, addr_t page_addr, v3_cpu } break; default: - PrintError("Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); + PrintError(core->vm_info, core, "Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); return -1; } @@ -557,10 +539,10 @@ void v3_print_mem_map(struct v3_vm_info * vm) { struct v3_mem_region * reg = &(vm->mem_map.base_region); int i = 0; - V3_Print("Memory Layout (all cores):\n"); + V3_Print(vm, VCORE_NONE, "Memory Layout (all cores):\n"); - V3_Print("Base Region (all cores): 0x%p - 0x%p -> 0x%p\n", + V3_Print(vm, VCORE_NONE, "Base Region (all cores): 0x%p - 0x%p -> 0x%p\n", (void *)(reg->guest_start), (void *)(reg->guest_end - 1), (void *)(reg->host_addr)); @@ -574,12 +556,12 @@ void v3_print_mem_map(struct v3_vm_info * vm) { do { reg = rb_entry(node, struct v3_mem_region, tree_node); - V3_Print("%d: 0x%p - 0x%p -> 0x%p\n", i, + V3_Print(vm, VCORE_NONE, "%d: 0x%p - 0x%p -> 0x%p\n", i, (void *)(reg->guest_start), (void *)(reg->guest_end - 1), (void *)(reg->host_addr)); - V3_Print("\t(flags=0x%x) (core=0x%x) (unhandled = 0x%p)\n", + V3_Print(vm, VCORE_NONE, "\t(flags=0x%x) (core=0x%x) (unhandled = 0x%p)\n", reg->flags.value, reg->core_id, reg->unhandled);