From: Jack Lange Date: Thu, 27 Oct 2011 23:34:15 +0000 (-0400) Subject: added a global machine type to determine machine architecture X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=59bdbcb4c2f236ceebec83a9e526ca762b7e685d added a global machine type to determine machine architecture --- diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index 72f980c..46b1369 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -488,7 +488,7 @@ void v3_print_GPRs(struct guest_info * info) { #include #include static int info_hcall(struct guest_info * core, uint_t hcall_id, void * priv_data) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; int cpu_valid = 0; V3_Print("************** Guest State ************\n"); @@ -496,19 +496,19 @@ static int info_hcall(struct guest_info * core, uint_t hcall_id, void * priv_dat // init SVM/VMX #ifdef V3_CONFIG_SVM - if ((cpu_type == V3_SVM_CPU) || (cpu_type == V3_SVM_REV3_CPU)) { + if ((v3_mach_type == V3_SVM_CPU) || (v3_mach_type == V3_SVM_REV3_CPU)) { cpu_valid = 1; PrintDebugVMCB((vmcb_t *)(core->vmm_data)); } #endif #ifdef V3_CONFIG_VMX - if ((cpu_type == V3_VMX_CPU) || (cpu_type == V3_VMX_EPT_CPU) || (cpu_type == V3_VMX_EPT_UG_CPU)) { + if ((v3_mach_type == V3_VMX_CPU) || (v3_mach_type == V3_VMX_EPT_CPU) || (v3_mach_type == V3_VMX_EPT_UG_CPU)) { cpu_valid = 1; v3_print_vmcs(); } #endif if (!cpu_valid) { - PrintError("Invalid CPU Type 0x%x\n", cpu_type); + PrintError("Invalid CPU Type 0x%x\n", v3_mach_type); return -1; } @@ -531,7 +531,7 @@ 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()); + extern v3_cpu_arch_t v3_mach_type; @@ -574,7 +574,7 @@ int v3_init_vm(struct v3_vm_info * vm) { // init SVM/VMX - switch (cpu_type) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -591,7 +591,7 @@ int v3_init_vm(struct v3_vm_info * vm) { break; #endif default: - PrintError("Invalid CPU Type 0x%x\n", cpu_type); + PrintError("Invalid CPU Type 0x%x\n", v3_mach_type); return -1; } @@ -604,7 +604,7 @@ 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()); + extern v3_cpu_arch_t v3_mach_type; v3_remove_hypercall(vm, GUEST_INFO_HCALL); @@ -615,7 +615,7 @@ int v3_free_vm_internal(struct v3_vm_info * vm) { #endif // init SVM/VMX - switch (cpu_type) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -632,7 +632,7 @@ int v3_free_vm_internal(struct v3_vm_info * vm) { break; #endif default: - PrintError("Invalid CPU Type 0x%x\n", cpu_type); + PrintError("Invalid CPU Type 0x%x\n", v3_mach_type); return -1; } @@ -665,7 +665,7 @@ int v3_free_vm_internal(struct v3_vm_info * vm) { int v3_init_core(struct guest_info * core) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; struct v3_vm_info * vm = core->vm_info; @@ -695,7 +695,7 @@ int v3_init_core(struct guest_info * core) { // init SVM/VMX - switch (cpu_type) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -716,7 +716,7 @@ int v3_init_core(struct guest_info * core) { break; #endif default: - PrintError("Invalid CPU Type 0x%x\n", cpu_type); + PrintError("Invalid CPU Type 0x%x\n", v3_mach_type); return -1; } @@ -726,7 +726,7 @@ int v3_init_core(struct guest_info * core) { int v3_free_core(struct guest_info * core) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; #ifdef V3_CONFIG_SYMBIOTIC @@ -748,7 +748,7 @@ int v3_free_core(struct guest_info * core) { v3_deinit_core_telemetry(core); #endif - switch (cpu_type) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -769,7 +769,7 @@ int v3_free_core(struct guest_info * core) { break; #endif default: - PrintError("Invalid CPU Type 0x%x\n", cpu_type); + PrintError("Invalid CPU Type 0x%x\n", v3_mach_type); return -1; } diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 855b11c..589f576 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -39,6 +39,8 @@ v3_cpu_arch_t v3_cpu_types[V3_CONFIG_MAX_CPUS]; +v3_cpu_arch_t v3_mach_type = V3_INVALID_CPU; + struct v3_os_hooks * os_hooks = NULL; int v3_dbg_enable = 0; @@ -105,6 +107,9 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { // Set global variables. os_hooks = hooks; + // Determine the global machine type + v3_mach_type = V3_INVALID_CPU; + for (i = 0; i < V3_CONFIG_MAX_CPUS; i++) { v3_cpu_types[i] = V3_INVALID_CPU; } @@ -131,11 +136,15 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { if ((hooks) && (hooks->call_on_cpu)) { - for (i = 0; i < num_cpus; i++) { V3_Print("Initializing VMM extensions on cpu %d\n", i); hooks->call_on_cpu(i, &init_cpu, (void *)(addr_t)i); + + if (v3_mach_type == V3_INVALID_CPU) { + v3_mach_type = v3_cpu_types[i]; + } + } } @@ -210,7 +219,7 @@ static int start_core(void * p) PrintDebug("virtual core %u (on logical core %u): in start_core (RIP=%p)\n", core->vcpu_id, core->pcpu_id, (void *)(addr_t)core->rip); - switch (v3_cpu_types[0]) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -628,7 +637,7 @@ void v3_interrupt_cpu(struct v3_vm_info * vm, int logical_cpu, int vector) { int v3_vm_enter(struct guest_info * info) { - switch (v3_cpu_types[0]) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: diff --git a/palacios/src/palacios/vmm_checkpoint.c b/palacios/src/palacios/vmm_checkpoint.c index 3258779..5ba96ac 100644 --- a/palacios/src/palacios/vmm_checkpoint.c +++ b/palacios/src/palacios/vmm_checkpoint.c @@ -237,12 +237,12 @@ static int save_memory(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { } int save_header(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; void * ctx = NULL; ctx = v3_chkpt_open_ctx(chkpt, NULL, "header"); - switch (cpu_type) { + switch (v3_mach_type) { case V3_SVM_CPU: case V3_SVM_REV3_CPU: { v3_chkpt_save(ctx, "header", strlen(svm_chkpt_header), svm_chkpt_header); @@ -266,12 +266,12 @@ int save_header(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { } static int load_header(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; void * ctx = NULL; ctx = v3_chkpt_open_ctx(chkpt, NULL, "header"); - switch (cpu_type) { + switch (v3_mach_type) { case V3_SVM_CPU: case V3_SVM_REV3_CPU: { char header[strlen(svm_chkpt_header) + 1]; @@ -302,7 +302,7 @@ static int load_header(struct v3_vm_info * vm, struct v3_chkpt * chkpt) { static int load_core(struct guest_info * info, struct v3_chkpt * chkpt) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; void * ctx = NULL; char key_name[16]; memset(key_name, 0, 16); @@ -349,7 +349,7 @@ static int load_core(struct guest_info * info, struct v3_chkpt * chkpt) { } - switch (cpu_type) { + switch (v3_mach_type) { case V3_SVM_CPU: case V3_SVM_REV3_CPU: { char key_name[16]; @@ -384,7 +384,7 @@ static int load_core(struct guest_info * info, struct v3_chkpt * chkpt) { break; } default: - PrintError("Invalid CPU Type (%d)\n", cpu_type); + PrintError("Invalid CPU Type (%d)\n", v3_mach_type); return -1; } @@ -395,7 +395,7 @@ static int load_core(struct guest_info * info, struct v3_chkpt * chkpt) { static int save_core(struct guest_info * info, struct v3_chkpt * chkpt) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; void * ctx = NULL; char key_name[16]; @@ -428,7 +428,7 @@ static int save_core(struct guest_info * info, struct v3_chkpt * chkpt) { v3_chkpt_close_ctx(ctx); //Architechture specific code - switch (cpu_type) { + switch (v3_mach_type) { case V3_SVM_CPU: case V3_SVM_REV3_CPU: { char key_name[16]; @@ -468,7 +468,7 @@ static int save_core(struct guest_info * info, struct v3_chkpt * chkpt) { break; } default: - PrintError("Invalid CPU Type (%d)\n", cpu_type); + PrintError("Invalid CPU Type (%d)\n", v3_mach_type); return -1; } diff --git a/palacios/src/palacios/vmm_config.c b/palacios/src/palacios/vmm_config.c index 8d348e6..de882d0 100644 --- a/palacios/src/palacios/vmm_config.c +++ b/palacios/src/palacios/vmm_config.c @@ -280,7 +280,7 @@ static int pre_config_vm(struct v3_vm_info * vm, v3_cfg_tree_t * vm_cfg) { static int determine_paging_mode(struct guest_info * info, v3_cfg_tree_t * core_cfg) { - extern v3_cpu_arch_t v3_cpu_types[]; + extern v3_cpu_arch_t v3_mach_type; v3_cfg_tree_t * vm_tree = info->vm_info->cfg_data->cfg; v3_cfg_tree_t * pg_tree = v3_cfg_subtree(vm_tree, "paging"); @@ -291,9 +291,9 @@ static int determine_paging_mode(struct guest_info * info, v3_cfg_tree_t * core_ if (pg_mode) { if ((strcasecmp(pg_mode, "nested") == 0)) { // we assume symmetric cores, so if core 0 has nested paging they all do - if ((v3_cpu_types[0] == V3_SVM_REV3_CPU) || - (v3_cpu_types[0] == V3_VMX_EPT_CPU) || - (v3_cpu_types[0] == V3_VMX_EPT_UG_CPU)) { + if ((v3_mach_type == V3_SVM_REV3_CPU) || + (v3_mach_type == V3_VMX_EPT_CPU) || + (v3_mach_type == V3_VMX_EPT_UG_CPU)) { info->shdw_pg_mode = NESTED_PAGING; } else { PrintError("Nested paging not supported on this hardware. Defaulting to shadow paging\n"); @@ -432,7 +432,7 @@ static struct v3_vm_info * allocate_guest(int num_cores) { struct v3_vm_info * v3_config_guest(void * cfg_blob, void * priv_data) { - v3_cpu_arch_t cpu_type = v3_get_cpu_type(V3_Get_CPU()); + extern v3_cpu_arch_t v3_mach_type; struct v3_config * cfg_data = NULL; struct v3_vm_info * vm = NULL; int num_cores = 0; @@ -440,7 +440,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 (cpu_type == V3_INVALID_CPU) { + if (v3_mach_type == V3_INVALID_CPU) { PrintError("Configuring guest on invalid CPU\n"); return NULL; } diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index f76f876..4f37e8e 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -1111,8 +1111,9 @@ int v3_reset_vmx_vm_core(struct guest_info * core, addr_t rip) { void v3_init_vmx_cpu(int cpu_id) { addr_t vmx_on_region = 0; + extern v3_cpu_arch_t v3_mach_type; - if (cpu_id == 0) { + if (v3_mach_type == V3_INVALID_CPU) { if (v3_init_vmx_hw(&hw_info) == -1) { PrintError("Could not initialize VMX hardware features on cpu %d\n", cpu_id); return; @@ -1151,6 +1152,7 @@ void v3_init_vmx_cpu(int cpu_id) { v3_cpu_types[cpu_id] = V3_VMX_EPT_UG_CPU; } } + }