x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 x86 Virtualization Hardware/Software Techniques Host/Guest Communication Corentin Derbois Marc Angel corentin@lse.epita.fr null@lse.epita.fr http://lse.epita.fr/ July 17, 2013
x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 1 Virtualization 101 Hardware/Software Techniques Host/Guest 2 Hardware/Software Techniques Communication 3 Host/Guest Communication
What? x86 Virtualization Corentin Derbois, Marc Angel • Single computer, multiple OSs • Hardware-level virtualization Virtualization 101 What Why • As opposed to OS-level virtualization How Hardware/Software • LXC, OpenVZ, FreeBSD jails. . . Techniques Host/Guest Communication
Why? x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 What Why How • Kernel Debugging Hardware/Software Techniques • Money Host/Guest Communication • Flexibility • . . .
How? x86 Virtualization Corentin Derbois, Marc Angel • Popek and Goldberg requirements Virtualization 101 • Fidelity What Why • Safety How Hardware/Software • Performance Techniques • Binary Translation Host/Guest Communication • VMware, VirtualBox, KQEMU • Paravirtualization • Xen • Full Virtualization • KVM, VMware, VirtualBox, Xen. . .
Instruction Set Virtualization x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software • Run the VMM at a higher level of privilege Techniques Instruction Set Virt. • trap-and-emulate Memory Virtualization I/O Virtualization • Sensitive instructions yield control to ring 0 Host/Guest Communication • The VMM emulates them • Some instructions do not trap (popf, sidt. . . ) • 17 of those
Software: Binary Translation x86 Virtualization • Replace critical instructions with traps Corentin Derbois, Marc Angel • Let the VMM emulate them • Run userland code “as is” Virtualization 101 • Need to emulate syscalls Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
Software: Paravirtualization x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
Intel & AMD Hardware Solution x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. • VT-x and AMD-v Memory Virtualization I/O Virtualization • One ring to rule them all Host/Guest Communication • new set of instructions at ring -1 • Guest OS goes back to ring 0
Intel: VMX x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
AMD: SVM x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
Intel & AMD Hardware Solution x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 • Add protection to specific instructions Hardware/Software Techniques Instruction Set Virt. • CPUID Memory Virtualization I/O Virtualization • LGDT Host/Guest • . . . Communication • Two ways to handle critical instructions • Trigger VMEXIT • Let the processor handle them directly
Hardware: VMEXIT & native x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. • Processor data are stored in specific data structures Memory Virtualization I/O Virtualization • AMD: VMCB Host/Guest Communication • Intel: VMCS • Store to CRx, GDT, selectors. . .
Hardware: VMEXIT & native x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software • Some behaviors can’t be automatically handled by the Techniques Instruction Set Virt. CPU Memory Virtualization I/O Virtualization • I/O Host/Guest • CPUID Communication • PageFault • In this case, a VMEXIT is triggered to ask the host OS to emulate them
MMU Virtualization x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. • Three levels of memory Memory Virtualization I/O Virtualization • Guest virtual address space Host/Guest Communication • Guest physical address space • VMM physical memory
Software: Shadow Page Tables x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
Hardware: Intel EPT, AMD RVI x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
I/O Virtualization x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
IOMMU x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Instruction Set Virt. Memory Virtualization I/O Virtualization Host/Guest Communication
CPUID x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software • Triggers VMEXIT Techniques Host/Guest • Offers a decent interface for Question/Answer Communication CPUID • Static I/O Ports PCI • Xen Virtio • CPUID is overwritable in PVM • Can get specific value from Xen
I/O Ports x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 • Triggers VMEXIT Hardware/Software • Offers a large choice to make I/O requests Techniques • Dynamic discussion at each VMEXIT Host/Guest Communication • VMware CPUID I/O Ports PCI • Port: 0x5658 Virtio • Can get lots of information: • Processor Speed • VMware version • Memory size • . . .
PCI x86 Virtualization Corentin Derbois, Marc Angel • PCI offers a decent interface to communicate Virtualization 101 Hardware/Software • Some HVM use it to make their video driver and do Techniques some communication Host/Guest Communication • Mainly for Desktop drivers CPUID I/O Ports PCI • VirtualBox Virtio • BEEF - > video driver • CAFE - > some other driver • VMware • PCI driver for SVGA monitor
Virtio x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication CPUID I/O Ports PCI Virtio • A common framework for I/O virtualization for hypervisors • Main I/O virtualization platform in KVM • High performance
Virtio Architecture x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication CPUID I/O Ports PCI Virtio
Supported Devices x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software • Network Techniques • Block Host/Guest Communication • Console CPUID I/O Ports • Entropy PCI Virtio • Balloon • Rpmsg • SCSI Host
Virtio Devices x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software • Presented by the host as a regular PCI device Techniques Host/Guest • Vendor ID: 0x1AF4 (Qumranet) Communication CPUID • Device ID for each type of device I/O Ports PCI • Configuration header at the start of the BAR Virtio • Memory mapped header for embedded devices without PCI support
Virtio PCI Header x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication CPUID I/O Ports PCI Can be followed by device specific headers: Virtio • MAC addresses for network devices • Other information for block devices (cylinder/head/sector counts. . . )
Virtio PCI Device Init x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication 1 RESET CPUID I/O Ports 2 ACKNOWLEDGE PCI Virtio • Valid virtio PCI device 3 DRIVER • We know how to use the device 4 DRIVER OK • Virtqueue configuration • Feature exchange
Virtqueues x86 Virtualization • 0 or more virtqueues per devices Corentin Derbois, • Spans 2 pages Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication CPUID I/O Ports PCI Virtio
Conclusion x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication Conclusion
Questions? x86 Virtualization Corentin Derbois, Marc Angel Virtualization 101 Hardware/Software Techniques Host/Guest Communication Thank you
Recommend
More recommend