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_64_H__
22 #define __VMM_DIRECT_PAGING_64_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>
30 #define DEBUG_NESTED_PAGING 1
32 #ifndef DEBUG_NESTED_PAGING
34 #define PrintDebug(fmt, args...)
38 static inline int handle_passthrough_pagefault_64(struct guest_info * info,
40 pf_error_t error_code) {
41 pml4e64_t * pml = NULL;
42 pdpe64_t * pdpe = NULL;
47 int pml_index = PML4E64_INDEX(fault_addr);
48 int pdpe_index = PDPE64_INDEX(fault_addr);
49 int pde_index = PDE64_INDEX(fault_addr);
50 int pte_index = PTE64_INDEX(fault_addr);
55 struct v3_shadow_region * region = v3_get_shadow_region(info, fault_addr);
57 if ((region == NULL) ||
58 (region->host_type == SHDW_REGION_INVALID)) {
59 PrintError("Invalid region in passthrough page fault 64, addr=%p\n",
64 host_addr = v3_get_shadow_addr(region, fault_addr);
67 // Lookup the correct PML address based on the PAGING MODE
68 if (info->shdw_pg_mode == SHADOW_PAGING) {
69 pml = CR3_TO_PML4E64_VA(info->ctrl_regs.cr3);
71 pml = CR3_TO_PML4E64_VA(info->direct_map_pt);
74 //Fix up the PML entry
75 if (pml[pml_index].present == 0) {
76 pdpe = (pdpe64_t *)create_generic_pt_page();
78 // Set default PML Flags...
79 pml[pml_index].present = 1;
80 pml[pml_index].writable = 1;
81 pml[pml_index].user_page = 1;
83 pml[pml_index].pdp_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pdpe));
85 pdpe = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pml[pml_index].pdp_base_addr));
88 // Fix up the PDPE entry
89 if (pdpe[pdpe_index].present == 0) {
90 pde = (pde64_t *)create_generic_pt_page();
92 // Set default PDPE Flags...
93 pdpe[pdpe_index].present = 1;
94 pdpe[pdpe_index].writable = 1;
95 pdpe[pdpe_index].user_page = 1;
97 pdpe[pdpe_index].pd_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pde));
99 pde = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pdpe[pdpe_index].pd_base_addr));
103 // Fix up the PDE entry
104 if (pde[pde_index].present == 0) {
105 pte = (pte64_t *)create_generic_pt_page();
107 pde[pde_index].present = 1;
108 pde[pde_index].writable = 1;
109 pde[pde_index].user_page = 1;
111 pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
113 pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
117 // Fix up the PTE entry
118 if (pte[pte_index].present == 0) {
119 pte[pte_index].user_page = 1;
121 if (region->host_type == SHDW_REGION_ALLOCATED) {
123 pte[pte_index].present = 1;
124 pte[pte_index].writable = 1;
126 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
128 } else if (region->host_type == SHDW_REGION_WRITE_HOOK) {
130 pte[pte_index].present = 1;
131 pte[pte_index].writable = 0;
133 pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
135 } else if (region->host_type == SHDW_REGION_FULL_HOOK) {
137 return v3_handle_mem_full_hook(info, fault_addr, fault_addr, region, error_code);
140 PrintError("Unknown Region Type...\n");
145 if ( (region->host_type == SHDW_REGION_WRITE_HOOK) &&
146 (error_code.write == 1) ) {
147 return v3_handle_mem_wr_hook(info, fault_addr, fault_addr, region, error_code);