3
3
*
4
4
* SPDX-License-Identifier: BSD-3-Clause
5
5
*/
6
-
6
+ /**
7
+ * @file mmu.h
8
+ *
9
+ * @brief APIs for Memory Management module
10
+ */
7
11
#ifndef MMU_H
8
12
#define MMU_H
9
-
13
+ /**
14
+ * @brief Memory Management
15
+ *
16
+ * @defgroup acrn_mem ACRN Memory Management
17
+ * @{
18
+ */
10
19
/** The flag that indicates that the page fault was caused by a non present
11
20
* page.
12
21
*/
@@ -54,11 +63,25 @@ static inline uint64_t round_page_down(uint64_t addr)
54
63
return (addr & CPU_PAGE_MASK );
55
64
}
56
65
57
- /* Represent the 4 levels of translation tables in IA-32e paging mode */
66
+ /**
67
+ * @brief Page tables level in IA32 paging mode
68
+ */
58
69
enum _page_table_level {
70
+ /**
71
+ * @brief The PML4 level in the page tables
72
+ */
59
73
IA32E_PML4 = 0 ,
74
+ /**
75
+ * @brief The Page-Directory-Pointer-Table level in the page tables
76
+ */
60
77
IA32E_PDPT = 1 ,
78
+ /**
79
+ * @brief The Page-Directory level in the page tables
80
+ */
61
81
IA32E_PD = 2 ,
82
+ /**
83
+ * @brief The Page-Table level in the page tables
84
+ */
62
85
IA32E_PT = 3 ,
63
86
};
64
87
@@ -69,18 +92,74 @@ enum _page_table_level {
69
92
70
93
void sanitize_pte_entry (uint64_t * ptep );
71
94
void sanitize_pte (uint64_t * pt_page );
95
+ /**
96
+ * @brief MMU paging enable
97
+ *
98
+ * @return None
99
+ */
72
100
void enable_paging (void );
101
+ /**
102
+ * @brief Supervisor-mode execution prevention (SMEP) enable
103
+ *
104
+ * @return None
105
+ */
73
106
void enable_smep (void );
107
+ /**
108
+ * @brief MMU page tables initialization
109
+ *
110
+ * @return None
111
+ */
74
112
void init_paging (void );
75
113
void mmu_add (uint64_t * pml4_page , uint64_t paddr_base , uint64_t vaddr_base ,
76
114
uint64_t size , uint64_t prot , const struct memory_ops * mem_ops );
77
115
void mmu_modify_or_del (uint64_t * pml4_page , uint64_t vaddr_base , uint64_t size ,
78
116
uint64_t prot_set , uint64_t prot_clr , const struct memory_ops * mem_ops , uint32_t type );
117
+ /**
118
+ * @brief EPT and VPID capability checking
119
+ *
120
+ * @return 0 - on success
121
+ * @return -ENODEV - Don't support EPT or VPID capability
122
+ */
79
123
int check_vmx_mmu_cap (void );
124
+ /**
125
+ * @brief VPID allocation
126
+ *
127
+ * @return 0 - VPID overflow
128
+ * @return more than 0 - the valid VPID
129
+ */
80
130
uint16_t allocate_vpid (void );
131
+ /**
132
+ * @brief Specified signle VPID flush
133
+ *
134
+ * @param[in] vpid the specified VPID
135
+ *
136
+ * @return None
137
+ */
81
138
void flush_vpid_single (uint16_t vpid );
139
+ /**
140
+ * @brief All VPID flush
141
+ *
142
+ * @return None
143
+ */
82
144
void flush_vpid_global (void );
145
+ /**
146
+ * @brief Guest-physical mappings and combined mappings invalidation
147
+ *
148
+ * @param[in] vcpu the pointer that points the vcpu data structure
149
+ *
150
+ * @return None
151
+ */
83
152
void invept (const struct vcpu * vcpu );
153
+ /**
154
+ * @brief Host-physical address continous checking
155
+ *
156
+ * @param[in] vm the pointer that points the VM data structure
157
+ * @param[in] gpa_arg the start GPA address of the guest memory region
158
+ * @param[in] size_arg the size of the guest memory region
159
+ *
160
+ * @return true - The HPA of the guest memory region is continuous
161
+ * @return false - The HPA of the guest memory region is non-continuous
162
+ */
84
163
bool check_continuous_hpa (struct vm * vm , uint64_t gpa_arg , uint64_t size_arg );
85
164
/**
86
165
*@pre (pml4_page != NULL) && (pg_size != NULL)
@@ -128,33 +207,115 @@ static inline void clflush(volatile void *p)
128
207
#define INVALID_HPA (0x1UL << 52U)
129
208
#define INVALID_GPA (0x1UL << 52U)
130
209
/* External Interfaces */
210
+ /**
211
+ * @brief EPT page tables destroy
212
+ *
213
+ * @param[inout] vm the pointer that points to VM data structure
214
+ *
215
+ * @return None
216
+ */
131
217
void destroy_ept (struct vm * vm );
132
218
/**
219
+ * @brief Translating from guest-physical address to host-physcial address
220
+ *
221
+ * @param[in] vm the pointer that points to VM data structure
222
+ * @param[in] gpa the specified guest-physical address
223
+ *
133
224
* @return INVALID_HPA - the HPA of parameter gpa is unmapping
134
225
* @return hpa - the HPA of parameter gpa is hpa
135
226
*/
136
227
uint64_t gpa2hpa (struct vm * vm , uint64_t gpa );
137
228
/**
229
+ * @brief Translating from guest-physical address to host-physcial address
230
+ *
231
+ * @param[in] vm the pointer that points to VM data structure
232
+ * @param[in] gpa the specified guest-physical address
233
+ * @param[out] size the pointer that returns the page size of
234
+ * the page in which the gpa is
235
+ *
138
236
* @return INVALID_HPA - the HPA of parameter gpa is unmapping
139
237
* @return hpa - the HPA of parameter gpa is hpa
140
238
*/
141
239
uint64_t local_gpa2hpa (struct vm * vm , uint64_t gpa , uint32_t * size );
142
240
/**
241
+ * @brief Translating from host-physical address to guest-physical address for VM0
242
+ *
243
+ * @param[in] hpa the specified host-physical address
244
+ *
143
245
* @pre: the gpa and hpa are identical mapping in SOS.
144
246
*/
145
247
uint64_t vm0_hpa2gpa (uint64_t hpa );
248
+ /**
249
+ * @brief Guest-physical memory region mapping
250
+ *
251
+ * @param[in] vm the pointer that points to VM data structure
252
+ * @param[in] pml4_page The physical address of The EPTP
253
+ * @param[in] hpa The specified start host physical address of host
254
+ * physical memory region that GPA will be mapped
255
+ * @param[in] gpa The specified start guest physical address of guest
256
+ * physical memory region that needs to be mapped
257
+ * @param[in] size The size of guest physical memory region that needs
258
+ * to be mapped
259
+ * @param[in] prot_orig The specified memory access right and memory type
260
+ *
261
+ * @return None
262
+ */
146
263
void ept_mr_add (struct vm * vm , uint64_t * pml4_page , uint64_t hpa ,
147
264
uint64_t gpa , uint64_t size , uint64_t prot_orig );
265
+ /**
266
+ * @brief Guest-physical memory page access right or memory type updating
267
+ *
268
+ * @param[in] vm the pointer that points to VM data structure
269
+ * @param[in] pml4_page The physical address of The EPTP
270
+ * @param[in] gpa The specified start guest physical address of guest
271
+ * physical memory region whoes mapping needs to be updated
272
+ * @param[in] size The size of guest physical memory region
273
+ * @param[in] prot_set The specified memory access right and memory type
274
+ * that will be set
275
+ * @param[in] prot_clr The specified memory access right and memory type
276
+ * that will be cleared
277
+ *
278
+ * @return None
279
+ */
148
280
void ept_mr_modify (struct vm * vm , uint64_t * pml4_page , uint64_t gpa ,
149
281
uint64_t size , uint64_t prot_set , uint64_t prot_clr );
150
282
/**
283
+ * @brief Guest-physical memory region unmapping
284
+ *
285
+ * @param[in] vm the pointer that points to VM data structure
286
+ * @param[in] pml4_page The physical address of The EPTP
287
+ * @param[in] gpa The specified start guest physical address of guest
288
+ * physical memory region whoes mapping needs to be deleted
289
+ * @param[in] size The size of guest physical memory region
290
+ *
291
+ * @return None
292
+ *
151
293
* @pre [gpa,gpa+size) has been mapped into host physical memory region
152
294
*/
153
295
void ept_mr_del (struct vm * vm , uint64_t * pml4_page , uint64_t gpa ,
154
296
uint64_t size );
297
+ /**
298
+ * @brief EPT violation handling
299
+ *
300
+ * @param[in] vcpu the pointer that points to vcpu data structure
301
+ *
302
+ * @return -EINVAL - fail to handle the EPT violation
303
+ * @return 0 - Success to handle the EPT violation
304
+ */
155
305
int ept_violation_vmexit_handler (struct vcpu * vcpu );
306
+ /**
307
+ * @brief EPT misconfiguration handling
308
+ *
309
+ * @param[in] vcpu the pointer that points to vcpu data structure
310
+ *
311
+ * @return -EINVAL - fail to handle the EPT misconfig
312
+ * @return 0 - Success to handle the EPT misconfig
313
+ */
156
314
int ept_misconfig_vmexit_handler (__unused struct vcpu * vcpu );
157
315
316
+ /**
317
+ * @}
318
+ */
158
319
#endif /* ASSEMBLER not defined */
159
320
160
321
#endif /* MMU_H */
0 commit comments