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 #include <palacios/vmm_direct_paging.h>
22 #include <palacios/vmm_paging.h>
23 #include <palacios/vmm.h>
24 #include <palacios/vm_guest_mem.h>
25 #include <palacios/vm_guest.h>
28 #ifndef V3_CONFIG_DEBUG_NESTED_PAGING
30 #define PrintDebug(fmt, args...)
34 static addr_t create_generic_pt_page(struct guest_info *core) {
38 temp = V3_AllocPagesExtended(1, PAGE_SIZE_4KB, -1,
39 core->shdw_pg_mode==SHADOW_PAGING ? V3_ALLOC_PAGES_CONSTRAINT_4GB : 0);
41 PrintError(VM_NONE, VCORE_NONE,"Cannot allocate page\n");
45 page = V3_VAddr(temp);
46 memset(page, 0, PAGE_SIZE);
51 // Inline handler functions for each cpu mode
52 #include "vmm_direct_paging_32.h"
53 #include "vmm_direct_paging_32pae.h"
54 #include "vmm_direct_paging_64.h"
56 int v3_init_passthrough_pts(struct guest_info * info) {
57 info->direct_map_pt = (addr_t)V3_PAddr((void *)create_generic_pt_page(info));
62 int v3_free_passthrough_pts(struct guest_info * core) {
63 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(core);
65 // Delete the old direct map page tables
69 delete_page_tables_32((pde32_t *)V3_VAddr((void *)(core->direct_map_pt)));
74 // Long mode will only use 32PAE page tables...
75 delete_page_tables_32pae((pdpe32pae_t *)V3_VAddr((void *)(core->direct_map_pt)));
78 PrintError(core->vm_info, core, "Unknown CPU Mode\n");
87 int v3_reset_passthrough_pts(struct guest_info * core) {
89 v3_free_passthrough_pts(core);
91 // create new direct map page table
92 v3_init_passthrough_pts(core);
99 int v3_activate_passthrough_pt(struct guest_info * info) {
100 // For now... But we need to change this....
101 // As soon as shadow paging becomes active the passthrough tables are hosed
102 // So this will cause chaos if it is called at that time
104 info->ctrl_regs.cr3 = *(addr_t*)&(info->direct_map_pt);
105 //PrintError(info->vm_info, info, "Activate Passthrough Page tables not implemented\n");
110 int v3_handle_passthrough_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
111 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info);
116 return handle_passthrough_pagefault_32(info, fault_addr, error_code);
121 // Long mode will only use 32PAE page tables...
122 return handle_passthrough_pagefault_32pae(info, fault_addr, error_code);
125 PrintError(info->vm_info, info, "Unknown CPU Mode\n");
133 int v3_handle_nested_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
134 v3_cpu_mode_t mode = v3_get_host_cpu_mode();
137 PrintDebug(info->vm_info, info, "Nested PageFault: fault_addr=%p, error_code=%u\n", (void *)fault_addr, *(uint_t *)&error_code);
142 return handle_passthrough_pagefault_32(info, fault_addr, error_code);
145 return handle_passthrough_pagefault_32pae(info, fault_addr, error_code);
149 return handle_passthrough_pagefault_64(info, fault_addr, error_code);
152 PrintError(info->vm_info, info, "Unknown CPU Mode\n");
158 int v3_invalidate_passthrough_addr(struct guest_info * info, addr_t inv_addr) {
159 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info);
164 return invalidate_addr_32(info, inv_addr);
169 // Long mode will only use 32PAE page tables...
170 return invalidate_addr_32pae(info, inv_addr);
173 PrintError(info->vm_info, info, "Unknown CPU Mode\n");
180 int v3_invalidate_passthrough_addr_range(struct guest_info * info,
181 addr_t inv_addr_start, addr_t inv_addr_end) {
182 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info);
187 return invalidate_addr_32_range(info, inv_addr_start, inv_addr_end);
192 // Long mode will only use 32PAE page tables...
193 return invalidate_addr_32pae_range(info, inv_addr_start, inv_addr_end);
196 PrintError(info->vm_info, info, "Unknown CPU Mode\n");
202 int v3_invalidate_nested_addr(struct guest_info * info, addr_t inv_addr) {
205 v3_cpu_mode_t mode = LONG;
207 v3_cpu_mode_t mode = PROTECTED;
213 return invalidate_addr_32(info, inv_addr);
216 return invalidate_addr_32pae(info, inv_addr);
220 return invalidate_addr_64(info, inv_addr);
223 PrintError(info->vm_info, info, "Unknown CPU Mode\n");
230 int v3_invalidate_nested_addr_range(struct guest_info * info,
231 addr_t inv_addr_start, addr_t inv_addr_end) {
234 v3_cpu_mode_t mode = LONG;
236 v3_cpu_mode_t mode = PROTECTED;
242 return invalidate_addr_32_range(info, inv_addr_start, inv_addr_end);
245 return invalidate_addr_32pae_range(info, inv_addr_start, inv_addr_end);
249 return invalidate_addr_64_range(info, inv_addr_start, inv_addr_end);
252 PrintError(info->vm_info, info, "Unknown CPU Mode\n");