VM Lecture 2 2 SystemVirtualizationMemory
VM Lecture 2 2 SystemVirtualizationMemory
VM Lecture 2 2 SystemVirtualizationMemory
Virtualization Technique
System Virtualization
Memory Virtualization
Agenda
• Basic concept of memory management
• Brief introduction to ARM v7 AMSA
• Memory Virtualization
Shadow page table
Hardware assistance
Comparison
BASIC CONCEPT OF MEMORY MAN
AGEMENT
Memory Management Unit
• A hardware component responsible for handling acces
ses to memory requested by the CPU
Address translation: virtual address to physical address (VA t
o PA)
Memory protection
Cache control
Bus arbitration
• Page tables are maintained by operating system, and M
MU only references them.
• TLB updates are performed automatically by page-tabl
e walking hardware
Page Tables
• A page table is the data structure used by a virtual
memory system to store the mapping between virt
ual addresses and physical addresses
• Translation table base register(TTBR)
Also called page table base register
A register that stores the address of the base page table
for MMU
TLB
• Translation look-aside buffer
A CPU cache that memory management hardware uses to improve
virtual address translation speed
The TLB is typically implemented as content-addressable memory
(CAM)
The CAM search key is the virtual address and the search result is a
physical address
BRIEF INTRODUCTION TO ARMV7 V
MSA
ARMv7 VMSA
• VMSA: Virtual memory system architecture
• Support four mapping types
16MB Super section
1MB Section
64KB Large page
4KB Small page
• L1 descriptor[1:0]
0b00, invalid or fault entry
• Translation fault
0b01, page table
• Address of 2nd level translation table
0b10, section of super-section
0b11, special usage with PXN attribute
1st Page Table Descriptor
L2 Page Table
• Second-level tables
The base address and translation properties for a Small
page or a Large page.
That is, page tables
1KB
• L2 descriptor[1:0]
0b00, invalid or fault entry
• Translation fault
0b01, large page
0b1x, small page
2nd Page Table Descriptor
Concepts
Shadow page table
Hardware assistance
Comparison
MEMORY VIRTUALIZATION
Memory Management on a VM
• Traditionally, OS fully controls all physical memor
y space and provides a continuous addressing spa
ce to each process
• Guest OS is just one of user space processes of hos
t OS
• If guest OS is allowed to access the physical memo
ry arbitrarily, then what happens?
• In system virtualization, VMM should make all virt
ual machines share the physical memory space
Memory Virtualization
• Memory virtualization architecture
15
Memory Virtualization
• The performance drop of memory access is usually unb
earable. VMM needs further optimization.
16
Goals of Memory Virtualization
• Address Translation
Control table-walking hardware that accesses translation tables in main memory.
• Memory Protection
Define access permission which uses the Access Control Hardware.
• Access Attribute
Define attribute and type of memory region to direct how memory operation to b
e handled.
• How to implement?
Software solution: shadow page table
Hardware solution
• NPT on SVM from AMD
• EPT on VMX from Intel
• ARM v7 VMSA (Virtual Memory System Architecture) with virtualization extension
Concepts
Shadow page table
Hardware assistance
Comparison
MEMORY VIRTUALIZATION
Shadow Page Table
• Map guest virtual address to host physical address
Shadow page table
• Guest OS will maintain its own virtual memory page table in the gu
est physical memory frames.
• For each guest physical memory frame, VMM should map it to hos
t physical memory frame.
• Shadow page table maintains the mapping from guest virtual addr
ess to host physical address.
Page table protection
• VMM will apply write protection to all the physical frames of guest
page tables, which lead the guest page table write exception and tr
ap to VMM.
Shadow Page Table: Overview
Shadow Page Table
• How does this technique work ?
VMM should make MMU virtualized
• VMM manages the real PTBR and a virtual PTBR for each VM
• When a guest OS is activated, the real PTBR points to the corresponding shadow
page table of the guest OS
• When the guest OS attempts to modify the PTBR, it will be intercepted by VMM
for further emulation
Shadow Page Table
• Construct shadow page table
Guest OS will maintain its own page table for each process.
VMM maps each guest physical page to host physical page.
Create shadow page tables for each guest page table.
VMM should protect host frame which contains guest page table. (that
means to write protect the guest page tables in host memory)
Write protection
Shadow Page Table
• Implement with PTBR :
For example, process 2 in guest OS wants to access its me
mory whose page number is 1.
SPT Maintenance
• If guest OS modify one of its page tables, then the correspo
nding entry of SPT must be updated.
We call it “shadow” because SPT is just like the shadow of page ta
bles of guest OS.
Access
PABT / DABT
Trap Real MMU Behavior Shadow Table Behavior
1 2 3 Initial Synchronization
Guest Guest MMIO Shadow Page Shadow Page
Page Table Permission Access Table Table
Walker Checker Checker Mapping Update
PABT / DABT
Trap
1
Guest Guest MMIO Shadow Page Shadow Page
Page Table Permission Access Table Table
Walker Checker Checker Mapping Update
PABT / DABT
Trap
2
Guest Guest MMIO Shadow Page Shadow Page
Page Table Permission Access Table Table
Walker Checker Checker Mapping Update
PABT / DABT
Trap
3
Guest Guest MMIO Shadow Page Shadow Page
Page Table Permission Access Table Table
Walker Checker Checker Mapping Update
PABT / DABT
Trap
4 5
Shadow
Kernel space table
Shadow The shadow tables of kernel space
table are shared by all guest processes
User space
Shadow
table
Other Issues
• Page fault and page protection issue
When a physical page fault occurs, VMM needs to decide
whether this exception should be injected to guest OS or
not
• If the page entry in a guest page table is still valid, VMM prepares f
or the corresponding page and does not inject any exception to gu
est OS.
• If the page entry in a guest page table is invalid, then VMM directl
y injects the virtual page fault to guest OS.
Concepts
Shadow page table
Hardware assistance
Comparison
MEMORY VIRTUALIZATION
Hardware Assistance: Overview
Hardware Solution
• Difficulties of shadow page table technique :
Shadow page table implementation is extremely complex.
Page fault mechanism and synchronization issues are critical.
Host memory space overhead is considerable.
MEMORY VIRTUALIZATION
Question
• Computer architecture with virtualization extensio
n is a trend.
• Hardware assistance
Extended page table
• Hardware walk guest and host page table simultaneously
Reference
• Selective hardware/software memory virtualizatio
n
http://www.cs.mtu.edu/~zlwang/papers/vee11.pdf
• ARM® Architecture Reference Manual: ARMv7-A a
nd ARMv7-R edition