#include <palacios/vmx.h>
#include <palacios/vmm_checkpoint.h>
#include <palacios/vmm_hashtable.h>
+#include <palacios/vmm_direct_paging.h>
#include <palacios/vmm_dev_mgr.h>
}
-/* Temporary */
-#define V3_CHKPT_STD_SAVE(ctx,x) v3_chkpt_save(ctx,#x,sizeof(x),&(x))
-#define V3_CHKPT_STD_LOAD(ctx,x) v3_chkpt_load(ctx,#x,sizeof(x),&(x))
+
int v3_chkpt_save(struct v3_chkpt_ctx * ctx, char * tag, uint64_t len, void * buf) {
}
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);
ctx = v3_chkpt_open_ctx(chkpt, NULL, key_name);
+ v3_chkpt_load_64(ctx, "RIP", &(info->rip));
+
V3_CHKPT_STD_LOAD(ctx, info->vm_regs);
V3_CHKPT_STD_LOAD(ctx, info->ctrl_regs.cr0);
info->cpu_mode = v3_get_vm_cpu_mode(info);
info->mem_mode = v3_get_vm_mem_mode(info);
+ if (info->shdw_pg_mode == SHADOW_PAGING) {
+ if (v3_get_vm_mem_mode(info) == VIRTUAL_MEM) {
+ if (v3_activate_shadow_pt(info) == -1) {
+ PrintError("Failed to activate shadow page tables\n");
+ return -1;
+ }
+ } else {
+ if (v3_activate_passthrough_pt(info) == -1) {
+ PrintError("Failed to activate passthrough page tables\n");
+ return -1;
+ }
+ }
+ }
+
- 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;
}
+ v3_print_guest_state(info);
+
return 0;
}
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];
memset(key_name, 0, 16);
+ v3_print_guest_state(info);
+
snprintf(key_name, 16, "guest_info%d", info->vcpu_id);
ctx = v3_chkpt_open_ctx(chkpt, NULL, key_name);
+ v3_chkpt_save_64(ctx, "RIP", &(info->rip));
+
V3_CHKPT_STD_SAVE(ctx, info->vm_regs);
V3_CHKPT_STD_SAVE(ctx, info->ctrl_regs.cr0);
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;
}
goto out;
}
- /*
- if ((ret = v3_chkpt_save_dev(vm)) == -1) {
+
+ if ((ret = v3_save_vm_devices(vm, chkpt)) == -1) {
PrintError("Unable to save devices\n");
goto out;
}
- */
+
if ((ret = save_header(vm, chkpt)) == -1) {
PrintError("Unable to save header\n");
}
for (i = 0; i < vm->num_cores; i++){
-
if ((ret = save_core(&(vm->cores[i]), chkpt)) == -1) {
PrintError("chkpt of core %d failed\n", i);
goto out;
}
- }
+ }
out:
}
- /* Don't handle devices just yet
- if (v3_chkpt_load_dev(vm) == -1) {
+ if ((ret = v3_load_vm_devices(vm, chkpt)) == -1) {
PrintError("Unable to load devies\n");
+ goto out;
}
- */
if ((ret = load_header(vm, chkpt)) == -1) {
PrintError("Unable to load header\n");
}
}
- out:
+ out:
/* Resume the guest if it was running and we didn't just trash the state*/
if (vm->run_state == VM_RUNNING) {