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.


Cleanup and sanity-checking of before/after null-check and copy+paste errors (Coverit...
[palacios.git] / palacios / src / palacios / vmm_config.c
index de646bf..e4c9b4f 100644 (file)
 #include <palacios/vmm_sprintf.h>
 
 
+#ifdef V3_CONFIG_SWAPPING
+#include <palacios/vmm_swapping.h>
+#endif
 
+#ifdef V3_CONFIG_MULTIBOOT
+#include <palacios/vmm_multiboot.h>
+#endif
 
+#ifdef V3_CONFIG_HVM
+#include <palacios/vmm_hvm.h>
+#endif
 
 #include <palacios/vmm_host_events.h>
 #include <palacios/vmm_perftune.h>
@@ -52,9 +61,6 @@
 #define COOKIE_V0 "v3vee\0\0\0"
 #define COOKIE_V1 "v3vee\0\0\1"
 
-
-
-
 // This is used to access the configuration file index table
 struct file_hdr_v0 {
     uint32_t index;
@@ -223,6 +229,7 @@ static struct v3_config * parse_config(void * cfg_blob) {
        V3_Print(VM_NONE, VCORE_NONE, "File index=%d id=%s\n", idx, id);
 
        strncpy(file->tag, id, V3_MAX_TAG_LEN);
+       file->tag[V3_MAX_TAG_LEN-1] = 0 ;
 
        if (version==0) { 
            struct file_hdr_v0 * hdr = &(files_v0->hdrs[idx]);
@@ -287,6 +294,7 @@ static inline uint32_t get_alignment(char * align_str) {
     if (alignment != PAGE_SIZE_4KB) {
        PrintError(VM_NONE, VCORE_NONE, "Aligned page allocations are not supported in this host (requested alignment=%d)\n", alignment);
        PrintError(VM_NONE, VCORE_NONE, "Ignoring alignment request\n");
+       alignment = PAGE_SIZE_4KB;
     }
 #endif 
 
@@ -294,13 +302,14 @@ static inline uint32_t get_alignment(char * align_str) {
 }
 
 
+
 static int pre_config_vm(struct v3_vm_info * vm, v3_cfg_tree_t * vm_cfg) {
     char * memory_str = v3_cfg_val(vm_cfg, "memory");
     char * schedule_hz_str = v3_cfg_val(vm_cfg, "schedule_hz");
     char * vm_class = v3_cfg_val(vm_cfg, "class");
     char * align_str = v3_cfg_val(v3_cfg_subtree(vm_cfg, "memory"), "alignment");
     uint32_t sched_hz = 100;   // set the schedule frequency to 100 HZ
-
+   
 
     if (!memory_str) {
        PrintError(VM_NONE, VCORE_NONE, "Memory is a required configuration parameter\n");
@@ -318,7 +327,23 @@ static int pre_config_vm(struct v3_vm_info * vm, v3_cfg_tree_t * vm_cfg) {
     vm->mem_size = (addr_t)atoi(memory_str) * 1024 * 1024;
     vm->mem_align = get_alignment(align_str);
 
-
+    // set up defaults for memory management for threads associated 
+    // with this VM
+    vm->resource_control.pg_alignment=vm->mem_align;
+    vm->resource_control.pg_node_id=-1;
+    
+#ifdef V3_CONFIG_SWAPPING
+    if (v3_init_swapping_vm(vm,vm_cfg)) {
+       PrintError(vm,VCORE_NONE,"Unable to initialize swapping correctly\n");
+       return -1;
+    }
+    if (vm->swap_state.enable_swapping) { 
+       PrintDebug(vm,VCORE_NONE,"Swapping enabled\n");
+    } else {
+       PrintDebug(vm,VCORE_NONE,"Swapping disabled\n");
+    }
+#endif
+        
     PrintDebug(VM_NONE, VCORE_NONE, "Alignment for %lu bytes of memory computed as 0x%x\n", vm->mem_size, vm->mem_align);
 
     if (strcasecmp(vm_class, "PC") == 0) {
@@ -346,7 +371,18 @@ static int pre_config_vm(struct v3_vm_info * vm, v3_cfg_tree_t * vm_cfg) {
        return -1;
     }
 
-
+#ifdef V3_CONFIG_MULTIBOOT
+    if (v3_init_multiboot_vm(vm,vm_cfg)) { 
+       PrintError(vm,VCORE_NONE,"Cannot initialize Multiboot for VM\n");
+       return -1;
+    }
+#endif
+#ifdef V3_CONFIG_HVM
+    if (v3_init_hvm_vm(vm,vm_cfg)) { 
+       PrintError(vm,VCORE_NONE,"Cannot initialize HVM for VM\n");
+       return -1;
+    }
+#endif
 
    if (schedule_hz_str) {
        sched_hz = atoi(schedule_hz_str);
@@ -415,6 +451,19 @@ static int pre_config_core(struct guest_info * info, v3_cfg_tree_t * core_cfg) {
        return -1;
     }
 
+#ifdef V3_CONFIG_MULTIBOOT
+    if (v3_init_multiboot_core(info)) { 
+       PrintError(info->vm_info, info, "Error Initializing Multiboot Core\n");
+       return -1;
+    }
+#endif
+#ifdef V3_CONFIG_HVM
+    if (v3_init_hvm_core(info)) { 
+       PrintError(info->vm_info, info, "Error Initializing HVM Core\n");
+       return -1;
+    }
+#endif
+
     if (info->vm_info->vm_class == V3_PC_VM) {
        if (pre_config_pc_core(info, core_cfg) == -1) {
            PrintError(info->vm_info, info, "PC Post configuration failure\n");
@@ -543,6 +592,10 @@ static struct v3_vm_info * allocate_guest(int num_cores) {
     return vm;
 }
 
+/*
+   
+
+*/
 
 
 struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
@@ -554,6 +607,7 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
     v3_cfg_tree_t * cores_cfg = NULL;
     v3_cfg_tree_t * per_core_cfg = NULL;
 
+
     if (v3_mach_type == V3_INVALID_CPU) {
        PrintError(VM_NONE, VCORE_NONE, "Configuring guest on invalid CPU\n");
        return NULL;
@@ -561,11 +615,13 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
 
     cfg_data = parse_config(cfg_blob);
 
+
     if (!cfg_data) {
        PrintError(VM_NONE, VCORE_NONE, "Could not parse configuration\n");
        return NULL;
     }
 
+
     cores_cfg = v3_cfg_subtree(cfg_data->cfg, "cores");
 
     if (!cores_cfg) {
@@ -584,10 +640,20 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
     vm = allocate_guest(num_cores);    
 
     if (!vm) {
-       PrintError(VM_NONE, VCORE_NONE, "Could not allocate %d core guest\n", vm->num_cores);
+       PrintError(VM_NONE, VCORE_NONE, "Could not allocate %d core guest\n", num_cores);
        return NULL;
     }
 
+#ifdef V3_CONFIG_CACHEPART
+    // Need to initialize cache management and resource control
+    // as early as possible so that allocations are done accordingly
+    if (v3_init_cachepart_vm(vm,cfg_data->cfg)) {
+       PrintError(VM_NONE, VCORE_NONE, "Could not initialize cache partioning\n");
+       V3_Free(vm);
+       return NULL;
+    }
+#endif
+
     vm->host_priv_data = priv_data;
 
     vm->cfg_data = cfg_data;
@@ -595,7 +661,9 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
     V3_Print(vm, VCORE_NONE, "Preconfiguration\n");
 
     if (pre_config_vm(vm, vm->cfg_data->cfg) == -1) {
-       PrintError(vm, VCORE_NONE, "Error in preconfiguration\n");
+       PrintError(vm, VCORE_NONE, "Error in preconfiguration, attempting to free\n");
+       vm->run_state=VM_ERROR;
+       v3_free_vm(vm);
        return NULL;
     }
 
@@ -611,7 +679,9 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
        info->core_cfg_data = per_core_cfg;
 
        if (pre_config_core(info, per_core_cfg) == -1) {
-           PrintError(vm, VCORE_NONE, "Error in core %d preconfiguration\n", i);
+           PrintError(vm, VCORE_NONE, "Error in core %d preconfiguration, attempting to free guest\n", i);
+           vm->run_state=VM_ERROR;
+           v3_free_vm(vm);
            return NULL;
        }
 
@@ -623,7 +693,9 @@ struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) {
     V3_Print(vm, VCORE_NONE, "Post Configuration\n");
 
     if (post_config_vm(vm, vm->cfg_data->cfg) == -1) {
-        PrintError(vm, VCORE_NONE, "Error in postconfiguration\n");
+        PrintError(vm, VCORE_NONE, "Error in postconfiguration, attempting to free guest\n");
+       vm->run_state=VM_ERROR;
+       v3_free_vm(vm);
        return NULL;
     }