2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Steven Jaconette <stevenjaconette2007@u.northwestern.edu>
11 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
12 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
13 * All rights reserved.
15 * Author: Steven Jaconette <stevenjaconette2007@u.northwestern.edu>
17 * This is free software. You are permitted to use,
18 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #ifndef __VMM_DIRECT_PAGING_32_H__
22 #define __VMM_DIRECT_PAGING_32_H__
24 #include <palacios/vmm_mem.h>
25 #include <palacios/vmm_paging.h>
26 #include <palacios/vmm.h>
27 #include <palacios/vm_guest_mem.h>
28 #include <palacios/vm_guest.h>
31 static inline int handle_passthrough_pagefault_32(struct guest_info * info,
33 pf_error_t error_code) {
34 // Check to see if pde and pte exist (create them if not)
39 int pde_index = PDE32_INDEX(fault_addr);
40 int pte_index = PTE32_INDEX(fault_addr);
42 struct v3_mem_region * region = v3_get_mem_region(info->vm_info, info->vcpu_id, fault_addr);
45 PrintError(info->vm_info, info, "Invalid region in passthrough page fault 32, addr=%p\n",
50 // Lookup the correct PDE address based on the PAGING MODE
51 if (info->shdw_pg_mode == SHADOW_PAGING) {
52 pde = CR3_TO_PDE32_VA(info->ctrl_regs.cr3);
54 pde = CR3_TO_PDE32_VA(info->direct_map_pt);
58 // Fix up the PDE entry
59 if (pde[pde_index].present == 0) {
60 pte = (pte32_t *)create_generic_pt_page();
62 pde[pde_index].present = 1;
63 pde[pde_index].writable = 1;
64 pde[pde_index].user_page = 1;
65 pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
68 pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
71 // Fix up the PTE entry
72 if (pte[pte_index].present == 0) {
75 if ((region->flags.alloced == 1) &&
76 (region->flags.read == 1)) {
78 pte[pte_index].user_page = 1;
80 pte[pte_index].present = 1;
82 if (region->flags.write == 1) {
83 pte[pte_index].writable = 1;
85 pte[pte_index].writable = 0;
88 if (v3_gpa_to_hpa(info, fault_addr, &host_addr) == -1) {
89 PrintError(info->vm_info, info, "Could not translate fault address (%p)\n", (void *)fault_addr);
93 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
95 return region->unhandled(info, fault_addr, fault_addr, region, error_code);
98 // We fix all permissions on the first pass,
99 // so we only get here if its an unhandled exception
100 return region->unhandled(info, fault_addr, fault_addr, region, error_code);
109 static inline int invalidate_addr_32_internal(struct guest_info * info, addr_t inv_addr,
110 addr_t *actual_start, uint64_t *actual_size) {
111 pde32_t * pde = NULL;
112 pte32_t * pte = NULL;
117 // clear the page table entry
118 int pde_index = PDE32_INDEX(inv_addr);
119 int pte_index = PTE32_INDEX(inv_addr);
122 // Lookup the correct PDE address based on the PAGING MODE
123 if (info->shdw_pg_mode == SHADOW_PAGING) {
124 pde = CR3_TO_PDE32_VA(info->ctrl_regs.cr3);
126 pde = CR3_TO_PDE32_VA(info->direct_map_pt);
129 if (pde[pde_index].present == 0) {
130 *actual_start = BASE_TO_PAGE_ADDR_4MB(PAGE_BASE_ADDR_4MB(inv_addr));
131 *actual_size = PAGE_SIZE_4MB;
133 } else if (pde[pde_index].large_page) {
134 pde[pde_index].present = 0;
135 pde[pde_index].writable = 0;
136 pde[pde_index].user_page = 0;
137 *actual_start = BASE_TO_PAGE_ADDR_4MB(PAGE_BASE_ADDR_4MB(inv_addr));
138 *actual_size = PAGE_SIZE_4MB;
142 pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
144 pte[pte_index].present = 0;
145 pte[pte_index].writable = 0;
146 pte[pte_index].user_page = 0;
148 *actual_start = BASE_TO_PAGE_ADDR_4KB(PAGE_BASE_ADDR_4KB(inv_addr));
149 *actual_size = PAGE_SIZE_4KB;
155 static inline int invalidate_addr_32(struct guest_info * core, addr_t inv_addr)
160 return invalidate_addr_32_internal(core,inv_addr,&start,&len);
163 static inline int invalidate_addr_32_range(struct guest_info * core, addr_t inv_addr_start, addr_t inv_addr_end)
170 for (next=inv_addr_start; next<=inv_addr_end; ) {
171 rc = invalidate_addr_32_internal(core,next,&start, &len);