X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_paging.c;h=516073a0b6cd5f2a2c4575e2af04efcbfad40054;hb=9ed850393ba752a7c0bb83673b5ff98f9573f2da;hp=8ae430d509a2aa7b2c92e15dd6d8243c6062c008;hpb=a109eb919a162bd7de58d62020801bc2e633be50;p=palacios.releases.git diff --git a/palacios/src/palacios/vmm_paging.c b/palacios/src/palacios/vmm_paging.c index 8ae430d..516073a 100644 --- a/palacios/src/palacios/vmm_paging.c +++ b/palacios/src/palacios/vmm_paging.c @@ -46,21 +46,24 @@ pde32_entry_type_t pde32_lookup(pde32_t * pde, addr_t addr, addr_t * entry) { if (!pde_entry->present) { *entry = 0; - return NOT_PRESENT; + return PDE32_ENTRY_NOT_PRESENT; } else { *entry = PAGE_ADDR(pde_entry->pt_base_addr); - if (pde_entry->large_pages) { + if (pde_entry->large_page) { *entry += PAGE_OFFSET(addr); - return LARGE_PAGE; + return PDE32_ENTRY_LARGE_PAGE; } else { - return PTE32; + return PDE32_ENTRY_PTE32; } } - return NOT_PRESENT; + return PDE32_ENTRY_NOT_PRESENT; } + +/* Takes a virtual addr (addr) and returns the physical addr (entry) as defined in the page table + */ int pte32_lookup(pte32_t * pte, addr_t addr, addr_t * entry) { pte32_t * pte_entry = &(pte[PTE32_INDEX(addr)]); @@ -78,7 +81,36 @@ int pte32_lookup(pte32_t * pte, addr_t addr, addr_t * entry) { +pt_access_status_t can_access_pde32(pde32_t * pde, addr_t addr, pf_error_t access_type) { + pde32_t * entry = &pde[PDE32_INDEX(addr)]; + + if (entry->present == 0) { + return PT_ENTRY_NOT_PRESENT; + } 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 + return PT_USER_ERROR; + } + + return PT_ACCESS_OK; +} + + +pt_access_status_t can_access_pte32(pte32_t * pte, addr_t addr, pf_error_t access_type) { + pte32_t * entry = &pte[PTE32_INDEX(addr)]; + + if (entry->present == 0) { + return PT_ENTRY_NOT_PRESENT; + } 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 + return PT_USER_ERROR; + } + return PT_ACCESS_OK; +} @@ -90,7 +122,7 @@ int pte32_lookup(pte32_t * pte, addr_t addr, addr_t * entry) { pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { ullong_t current_page_addr = 0; int i, j; - shadow_map_t * map = &(guest_info->mem_map); + struct shadow_map * map = &(guest_info->mem_map); pde32_t * pde = os_hooks->allocate_pages(1); @@ -110,7 +142,10 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { (region->host_type == HOST_REGION_REMOTE) || (region->host_type == HOST_REGION_SWAPPED)) { pte[j].present = 0; - pte[j].flags = 0; + pte[j].writable = 0; + pte[j].user_page = 0; + pte[j].write_through = 0; + pte[j].cache_disable = 0; pte[j].accessed = 0; pte[j].dirty = 0; pte[j].pte_attr = 0; @@ -120,8 +155,10 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { } else { addr_t host_addr; pte[j].present = 1; - pte[j].flags = VM_READ | VM_WRITE | VM_EXEC | VM_USER; - + pte[j].writable = 1; + pte[j].user_page = 1; + pte[j].write_through = 0; + pte[j].cache_disable = 0; pte[j].accessed = 0; pte[j].dirty = 0; pte[j].pte_attr = 0; @@ -146,19 +183,25 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { os_hooks->free_page(pte); pde[i].present = 0; - pde[i].flags = 0; + pde[i].writable = 0; + pde[i].user_page = 0; + pde[i].write_through = 0; + pde[i].cache_disable = 0; pde[i].accessed = 0; pde[i].reserved = 0; - pde[i].large_pages = 0; + pde[i].large_page = 0; pde[i].global_page = 0; pde[i].vmm_info = 0; pde[i].pt_base_addr = 0; } else { pde[i].present = 1; - pde[i].flags = VM_READ | VM_WRITE | VM_EXEC | VM_USER; + pde[i].writable = 1; + pde[i].user_page = 1; + pde[i].write_through = 0; + pde[i].cache_disable = 0; pde[i].accessed = 0; pde[i].reserved = 0; - pde[i].large_pages = 0; + pde[i].large_page = 0; pde[i].global_page = 0; pde[i].vmm_info = 0; pde[i].pt_base_addr = PAGE_ALIGNED_ADDR(pte); @@ -174,32 +217,38 @@ pde32_t * create_passthrough_pde32_pts(struct guest_info * guest_info) { -void PrintPDE32(void * virtual_address, pde32_t * pde) +void PrintPDE32(addr_t virtual_address, pde32_t * pde) { - PrintDebug("PDE %p -> %p : present=%x, flags=%x, accessed=%x, reserved=%x, largePages=%x, globalPage=%x, kernelInfo=%x\n", - virtual_address, - (void *) (pde->pt_base_addr << PAGE_POWER), - pde->present, - pde->flags, - pde->accessed, - pde->reserved, - pde->large_pages, - pde->global_page, - pde->vmm_info); + 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", + virtual_address, + (void *) (pde->pt_base_addr << PAGE_POWER), + pde->present, + pde->writable, + pde->user_page, + pde->write_through, + pde->cache_disable, + pde->accessed, + pde->reserved, + pde->large_page, + pde->global_page, + pde->vmm_info); } -void PrintPTE32(void * virtual_address, pte32_t * pte) +void PrintPTE32(addr_t virtual_address, pte32_t * pte) { - PrintDebug("PTE %p -> %p : present=%x, flags=%x, accessed=%x, dirty=%x, pteAttribute=%x, globalPage=%x, vmm_info=%x\n", - virtual_address, - (void*)(pte->page_base_addr << PAGE_POWER), - pte->present, - pte->flags, - pte->accessed, - pte->dirty, - pte->pte_attr, - pte->global_page, - pte->vmm_info); + 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), + pte->present, + pte->writable, + pte->user_page, + pte->write_through, + pte->cache_disable, + pte->accessed, + pte->dirty, + pte->pte_attr, + pte->global_page, + pte->vmm_info); } @@ -209,18 +258,22 @@ void PrintPD32(pde32_t * pde) int i; PrintDebug("Page Directory at %p:\n", pde); - for (i = 0; (i < MAX_PDE32_ENTRIES) && pde[i].present; i++) { - PrintPDE32((void*)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), &(pde[i])); + for (i = 0; (i < MAX_PDE32_ENTRIES); i++) { + if ( pde[i].present) { + PrintPDE32((addr_t)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), &(pde[i])); + } } } -void PrintPT32(void * starting_address, pte32_t * pte) +void PrintPT32(addr_t starting_address, pte32_t * pte) { int i; PrintDebug("Page Table at %p:\n", pte); - for (i = 0; (i < MAX_PTE32_ENTRIES) && pte[i].present; i++) { - PrintPTE32(starting_address + (PAGE_SIZE * i), &(pte[i])); + for (i = 0; (i < MAX_PTE32_ENTRIES) ; i++) { + if (pte[i].present) { + PrintPTE32(starting_address + (PAGE_SIZE * i), &(pte[i])); + } } } @@ -234,9 +287,11 @@ void PrintDebugPageTables(pde32_t * pde) PrintDebug("Dumping the pages starting with the pde page at %p\n", pde); - for (i = 0; (i < MAX_PDE32_ENTRIES) && pde[i].present; i++) { - PrintPDE32((void *)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), &(pde[i])); - PrintPT32((void *)(PAGE_SIZE * MAX_PTE32_ENTRIES * i), (void *)(pde[i].pt_base_addr << PAGE_POWER)); + 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)); + } } }