Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


9a6eeed9da8c1d8a4e5ca90f5b8f9fe5e7d97ced
[palacios.git] / palacios / src / palacios / vmm_direct_paging_64.h
1 /*
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.
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at
8  * http://www.v3vee.org
9  *
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.
14  *
15  * Author: Steven Jaconette <stevenjaconette2007@u.northwestern.edu>
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #ifndef __VMM_DIRECT_PAGING_64_H__
22 #define __VMM_DIRECT_PAGING_64_H__
23
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>
29
30 #ifndef DEBUG_NESTED_PAGING
31 #undef PrintDebug
32 #define PrintDebug(fmt, args...)
33 #endif
34
35
36 static inline int handle_passthrough_pagefault_64(struct guest_info * info, 
37                                                      addr_t fault_addr, 
38                                                      pf_error_t error_code) {
39     pml4e64_t * pml = NULL;
40     pdpe64_t * pdpe = NULL;
41     pde64_t * pde = NULL;
42     pte64_t * pte = NULL;
43     addr_t host_addr = 0;
44
45     int pml_index = PML4E64_INDEX(fault_addr);
46     int pdpe_index = PDPE64_INDEX(fault_addr);
47     int pde_index = PDE64_INDEX(fault_addr);
48     int pte_index = PTE64_INDEX(fault_addr);
49
50
51     
52
53     struct v3_shadow_region * region =  v3_get_shadow_region(info, fault_addr);
54   
55     if ((region == NULL) || 
56         (region->host_type == SHDW_REGION_INVALID)) {
57         PrintError("Invalid region in passthrough page fault 64, addr=%p\n", 
58                    (void *)fault_addr);
59         return -1;
60     }
61
62     host_addr = v3_get_shadow_addr(region, fault_addr);
63     //
64
65     // Lookup the correct PML address based on the PAGING MODE
66     if (info->shdw_pg_mode == SHADOW_PAGING) {
67         pml = CR3_TO_PML4E64_VA(info->ctrl_regs.cr3);
68     } else {
69         pml = CR3_TO_PML4E64_VA(info->direct_map_pt);
70     }
71
72     //Fix up the PML entry
73     if (pml[pml_index].present == 0) {
74         pdpe = (pdpe64_t *)create_generic_pt_page();
75    
76         // Set default PML Flags...
77         pml[pml_index].present = 1;
78         pml[pml_index].writable = 1;
79         pml[pml_index].user_page = 1;
80
81         pml[pml_index].pdp_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pdpe));    
82     } else {
83         pdpe = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pml[pml_index].pdp_base_addr));
84     }
85
86     // Fix up the PDPE entry
87     if (pdpe[pdpe_index].present == 0) {
88         pde = (pde64_t *)create_generic_pt_page();
89         
90         // Set default PDPE Flags...
91         pdpe[pdpe_index].present = 1;
92         pdpe[pdpe_index].writable = 1;
93         pdpe[pdpe_index].user_page = 1;
94
95         pdpe[pdpe_index].pd_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pde));    
96     } else {
97         pde = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pdpe[pdpe_index].pd_base_addr));
98     }
99
100
101     // Fix up the PDE entry
102     if (pde[pde_index].present == 0) {
103         pte = (pte64_t *)create_generic_pt_page();
104         
105         pde[pde_index].present = 1;
106         pde[pde_index].writable = 1;
107         pde[pde_index].user_page = 1;
108         
109         pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
110     } else {
111         pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
112     }
113
114
115     // Fix up the PTE entry
116     if (pte[pte_index].present == 0) {
117         pte[pte_index].user_page = 1;
118         
119         if (region->host_type == SHDW_REGION_ALLOCATED) {
120             // Full access
121             pte[pte_index].present = 1;
122             pte[pte_index].writable = 1;
123
124             pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
125             
126         } else if (region->host_type == SHDW_REGION_WRITE_HOOK) {
127             // Only trap writes
128             pte[pte_index].present = 1; 
129             pte[pte_index].writable = 0;
130
131             pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
132
133         } else if (region->host_type == SHDW_REGION_FULL_HOOK) {
134             // trap all accesses
135             return v3_handle_mem_full_hook(info, fault_addr, fault_addr, region, error_code);
136
137         } else {
138             PrintError("Unknown Region Type...\n");
139             return -1;
140         }
141     }
142    
143     if ( (region->host_type == SHDW_REGION_WRITE_HOOK) && 
144          (error_code.write == 1) ) {
145         return v3_handle_mem_wr_hook(info, fault_addr, fault_addr, region, error_code);
146     }
147
148     return 0;
149 }
150
151
152 #endif