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.


added vmcs/vmcb freeing
Jack Lange [Thu, 6 Jan 2011 21:28:09 +0000 (15:28 -0600)]
palacios/include/palacios/svm.h
palacios/include/palacios/vm_guest.h
palacios/include/palacios/vmx.h
palacios/src/palacios/svm.c
palacios/src/palacios/vm_guest.c
palacios/src/palacios/vmm.c
palacios/src/palacios/vmx.c

index 1a9ecfd..1e26c55 100644 (file)
@@ -80,7 +80,8 @@
 void v3_init_svm_cpu(int cpu_id);
 int v3_is_svm_capable();
 
-int v3_init_svm_vmcb(struct guest_info * info, v3_vm_class_t vm_class);
+int v3_init_svm_vmcb(struct guest_info * core, v3_vm_class_t vm_class);
+int v3_deinit_svm_vmcb(struct guest_info * core);
 
 int v3_svm_enter(struct guest_info * info);
 int v3_start_svm_guest(struct guest_info *info);
index 9871d3a..638c752 100644 (file)
@@ -189,6 +189,9 @@ struct v3_vm_info {
 int v3_init_vm(struct v3_vm_info * vm);
 int v3_init_core(struct guest_info * core);
 
+int v3_free_vm_internal(struct v3_vm_info * vm);
+int v3_free_core(struct guest_info * core);
+
 
 uint_t v3_get_addr_width(struct guest_info * info);
 v3_cpu_mode_t v3_get_vm_cpu_mode(struct guest_info * info);
index a37ead8..034cbfa 100644 (file)
@@ -244,6 +244,7 @@ int v3_start_vmx_guest(struct guest_info* info);
 int v3_vmx_enter(struct guest_info * info);
 
 int v3_init_vmx_vmcs(struct guest_info * info, v3_vm_class_t vm_class);
+int v3_deinit_vmx_vmcs(struct guest_info * core);
 
 #endif // ! __V3VEE__
 
index f20d78c..f59bdc7 100644 (file)
@@ -288,19 +288,19 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info * core) {
 }
 
 
-int v3_init_svm_vmcb(struct guest_info * info, v3_vm_class_t vm_class) {
+int v3_init_svm_vmcb(struct guest_info * core, v3_vm_class_t vm_class) {
 
     PrintDebug("Allocating VMCB\n");
-    info->vmm_data = (void*)Allocate_VMCB();
+    core->vmm_data = (void*)Allocate_VMCB();
     
-    if (info->vmm_data == NULL) {
+    if (core->vmm_data == NULL) {
        PrintError("Could not allocate VMCB, Exiting...\n");
        return -1;
     }
 
     if (vm_class == V3_PC_VM) {
-       PrintDebug("Initializing VMCB (addr=%p)\n", (void *)info->vmm_data);
-       Init_VMCB_BIOS((vmcb_t*)(info->vmm_data), info);
+       PrintDebug("Initializing VMCB (addr=%p)\n", (void *)core->vmm_data);
+       Init_VMCB_BIOS((vmcb_t*)(core->vmm_data), core);
     } else {
        PrintError("Invalid VM class\n");
        return -1;
@@ -310,6 +310,11 @@ int v3_init_svm_vmcb(struct guest_info * info, v3_vm_class_t vm_class) {
 }
 
 
+int v3_deinit_svm_vmcb(struct guest_info * core) {
+    V3_FreePages(core->vmm_data, 1);
+    return 0;
+}
+
 
 static int update_irq_exit_state(struct guest_info * info) {
     vmcb_ctrl_t * guest_ctrl = GET_VMCB_CTRL_AREA((vmcb_t*)(info->vmm_data));
index e9ff5f7..95b109f 100644 (file)
@@ -383,7 +383,7 @@ void v3_print_GPRs(struct guest_info * info) {
     v3_reg_t * reg_ptr;
     char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
 
-    reg_ptr= (v3_reg_t *)regs;
+    reg_ptr = (v3_reg_t *)regs;
 
     V3_Print("32 bit GPRs:\n");
 
@@ -581,3 +581,43 @@ int v3_init_core(struct guest_info * core) {
 
     return 0;
 }
+
+
+
+int v3_free_core(struct guest_info * core) {
+    v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU());
+
+    switch (cpu_type) {
+#ifdef CONFIG_SVM
+       case V3_SVM_CPU:
+       case V3_SVM_REV3_CPU:
+           if (v3_deinit_svm_vmcb(core) == -1) {
+               PrintError("Error in SVM initialization\n");
+               return -1;
+           }
+           break;
+#endif
+#ifdef CONFIG_VMX
+       case V3_VMX_CPU:
+       case V3_VMX_EPT_CPU:
+           if (v3_deinit_vmx_vmcs(core) == -1) {
+               PrintError("Error in VMX initialization\n");
+               return -1;
+           }
+           break;
+#endif
+       default:
+           PrintError("Invalid CPU Type 0x%x\n", cpu_type);
+           return -1;
+    }
+
+    return 0;
+}
+
+
+
+int v3_free_vm_internal(struct v3_vm_info * vm) {
+
+    
+    return 0;
+}
index de6ee04..d67509c 100644 (file)
@@ -271,7 +271,6 @@ int v3_stop_vm(struct v3_vm_info * vm) {
 
     // force exit all cores via a cross call/IPI
 
-
     while (1) {
        int i = 0;
        int still_running = 0;
@@ -298,10 +297,22 @@ int v3_stop_vm(struct v3_vm_info * vm) {
 
 
 int v3_free_vm(struct v3_vm_info * vm) {
+    int i = 0;
     // deinitialize guest (free memory, etc...)
 
     v3_dev_mgr_deinit(vm);
 
+    for (i = 0; i < vm->num_cores; i++) {
+       // free cores
+
+       v3_free_core(&(vm->cores[i]));
+
+    }
+
+    v3_free_vm_internal(vm);
+
+    // free vm
+
     return 0;
 }
 
index 2d75065..6d50ff3 100644 (file)
@@ -463,6 +463,18 @@ int v3_init_vmx_vmcs(struct guest_info * info, v3_vm_class_t vm_class) {
     return 0;
 }
 
+
+int v3_deinit_vmx_vmcs(struct guest_info * core) {
+    struct vmx_data * vmx_state = core->vmm_data;
+
+    V3_FreePages((void *)(vmx_state->vmcs_ptr_phys), 1);
+
+    V3_Free(vmx_state);
+
+    return 0;
+}
+
+
 static int update_irq_exit_state(struct guest_info * info) {
     struct vmx_exit_idt_vec_info idt_vec_info;