X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvm_guest_mem.c;h=32d4ab65d2f5d745c008ad394742901f47bba655;hb=8c767ddb04d3ac42d080d9f9f5f40196d6f8f217;hp=21c1b54cec464642ad9e726bf2f9e2817f7f5fe4;hpb=8ee31494ea28d1756689574fb69791746daac3f3;p=palacios.git diff --git a/palacios/src/palacios/vm_guest_mem.c b/palacios/src/palacios/vm_guest_mem.c index 21c1b54..32d4ab6 100644 --- a/palacios/src/palacios/vm_guest_mem.c +++ b/palacios/src/palacios/vm_guest_mem.c @@ -1,8 +1,27 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + #include #include #include -extern struct vmm_os_hooks * os_hooks; +extern struct v3_os_hooks * os_hooks; /**********************************/ @@ -15,11 +34,12 @@ int host_va_to_host_pa(addr_t host_va, addr_t * host_pa) { *host_pa = (addr_t)(os_hooks)->vaddr_to_paddr((void *)host_va); if (*host_pa == 0) { - PrintDebug("In HVA->HPA: Invalid HVA(%x)->HPA lookup\n", host_va); + PrintError("In HVA->HPA: Invalid HVA(%p)->HPA lookup\n", + (void *)host_va); return -1; } } else { - PrintDebug("In HVA->HPA: os_hooks not defined\n"); + PrintError("In HVA->HPA: os_hooks not defined\n"); return -1; } return 0; @@ -32,11 +52,12 @@ int host_pa_to_host_va(addr_t host_pa, addr_t * host_va) { *host_va = (addr_t)(os_hooks)->paddr_to_vaddr((void *)host_pa); if (*host_va == 0) { - PrintDebug("In HPA->HVA: Invalid HPA(%x)->HVA lookup\n", host_pa); + PrintError("In HPA->HVA: Invalid HPA(%p)->HVA lookup\n", + (void *)host_pa); return -1; } } else { - PrintDebug("In HPA->HVA: os_hooks not defined\n"); + PrintError("In HPA->HVA: os_hooks not defined\n"); return -1; } return 0; @@ -46,8 +67,11 @@ int host_pa_to_host_va(addr_t host_pa, addr_t * host_va) { int guest_pa_to_host_pa(struct guest_info * guest_info, addr_t guest_pa, addr_t * host_pa) { // we use the shadow map here... - if (lookup_shadow_map_addr(&(guest_info->mem_map), guest_pa, host_pa) != HOST_REGION_PHYSICAL_MEMORY) { - PrintDebug("In GPA->HPA: Could not find address in shadow map (addr=%x)\n", guest_pa); + host_region_type_t reg_type = lookup_shadow_map_addr(&(guest_info->mem_map), guest_pa, host_pa); + + if (reg_type != HOST_REGION_PHYSICAL_MEMORY) { + PrintError("In GPA->HPA: Could not find address in shadow map (addr=%p) (reg_type=%d)\n", + (void *)guest_pa, reg_type); return -1; } @@ -61,7 +85,7 @@ int guest_pa_to_host_pa(struct guest_info * guest_info, addr_t guest_pa, addr_t // int host_pa_to_guest_pa(struct guest_info * guest_info, addr_t host_pa, addr_t * guest_pa) { *guest_pa = 0; - PrintDebug("ERROR!!! HPA->GPA currently not implemented!!!\n"); + PrintError("ERROR!!! HPA->GPA currently not implemented!!!\n"); return -1; } @@ -80,12 +104,14 @@ int host_va_to_guest_pa(struct guest_info * guest_info, addr_t host_va, addr_t * *guest_pa = 0; if (host_va_to_host_pa(host_va, &host_pa) != 0) { - PrintDebug("In HVA->GPA: Invalid HVA(%x)->HPA lookup\n", host_va); + PrintError("In HVA->GPA: Invalid HVA(%p)->HPA lookup\n", + (void *)host_va); return -1; } if (host_pa_to_guest_pa(guest_info, host_pa, guest_pa) != 0) { - PrintDebug("In HVA->GPA: Invalid HPA(%x)->GPA lookup\n", host_pa); + PrintError("In HVA->GPA: Invalid HPA(%p)->GPA lookup\n", + (void *)host_pa); return -1; } @@ -101,12 +127,14 @@ int guest_pa_to_host_va(struct guest_info * guest_info, addr_t guest_pa, addr_t *host_va = 0; if (guest_pa_to_host_pa(guest_info, guest_pa, &host_pa) != 0) { - PrintDebug("In GPA->HVA: Invalid GPA(%x)->HPA lookup\n", guest_pa); + PrintError("In GPA->HVA: Invalid GPA(%p)->HPA lookup\n", + (void *)guest_pa); return -1; } if (host_pa_to_host_va(host_pa, host_va) != 0) { - PrintDebug("In GPA->HVA: Invalid HPA(%x)->HVA lookup\n", host_pa); + PrintError("In GPA->HVA: Invalid HPA(%p)->HVA lookup\n", + (void *)host_pa); return -1; } @@ -132,13 +160,14 @@ int guest_va_to_guest_pa(struct guest_info * guest_info, addr_t guest_va, addr_t addr_t guest_pde = 0; if (guest_info->shdw_pg_mode == SHADOW_PAGING) { - guest_pde = CR3_TO_PDE32(guest_info->shdw_pg_state.guest_cr3); + guest_pde = (addr_t)CR3_TO_PDE32((void *)(guest_info->shdw_pg_state.guest_cr3)); } else if (guest_info->shdw_pg_mode == NESTED_PAGING) { - guest_pde = CR3_TO_PDE32(guest_info->ctrl_regs.cr3); + guest_pde = (addr_t)CR3_TO_PDE32((void *)(guest_info->ctrl_regs.cr3)); } if (guest_pa_to_host_va(guest_info, guest_pde, (addr_t *)&pde) == -1) { - PrintDebug("In GVA->GPA: Invalid GPA(%x)->HVA PDE32 lookup\n", guest_pde); + PrintError("In GVA->GPA: Invalid GPA(%p)->HVA PDE32 lookup\n", + (void *)guest_pde); return -1; } @@ -156,14 +185,16 @@ int guest_va_to_guest_pa(struct guest_info * guest_info, addr_t guest_va, addr_t if (guest_pa_to_host_va(guest_info, tmp_pa, (addr_t*)&pte) == -1) { - PrintDebug("In GVA->GPA: Invalid GPA(%x)->HVA PTE32 lookup\n", guest_pa); + PrintError("In GVA->GPA: Invalid GPA(%p)->HVA PTE32 lookup\n", + (void *)guest_pa); return -1; } - PrintDebug("PTE host addr=%x, GVA=%x, GPA=%x(should be 0)\n", pte, guest_va, *guest_pa); - + //PrintDebug("PTE host addr=%x, GVA=%x, GPA=%x(should be 0)\n", pte, guest_va, *guest_pa); + if (pte32_lookup(pte, guest_va, guest_pa) != 0) { - PrintDebug("In GVA->GPA: PTE32 Lookup failure GVA=%x; PTE=%x\n", guest_va, pte); + PrintError("In GVA->GPA: PTE32 Lookup failure GVA=%p; PTE=%p\n", + (void *)guest_va, (void *)pte); // PrintPT32(PDE32_INDEX(guest_va) << 22, pte); return -1; } @@ -200,7 +231,7 @@ int guest_va_to_guest_pa(struct guest_info * guest_info, addr_t guest_va, addr_t */ int guest_pa_to_guest_va(struct guest_info * guest_info, addr_t guest_pa, addr_t * guest_va) { *guest_va = 0; - PrintDebug("ERROR!!: GPA->GVA Not Implemented!!\n"); + PrintError("ERROR!!: GPA->GVA Not Implemented!!\n"); return -1; } @@ -216,12 +247,14 @@ int guest_va_to_host_pa(struct guest_info * guest_info, addr_t guest_va, addr_t *host_pa = 0; if (guest_va_to_guest_pa(guest_info, guest_va, &guest_pa) != 0) { - PrintDebug("In GVA->HPA: Invalid GVA(%x)->GPA lookup\n", guest_va); + PrintError("In GVA->HPA: Invalid GVA(%p)->GPA lookup\n", + (void *)guest_va); return -1; } if (guest_pa_to_host_pa(guest_info, guest_pa, host_pa) != 0) { - PrintDebug("In GVA->HPA: Invalid GPA(%x)->HPA lookup\n", guest_pa); + PrintError("In GVA->HPA: Invalid GPA(%p)->HPA lookup\n", + (void *)guest_pa); return -1; } @@ -235,12 +268,14 @@ int host_pa_to_guest_va(struct guest_info * guest_info, addr_t host_pa, addr_t * *guest_va = 0; if (host_pa_to_guest_pa(guest_info, host_pa, &guest_pa) != 0) { - PrintDebug("In HPA->GVA: Invalid HPA(%x)->GPA lookup\n", host_pa); + PrintError("In HPA->GVA: Invalid HPA(%p)->GPA lookup\n", + (void *)host_pa); return -1; } if (guest_pa_to_guest_va(guest_info, guest_pa, guest_va) != 0) { - PrintDebug("In HPA->GVA: Invalid GPA(%x)->GVA lookup\n", guest_pa); + PrintError("In HPA->GVA: Invalid GPA(%p)->GVA lookup\n", + (void *)guest_pa); return -1; } @@ -257,17 +292,20 @@ int guest_va_to_host_va(struct guest_info * guest_info, addr_t guest_va, addr_t *host_va = 0; if (guest_va_to_guest_pa(guest_info, guest_va, &guest_pa) != 0) { - PrintDebug("In GVA->HVA: Invalid GVA(%x)->GPA lookup\n", guest_va); + PrintError("In GVA->HVA: Invalid GVA(%p)->GPA lookup\n", + (void *)guest_va); return -1; } if (guest_pa_to_host_pa(guest_info, guest_pa, &host_pa) != 0) { - PrintDebug("In GVA->HVA: Invalid GPA(%x)->HPA lookup\n", guest_pa); + PrintError("In GVA->HVA: Invalid GPA(%p)->HPA lookup\n", + (void *)guest_pa); return -1; } if (host_pa_to_host_va(host_pa, host_va) != 0) { - PrintDebug("In GVA->HVA: Invalid HPA(%x)->HVA lookup\n", host_pa); + PrintError("In GVA->HVA: Invalid HPA(%p)->HVA lookup\n", + (void *)host_pa); return -1; } @@ -283,17 +321,20 @@ int host_va_to_guest_va(struct guest_info * guest_info, addr_t host_va, addr_t * *guest_va = 0; if (host_va_to_host_pa(host_va, &host_pa) != 0) { - PrintDebug("In HVA->GVA: Invalid HVA(%x)->HPA lookup\n", host_va); + PrintError("In HVA->GVA: Invalid HVA(%p)->HPA lookup\n", + (void *)host_va); return -1; } if (host_pa_to_guest_pa(guest_info, host_pa, &guest_pa) != 0) { - PrintDebug("In HVA->GVA: Invalid HPA(%x)->GPA lookup\n", host_va); + PrintError("In HVA->GVA: Invalid HPA(%p)->GPA lookup\n", + (void *)host_va); return -1; } if (guest_pa_to_guest_va(guest_info, guest_pa, guest_va) != 0) { - PrintDebug("In HVA->GVA: Invalid GPA(%x)->GVA lookup\n", guest_pa); + PrintError("In HVA->GVA: Invalid GPA(%p)->GVA lookup\n", + (void *)guest_pa); return -1; } @@ -308,7 +349,7 @@ int host_va_to_guest_va(struct guest_info * guest_info, addr_t host_va, addr_t * /* This is a straight address conversion + copy, * except for the tiny little issue of crossing page boundries..... */ -int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int count, char * dest) { +int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int count, uchar_t * dest) { addr_t cursor = guest_va; int bytes_read = 0; @@ -319,39 +360,9 @@ int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int co int bytes_to_copy = (dist_to_pg_edge > count) ? count : dist_to_pg_edge; addr_t host_addr = 0; - - - /* JRL FIXME: - * This should be somewhere else.... - */ - /* - addr_t tmp_addr; - - addr_t shadow_pde = CR3_TO_PDE32(guest_info->shdw_pg_state.shadow_cr3); - - // Check the Shadow Page Tables first (Virtual TLB) - if (pt32_lookup((pde32_t *)shadow_pde, cursor, &tmp_addr) == 0) { - host_addr = tmp_addr; - - if (host_pa_to_host_va(tmp_addr, &host_addr) != 0) { - return bytes_read; - } - } else { - - // No entry in the VTLB, do a guest page table walk - - if (guest_va_to_host_va(guest_info, cursor, &host_addr) != 0) { - PrintDebug("Invalid GVA(%x)->HVA lookup\n", cursor); - return bytes_read; - } - } -*/ - /* JRL: END GRUESOME HACK */ - - if (guest_va_to_host_va(guest_info, cursor, &host_addr) != 0) { - PrintDebug("Invalid GVA(%x)->HVA lookup\n", cursor); + PrintDebug("Invalid GVA(%p)->HVA lookup\n", (void *)cursor); return bytes_read; } @@ -375,7 +386,7 @@ int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int co /* This is a straight address conversion + copy, * except for the tiny little issue of crossing page boundries..... */ -int read_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, char * dest) { +int read_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uchar_t * dest) { addr_t cursor = guest_pa; int bytes_read = 0; @@ -411,7 +422,7 @@ int read_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int co /* This is a straight address conversion + copy, * except for the tiny little issue of crossing page boundries..... */ -int write_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, char * src) { +int write_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uchar_t * src) { addr_t cursor = guest_pa; int bytes_written = 0;