Virtualization Technologies: IBM Haifa Research Lab
Virtualization Technologies: IBM Haifa Research Lab
Virtualization Technologies
Alex Landau ([email protected]) IBM Haifa Research Lab
What is virtualization?
Virtualization is way to run multiple operating systems and user applications on the same hardware E.g., run both Windows and Linux on the same laptop
How is it different from dual-boot? Both OSes run simultaneously The OSes are completely isolated from each other
Uses of virtualization
Server consolidation Run a web server and a mail server on the same physical server
Easier development Develop critical operating system components (file system, disk driver) without affecting computer stability QA Testing a network product (e.g., a firewall) may require tens of computers Try testing thoroughly a product at each pre-release milestone and have a straight face when your boss shows you the electricity bill Cloud computing The modern buzz-word Amazon sells computing power You pay for e.g., 2 CPU cores for 3 hours plus 10GB of network traffic
Indeed an OS provides isolation between processes Each has its own virtual memory Controlled access to I/O devices (disk, network) via system calls Process scheduler to decide which process runs on which CPU core
So whats the hype about? Try running Microsoft Exchange requiring Windows and your internal warehouse mgmt. application requiring Linux simultaneously on the same server! Or better yet, try to persuade competing companies to run their processes side-by-side in Amazons cloud (had it not been virtualized) Psychological effect what sounds better? Youre given your own virtual machine and youre root there do whatever you want You can run certain processes, but you dont get root, call our helpdesk with your configuration requests and well get back to you in 5 business days
Definitions Hypervisor (or VMM Virtual Machine Monitor) is a software layer that allows several virtual machines to run on a physical machine The physical OS and hardware are called the Host The virtual machine OS and applications are called the Guest
Type 1 (bare-metal) Type 2 (hosted) VM1
Guest
Host
VM2
Guest
VM1
VM2
Process
Hypervisor OS
Host
Hypervisor
Hardware
VMware ESX, Microsoft Hyper-V, Xen
Hardware
VMware Workstation, Microsoft Virtual PC, Sun VirtualBox, QEMU, KVM
Bare-metal or hosted?
Example: addl %ebx, %eax is emulated as: enum {EAX=0, EBX=1, ECX=2, EDX=3, }; unsigned long regs[8]; regs[EAX] += regs[EBX];
Pro: Simple!
Con: Slooooooooow
Pro: Performance!
Cons: Harder to implement Need hardware support Not all sensitive instructions cause a trap when executed in usermode E.g., POPF, that may be used to clear IF This instruction does not trap, but value of IF does not change! This hardware support is called VMX (Intel) or SVM (AMD) Exists in modern CPUs Example hypervisor: KVM
10
Translation rules? Most code translates identically (e.g., movl %eax, %ebx translates to itself) Sensitive operations are translated into hypercalls Hypercall call into the hypervisor to ask for service Implemented as trapping instructions (unlike POPF) Similar to syscall call into the OS to request service
11
12
E.g., instead of doing cli to turn off interrupts, guest OS should do hypercall(DISABLE_INTERRUPTS)
13
14
Industry trends
VMX, SVM
15
I/O Virtualization
Types of I/O: Block (e.g., hard disk) Network Input (e.g., keyboard, mouse) Sound Video
16
Side note How does a NIC (network interface card) driver work?
Transmit path: OS prepares packet to transmit in a buffer in memory Driver writes start address of buffer to register X of the NIC Driver writes length of buffer to register Y Driver writes 1 (GO!) into register T NIC reads packet from memory addresses [X,X+Y) and sends it on the wire NIC sends interrupt to host (TX complete, next packet please)
Receive path: Driver prepares buffer to receive packet into Driver writes start address of buffer to register X Driver writes length of buffer to register Y Driver writes 1 (READY-TO-RECEIVE) into register R When packet arrives, NIC copies it into memory at [X,X+Y) NIC interrupts host (RX) OS processes packet (e.g., wake the waiting process up)
17
Hypervisor implements virtual NIC (by the specification of a real NIC, e.g., Intel, Realtek, Broadcom)
NIC registers (X, Y, Z, T, R, ) are just variables in hypervisor (host) memory If guest writes 1 to register T, hypervisor reads buffer from memory [X,X+Y) and passes it to physical NIC driver for transmission
When physical NIC interrupts (TX complete), hypervisor injects TX complete interrupt into guest
Similar for RX path
18
Pro: Unmodified guest (guest already has drivers for Intel NICs)
Cons: Slow every access to every NIC register causes a VM exit (trap to hypervisor) Hypervisor needs to emulate complex hardware Example hypervisors: QEMU, KVM, VMware (without VMware Tools)
19
Protocol in emulation case: Guest writes registers X, Y, waits at least 3 nano-sec and writes to register T Hypervisor infers guest wants to transmit packet Paravirtual protocol: Guest does a hypercall, passes it start address and length as arguments Hypervisor knows what it should do Paravirtual protocol can be high-level, e.g., ring of buffers to transmit (so NIC doesnt stay idle after one transmission), and independent of particular NIC registers
20
How is paravirtual I/O different from paravirtual guest? Paravirtual guest requires to modify whole OS Try doing it on Windows (without source code), or even Linux (lots of changes) Paravirtual I/O requires the addition of a single driver to a guest Easy to do on both Windows and Linux guests
21
Pull NIC out of the host, and plug it into the guest
Guest is allowed to access NIC registers directly, no hypervisor intervention Host cant access NIC anymore
22
23
24
Pros: As fast as possible! Need only one NIC (as opposed to direct assignment)
Cons: Emerging standard Few hypervisors fully support it Expensive! Requires new hardware Cant do cool stuff
25
Paravirtual I/O is cheap But much worse performance Companies (Red Hat, IBM, ) are looking at paravirtual I/O, trying to optimize it
26
Advanced topics
Memory over-commit
Nested virtualization
Live migration
27
The end!
Questions?
28