From: Jack Lange Date: Wed, 12 Jan 2011 03:55:30 +0000 (-0600) Subject: deallocate arch specific IO/MSR hook state X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=c31bb26014522e5678e9c9dcc9eda760eeb5907a;p=palacios.git deallocate arch specific IO/MSR hook state --- diff --git a/palacios/include/palacios/svm_io.h b/palacios/include/palacios/svm_io.h index f363a59..8f79682 100644 --- a/palacios/include/palacios/svm_io.h +++ b/palacios/include/palacios/svm_io.h @@ -44,6 +44,7 @@ struct svm_io_info { int v3_init_svm_io_map(struct v3_vm_info * vm); +int v3_deinit_svm_io_map(struct v3_vm_info * vm); int v3_handle_svm_io_in(struct guest_info * info, struct svm_io_info * io_info); int v3_handle_svm_io_ins(struct guest_info * info, struct svm_io_info * io_info); diff --git a/palacios/include/palacios/svm_msr.h b/palacios/include/palacios/svm_msr.h index 1ef8e75..1405083 100644 --- a/palacios/include/palacios/svm_msr.h +++ b/palacios/include/palacios/svm_msr.h @@ -26,6 +26,7 @@ #include int v3_init_svm_msr_map(struct v3_vm_info * vm); +int v3_deinit_svm_msr_map(struct v3_vm_info * vm); #endif // ! __V3VEE__ diff --git a/palacios/include/palacios/vmm_hypercall.h b/palacios/include/palacios/vmm_hypercall.h index a7c79f2..9c2407b 100644 --- a/palacios/include/palacios/vmm_hypercall.h +++ b/palacios/include/palacios/vmm_hypercall.h @@ -63,8 +63,7 @@ void v3_init_hypercall_map(struct v3_vm_info * vm); int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, int (*hypercall)(struct guest_info * info , hcall_id_t hcall_id, void * priv_data), void * priv_data); - - +int v3_remove_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id); int v3_handle_hypercall(struct guest_info * info); diff --git a/palacios/include/palacios/vmx_io.h b/palacios/include/palacios/vmx_io.h index 62cd3b5..e065e70 100644 --- a/palacios/include/palacios/vmx_io.h +++ b/palacios/include/palacios/vmx_io.h @@ -27,6 +27,7 @@ struct guest_info; struct v3_vm_info; int v3_init_vmx_io_map(struct v3_vm_info * vm); +int v3_deinit_vmx_io_map(struct v3_vm_info * vm); int v3_handle_vmx_io_in(struct guest_info * info, struct vmx_exit_info * exit_info); int v3_handle_vmx_io_ins(struct guest_info * info, struct vmx_exit_info * exit_info); diff --git a/palacios/include/palacios/vmx_msr.h b/palacios/include/palacios/vmx_msr.h index be30c7f..4ddd6fd 100644 --- a/palacios/include/palacios/vmx_msr.h +++ b/palacios/include/palacios/vmx_msr.h @@ -25,6 +25,7 @@ #include int v3_init_vmx_msr_map(struct v3_vm_info * vm); +int v3_deinit_vmx_msr_map(struct v3_vm_info * vm); #endif #endif diff --git a/palacios/src/palacios/svm_io.c b/palacios/src/palacios/svm_io.c index 3fb5bcc..1aa76ae 100644 --- a/palacios/src/palacios/svm_io.c +++ b/palacios/src/palacios/svm_io.c @@ -57,6 +57,11 @@ int v3_init_svm_io_map(struct v3_vm_info * vm) { return 0; } +int v3_deinit_svm_io_map(struct v3_vm_info * vm) { + V3_FreePages(V3_PAddr(vm->io_map.arch_data), 3); + return 0; +} + // This should package up an IO request and call vmm_handle_io diff --git a/palacios/src/palacios/svm_msr.c b/palacios/src/palacios/svm_msr.c index 747ec89..345ab1a 100644 --- a/palacios/src/palacios/svm_msr.c +++ b/palacios/src/palacios/svm_msr.c @@ -89,4 +89,7 @@ int v3_init_svm_msr_map(struct v3_vm_info * vm) { return 0; } - +int v3_deinit_svm_msr_map(struct v3_vm_info * vm) { + V3_FreePages(V3_PAddr(vm->msr_map.arch_data), 2); + return 0; +} diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index 9c37b6f..aa42528 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -33,6 +33,7 @@ #include + v3_cpu_mode_t v3_get_vm_cpu_mode(struct guest_info * info) { struct cr0_32 * cr0; struct efer_64 * efer; @@ -461,7 +462,6 @@ static int info_hcall(struct guest_info * core, uint_t hcall_id, void * priv_dat int v3_init_vm(struct v3_vm_info * vm) { v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); - int cpu_valid = 0; if (v3_get_foreground_vm() == NULL) { v3_set_foreground_vm(vm); @@ -503,23 +503,24 @@ int v3_init_vm(struct v3_vm_info * vm) { // init SVM/VMX + switch (cpu_type) { #ifdef CONFIG_SVM - if ((cpu_type == V3_SVM_CPU) || (cpu_type == V3_SVM_REV3_CPU)) { - v3_init_svm_io_map(vm); - v3_init_svm_msr_map(vm); - cpu_valid = 1; - } + case V3_SVM_CPU: + case V3_SVM_REV3_CPU: + v3_deinit_svm_io_map(vm); + v3_deinit_svm_msr_map(vm); + break; #endif #ifdef CONFIG_VMX - if ((cpu_type == V3_VMX_CPU) || (cpu_type == V3_VMX_EPT_CPU)) { - v3_init_vmx_io_map(vm); - v3_init_vmx_msr_map(vm); - cpu_valid = 1; - } + case V3_VMX_CPU: + case V3_VMX_EPT_CPU: + v3_deinit_vmx_io_map(vm); + v3_deinit_vmx_msr_map(vm); + break; #endif - if (!cpu_valid) { - PrintError("Invalid CPU Type 0x%x\n", cpu_type); - return -1; + default: + PrintError("Invalid CPU Type 0x%x\n", cpu_type); + return -1; } v3_register_hypercall(vm, GUEST_INFO_HCALL, info_hcall, NULL); @@ -531,6 +532,31 @@ int v3_init_vm(struct v3_vm_info * vm) { int v3_free_vm_internal(struct v3_vm_info * vm) { + v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + + v3_remove_hypercall(vm, GUEST_INFO_HCALL); + + + // init SVM/VMX + switch (cpu_type) { +#ifdef CONFIG_SVM + case V3_SVM_CPU: + case V3_SVM_REV3_CPU: + v3_init_svm_io_map(vm); + v3_init_svm_msr_map(vm); + break; +#endif +#ifdef CONFIG_VMX + case V3_VMX_CPU: + case V3_VMX_EPT_CPU: + v3_init_vmx_io_map(vm); + v3_init_vmx_msr_map(vm); + break; +#endif + default: + PrintError("Invalid CPU Type 0x%x\n", cpu_type); + return -1; + } return 0; diff --git a/palacios/src/palacios/vmm_hypercall.c b/palacios/src/palacios/vmm_hypercall.c index 7dda3a4..c664a83 100644 --- a/palacios/src/palacios/vmm_hypercall.c +++ b/palacios/src/palacios/vmm_hypercall.c @@ -127,6 +127,22 @@ int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, } +int v3_remove_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id) { + struct hypercall * hcall = get_hypercall(vm, hypercall_id); + + if (hcall == NULL) { + PrintError("Attempted to remove non existant hypercall\n"); + return -1; + } + + v3_rb_erase(&(hcall->tree_node), &(vm->hcall_map)); + + V3_Free(hcall); + + return 0; +} + + int v3_handle_hypercall(struct guest_info * info) { hcall_id_t hypercall_id = *(uint_t *)&info->vm_regs.rax; struct hypercall * hcall = get_hypercall(info->vm_info, hypercall_id); diff --git a/palacios/src/palacios/vmx_io.c b/palacios/src/palacios/vmx_io.c index f1cf40c..411eb1a 100644 --- a/palacios/src/palacios/vmx_io.c +++ b/palacios/src/palacios/vmx_io.c @@ -57,6 +57,12 @@ int v3_init_vmx_io_map(struct v3_vm_info * vm) { return 0; } +int v3_deinit_vmx_io_map(struct v3_vm_info * vm) { + V3_FreePages(V3_PAddr(vm->io_map.arch_data), 2); + return 0; +} + + int v3_handle_vmx_io_in(struct guest_info * core, struct vmx_exit_info * exit_info) { struct vmx_exit_io_qual io_qual = *(struct vmx_exit_io_qual *)&(exit_info->exit_qual);; struct v3_io_hook * hook = NULL; diff --git a/palacios/src/palacios/vmx_msr.c b/palacios/src/palacios/vmx_msr.c index 4368c9c..bf0e79f 100644 --- a/palacios/src/palacios/vmx_msr.c +++ b/palacios/src/palacios/vmx_msr.c @@ -75,3 +75,8 @@ int v3_init_vmx_msr_map(struct v3_vm_info * vm) { return 0; } + +int v3_deinit_vmx_msr_map(struct v3_vm_info * vm) { + V3_FreePages(V3_PAddr(vm->msr_map.arch_data), 1); + return 0; +}