Skip to content

Commit 7c3c6ea

Browse files
Xiangyang Wudbkinder
authored andcommitted
HV:MM:add API docs
This patch adds more comment to describe functions that are interfaces to the other modules in the hypervisor. The comments are in doxygen-style for document generation. V1-->V2: Rebase Tracked-On: #1595 Signed-off-by: Xiangyang Wu <xiangyang.wu@linux.intel.com>
1 parent 17d43fe commit 7c3c6ea

File tree

4 files changed

+294
-14
lines changed

4 files changed

+294
-14
lines changed

hypervisor/include/arch/x86/guest/guest.h

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
6-
6+
/**
7+
* @file guest.h
8+
*
9+
* @brief Data transferring between hypervisor and VM
10+
*/
711
#ifndef GUEST_H
812
#define GUEST_H
913

@@ -142,29 +146,84 @@ int general_sw_loader(struct vm *vm);
142146

143147
typedef int (*vm_sw_loader_t)(struct vm *vm);
144148
extern vm_sw_loader_t vm_sw_loader;
145-
146-
/* @pre Caller(Guest) should make sure gpa is continuous.
149+
/**
150+
* @brief Data transfering between hypervisor and VM
151+
*
152+
* @defgroup acrn_mem ACRN Memory Management
153+
* @{
154+
*/
155+
/**
156+
* @brief Copy data from VM GPA space to HV address space
157+
*
158+
* @param[in] vm The pointer that points to VM data structure
159+
* @param[in] h_ptr The pointer that points the start HV address
160+
* of HV memory region which data is stored in
161+
* @param[out] gpa The start GPA address of GPA memory region which data
162+
* will be copied into
163+
* @param[in] size The size (bytes) of GPA memory region which data is
164+
* stored in
165+
*
166+
* @pre Caller(Guest) should make sure gpa is continuous.
147167
* - gpa from hypercall input which from kernel stack is gpa continuous, not
148168
* support kernel stack from vmap
149169
* - some other gpa from hypercall parameters, VHM should make sure it's
150170
* continuous
151171
* @pre Pointer vm is non-NULL
152172
*/
153173
int copy_from_gpa(struct vm *vm, void *h_ptr, uint64_t gpa, uint32_t size);
154-
/* @pre Caller(Guest) should make sure gpa is continuous.
174+
/**
175+
* @brief Copy data from HV address space to VM GPA space
176+
*
177+
* @param[in] vm The pointer that points to VM data structure
178+
* @param[in] h_ptr The pointer that points the start HV address
179+
* of HV memory region which data is stored in
180+
* @param[out] gpa The start GPA address of GPA memory region which data
181+
* will be copied into
182+
* @param[in] size The size (bytes) of GPA memory region which data will be
183+
* copied into
184+
*
185+
* @pre Caller(Guest) should make sure gpa is continuous.
155186
* - gpa from hypercall input which from kernel stack is gpa continuous, not
156187
* support kernel stack from vmap
157188
* - some other gpa from hypercall parameters, VHM should make sure it's
158189
* continuous
159190
* @pre Pointer vm is non-NULL
160191
*/
161192
int copy_to_gpa(struct vm *vm, void *h_ptr, uint64_t gpa, uint32_t size);
193+
/**
194+
* @brief Copy data from VM GVA space to HV address space
195+
*
196+
* @param[in] vcpu The pointer that points to vcpu data structure
197+
* @param[out] h_ptr The pointer that returns the start HV address
198+
* of HV memory region which data will be copied to
199+
* @param[in] gva The start GVA address of GVA memory region which data
200+
* is stored in
201+
* @param[in] size The size (bytes) of GVA memory region which data is
202+
* stored in
203+
* @param[out] err_code The page fault flags
204+
* @param[out] fault_addr The GVA address that causes a page fault
205+
*/
162206
int copy_from_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva,
163207
uint32_t size, uint32_t *err_code, uint64_t *fault_addr);
208+
/**
209+
* @brief Copy data from HV address space to VM GVA space
210+
*
211+
* @param[in] vcpu The pointer that points to vcpu data structure
212+
* @param[in] h_ptr The pointer that points the start HV address
213+
* of HV memory region which data is stored in
214+
* @param[out] gva The start GVA address of GVA memory region which data
215+
* will be copied into
216+
* @param[in] size The size (bytes) of GVA memory region which data will
217+
* be copied into
218+
* @param[out] err_code The page fault flags
219+
* @param[out] fault_addr The GVA address that causes a page fault
220+
*/
164221
int copy_to_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva,
165222
uint32_t size, uint32_t *err_code, uint64_t *fault_addr);
166223
extern struct acrn_vcpu_regs vm0_boot_context;
167-
224+
/**
225+
* @}
226+
*/
168227
#endif /* !ASSEMBLER */
169228

170229
#endif /* GUEST_H*/

hypervisor/include/arch/x86/mmu.h

Lines changed: 164 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
6-
6+
/**
7+
* @file mmu.h
8+
*
9+
* @brief APIs for Memory Management module
10+
*/
711
#ifndef MMU_H
812
#define MMU_H
9-
13+
/**
14+
* @brief Memory Management
15+
*
16+
* @defgroup acrn_mem ACRN Memory Management
17+
* @{
18+
*/
1019
/** The flag that indicates that the page fault was caused by a non present
1120
* page.
1221
*/
@@ -54,11 +63,25 @@ static inline uint64_t round_page_down(uint64_t addr)
5463
return (addr & CPU_PAGE_MASK);
5564
}
5665

57-
/* Represent the 4 levels of translation tables in IA-32e paging mode */
66+
/**
67+
* @brief Page tables level in IA32 paging mode
68+
*/
5869
enum _page_table_level {
70+
/**
71+
* @brief The PML4 level in the page tables
72+
*/
5973
IA32E_PML4 = 0,
74+
/**
75+
* @brief The Page-Directory-Pointer-Table level in the page tables
76+
*/
6077
IA32E_PDPT = 1,
78+
/**
79+
* @brief The Page-Directory level in the page tables
80+
*/
6181
IA32E_PD = 2,
82+
/**
83+
* @brief The Page-Table level in the page tables
84+
*/
6285
IA32E_PT = 3,
6386
};
6487

@@ -69,18 +92,74 @@ enum _page_table_level {
6992

7093
void sanitize_pte_entry(uint64_t *ptep);
7194
void sanitize_pte(uint64_t *pt_page);
95+
/**
96+
* @brief MMU paging enable
97+
*
98+
* @return None
99+
*/
72100
void enable_paging(void);
101+
/**
102+
* @brief Supervisor-mode execution prevention (SMEP) enable
103+
*
104+
* @return None
105+
*/
73106
void enable_smep(void);
107+
/**
108+
* @brief MMU page tables initialization
109+
*
110+
* @return None
111+
*/
74112
void init_paging(void);
75113
void mmu_add(uint64_t *pml4_page, uint64_t paddr_base, uint64_t vaddr_base,
76114
uint64_t size, uint64_t prot, const struct memory_ops *mem_ops);
77115
void mmu_modify_or_del(uint64_t *pml4_page, uint64_t vaddr_base, uint64_t size,
78116
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+
*/
79123
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+
*/
80130
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+
*/
81138
void flush_vpid_single(uint16_t vpid);
139+
/**
140+
* @brief All VPID flush
141+
*
142+
* @return None
143+
*/
82144
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+
*/
83152
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+
*/
84163
bool check_continuous_hpa(struct vm *vm, uint64_t gpa_arg, uint64_t size_arg);
85164
/**
86165
*@pre (pml4_page != NULL) && (pg_size != NULL)
@@ -128,33 +207,115 @@ static inline void clflush(volatile void *p)
128207
#define INVALID_HPA (0x1UL << 52U)
129208
#define INVALID_GPA (0x1UL << 52U)
130209
/* 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+
*/
131217
void destroy_ept(struct vm *vm);
132218
/**
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+
*
133224
* @return INVALID_HPA - the HPA of parameter gpa is unmapping
134225
* @return hpa - the HPA of parameter gpa is hpa
135226
*/
136227
uint64_t gpa2hpa(struct vm *vm, uint64_t gpa);
137228
/**
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+
*
138236
* @return INVALID_HPA - the HPA of parameter gpa is unmapping
139237
* @return hpa - the HPA of parameter gpa is hpa
140238
*/
141239
uint64_t local_gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size);
142240
/**
241+
* @brief Translating from host-physical address to guest-physical address for VM0
242+
*
243+
* @param[in] hpa the specified host-physical address
244+
*
143245
* @pre: the gpa and hpa are identical mapping in SOS.
144246
*/
145247
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+
*/
146263
void ept_mr_add(struct vm *vm, uint64_t *pml4_page, uint64_t hpa,
147264
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+
*/
148280
void ept_mr_modify(struct vm *vm, uint64_t *pml4_page, uint64_t gpa,
149281
uint64_t size, uint64_t prot_set, uint64_t prot_clr);
150282
/**
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+
*
151293
* @pre [gpa,gpa+size) has been mapped into host physical memory region
152294
*/
153295
void ept_mr_del(struct vm *vm, uint64_t *pml4_page, uint64_t gpa,
154296
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+
*/
155305
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+
*/
156314
int ept_misconfig_vmexit_handler(__unused struct vcpu *vcpu);
157315

316+
/**
317+
* @}
318+
*/
158319
#endif /* ASSEMBLER not defined */
159320

160321
#endif /* MMU_H */

hypervisor/include/arch/x86/mtrr.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22
* Copyright (C) <2018> Intel Corporation
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5-
5+
/**
6+
* @file mtrr.h
7+
*
8+
* @brief MTRR Virtualization
9+
*/
610
#ifndef MTRR_H
711
#define MTRR_H
8-
12+
/**
13+
* @brief MTRR Virtualization
14+
*
15+
* @addtogroup acrn_mem ACRN Memory Management
16+
* @{
17+
*/
918
#define FIXED_RANGE_MTRR_NUM 11U
1019
#define MTRR_SUB_RANGE_NUM 8U
1120

@@ -44,8 +53,34 @@ struct mtrr_state {
4453
union mtrr_fixed_range_reg fixed_range[FIXED_RANGE_MTRR_NUM];
4554
};
4655

56+
/**
57+
* @brief Virtual MTRR MSR write
58+
*
59+
* @param[inout] vcpu The pointer that points VCPU data structure
60+
* @param[in] msr Virtual MTRR MSR Address
61+
* @param[in] value The value that will be writen into virtual MTRR MSR
62+
*
63+
* @return None
64+
*/
4765
void mtrr_wrmsr(struct vcpu *vcpu, uint32_t msr, uint64_t value);
66+
/**
67+
* @brief Virtual MTRR MSR read
68+
*
69+
* @param[in] vcpu The pointer that points VCPU data structure
70+
* @param[in] msr Virtual MTRR MSR Address
71+
*
72+
* @return unsigned long integer - The specified virtual MTRR MSR value
73+
*/
4874
uint64_t mtrr_rdmsr(const struct vcpu *vcpu, uint32_t msr);
75+
/**
76+
* @brief Virtual MTRR initialization
77+
*
78+
* @param[inout] vcpu The pointer that points VCPU data structure
79+
*
80+
* @return None
81+
*/
4982
void init_mtrr(struct vcpu *vcpu);
50-
83+
/**
84+
* @}
85+
*/
5186
#endif /* MTRR_H */

0 commit comments

Comments
 (0)