X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_mem.c;h=182e5634a7abd4f9db93819b0762753c3d1364e6;hb=78818a71a31b4cbe264c1292f7bcbdbfd2ceb544;hp=92b6c63e49071a0f7fb4a1fd024363fabb85e306;hpb=c163873b7b96544683030cafba0e73a7ed988171;p=palacios.git diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 92b6c63..182e563 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -22,6 +22,9 @@ #include #include +#include +#include + #define MEM_OFFSET_HCALL 0x1000 @@ -46,11 +49,15 @@ void v3_init_shadow_map(struct guest_info * info) { map->hook_hva = (addr_t)V3_VAddr(V3_AllocPages(1)); // 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); + map->base_region.guest_start = 0; - map->base_region.guest_end = info->mem_size; + map->base_region.guest_end = mem_pages * PAGE_SIZE_4KB; map->base_region.host_type = SHDW_REGION_ALLOCATED; map->base_region.host_addr = (addr_t)V3_AllocPages(mem_pages); + //memset(V3_VAddr((void *)map->base_region.host_addr), 0xffffffff, map->base_region.guest_end); + v3_register_hypercall(info, MEM_OFFSET_HCALL, mem_offset_hypercall, NULL); } @@ -147,6 +154,22 @@ int v3_hook_full_mem(struct guest_info * info, addr_t guest_addr_start, addr_t g } +// This will unhook the memory hook registered at start address +// We do not support unhooking subregions +int v3_unhook_mem(struct guest_info * info, addr_t guest_addr_start) { + struct v3_shadow_region * reg = v3_get_shadow_region(info, guest_addr_start); + + if ((reg->host_type != SHDW_REGION_FULL_HOOK) || + (reg->host_type != SHDW_REGION_WRITE_HOOK)) { + PrintError("Trying to unhook a non hooked memory region (addr=%p)\n", (void *)guest_addr_start); + return -1; + } + + v3_delete_shadow_region(info, reg); + + return 0; +} + static inline @@ -187,8 +210,34 @@ struct v3_shadow_region * insert_shadow_region(struct guest_info * info, v3_rb_insert_color(&(region->tree_node), &(info->mem_map.shdw_regions)); + // flush virtual page tables // 3 cases shadow, shadow passthrough, and nested + if (info->shdw_pg_mode == SHADOW_PAGING) { + 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); + } + } else { + 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); + } + } return NULL; } @@ -286,12 +335,43 @@ struct v3_shadow_region * v3_get_shadow_region(struct guest_info * info, addr_t void v3_delete_shadow_region(struct guest_info * info, struct v3_shadow_region * reg) { - if (reg != NULL) { - v3_rb_erase(&(reg->tree_node), &(info->mem_map.shdw_regions)); + if (reg == NULL) { + return; + } - V3_Free(reg); + // flush virtual page tables + // 3 cases shadow, shadow passthrough, and nested + if (info->shdw_pg_mode == SHADOW_PAGING) { + 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); + } + } else { + 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); + } } + + v3_rb_erase(&(reg->tree_node), &(info->mem_map.shdw_regions)); + + V3_Free(reg); + // flush virtual page tables // 3 cases shadow, shadow passthrough, and nested @@ -305,7 +385,7 @@ addr_t v3_get_shadow_addr(struct v3_shadow_region * reg, addr_t guest_addr) { (reg->host_type != SHDW_REGION_FULL_HOOK)) { return (guest_addr - reg->guest_start) + reg->host_addr; } else { - PrintDebug("MEM Region Invalid\n"); + PrintError("MEM Region Invalid\n"); return 0; }