X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_paging.c;h=e850f88427ad079af915ef4082d5a5d9eeeac886;hb=a2b7cc4f2d739213d1edefb85ff941c41c86907b;hp=2c6a07862d427f7d6ef9bed5fab55dd2a0103edf;hpb=639fdba00d36b2a60fad3d28703459354cf8744f;p=palacios.git diff --git a/palacios/src/palacios/vmm_paging.c b/palacios/src/palacios/vmm_paging.c index 2c6a078..e850f88 100644 --- a/palacios/src/palacios/vmm_paging.c +++ b/palacios/src/palacios/vmm_paging.c @@ -1,3 +1,22 @@ +/* + * 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 @@ -5,10 +24,10 @@ #include -extern struct vmm_os_hooks * os_hooks; + void delete_page_tables_pde32(pde32_t * pde) { - int i, j; + int i;//, j; if (pde == NULL) { return; @@ -16,25 +35,49 @@ void delete_page_tables_pde32(pde32_t * pde) { for (i = 0; (i < MAX_PDE32_ENTRIES); i++) { if (pde[i].present) { - pte32_t * pte = (pte32_t *)(pde[i].pt_base_addr << PAGE_POWER); - - for (j = 0; (j < MAX_PTE32_ENTRIES); j++) { + // We double cast, first to an addr_t to handle 64 bit issues, then to the pointer + pte32_t * pte = (pte32_t *)((addr_t)(pde[i].pt_base_addr << PAGE_POWER)); + + /* + for (j = 0; (j < MAX_PTE32_ENTRIES); j++) { if ((pte[j].present)) { - os_hooks->free_page((void *)(pte[j].page_base_addr << PAGE_POWER)); + os_hooks->free_page((void *)(pte[j].page_base_addr << PAGE_POWER)); } - } - - os_hooks->free_page(pte); + } + */ + //PrintDebug("Deleting PTE %d (%x)\n", i, pte); + V3_FreePage(pte); } } - os_hooks->free_page(pde); + // PrintDebug("Deleting PDE (%x)\n", pde); + V3_FreePage(V3_PAddr(pde)); } +int pt32_lookup(pde32_t * pd, addr_t vaddr, addr_t * paddr) { + addr_t pde_entry; + pde32_entry_type_t pde_entry_type; + + if (pd == 0) { + return -1; + } + + pde_entry_type = pde32_lookup(pd, vaddr, &pde_entry); + + if (pde_entry_type == PDE32_ENTRY_PTE32) { + return pte32_lookup((pte32_t *)pde_entry, vaddr, paddr); + } else if (pde_entry_type == PDE32_ENTRY_LARGE_PAGE) { + *paddr = pde_entry; + return 0; + } + + return -1; +} + /* We can't do a full lookup because we don't know what context the page tables are in... @@ -48,10 +91,12 @@ pde32_entry_type_t pde32_lookup(pde32_t * pd, addr_t addr, addr_t * entry) { *entry = 0; return PDE32_ENTRY_NOT_PRESENT; } else { - *entry = PAGE_ADDR(pde_entry->pt_base_addr); - + if (pde_entry->large_page) { - *entry += PAGE_OFFSET(addr); + pde32_4MB_t * large_pde = (pde32_4MB_t *)pde_entry; + + *entry = PDE32_4MB_T_ADDR(*large_pde); + *entry += PD32_4MB_PAGE_OFFSET(addr); return PDE32_ENTRY_LARGE_PAGE; } else { *entry = PDE32_T_ADDR(*pde_entry); @@ -90,7 +135,7 @@ pt_access_status_t can_access_pde32(pde32_t * pde, addr_t addr, pf_error_t acces } else if ((entry->writable == 0) && (access_type.write == 1)) { return PT_WRITE_ERROR; } else if ((entry->user_page == 0) && (access_type.user == 1)) { - // Check CR0.WP + // Check CR0.WP? return PT_USER_ERROR; } @@ -106,7 +151,7 @@ pt_access_status_t can_access_pte32(pte32_t * pte, addr_t addr, pf_error_t acces } else if ((entry->writable == 0) && (access_type.write == 1)) { return PT_WRITE_ERROR; } else if ((entry->user_page == 0) && (access_type.user == 1)) { - // Check CR0.WP + // Check CR0.WP? return PT_USER_ERROR; } @@ -125,18 +170,18 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { int i, j; struct shadow_map * map = &(guest_info->mem_map); - pde32_t * pde = os_hooks->allocate_pages(1); + pde32_t * pde = V3_VAddr(V3_AllocPages(1)); for (i = 0; i < MAX_PDE32_ENTRIES; i++) { int pte_present = 0; - pte32_t * pte = os_hooks->allocate_pages(1); + pte32_t * pte = V3_VAddr(V3_AllocPages(1)); for (j = 0; j < MAX_PTE32_ENTRIES; j++) { - shadow_region_t * region = get_shadow_region_by_addr(map, current_page_addr); + struct shadow_region * region = get_shadow_region_by_addr(map, current_page_addr); if (!region || - (region->host_type == HOST_REGION_NOTHING) || + (region->host_type == HOST_REGION_HOOK) || (region->host_type == HOST_REGION_UNALLOCATED) || (region->host_type == HOST_REGION_MEMORY_MAPPED_DEVICE) || (region->host_type == HOST_REGION_REMOTE) || @@ -180,7 +225,7 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { } if (pte_present == 0) { - os_hooks->free_page(pte); + V3_FreePage(V3_PAddr(pte)); pde[i].present = 0; pde[i].writable = 0; @@ -204,7 +249,7 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { pde[i].large_page = 0; pde[i].global_page = 0; pde[i].vmm_info = 0; - pde[i].pt_base_addr = PAGE_ALIGNED_ADDR(pte); + pde[i].pt_base_addr = PAGE_ALIGNED_ADDR((addr_t)V3_PAddr(pte)); } } @@ -219,9 +264,9 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { void PrintPDE32(addr_t virtual_address, pde32_t * pde) { - PrintDebug("PDE %p -> %p : present=%x, writable=%x, user=%x, wt=%x, cd=%x, accessed=%x, reserved=%x, largePages=%x, globalPage=%x, kernelInfo=%x\n", + PrintDebug("PDE %x -> %p : present=%x, writable=%x, user=%x, wt=%x, cd=%x, accessed=%x, reserved=%x, largePages=%x, globalPage=%x, kernelInfo=%x\n", virtual_address, - (void *) (pde->pt_base_addr << PAGE_POWER), + (void *)(addr_t) (pde->pt_base_addr << PAGE_POWER), pde->present, pde->writable, pde->user_page, @@ -238,7 +283,7 @@ void PrintPTE32(addr_t virtual_address, pte32_t * pte) { PrintDebug("PTE %p -> %p : present=%x, writable=%x, user=%x, wt=%x, cd=%x, accessed=%x, dirty=%x, pteAttribute=%x, globalPage=%x, vmm_info=%x\n", virtual_address, - (void*)(pte->page_base_addr << PAGE_POWER), + (void*)(addr_t)(pte->page_base_addr << PAGE_POWER), pte->present, pte->writable, pte->user_page, @@ -290,7 +335,7 @@ void PrintDebugPageTables(pde32_t * pde) for (i = 0; (i < MAX_PDE32_ENTRIES); i++) { if (pde[i].present) { PrintPDE32((addr_t)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), &(pde[i])); - PrintPT32((addr_t)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), (pte32_t *)(pde[i].pt_base_addr << PAGE_POWER)); + PrintPT32((addr_t)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), (pte32_t *)V3_VAddr((void *)(addr_t)(pde[i].pt_base_addr << PAGE_POWER))); } } }