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.


integrated new configuration system
[palacios.git] / palacios / src / palacios / vmm_mem.c
index dc3f1ae..4248845 100644 (file)
 #include <palacios/vmm.h>
 #include <palacios/vmm_util.h>
 #include <palacios/vmm_emulator.h>
+#include <palacios/vm_guest.h>
 
 #include <palacios/vmm_shadow_paging.h>
 #include <palacios/vmm_direct_paging.h>
 
-
 #define MEM_OFFSET_HCALL 0x1000
 
 
@@ -41,7 +41,7 @@ static int mem_offset_hypercall(struct guest_info * info, uint_t hcall_id, void
 }
 
 
-void v3_init_shadow_map(struct guest_info * info) {
+int v3_init_shadow_map(struct guest_info * info) {
     v3_shdw_map_t * map = &(info->mem_map);
     addr_t mem_pages = info->mem_size >> 12;
 
@@ -49,12 +49,24 @@ 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);
 
+
+    if ((void *)map->base_region.host_addr == NULL) {
+       PrintError("Could not allocate Guest memory\n");
+       return -1;
+    }
+       
+    //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);
+
+    return 0;
 }
 
 void v3_delete_shadow_map(struct guest_info * info) {
@@ -161,7 +173,9 @@ int v3_unhook_mem(struct guest_info * info, addr_t guest_addr_start) {
        return -1;
     }
 
-    return v3_delete_shadow_region(info, reg);
+    v3_delete_shadow_region(info, reg);
+
+    return 0;
 }
 
 
@@ -200,7 +214,7 @@ struct v3_shadow_region * insert_shadow_region(struct guest_info * info,
     if ((ret = __insert_shadow_region(info, region))) {
        return ret;
     }
-  
+
     v3_rb_insert_color(&(region->tree_node), &(info->mem_map.shdw_regions));
 
 
@@ -208,7 +222,7 @@ struct v3_shadow_region * insert_shadow_region(struct guest_info * info,
     // flush virtual page tables 
     // 3 cases shadow, shadow passthrough, and nested
     if (info->shdw_pg_mode == SHADOW_PAGING) {
-       v3_vm_mem_mode_t mem_mode = v3_get_mem_mode(info);
+       v3_mem_mode_t mem_mode = v3_get_vm_mem_mode(info);
 
        if (mem_mode == PHYSICAL_MEM) {
            addr_t cur_addr;
@@ -321,6 +335,8 @@ struct v3_shadow_region * v3_get_shadow_region(struct guest_info * info, addr_t
     if (guest_addr > info->mem_map.base_region.guest_end) {
        PrintError("Guest Address Exceeds Base Memory Size (ga=%p), (limit=%p)\n", 
                   (void *)guest_addr, (void *)info->mem_map.base_region.guest_end);
+       v3_print_mem_map(info);
+
        return NULL;
     }
     
@@ -336,7 +352,7 @@ void v3_delete_shadow_region(struct guest_info * info, struct v3_shadow_region *
     // flush virtual page tables 
     // 3 cases shadow, shadow passthrough, and nested
     if (info->shdw_pg_mode == SHADOW_PAGING) {
-       v3_vm_mem_mode_t mem_mode = v3_get_mem_mode(info);
+       v3_mem_mode_t mem_mode = v3_get_vm_mem_mode(info);
            
        if (mem_mode == PHYSICAL_MEM) {
            addr_t cur_addr;
@@ -379,7 +395,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;
     }
 
@@ -387,28 +403,34 @@ addr_t v3_get_shadow_addr(struct v3_shadow_region * reg, addr_t guest_addr) {
 
 
 
-void print_shadow_map(struct guest_info * info) {
+void v3_print_mem_map(struct guest_info * info) {
     struct rb_node * node = v3_rb_first(&(info->mem_map.shdw_regions));
     struct v3_shadow_region * reg = &(info->mem_map.base_region);
     int i = 0;
 
-    PrintDebug("Memory Layout:\n");
+    V3_Print("Memory Layout:\n");
     
 
-    PrintDebug("Base Region:  0x%p - 0x%p -> 0x%p\n", 
+    V3_Print("Base Region:  0x%p - 0x%p -> 0x%p\n", 
               (void *)(reg->guest_start), 
               (void *)(reg->guest_end - 1), 
               (void *)(reg->host_addr));
     
+
+    // If the memory map is empty, don't print it
+    if (node == NULL) {
+       return;
+    }
+
     do {
        reg = rb_entry(node, struct v3_shadow_region, tree_node);
 
-       PrintDebug("%d:  0x%p - 0x%p -> 0x%p\n", i, 
+       V3_Print("%d:  0x%p - 0x%p -> 0x%p\n", i, 
                   (void *)(reg->guest_start), 
                   (void *)(reg->guest_end - 1), 
                   (void *)(reg->host_addr));
 
-       PrintDebug("\t(%s) (WriteHook = 0x%p) (ReadHook = 0x%p)\n", 
+       V3_Print("\t(%s) (WriteHook = 0x%p) (ReadHook = 0x%p)\n", 
                   v3_shdw_region_type_to_str(reg->host_type),
                   (void *)(reg->write_hook), 
                   (void *)(reg->read_hook));