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() {
38 temp = V3_AllocPages(1);
40 PrintError("Cannot allocate page\n");
44 page = V3_VAddr(temp);
45 memset(page, 0, PAGE_SIZE);
50 // Inline handler functions for each cpu mode
51 #include "vmm_direct_paging_32.h"
52 #include "vmm_direct_paging_32pae.h"
53 #include "vmm_direct_paging_64.h"
55 int v3_init_passthrough_pts(struct guest_info * info) {
56 info->direct_map_pt = (addr_t)V3_PAddr((void *)create_generic_pt_page());
61 int v3_free_passthrough_pts(struct guest_info * core) {
62 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(core);
64 // Delete the old direct map page tables
68 delete_page_tables_32((pde32_t *)V3_VAddr((void *)(core->direct_map_pt)));
73 // Long mode will only use 32PAE page tables...
74 delete_page_tables_32pae((pdpe32pae_t *)V3_VAddr((void *)(core->direct_map_pt)));
77 PrintError("Unknown CPU Mode\n");
86 int v3_reset_passthrough_pts(struct guest_info * core) {
88 v3_free_passthrough_pts(core);
90 // create new direct map page table
91 v3_init_passthrough_pts(core);
98 int v3_activate_passthrough_pt(struct guest_info * info) {
99 // For now... But we need to change this....
100 // As soon as shadow paging becomes active the passthrough tables are hosed
101 // So this will cause chaos if it is called at that time
103 info->ctrl_regs.cr3 = *(addr_t*)&(info->direct_map_pt);
104 //PrintError("Activate Passthrough Page tables not implemented\n");
109 int v3_handle_passthrough_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
110 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info);
115 return handle_passthrough_pagefault_32(info, fault_addr, error_code);
120 // Long mode will only use 32PAE page tables...
121 return handle_passthrough_pagefault_32pae(info, fault_addr, error_code);
124 PrintError("Unknown CPU Mode\n");
132 int v3_handle_nested_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
133 v3_cpu_mode_t mode = v3_get_host_cpu_mode();
136 PrintDebug("Nested PageFault: fault_addr=%p, error_code=%u\n", (void *)fault_addr, *(uint_t *)&error_code);
141 return handle_passthrough_pagefault_32(info, fault_addr, error_code);
144 return handle_passthrough_pagefault_32pae(info, fault_addr, error_code);
148 return handle_passthrough_pagefault_64(info, fault_addr, error_code);
151 PrintError("Unknown CPU Mode\n");
157 int v3_invalidate_passthrough_addr(struct guest_info * info, addr_t inv_addr) {
158 v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info);
163 return invalidate_addr_32(info, inv_addr);
168 // Long mode will only use 32PAE page tables...
169 return invalidate_addr_32pae(info, inv_addr);
172 PrintError("Unknown CPU Mode\n");
179 int v3_invalidate_nested_addr(struct guest_info * info, addr_t inv_addr) {
182 v3_cpu_mode_t mode = LONG;
184 v3_cpu_mode_t mode = PROTECTED;
190 return invalidate_addr_32(info, inv_addr);
193 return invalidate_addr_32pae(info, inv_addr);
197 return invalidate_addr_64(info, inv_addr);
200 PrintError("Unknown CPU Mode\n");