X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fsvm.c;h=9c58c25d90544850021dadfb218ed37aa163ec2e;hb=c016bb46bd68474161e275a5ace086c3fb810d9f;hp=3707d1f90c3a4c3d0e2b615ab8b2121042d43c6c;hpb=c163873b7b96544683030cafba0e73a7ed988171;p=palacios.git diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 3707d1f..9c58c25 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -41,6 +41,8 @@ #include #include +#include +#include extern void v3_stgi(); @@ -65,10 +67,11 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { uint_t i; - guest_state->rsp = vm_info->vm_regs.rsp; - // guest_state->rip = vm_info->rip; + // + guest_state->rsp = 0x00; guest_state->rip = 0xfff0; + guest_state->cpl = 0; guest_state->efer |= EFER_MSR_svm_enable; @@ -163,37 +166,16 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { guest_state->dr7 = 0x0000000000000400LL; - if ( !RB_EMPTY_ROOT(&(vm_info->io_map)) ) { - struct v3_io_hook * iter; - struct rb_node * io_node = v3_rb_first(&(vm_info->io_map)); - addr_t io_port_bitmap; - int i = 0; - - io_port_bitmap = (addr_t)V3_VAddr(V3_AllocPages(3)); - memset((uchar_t*)io_port_bitmap, 0, PAGE_SIZE * 3); - - ctrl_area->IOPM_BASE_PA = (addr_t)V3_PAddr((void *)io_port_bitmap); - - //PrintDebug("Setting up IO Map at 0x%x\n", io_port_bitmap); - - do { - iter = rb_entry(io_node, struct v3_io_hook, tree_node); - - ushort_t port = iter->port; - uchar_t * bitmap = (uchar_t *)io_port_bitmap; - //PrintDebug("%d: Hooking Port %d\n", i, port); + v3_init_svm_io_map(vm_info); + ctrl_area->IOPM_BASE_PA = (addr_t)V3_PAddr(vm_info->io_map.arch_data); + ctrl_area->instrs.IOIO_PROT = 1; - bitmap += (port / 8); - // PrintDebug("Setting Bit for port 0x%x\n", port); - *bitmap |= 1 << (port % 8); - i++; - } while ((io_node = v3_rb_next(io_node))); - //PrintDebugMemDump((uchar_t*)io_port_bitmap, PAGE_SIZE *2); + v3_init_svm_msr_map(vm_info); + ctrl_area->MSRPM_BASE_PA = (addr_t)V3_PAddr(vm_info->msr_map.arch_data); + ctrl_area->instrs.MSR_PROT = 1; - ctrl_area->instrs.IOIO_PROT = 1; - } PrintDebug("Exiting on interrupts\n"); @@ -204,6 +186,9 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { if (vm_info->shdw_pg_mode == SHADOW_PAGING) { PrintDebug("Creating initial shadow page table\n"); + /* JRL: This is a performance killer, and a simplistic solution */ + /* We need to fix this */ + ctrl_area->TLB_CONTROL = 1; ctrl_area->guest_ASID = 1; @@ -225,8 +210,6 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { ctrl_area->cr_reads.cr3 = 1; ctrl_area->cr_writes.cr3 = 1; - vm_info->guest_efer.value = 0x0LL; - v3_hook_msr(vm_info, EFER_MSR, &v3_handle_efer_read, &v3_handle_efer_write, @@ -236,10 +219,6 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { ctrl_area->exceptions.pf = 1; - /* JRL: This is a performance killer, and a simplistic solution */ - /* We need to fix this */ - ctrl_area->TLB_CONTROL = 1; - guest_state->g_pat = 0x7040600070406ULL; guest_state->cr0 |= 0x80000000; @@ -264,40 +243,22 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info *vm_info) { guest_state->g_pat = 0x7040600070406ULL; } +} - if (vm_info->msr_map.num_hooks > 0) { - PrintDebug("Hooking %d msrs\n", vm_info->msr_map.num_hooks); - ctrl_area->MSRPM_BASE_PA = v3_init_svm_msr_map(vm_info); - ctrl_area->instrs.MSR_PROT = 1; - } - /* Safety locations for fs/gs */ - // vm_info->fs = 0; - // vm_info->gs = 0; -} +static int init_svm_guest(struct guest_info * info, struct v3_vm_config * config_ptr) { + + v3_pre_config_guest(info, config_ptr); -static int init_svm_guest(struct guest_info *info) { PrintDebug("Allocating VMCB\n"); info->vmm_data = (void*)Allocate_VMCB(); PrintDebug("Initializing VMCB (addr=%p)\n", (void *)info->vmm_data); Init_VMCB_BIOS((vmcb_t*)(info->vmm_data), info); - - info->run_state = VM_STOPPED; + v3_post_config_guest(info, config_ptr); - // info->rip = 0; - - info->vm_regs.rdi = 0; - info->vm_regs.rsi = 0; - info->vm_regs.rbp = 0; - info->vm_regs.rsp = 0; - info->vm_regs.rbx = 0; - info->vm_regs.rdx = 0; - info->vm_regs.rcx = 0; - info->vm_regs.rax = 0; - return 0; } @@ -320,24 +281,33 @@ static int start_svm_guest(struct guest_info *info) { ullong_t tmp_tsc; +#ifdef __V3_64BIT__ -#define MSR_STAR 0xc0000081 -#define MSR_LSTAR 0xc0000082 -#define MSR_CSTAR 0xc0000083 -#define MSR_SF_MASK 0xc0000084 -#define MSR_GS_BASE 0xc0000101 +#define MSR_LSTAR 0xc0000082 +#define MSR_CSTAR 0xc0000083 +#define MSR_SF_MASK 0xc0000084 +#define MSR_GS_BASE 0xc0000101 #define MSR_KERNGS_BASE 0xc0000102 - - struct v3_msr host_cstar; - struct v3_msr host_star; struct v3_msr host_lstar; struct v3_msr host_syscall_mask; struct v3_msr host_gs_base; struct v3_msr host_kerngs_base; -/* v3_enable_ints(); */ -/* v3_clgi(); */ +#else + +#define MSR_SYSENTER_CS 0x00000174 +#define MSR_SYSENTER_ESP 0x00000175 +#define MSR_SYSENTER_EIP 0x00000176 + + struct v3_msr host_sysenter_cs; + struct v3_msr host_sysenter_esp; + struct v3_msr host_sysenter_eip; + +#endif + +#define MSR_STAR 0xc0000081 + struct v3_msr host_star; /* @@ -347,28 +317,39 @@ static int start_svm_guest(struct guest_info *info) { */ - v3_get_msr(MSR_STAR, &(host_star.hi), &(host_star.lo)); +#ifdef __V3_64BIT__ + v3_get_msr(MSR_SF_MASK, &(host_syscall_mask.hi), &(host_syscall_mask.lo)); v3_get_msr(MSR_LSTAR, &(host_lstar.hi), &(host_lstar.lo)); v3_get_msr(MSR_CSTAR, &(host_cstar.hi), &(host_cstar.lo)); - v3_get_msr(MSR_SF_MASK, &(host_syscall_mask.hi), &(host_syscall_mask.lo)); v3_get_msr(MSR_GS_BASE, &(host_gs_base.hi), &(host_gs_base.lo)); v3_get_msr(MSR_KERNGS_BASE, &(host_kerngs_base.hi), &(host_kerngs_base.lo)); - +#else + v3_get_msr(MSR_SYSENTER_CS, &(host_sysenter_cs.hi), &(host_sysenter_cs.lo)); + v3_get_msr(MSR_SYSENTER_ESP, &(host_sysenter_esp.hi), &(host_sysenter_esp.lo)); + v3_get_msr(MSR_SYSENTER_EIP, &(host_sysenter_eip.hi), &(host_sysenter_eip.lo)); +#endif + v3_get_msr(MSR_STAR, &(host_star.hi), &(host_star.lo)); rdtscll(info->time_state.cached_host_tsc); // guest_ctrl->TSC_OFFSET = info->time_state.guest_tsc - info->time_state.cached_host_tsc; - //v3_svm_launch((vmcb_t*)V3_PAddr(info->vmm_data), &(info->vm_regs), &(info->fs), &(info->gs)); v3_svm_launch((vmcb_t*)V3_PAddr(info->vmm_data), &(info->vm_regs)); rdtscll(tmp_tsc); - v3_set_msr(MSR_STAR, host_star.hi, host_star.lo); +#ifdef __V3_64BIT__ + v3_set_msr(MSR_SF_MASK, host_syscall_mask.hi, host_syscall_mask.lo); v3_set_msr(MSR_LSTAR, host_lstar.hi, host_lstar.lo); v3_set_msr(MSR_CSTAR, host_cstar.hi, host_cstar.lo); - v3_set_msr(MSR_SF_MASK, host_syscall_mask.hi, host_syscall_mask.lo); v3_set_msr(MSR_GS_BASE, host_gs_base.hi, host_gs_base.lo); v3_set_msr(MSR_KERNGS_BASE, host_kerngs_base.hi, host_kerngs_base.lo); +#else + v3_set_msr(MSR_SYSENTER_CS, host_sysenter_cs.hi, host_sysenter_cs.lo); + v3_set_msr(MSR_SYSENTER_ESP, host_sysenter_esp.hi, host_sysenter_esp.lo); + v3_set_msr(MSR_SYSENTER_EIP, host_sysenter_eip.hi, host_sysenter_eip.lo); +#endif + v3_set_msr(MSR_STAR, host_star.hi, host_star.lo); + //PrintDebug("SVM Returned\n"); @@ -413,7 +394,7 @@ static int start_svm_guest(struct guest_info *info) { PrintDebug("Shadow Paging Guest Registers:\n"); PrintDebug("\tGuest CR0=%p\n", (void *)(addr_t)(info->shdw_pg_state.guest_cr0)); PrintDebug("\tGuest CR3=%p\n", (void *)(addr_t)(info->shdw_pg_state.guest_cr3)); - // efer + PrintDebug("\tGuest EFER=%p\n", (void *)(addr_t)(info->shdw_pg_state.guest_efer.value)); // CR4 } v3_print_GPRs(info);