From: Jack Lange Date: Thu, 27 Jan 2011 20:00:44 +0000 (-0600) Subject: build fixes and cleanup code to handle VMM shutdown X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=18713f98a14335b09cb7d87b3bea087255eaf10d;hp=da5c386c3153196bd0aa4610d8ad513d3f7f1bbc;p=palacios.releases.git build fixes and cleanup code to handle VMM shutdown --- diff --git a/Kconfig b/Kconfig index 3cb3f70..dcee752 100644 --- a/Kconfig +++ b/Kconfig @@ -142,13 +142,6 @@ config SHADOW_PAGING_TELEMETRY Enable telemetry information for shadow paging -config INSTRUMENT_VMM - bool "Enable VMM instrumentation" - default n - help - Enable the instrumentation framework - -------- - This is much heavier weight than profiling config EXPERIMENTAL bool "Enable Experimental options" diff --git a/Makefile b/Makefile index b989348..d1b637b 100644 --- a/Makefile +++ b/Makefile @@ -298,7 +298,10 @@ V3_INCLUDE := -Ipalacios/include \ CPPFLAGS := $(V3_INCLUDE) -D__V3VEE__ -CFLAGS := -fno-stack-protector -Wall -Werror -fPIC -mno-red-zone -fno-common +CFLAGS := -fno-stack-protector -Wall -Werror -mno-red-zone -fno-common +#-fPIC +#-ffreestanding + LDFLAGS := --whole-archive diff --git a/palacios/include/palacios/svm.h b/palacios/include/palacios/svm.h index 1e26c55..a0078ca 100644 --- a/palacios/include/palacios/svm.h +++ b/palacios/include/palacios/svm.h @@ -76,9 +76,11 @@ #define SVM_HANDLER_ERROR 0x1 #define SVM_HANDLER_HALT 0x2 +int v3_is_svm_capable(); void v3_init_svm_cpu(int cpu_id); -int v3_is_svm_capable(); +void v3_deinit_svm_cpu(int cpu_id); + int v3_init_svm_vmcb(struct guest_info * core, v3_vm_class_t vm_class); int v3_deinit_svm_vmcb(struct guest_info * core); diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index c39d7a1..ae4421c 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -22,13 +22,13 @@ /*#include */ -#include -#include struct guest_info; #ifdef __V3VEE__ +#include +#include //#include #include diff --git a/palacios/include/palacios/vmm_symmod.h b/palacios/include/palacios/vmm_symmod.h index 4d28fff..22e2dc7 100644 --- a/palacios/include/palacios/vmm_symmod.h +++ b/palacios/include/palacios/vmm_symmod.h @@ -95,7 +95,7 @@ struct v3_sym_capsule * v3_get_sym_capsule(struct v3_vm_info * vm, char * name); int V3_init_symmod(); - +int V3_deinit_symmod(); diff --git a/palacios/include/palacios/vmx.h b/palacios/include/palacios/vmx.h index 034cbfa..9f07886 100644 --- a/palacios/include/palacios/vmx.h +++ b/palacios/include/palacios/vmx.h @@ -1,5 +1,3 @@ - - /* * This file is part of the Palacios Virtual Machine Monitor developed * by the V3VEE Project with funding from the United States National @@ -238,7 +236,9 @@ struct vmx_data { }; int v3_is_vmx_capable(); + void v3_init_vmx_cpu(int cpu_id); +void v3_deinit_vmx_cpu(int cpu_id); int v3_start_vmx_guest(struct guest_info* info); int v3_vmx_enter(struct guest_info * info); diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 3bde027..20adea3 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -769,7 +769,27 @@ void v3_init_svm_cpu(int cpu_id) { +void v3_deinit_svm_cpu(int cpu_id) { + reg_ex_t msr; + extern v3_cpu_arch_t v3_cpu_types[]; + + // reset SVM_VM_HSAVE_PA_MSR + // Does setting it to NULL disable?? + msr.r_reg = 0; + v3_set_msr(SVM_VM_HSAVE_PA_MSR, msr.e_reg.high, msr.e_reg.low); + + // Disable SVM? + v3_get_msr(EFER_MSR, &(msr.e_reg.high), &(msr.e_reg.low)); + msr.e_reg.low &= ~EFER_MSR_svm_enable; + v3_set_msr(EFER_MSR, 0, msr.e_reg.low); + + v3_cpu_types[cpu_id] = V3_INVALID_CPU; + V3_FreePages((void *)host_vmcbs[cpu_id], 4); + + V3_Print("Host CPU %d host area freed, and SVM disabled\n", cpu_id); + return; +} diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index 09770a8..c85c235 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -339,7 +339,7 @@ void v3_print_guest_state(struct guest_info * info) { void v3_print_guest_state_all(struct v3_vm_info * vm) { int i = 0; - + V3_Print("VM Core states for %s\n", vm->name); for (i = 0; i < 80; i++) { diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index a7e83cc..0060bc2 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -67,29 +66,33 @@ static void init_cpu(void * arg) { } } -#if 0 + static void deinit_cpu(void * arg) { -// uint32_t cpu_id = (uint32_t)(addr_t)arg; + uint32_t cpu_id = (uint32_t)(addr_t)arg; - #ifdef CONFIG_SVM - if (v3_is_svm_capable()) { - PrintDebug("Machine is SVM Capable\n"); - //v3_deinit_svm_cpu(cpu_id); - } else + switch (v3_cpu_types[cpu_id]) { + #ifdef CONFIG_SVM + case V3_VMX_CPU: + case V3_VMX_EPT_CPU: + PrintDebug("Machine is SVM Capable\n"); + v3_deinit_svm_cpu(cpu_id); + break; #endif #ifdef CONFIG_VMX - if (v3_is_vmx_capable()) { - PrintDebug("Machine is VMX Capable\n"); - //v3_deinit_vmx_cpu(cpu_id); - - } else + case V3_SVM_CPU: + case V3_SVM_REV3_CPU: + PrintDebug("Machine is VMX Capable\n"); + v3_deinit_vmx_cpu(cpu_id); + break; #endif - { - PrintError("CPU has no virtualization Extensions\n"); + case V3_INVALID_CPU: + default: + PrintError("CPU has no virtualization Extensions\n"); + break; } } -#endif + void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { @@ -115,10 +118,6 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { V3_init_symmod(); #endif -#ifdef CONFIG_INSTRUMENT_VMM - v3_init_instrumentation(); -#endif - #ifdef CONFIG_VNET v3_init_vnet(); @@ -142,30 +141,25 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { void Shutdown_V3() { - // int i; + int i; V3_deinit_devices(); V3_deinit_shdw_paging(); -#if 0 - #ifdef CONFIG_SYMMOD V3_deinit_symmod(); #endif -#ifdef CONFIG_INSTRUMENT_VMM - v3_deinit_instrumentation(); -#endif #ifdef CONFIG_VNET v3_deinit_vnet(); #endif #ifdef CONFIG_MULTITHREAD_OS - if ((hooks) && (hooks->call_on_cpu)) { + if ((os_hooks) && (os_hooks->call_on_cpu)) { for (i = 0; i < CONFIG_MAX_CPUS; i++) { if (v3_cpu_types[i] != V3_INVALID_CPU) { - deinit_cpu(i); + deinit_cpu((void *)(addr_t)i); } } } @@ -173,8 +167,6 @@ void Shutdown_V3() { deinit_cpu(0); #endif -#endif - } diff --git a/palacios/src/palacios/vmm_symmod.c b/palacios/src/palacios/vmm_symmod.c index b037635..5f14566 100644 --- a/palacios/src/palacios/vmm_symmod.c +++ b/palacios/src/palacios/vmm_symmod.c @@ -106,6 +106,7 @@ int V3_init_symmod() { PrintError("Could not insert module %s to master list\n", tmp_def->name); return -1; } + list_add(&(capsule->node), &capsule_list); tmp_def = &(__start__v3_capsules[++i]); @@ -114,6 +115,12 @@ int V3_init_symmod() { return 0; } +int V3_deinit_symmod() { + v3_free_htable(capsule_table, 1, 0); + + return 0; +} + /* ***************** */ /* Linkage functions */ /* ***************** */ diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index 6d50ff3..f71df0a 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -857,7 +857,8 @@ void v3_init_vmx_cpu(int cpu_id) { struct v3_msr tmp_msr; uint64_t ret = 0; - v3_get_msr(VMX_CR4_FIXED0_MSR,&(tmp_msr.hi),&(tmp_msr.lo)); + v3_get_msr(VMX_CR4_FIXED0_MSR, &(tmp_msr.hi), &(tmp_msr.lo)); + #ifdef __V3_64BIT__ __asm__ __volatile__ ( "movq %%cr4, %%rbx;" @@ -944,3 +945,9 @@ void v3_init_vmx_cpu(int cpu_id) { } + +void v3_deinit_vmx_cpu(int cpu_id) { + extern v3_cpu_arch_t v3_cpu_types[]; + v3_cpu_types[cpu_id] = V3_INVALID_CPU; + V3_FreePages((void *)host_vmcs_ptrs[cpu_id], 1); +}