Skip to content

Commit ea601e4

Browse files
lifeixwenlingz
authored andcommitted
doc: update memory management hld
1. Some security features are added into ACRN HV memory management. 2. Dynamic memory allocation is removed. Instead, static memory page allocation is added. 3. The guest to host mapping is not static any more for Service OS after it begins running since the Service OS support PCI BAR re-pregramming now. Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent c8abc7c commit ea601e4

File tree

1 file changed

+53
-25
lines changed

1 file changed

+53
-25
lines changed

doc/developer-guides/hld/hv-memmgt.rst

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Overview
99
********
1010

1111
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
1313
managing its own contiguous physical memory. HV uses virtual-processor
1414
identifiers (VPIDs) and the extended page-table mechanism (EPT) to
1515
translate guest-physical address into host-physical address. HV enables
@@ -22,8 +22,7 @@ consider. From the hypervisor's point of view there are:
2222

2323
- **Host Physical Address (HPA)**: the native physical address space, and
2424
- **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.
2726

2827
From the Guest OS running on a hypervisor there are:
2928

@@ -62,7 +61,10 @@ Hypervisor Physical Memory Management
6261
In the ACRN, the HV initializes MMU page tables to manage all physical
6362
memory and then switches to the new MMU page tables. After MMU page
6463
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.
6668

6769
Hypervisor Physical Memory Layout - E820
6870
========================================
@@ -91,9 +93,12 @@ Hypervisor Memory Initialization
9193

9294
The ACRN hypervisor runs under paging mode. After the bootstrap
9395
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.
97102
:numref:`hv-mem-init` describes the hypervisor memory initialization for BSP
98103
and APs.
99104

@@ -107,8 +112,14 @@ The memory mapping policy used is:
107112

108113
- Identical mapping (ACRN hypervisor memory could be relocatable in
109114
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
112123

113124
.. figure:: images/mem-image69.png
114125
:align: center
@@ -125,17 +136,16 @@ The memory mapping policy used is:
125136
code/data (< 1M part is for secondary CPU reset code)
126137

127138
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.
129142

130143
- If 1GB hugepage can be used
131144
for virtual address space mapping, the corresponding PDPT entry shall be
132145
set for this 1GB hugepage.
133146
- If 1GB hugepage can't be used for virtual
134147
address space mapping and 2MB hugepage can be used, the corresponding
135148
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.
139149

140150
If memory type or access rights of a page is updated, or some virtual
141151
address space is deleted, it will lead to splitting of the corresponding
@@ -145,10 +155,9 @@ virtual address space into physical address space.
145155
Memory Pages Pool Functions
146156
===========================
147157

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.
152161

153162
Data Flow Design
154163
================
@@ -175,6 +184,9 @@ MMU Initialization
175184
.. doxygenfunction:: enable_smep
176185
:project: Project ACRN
177186

187+
.. doxygenfunction:: enable_smap
188+
:project: Project ACRN
189+
178190
.. doxygenfunction:: enable_paging
179191
:project: Project ACRN
180192

@@ -184,6 +196,12 @@ MMU Initialization
184196
Address Space Translation
185197
-------------------------
186198

199+
.. doxygenfunction:: hpa2hva_early
200+
:project: Project ACRN
201+
202+
.. doxygenfunction:: hva2hpa_early
203+
:project: Project ACRN
204+
187205
.. doxygenfunction:: hpa2hva
188206
:project: Project ACRN
189207

@@ -268,8 +286,8 @@ hypervisor should still keep to using minimum EPT pages to map from GPA
268286
space into HPA space.
269287

270288
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.
273291

274292
Virtual MTRR
275293
************
@@ -420,6 +438,15 @@ EPT
420438
.. doxygenfunction:: ept_misconfig_vmexit_handler
421439
:project: Project ACRN
422440

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+
423450
Virtual MTRR
424451
------------
425452

@@ -469,21 +496,22 @@ almost all the system memory as shown here:
469496
Host to Guest Mapping
470497
=====================
471498

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
473500
(EPT mapping) through the function ``prepare_sos_vm_memmap()``
474501
when it creates the SOS VM. It follows these rules:
475502

476503
- Identical mapping
477504
- Map all memory range with UNCACHED type
478505
- Remap RAM entries in E820 (revised) with WRITE-BACK type
479506
- Unmap ACRN hypervisor memory range
507+
- Unmap all platform EPC resource
480508
- Unmap ACRN hypervisor emulated vLAPIC/vIOAPIC MMIO range
481509

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.
487515

488516
Trusty
489517
******

0 commit comments

Comments
 (0)