X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fsvm_handler.c;h=8495a170c36226197d7f8c8faf946221f277631b;hb=5b6278751429f59297ce74e614d50632daea3748;hp=2cfe74eed4246a60b1385f517eb1b0e26cb83366;hpb=85dbf9793951dfd1cc387b5b54284983ab984c1b;p=palacios.git diff --git a/palacios/src/palacios/svm_handler.c b/palacios/src/palacios/svm_handler.c index 2cfe74e..8495a17 100644 --- a/palacios/src/palacios/svm_handler.c +++ b/palacios/src/palacios/svm_handler.c @@ -29,7 +29,7 @@ #include #include #include - +#include @@ -83,7 +83,7 @@ int v3_handle_svm_exit(struct guest_info * info) { // Dump out the instr stream //PrintDebug("RIP: %x\n", guest_state->rip); - PrintDebug("RIP Linear: %x\n", get_addr_linear(info, info->rip, &(info->segments.cs))); + PrintDebug("RIP Linear: %p\n", (void *)get_addr_linear(info, info->rip, &(info->segments.cs))); // OK, now we will read the instruction // The only difference between PROTECTED and PROTECTED_PG is whether we read @@ -118,139 +118,173 @@ int v3_handle_svm_exit(struct guest_info * info) { switch (exit_code) { - case VMEXIT_IOIO: { - struct svm_io_info * io_info = (struct svm_io_info *)&(guest_ctrl->exit_info1); - - if (io_info->type == 0) { - if (io_info->str) { - if (v3_handle_svm_io_outs(info) == -1 ) { - return -1; + case VMEXIT_IOIO: + { + struct svm_io_info * io_info = (struct svm_io_info *)&(guest_ctrl->exit_info1); + + if (io_info->type == 0) { + if (io_info->str) { + if (v3_handle_svm_io_outs(info) == -1 ) { + return -1; + } + } else { + if (v3_handle_svm_io_out(info) == -1) { + return -1; + } } } else { - if (v3_handle_svm_io_out(info) == -1) { - return -1; + if (io_info->str) { + if (v3_handle_svm_io_ins(info) == -1) { + return -1; + } + } else { + if (v3_handle_svm_io_in(info) == -1) { + return -1; + } } } - } else { - if (io_info->str) { - if (v3_handle_svm_io_ins(info) == -1) { + break; + } + case VMEXIT_MSR: + { + + if (guest_ctrl->exit_info1 == 0) { + if (v3_handle_msr_read(info) == -1) { return -1; } - } else { - if (v3_handle_svm_io_in(info) == -1) { + } else if (guest_ctrl->exit_info1 == 1) { + if (v3_handle_msr_write(info) == -1) { return -1; } + } else { + PrintError("Invalid MSR Operation\n"); + return -1; } - } - } - break; - - case VMEXIT_CR0_WRITE: { + break; + } + case VMEXIT_CR0_WRITE: + { #ifdef DEBUG_CTRL_REGS - PrintDebug("CR0 Write\n"); + PrintDebug("CR0 Write\n"); #endif - if (v3_handle_cr0_write(info) == -1) { - return -1; + if (v3_handle_cr0_write(info) == -1) { + return -1; + } + break; + } + case VMEXIT_CR0_READ: + { +#ifdef DEBUG_CTRL_REGS + PrintDebug("CR0 Read\n"); +#endif + if (v3_handle_cr0_read(info) == -1) { + return -1; + } + break; + } + case VMEXIT_CR3_WRITE: + { +#ifdef DEBUG_CTRL_REGS + PrintDebug("CR3 Write\n"); +#endif + if (v3_handle_cr3_write(info) == -1) { + return -1; + } + break; } - } - break; - - case VMEXIT_CR0_READ: { + case VMEXIT_CR3_READ: + { #ifdef DEBUG_CTRL_REGS - PrintDebug("CR0 Read\n"); + PrintDebug("CR3 Read\n"); #endif - if (v3_handle_cr0_read(info) == -1) { - return -1; + if (v3_handle_cr3_read(info) == -1) { + return -1; + } + break; } - } - break; - - case VMEXIT_CR3_WRITE: { + case VMEXIT_CR4_WRITE: + { #ifdef DEBUG_CTRL_REGS - PrintDebug("CR3 Write\n"); + PrintDebug("CR4 Write\n"); #endif - if (v3_handle_cr3_write(info) == -1) { - return -1; - } - } - break; - - case VMEXIT_CR3_READ: { + if (v3_handle_cr4_write(info) == -1) { + return -1; + } + break; + } + case VMEXIT_CR4_READ: + { #ifdef DEBUG_CTRL_REGS - PrintDebug("CR3 Read\n"); + PrintDebug("CR4 Read\n"); #endif - if (v3_handle_cr3_read(info) == -1) { - return -1; + if (v3_handle_cr4_read(info) == -1) { + return -1; + } + break; } - } - break; - case VMEXIT_EXCP14: { - addr_t fault_addr = guest_ctrl->exit_info2; - pf_error_t * error_code = (pf_error_t *)&(guest_ctrl->exit_info1); + case VMEXIT_EXCP14: + { + addr_t fault_addr = guest_ctrl->exit_info2; + pf_error_t * error_code = (pf_error_t *)&(guest_ctrl->exit_info1); #ifdef DEBUG_SHADOW_PAGING - PrintDebug("PageFault at %x (error=%d)\n", fault_addr, *error_code); + PrintDebug("PageFault at %p (error=%d)\n", + (void *)fault_addr, *(uint_t *)error_code); #endif - if (info->shdw_pg_mode == SHADOW_PAGING) { - if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) { + if (info->shdw_pg_mode == SHADOW_PAGING) { + if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) { + return -1; + } + } else { + PrintError("Page fault in un implemented paging mode\n"); return -1; } - } else { - PrintError("Page fault in un implemented paging mode\n"); + break; + } + case VMEXIT_NPF: + { + PrintError("Currently unhandled Nested Page Fault\n"); return -1; - } - } - break; - - case VMEXIT_NPF: { - PrintError("Currently unhandled Nested Page Fault\n"); - return -1; - - } - break; - case VMEXIT_INVLPG: { - if (info->shdw_pg_mode == SHADOW_PAGING) { + break; + } + case VMEXIT_INVLPG: + { + if (info->shdw_pg_mode == SHADOW_PAGING) { #ifdef DEBUG_SHADOW_PAGING - PrintDebug("Invlpg\n"); + PrintDebug("Invlpg\n"); #endif - if (v3_handle_shadow_invlpg(info) == -1) { - return -1; + if (v3_handle_shadow_invlpg(info) == -1) { + return -1; + } } - } - /* - (exit_code == VMEXIT_INVLPGA) || - */ - - } - break; - - case VMEXIT_INTR: { - - // handled by interrupt dispatch earlier - - } - break; - - case VMEXIT_SMI: { - - // handle_svm_smi(info); // ignored for now - - } - break; - - case VMEXIT_HLT: { + /* + (exit_code == VMEXIT_INVLPGA) || + */ + break; + } + case VMEXIT_INTR: + { + // handled by interrupt dispatch earlier + break; + } + case VMEXIT_SMI: + { + // handle_svm_smi(info); // ignored for now + break; + } + case VMEXIT_HLT: + { #ifdef DEBUG_HALT - PrintDebug("Guest halted\n"); + PrintDebug("Guest halted\n"); #endif - if (v3_handle_svm_halt(info) == -1) { - return -1; + if (v3_handle_svm_halt(info) == -1) { + return -1; + } + break; } - } - break; - case VMEXIT_PAUSE: { //PrintDebug("Guest paused\n"); if (v3_handle_svm_pause(info) == -1) { @@ -337,11 +371,11 @@ int v3_handle_svm_exit(struct guest_info * info) { rip_addr = get_addr_linear(info, guest_state->rip, &(info->segments.cs)); - PrintError("SVM Returned:(VMCB=%x)\n", info->vmm_data); - PrintError("RIP: %x\n", guest_state->rip); - PrintError("RIP Linear: %x\n", rip_addr); + PrintError("SVM Returned:(VMCB=%p)\n", (void *)(info->vmm_data)); + PrintError("RIP: %p\n", (void *)(addr_t)(guest_state->rip)); + PrintError("RIP Linear: %p\n", (void *)(addr_t)(rip_addr)); - PrintError("SVM Returned: Exit Code: %x\n", exit_code); + PrintError("SVM Returned: Exit Code: %p\n", (void *)(addr_t)exit_code); PrintError("io_info1 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info1)); PrintError("io_info1 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info1)) + 4)); @@ -352,12 +386,12 @@ int v3_handle_svm_exit(struct guest_info * info) { if (info->mem_mode == PHYSICAL_MEM) { - if (guest_pa_to_host_pa(info, guest_state->rip, &host_addr) == -1) { + if (guest_pa_to_host_va(info, guest_state->rip, &host_addr) == -1) { PrintError("Could not translate guest_state->rip to host address\n"); return -1; } } else if (info->mem_mode == VIRTUAL_MEM) { - if (guest_va_to_host_pa(info, guest_state->rip, &host_addr) == -1) { + if (guest_va_to_host_va(info, guest_state->rip, &host_addr) == -1) { PrintError("Could not translate guest_state->rip to host address\n"); return -1; } @@ -366,11 +400,11 @@ int v3_handle_svm_exit(struct guest_info * info) { return -1; } - PrintError("Host Address of rip = 0x%x\n", host_addr); + PrintError("Host Address of rip = 0x%p\n", (void *)host_addr); memset(buf, 0, 32); - PrintError("Reading instruction stream in guest\n", rip_addr); + PrintError("Reading instruction stream in guest (addr=%p)\n", (void *)rip_addr); if (info->mem_mode == PHYSICAL_MEM) { read_guest_pa_memory(info, rip_addr - 16, 32, buf); @@ -414,7 +448,9 @@ int v3_handle_svm_exit(struct guest_info * info) { guest_ctrl->guest_ctrl.V_IGN_TPR = 1; guest_ctrl->guest_ctrl.V_INTR_PRIO = 0xf; #ifdef DEBUG_INTERRUPTS - PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, info->rip); + PrintDebug("Injecting Interrupt %d (EIP=%p)\n", + guest_ctrl->guest_ctrl.V_INTR_VECTOR, + (void *)(addr_t)info->rip); #endif v3_injecting_intr(info, irq, EXTERNAL_IRQ); @@ -441,7 +477,9 @@ int v3_handle_svm_exit(struct guest_info * info) { guest_ctrl->EVENTINJ.valid = 1; #ifdef DEBUG_INTERRUPTS - PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip); + PrintDebug("Injecting Interrupt %d (EIP=%p)\n", + guest_ctrl->EVENTINJ.vector, + (void *)(addr_t)info->rip); #endif v3_injecting_intr(info, excp, EXCEPTION); break;