Virtual Machines Marie Roch Tanenbaum 8.3 contains slides from: Tanenbaum 3 rd ed. 2008 1 Virtualization Started with the IBM System/360 in the 1960s Basic concept simulate multiple copies of the underlying hardware 2 1
Stability Why virtualization? most problems due to software easy to checkpoint/snapshot Manageability quick install to new machines virtual appliances load balancing/migration 3 Ease of use Why virtualization? legacy software on new system access to software on different OS while running another Development user software on multiple platforms stable platform for OS development simulate networked machines/clusters 4 2
Virtual machine (VM) properties (Popek and Goldberg 1974) Efficiency Instructions which do not affect hardware * are executed without translation Resource control User programs cannot affect hardware resources. Equivalence Programs behave identically to system without VM except for: timing resource availability * with the exception of user controlled registers, memory, etc. 5 Instructions Sensitive affect hardware state Privileged generate a trap For a machine to virtualizable, sensitive privileged 6 3
Type I Hypervisor Tanenbaum p. 572 7 Traps in Type I hypervisors Software interrupts Hardware interrupts similar, except hypervisor handles physical device and sets up virtual device. 8 4
Type I Hypervisor Hypervisor kernel is small Easier to provide stability Mission critical services (e.g. database, e-mail) can be run as appliances Application Traditional: large scale computing Becoming established on desktop computing Starting to appear on embedded devices (e.g. Open Kernel Labs OKL4 microvisor for smart phones) 9 Type 2 Hypervisor Tanenbaum p. 70 privileged How can we support VMs when sensitive? 10 5
Basic blocks Groups of instructions ending in an instruction that changes control flow. sum = 0; x=0; while (x < N) foobar: k = 2 * arg1; syscall( ) { sum = sum+ x; x = x + 1; } arg1 = sum/n; arg2 = ; foobar(arg1, arg2) more work return; Basic blocks are created on the instruction level. Source code display for illustrative purposes only. 11 Binary translation VM examines each basic block before executing Following instructions replaced with calls to the hypervisor: sensitive instructions last instruction of block Translated blocks cached for subsequent use 12 6
Hypervisor performance Near native speed Type I vs. II hypervisor Type II frequently faster Why? Consequence: ence Type I frequently entl uses binary translation 13 Paravirtualization Why not design the OS for the hypervisor? Sensitive instructions Replaced with calls to the hypervisor Creates an API for the OS (could also think of this as a HAL) Hypervisor is essentially a microkernel 14 7
Downside Paravirtualization Requires extensive modification of OS No standard interface for multiple type I hypervisors Xen (U. Cambridge) Hyper-V (aka Viridian, Microsoft) ESXi (VMware) 15 Upside Paravirtualization Microkernel can improve stability No need to emulate tricky semantics Multiple APIs Amsden et al. (2006) proposed common API with libraries linking to specific ones or hardware Tanenbaum p. 575 16 8
Memory virtualization logical l pages P93 physical frames 0x8 0x7 VM1 17 Memory virtualization Hypervisor could map to the physical frames but what would be the problem? 18 9
Shadow page tables logical pages P93 0x8 0x7 physical frames logical pages P729 0x8 0x7 physical frames VM1 VM2 current page table VM1 0x8 0x7 physical frames 0x8 0x7 Shadow page tables current page table VM2 type I hypervisor 19 Shadow page tables Guest OS change shadow table change Process change New MMU base register Easy to detect (sensitive intstruction) Changing table contents? Mark page table read only Analyze instructions for semantics It s a dirty job 20 10
Shadow page tables Cleaner in paravirtualization Update the page table Call the hypervisor to inform of changes Hardware virtualization Conceivable to add a second level of indirection logical virtual physical 21 Several approaches I/O Virtualization Trap I/O instructions and handle in hypervisor. Emulate a device (e.g. disk block as file offset) Single VM handles all I/O Can select OS w/ good device support Strategy used by Xen Issues Mutually exclusive devices. DMA 22 11
Virtual appliances http://www.esat.kuleuven.be/psi/spraak/research/recog/hmm.gif 23 12