// Parse host-os defined options into an easily-accessed format.
v3_parse_options(options);
+#ifdef V3_CONFIG_HVM
+ v3_init_hvm();
+#endif
+
// Memory manager initialization
v3_init_mem();
v3_deinit_mem();
+#ifdef V3_CONFIG_HVM
+ v3_deinit_hvm();
+#endif
+
v3_deinit_options();
return v3_cpu_types[cpu_id];
}
+static int start_core(void * p)
+{
+ struct guest_info * core = (struct guest_info *)p;
+
+ if (v3_scheduler_register_core(core) == -1){
+ PrintError(core->vm_info, core,"Error initializing scheduling in core %d\n", core->vcpu_id);
+ }
+
+ PrintDebug(core->vm_info,core,"virtual core %u (on logical core %u): in start_core (RIP=%p)\n",
+ core->vcpu_id, core->pcpu_id, (void *)(addr_t)core->rip);
-struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data, char * name) {
+ switch (v3_mach_type) {
+#ifdef V3_CONFIG_SVM
+ case V3_SVM_CPU:
+ case V3_SVM_REV3_CPU:
+ return v3_start_svm_guest(core);
+ break;
+#endif
+#if V3_CONFIG_VMX
+ case V3_VMX_CPU:
+ case V3_VMX_EPT_CPU:
+ case V3_VMX_EPT_UG_CPU:
+ return v3_start_vmx_guest(core);
+ break;
+#endif
+ default:
+ PrintError(core->vm_info, core, "Attempting to enter a guest on an invalid CPU\n");
+ return -1;
+ }
+ // should not happen
+ return 0;
+}
+
+struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data, char * name, unsigned int cpu_mask) {
struct v3_vm_info * vm = v3_config_guest(cfg, priv_data);
+ int vcore_id = 0;
if (vm == NULL) {
PrintError(VM_NONE, VCORE_NONE, "Could not configure guest\n");
PrintError(vm, VCORE_NONE,"Error registering VM with scheduler\n");
}
- return vm;
-}
+ if (v3_cpu_mapper_admit_vm(vm,cpu_mask) != 0){
+ PrintError(vm, VCORE_NONE,"Error admitting VM %s for mapping", vm->name);
+ }
+ for (vcore_id = 0; vcore_id < vm->num_cores; vcore_id++) {
+ struct guest_info * core = &(vm->cores[vcore_id]);
+ PrintDebug(vm, VCORE_NONE, "Creating virtual core %u on logical core %u\n",
+ vcore_id, core->pcpu_id);
-static int start_core(void * p)
-{
- struct guest_info * core = (struct guest_info *)p;
+ sprintf(core->exec_name, "%s-%u", vm->name, vcore_id);
- if (v3_scheduler_register_core(core) == -1){
- PrintError(core->vm_info, core,"Error initializing scheduling in core %d\n", core->vcpu_id);
- }
+ PrintDebug(vm, VCORE_NONE, "run: core=%u, func=0x%p, arg=0x%p, name=%s\n",
+ core->pcpu_id, start_core, core, core->exec_name);
- PrintDebug(core->vm_info,core,"virtual core %u (on logical core %u): in start_core (RIP=%p)\n",
- core->vcpu_id, core->pcpu_id, (void *)(addr_t)core->rip);
+ core->core_thread = V3_CREATE_THREAD_ON_CPU(core->pcpu_id, start_core, core, core->exec_name);
+
+ if (core->core_thread == NULL) {
+ PrintError(vm, VCORE_NONE, "Thread creation failed\n");
+ v3_stop_vm(vm);
+ return NULL;
+ }
- switch (v3_mach_type) {
-#ifdef V3_CONFIG_SVM
- case V3_SVM_CPU:
- case V3_SVM_REV3_CPU:
- return v3_start_svm_guest(core);
- break;
-#endif
-#if V3_CONFIG_VMX
- case V3_VMX_CPU:
- case V3_VMX_EPT_CPU:
- case V3_VMX_EPT_UG_CPU:
- return v3_start_vmx_guest(core);
- break;
-#endif
- default:
- PrintError(core->vm_info, core, "Attempting to enter a guest on an invalid CPU\n");
- return -1;
}
- // should not happen
- return 0;
+ return vm;
}
int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) {
return -1;
}
+#if V3_CONFIG_HVM
+ if (v3_setup_hvm_vm_for_boot(vm)) {
+ PrintError(vm, VCORE_NONE, "HVM setup for boot failed\n");
+ return -1;
+ }
+#endif
/// CHECK IF WE ARE MULTICORE ENABLED....
}
vm->avail_cores = avail_cores;
-
- if (v3_cpu_mapper_admit_vm(vm,cpu_mask) != 0){
- PrintError(vm, VCORE_NONE,"Error admitting VM %s for mapping", vm->name);
- }
if (v3_scheduler_admit_vm(vm) != 0){
PrintError(vm, VCORE_NONE,"Error admitting VM %s for scheduling", vm->name);
vm->run_state = VM_RUNNING;
-
for (vcore_id = 0; vcore_id < vm->num_cores; vcore_id++) {
struct guest_info * core = &(vm->cores[vcore_id]);
PrintDebug(vm, VCORE_NONE, "Starting virtual core %u on logical core %u\n",
vcore_id, core->pcpu_id);
-
- sprintf(core->exec_name, "%s-%u", vm->name, vcore_id);
-
- PrintDebug(vm, VCORE_NONE, "run: core=%u, func=0x%p, arg=0x%p, name=%s\n",
- core->pcpu_id, start_core, core, core->exec_name);
- if (core->core_run_state==CORE_INVALID) {
+ if (core->core_run_state==CORE_INVALID) {
// launch of a fresh VM
- core->core_run_state = CORE_STOPPED;
+ core->core_run_state = CORE_STOPPED;
// core zero will turn itself on
} else {
// this is a resume - use whatever its current run_state is
}
- core->core_thread = V3_CREATE_THREAD_ON_CPU(core->pcpu_id, start_core, core, core->exec_name);
+ V3_START_THREAD(core->core_thread);
- if (core->core_thread == NULL) {
- PrintError(vm, VCORE_NONE, "Thread launch failed\n");
- v3_stop_vm(vm);
- return -1;
- }
}
return 0;
new_hpa = V3_AllocPagesExtended(num_pages,
PAGE_SIZE_4KB,
new_node,
- 0); // no constraints given new shadow pager impl
+ 0, 0); // no constraints given new shadow pager impl
if (!new_hpa) {
PrintError(vm, VCORE_NONE, "Cannot allocate memory for new base region...\n");
core->num_vcores=numcores;
- for (i=0;i<vm->mem_map.num_base_regions;i++) {
+ for (i=0;i<numregions;i++) {
mem->region[i].host_paddr = (void*)(vm->mem_map.base_regions[i].host_addr);
mem->region[i].size = v3_mem_block_size;
#ifdef V3_CONFIG_SWAPPING