9
9
********
10
10
11
11
The hypervisor (HV) virtualizes real physical memory so an unmodified OS
12
- (such as Linux or Android) running in a virtual machine, has the view of
12
+ (such as Linux or Android), running in a virtual machine, has the view of
13
13
managing its own contiguous physical memory. HV uses virtual-processor
14
14
identifiers (VPIDs) and the extended page-table mechanism (EPT) to
15
15
translate guest-physical address into host-physical address. HV enables
@@ -22,8 +22,7 @@ consider. From the hypervisor's point of view there are:
22
22
23
23
- **Host Physical Address (HPA) **: the native physical address space, and
24
24
- **Host Virtual Address (HVA) **: the native virtual address space based on
25
- a MMU. A page table is used to translate between HPA and HVA
26
- spaces.
25
+ a MMU. A page table is used to translate from HVA to HPA spaces.
27
26
28
27
From the Guest OS running on a hypervisor there are:
29
28
@@ -62,7 +61,10 @@ Hypervisor Physical Memory Management
62
61
In the ACRN, the HV initializes MMU page tables to manage all physical
63
62
memory and then switches to the new MMU page tables. After MMU page
64
63
tables are initialized at the platform initialization stage, no updates
65
- are made for MMU page tables.
64
+ are made for MMU page tables except hv_access_memory_region_update is called.
65
+ However, the memory region updated by hv_access_memory_region_update
66
+ must not be accessed by ACRN hypervisor in advance. Because access could
67
+ make mapping in TLB and there is no TLB flush mechanism for ACRN hv memory.
66
68
67
69
Hypervisor Physical Memory Layout - E820
68
70
========================================
@@ -91,9 +93,12 @@ Hypervisor Memory Initialization
91
93
92
94
The ACRN hypervisor runs under paging mode. After the bootstrap
93
95
processor (BSP) gets the platform E820 table, BSP creates its MMU page
94
- table based on it. This is done by the function *init_paging() * and
95
- *smep() *. After the application processor (AP) receives IPI CPU startup
96
- interrupt, it uses the MMU page tables created by BSP and enable SMEP.
96
+ table based on it. This is done by the function *init_paging() *.
97
+ After the application processor (AP) receives IPI CPU startup
98
+ interrupt, it uses the MMU page tables created by BSP. In order to bring
99
+ the memory access rights into effect, some other APIs are provided:
100
+ enable_paging will enable IA32_EFER.NXE and CR0.WP, enable_smep will
101
+ enable CR4.SMEP and enable_smap will enale CR4.SMAP.
97
102
:numref: `hv-mem-init ` describes the hypervisor memory initialization for BSP
98
103
and APs.
99
104
@@ -107,8 +112,14 @@ The memory mapping policy used is:
107
112
108
113
- Identical mapping (ACRN hypervisor memory could be relocatable in
109
114
the future)
110
- - Map all memory regions with UNCACHED type
111
- - Remap RAM regions to WRITE-BACK type
115
+ - Map all the address space with UNCACHED type, read/write, user
116
+ and execute-disable access right
117
+ - Remap [0, low32_max_ram) regions to WRITE-BACK type
118
+ - Remap [4G, high64_max_ram) regions to WRITE-BACK type
119
+ - set the paging-structure entries' U/S flag to
120
+ supervisor-mode for hypervisor owned memroy
121
+ (exclude the memory reserve for trusty)
122
+ - remove 'NX' bit for pages that contain hv code section
112
123
113
124
.. figure :: images/mem-image69.png
114
125
:align: center
@@ -125,17 +136,16 @@ The memory mapping policy used is:
125
136
code/data (< 1M part is for secondary CPU reset code)
126
137
127
138
The hypervisor should use minimum memory pages to map from virtual
128
- address space into physical address space.
139
+ address space into physical address space. So ACRN only support
140
+ map linear addresses to 2-MByte pages, or 1-GByte pages, doesn't
141
+ support map linear addresses to 4-KByte pages.
129
142
130
143
- If 1GB hugepage can be used
131
144
for virtual address space mapping, the corresponding PDPT entry shall be
132
145
set for this 1GB hugepage.
133
146
- If 1GB hugepage can't be used for virtual
134
147
address space mapping and 2MB hugepage can be used, the corresponding
135
148
PDT entry shall be set for this 2MB hugepage.
136
- - If both of 1GB hugepage
137
- and 2MB hugepage can't be used for virtual address space mapping, the
138
- corresponding PT entry shall be set.
139
149
140
150
If memory type or access rights of a page is updated, or some virtual
141
151
address space is deleted, it will lead to splitting of the corresponding
@@ -145,10 +155,9 @@ virtual address space into physical address space.
145
155
Memory Pages Pool Functions
146
156
===========================
147
157
148
- Memory pages pool functions provide dynamic management of multiple
149
- 4KB page-size memory blocks, used by the hypervisor to store internal
150
- data. Through these functions, the hypervisor can allocate and
151
- deallocate pages.
158
+ Memory pages pool functions provide static management of one
159
+ 4KB page-size memory block for each page level for each VM or HV,
160
+ used by the hypervisor to do memory mapping.
152
161
153
162
Data Flow Design
154
163
================
@@ -175,6 +184,9 @@ MMU Initialization
175
184
.. doxygenfunction :: enable_smep
176
185
:project: Project ACRN
177
186
187
+ .. doxygenfunction :: enable_smap
188
+ :project: Project ACRN
189
+
178
190
.. doxygenfunction :: enable_paging
179
191
:project: Project ACRN
180
192
@@ -184,6 +196,12 @@ MMU Initialization
184
196
Address Space Translation
185
197
-------------------------
186
198
199
+ .. doxygenfunction :: hpa2hva_early
200
+ :project: Project ACRN
201
+
202
+ .. doxygenfunction :: hva2hpa_early
203
+ :project: Project ACRN
204
+
187
205
.. doxygenfunction :: hpa2hva
188
206
:project: Project ACRN
189
207
@@ -268,8 +286,8 @@ hypervisor should still keep to using minimum EPT pages to map from GPA
268
286
space into HPA space.
269
287
270
288
The hypervisor provides EPT guest-physical mappings adding service, EPT
271
- guest-physical mappings modifying/deleting service, EPT page tables
272
- deallocation, and EPT guest-physical mappings invalidation service.
289
+ guest-physical mappings modifying/deleting service and EPT guest-physical
290
+ mappings invalidation service.
273
291
274
292
Virtual MTRR
275
293
************
420
438
.. doxygenfunction :: ept_misconfig_vmexit_handler
421
439
:project: Project ACRN
422
440
441
+ .. doxygenfunction :: ept_flush_leaf_page
442
+ :project: Project ACRN
443
+
444
+ .. doxygenfunction :: get_ept_entry
445
+ :project: Project ACRN
446
+
447
+ .. doxygenfunction :: walk_ept_table
448
+ :project: Project ACRN
449
+
423
450
Virtual MTRR
424
451
------------
425
452
@@ -469,21 +496,22 @@ almost all the system memory as shown here:
469
496
Host to Guest Mapping
470
497
=====================
471
498
472
- ACRN hypervisor creates Service OS's host (HPA ) to guest (GPA ) mapping
499
+ ACRN hypervisor creates Service OS's guest (GPA ) to host (HPA ) mapping
473
500
(EPT mapping) through the function ``prepare_sos_vm_memmap() ``
474
501
when it creates the SOS VM. It follows these rules:
475
502
476
503
- Identical mapping
477
504
- Map all memory range with UNCACHED type
478
505
- Remap RAM entries in E820 (revised) with WRITE-BACK type
479
506
- Unmap ACRN hypervisor memory range
507
+ - Unmap all platform EPC resource
480
508
- Unmap ACRN hypervisor emulated vLAPIC/vIOAPIC MMIO range
481
509
482
- The host to guest mapping is static for the Service OS; it will not
483
- change after the Service OS begins running. Each native device driver
484
- can access its MMIO through this static mapping . EPT violation is only
485
- serving for vLAPIC/vIOAPIC's emulation in the hypervisor for Service OS
486
- VM.
510
+ The guest to host mapping is static for the Service OS; it will not
511
+ change after the Service OS begins running except the PCI device BAR
512
+ address mapping could be re-programmed by the Service OS . EPT violation
513
+ is serving for vLAPIC/vIOAPIC's emulation or PCI MSI-X table BAR's emulation
514
+ in the hypervisor for Service OS VM.
487
515
488
516
Trusty
489
517
******
0 commit comments