#include <palacios/vmcs.h>
#include <palacios/vmcb.h>
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");
// 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;
}
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;
// init SVM/VMX
- switch (cpu_type) {
+ switch (v3_mach_type) {
#ifdef V3_CONFIG_SVM
case V3_SVM_CPU:
case V3_SVM_REV3_CPU:
break;
#endif
default:
- PrintError("Invalid CPU Type 0x%x\n", cpu_type);
+ PrintError("Invalid CPU Type 0x%x\n", v3_mach_type);
return -1;
}
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);
#endif
// init SVM/VMX
- switch (cpu_type) {
+ switch (v3_mach_type) {
#ifdef V3_CONFIG_SVM
case V3_SVM_CPU:
case V3_SVM_REV3_CPU:
break;
#endif
default:
- PrintError("Invalid CPU Type 0x%x\n", cpu_type);
+ PrintError("Invalid CPU Type 0x%x\n", v3_mach_type);
return -1;
}
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;
// init SVM/VMX
- switch (cpu_type) {
+ switch (v3_mach_type) {
#ifdef V3_CONFIG_SVM
case V3_SVM_CPU:
case V3_SVM_REV3_CPU:
break;
#endif
default:
- PrintError("Invalid CPU Type 0x%x\n", cpu_type);
+ PrintError("Invalid CPU Type 0x%x\n", v3_mach_type);
return -1;
}
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
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:
break;
#endif
default:
- PrintError("Invalid CPU Type 0x%x\n", cpu_type);
+ PrintError("Invalid CPU Type 0x%x\n", v3_mach_type);
return -1;
}
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;
// 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;
}
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];
+ }
+
}
}
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:
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:
}
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);
}
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];
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);
}
- switch (cpu_type) {
+ switch (v3_mach_type) {
case V3_SVM_CPU:
case V3_SVM_REV3_CPU: {
char key_name[16];
break;
}
default:
- PrintError("Invalid CPU Type (%d)\n", cpu_type);
+ PrintError("Invalid CPU Type (%d)\n", v3_mach_type);
return -1;
}
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];
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];
break;
}
default:
- PrintError("Invalid CPU Type (%d)\n", cpu_type);
+ PrintError("Invalid CPU Type (%d)\n", v3_mach_type);
return -1;
}
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");
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");
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;
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;
}
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;
v3_cpu_types[cpu_id] = V3_VMX_EPT_UG_CPU;
}
}
+
}