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.


a840c2b94564b95a1af2a2577adf4d2f43cf7727
[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
31 static inline int handle_passthrough_pagefault_64(struct guest_info * info, 
32                                                      addr_t fault_addr, 
33                                                      pf_error_t error_code) {
34   pml4e64_t * pml = CR3_TO_PML4E64_VA(info->ctrl_regs.cr3);
35   pdpe64_t * pdpe = NULL;
36   pde64_t * pde = NULL;
37   pte64_t * pte = NULL;
38   addr_t host_addr = 0;
39
40   int pml_index = PML4E64_INDEX(fault_addr);
41   int pdpe_index = PDPE64_INDEX(fault_addr);
42   int pde_index = PDE64_INDEX(fault_addr);
43   int pte_index = PTE64_INDEX(fault_addr);
44
45   struct v3_shadow_region * region =  v3_get_shadow_region(info, fault_addr);
46   
47   if ((region == NULL) || 
48       (region->host_type == SHDW_REGION_INVALID)) {
49     PrintError("Invalid region in passthrough page fault 64, addr=%p\n", 
50                (void *)fault_addr);
51     return -1;
52   }
53
54   host_addr = v3_get_shadow_addr(region, fault_addr);
55
56   //Fix up the PML entry
57   if (pml[pml_index].present == 0) {
58     pdpe = (pdpe64_t *)create_generic_pt_page();
59    
60     pml[pml_index].present = 1;
61     // Set default PML Flags...
62     pml[pml_index].pdp_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pdpe));    
63   } else {
64     pdpe = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pml[pml_index].pdp_base_addr));
65   }
66
67   // Fix up the PDPE entry
68   if (pdpe[pdpe_index].present == 0) {
69     pde = (pde64_t *)create_generic_pt_page();
70    
71     pdpe[pdpe_index].present = 1;
72     // Set default PDPE Flags...
73     pdpe[pdpe_index].pd_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pde));    
74   } else {
75     pde = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pdpe[pdpe_index].pd_base_addr));
76   }
77
78
79   // Fix up the PDE entry
80   if (pde[pde_index].present == 0) {
81     pte = (pte64_t *)create_generic_pt_page();
82
83     pde[pde_index].present = 1;
84     pde[pde_index].writable = 1;
85     pde[pde_index].user_page = 1;
86
87     pde[pde_index].pt_base_addr = PAGE_BASE_ADDR((addr_t)V3_PAddr(pte));
88   } else {
89     pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr));
90   }
91
92
93   // Fix up the PTE entry
94   if (pte[pte_index].present == 0) {
95     pte[pte_index].user_page = 1;
96
97     if (region->host_type == SHDW_REGION_ALLOCATED) {
98       // Full access
99       pte[pte_index].present = 1;
100       pte[pte_index].writable = 1;
101
102       pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
103
104     } else if (region->host_type == SHDW_REGION_WRITE_HOOK) {
105       // Only trap writes
106      pte[pte_index].present = 1; 
107      pte[pte_index].writable = 0;
108
109      pte[pte_index].page_base_addr = PAGE_BASE_ADDR(host_addr);
110
111     } else if (region->host_type == SHDW_REGION_FULL_HOOK) {
112       // trap all accesses
113       return v3_handle_mem_full_hook(info, fault_addr, fault_addr, region, error_code);
114
115     } else {
116       PrintError("Unknown Region Type...\n");
117       return -1;
118     }
119   }
120    
121   if ( (region->host_type == SHDW_REGION_WRITE_HOOK) && 
122        (error_code.write == 1) ) {
123     return v3_handle_mem_wr_hook(info, fault_addr, fault_addr, region, error_code);
124   }
125
126   return 0;
127 }
128
129
130 #endif