X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fsvm.c;h=bb5b5250e767901054ae338f665e120b336c80ac;hb=6cff7c8b0ec58e3b94d9583f709ca9056ae928dd;hp=20adea34c63864f82590928c63e4677a3faf02b7;hpb=18713f98a14335b09cb7d87b3bea087255eaf10d;p=palacios-OLD.git diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 20adea3..bb5b525 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -44,7 +44,7 @@ #include -#ifndef CONFIG_DEBUG_SVM +#ifndef V3_CONFIG_DEBUG_SVM #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -53,7 +53,7 @@ uint32_t v3_last_exit; // This is a global pointer to the host's VMCB -static addr_t host_vmcbs[CONFIG_MAX_CPUS] = { [0 ... CONFIG_MAX_CPUS - 1] = 0}; +static addr_t host_vmcbs[V3_CONFIG_MAX_CPUS] = { [0 ... V3_CONFIG_MAX_CPUS - 1] = 0}; @@ -105,7 +105,7 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info * core) { ctrl_area->instrs.HLT = 1; -#ifdef CONFIG_TIME_VIRTUALIZE_TSC +#ifdef V3_CONFIG_TIME_VIRTUALIZE_TSC ctrl_area->instrs.RDTSC = 1; ctrl_area->svm_instrs.RDTSCP = 1; #endif @@ -218,6 +218,11 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info * core) { ctrl_area->instrs.INTR = 1; + v3_hook_msr(core->vm_info, EFER_MSR, + &v3_handle_efer_read, + &v3_handle_efer_write, + core); + if (core->shdw_pg_mode == SHADOW_PAGING) { PrintDebug("Creating initial shadow page table\n"); @@ -246,10 +251,7 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info * core) { ctrl_area->cr_reads.cr3 = 1; ctrl_area->cr_writes.cr3 = 1; - v3_hook_msr(core->vm_info, EFER_MSR, - &v3_handle_efer_read, - &v3_handle_efer_write, - core); + ctrl_area->instrs.INVLPG = 1; @@ -324,7 +326,7 @@ static int update_irq_exit_state(struct guest_info * info) { if ((info->intr_core_state.irq_pending == 1) && (guest_ctrl->guest_ctrl.V_IRQ == 0)) { -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("INTAK cycle completed for irq %d\n", info->intr_core_state.irq_vector); #endif @@ -335,7 +337,7 @@ static int update_irq_exit_state(struct guest_info * info) { } if ((info->intr_core_state.irq_started == 1) && (guest_ctrl->exit_int_info.valid == 0)) { -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("Interrupt %d taken by guest\n", info->intr_core_state.irq_vector); #endif @@ -343,7 +345,7 @@ static int update_irq_exit_state(struct guest_info * info) { info->intr_core_state.irq_started = 0; } else if ((info->intr_core_state.irq_started == 1) && (guest_ctrl->exit_int_info.valid == 1)) { -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("EXIT INT INFO is set (vec=%d)\n", guest_ctrl->exit_int_info.vector); #endif } @@ -369,7 +371,7 @@ static int update_irq_entry_state(struct guest_info * info) { if (info->excp_state.excp_error_code_valid) { guest_ctrl->EVENTINJ.error_code = info->excp_state.excp_error_code; guest_ctrl->EVENTINJ.ev = 1; -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("Injecting exception %d with error code %x\n", excp, guest_ctrl->EVENTINJ.error_code); #endif } @@ -378,7 +380,7 @@ static int update_irq_entry_state(struct guest_info * info) { guest_ctrl->EVENTINJ.valid = 1; -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("<%d> Injecting Exception %d (CR2=%p) (EIP=%p)\n", (int)info->num_exits, guest_ctrl->EVENTINJ.vector, @@ -388,7 +390,7 @@ static int update_irq_entry_state(struct guest_info * info) { v3_injecting_excp(info, excp); } else if (info->intr_core_state.irq_started == 1) { -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("IRQ pending from previous injection\n"); #endif guest_ctrl->guest_ctrl.V_IRQ = 1; @@ -406,7 +408,7 @@ static int update_irq_entry_state(struct guest_info * info) { guest_ctrl->guest_ctrl.V_IGN_TPR = 1; guest_ctrl->guest_ctrl.V_INTR_PRIO = 0xf; -#ifdef CONFIG_DEBUG_INTERRUPTS +#ifdef V3_CONFIG_DEBUG_INTERRUPTS PrintDebug("Injecting Interrupt %d (EIP=%p)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, (void *)(addr_t)info->rip); @@ -451,14 +453,18 @@ int v3_svm_enter(struct guest_info * info) { vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA((vmcb_t*)(info->vmm_data)); addr_t exit_code = 0, exit_info1 = 0, exit_info2 = 0; - v3_adjust_time(info); - // Conditionally yield the CPU if the timeslice has expired v3_yield_cond(info); + // Perform any additional yielding needed for time adjustment + v3_adjust_time(info); + // disable global interrupts for vm state transition v3_clgi(); + // Update timer devices prior to entering VM. + v3_update_timers(info); + // Synchronize the guest state to the VMCB guest_state->cr0 = info->ctrl_regs.cr0; guest_state->cr2 = info->ctrl_regs.cr2; @@ -478,7 +484,7 @@ int v3_svm_enter(struct guest_info * info) { guest_state->rip = info->rip; guest_state->rsp = info->vm_regs.rsp; -#ifdef CONFIG_SYMCALL +#ifdef V3_CONFIG_SYMCALL if (info->sym_core_state.symcall_state.sym_call_active == 0) { update_irq_entry_state(info); } @@ -495,7 +501,7 @@ int v3_svm_enter(struct guest_info * info) { (void *)(addr_t)info->rip); */ -#ifdef CONFIG_SYMCALL +#ifdef V3_CONFIG_SYMCALL if (info->sym_core_state.symcall_state.sym_call_active == 1) { if (guest_ctrl->guest_ctrl.V_IRQ == 1) { V3_Print("!!! Injecting Interrupt during Sym call !!!\n"); @@ -503,19 +509,20 @@ int v3_svm_enter(struct guest_info * info) { } #endif - v3_update_timers(info); + v3_time_enter_vm(info); guest_ctrl->TSC_OFFSET = v3_tsc_host_offset(&info->time_state); //V3_Print("Calling v3_svm_launch\n"); - v3_svm_launch((vmcb_t *)V3_PAddr(info->vmm_data), &(info->vm_regs), (vmcb_t *)host_vmcbs[info->cpu_id]); + v3_svm_launch((vmcb_t *)V3_PAddr(info->vmm_data), &(info->vm_regs), (vmcb_t *)host_vmcbs[V3_Get_CPU()]); //V3_Print("SVM Returned: Exit Code: %x, guest_rip=%lx\n", (uint32_t)(guest_ctrl->exit_code), (unsigned long)guest_state->rip); v3_last_exit = (uint32_t)(guest_ctrl->exit_code); - //PrintDebug("SVM Returned\n"); - + // Immediate exit from VM time bookkeeping + v3_time_exit_vm(info); + info->num_exits++; // Save Guest state from VMCB @@ -547,7 +554,7 @@ int v3_svm_enter(struct guest_info * info) { exit_info2 = guest_ctrl->exit_info2; -#ifdef CONFIG_SYMCALL +#ifdef V3_CONFIG_SYMCALL if (info->sym_core_state.symcall_state.sym_call_active == 0) { update_irq_exit_state(info); } @@ -567,6 +574,7 @@ int v3_svm_enter(struct guest_info * info) { if (v3_handle_svm_exit(info, exit_code, exit_info1, exit_info2) != 0) { PrintError("Error in SVM exit handler\n"); + PrintError(" last exit was %d\n", v3_last_exit); return -1; }