Top Banner
KVM: Virtualisation The Linux Way Amit Shah [email protected] GEEP
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The kvm virtualization way

KVM: Virtualisation The Linux Way

Amit [email protected]

GEEP

Page 2: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Virtualisation Strategies

“Native” HypervisorsHave a runtimeNeed a “primary” guest OSExamples: Xen, VMWare ESX Server, IBM mainframes

ContainersDifferent namespaces for different guestsRun on host kernelUserland can be different from hostExamples: OpenVZ, FreeVPS, Linux-Vserver

Paravirtualisation

EmulationExamples: QEMU, PearPC

Page 3: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.3

KVM: Architectures Supported

S390IBM mainframes: a hypervisor is a mustIncluded in 2.6.26

IA-64Included in 2.6.26

X86Included in 2.6.20KVM-lite: PV Linux guest on non-VTx / non-SVM host (proposed)

PowerPCPVArchitecture support for hypervisorIncluded in 2.6.26

Page 4: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

X86 Hardware Extensions

'guest mode' in addition to user and kernel modes

Raise a trap for all privileged instructions

Virtualised registers

ProcessorIntel-VTx (VMX)AMD-V (SVM)

MMEPT (Intel)NPT (AMD)

IOVT-d (Intel)IOMMU (AMD)

Page 5: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.5

What's handled in the kernel?

CPU virtualisation (special instructions)MMU virtualisationLocal APIC, PIC, IOAPIC, PIT(guest) paravirtualised network and block device drivers

virtio-netvirtio-block

(guest) paravirtualised kernel support codeparavirt_opsMMU

(guest) paravirtualised clock driver

Page 6: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.6

KVM Process Model

kernel

task task guest task task guest

Page 7: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.7

KVM Process Model (cont'd)

Guests are scheduled as regular processeskill(1), top(1) work as expectedGuest physical memory is mapped into the task's virtual memory spaceVirtual processors in one VM are threads

Page 8: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.8

KVM Execution Model

Native GuestExecution

KernelExit Handler

UserspaceExit Handler

Switch toGuest Mode

ioctl()

Userspace Kernel Guest

Lightweight ExitHeavyweight Exit

Page 9: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.9

Flow Example: MemoryAccess

Guest accesses an unmapped memory locationHardware traps into kernel modekvm walks the guest page table, determines guest physical addresskvm performs guest physical -> host physical translationkvm installs shadow page table entry containing guest virtual -> host physical translationProcessor restarts execution of faulting instruction

Page 10: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Paravirtualisation

Modifying guest OS for performanceVirtio

Common drivers for all hypervisorsHypervisor-specific backendKVM backend in qemuFaster performanceEfficient block, net driversBalloonlguest, KVM use it already

PV DMAPass through Ethernet devices

paravirt_ops

Page 11: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Network Devices

Fully virtualised device performance not great55 Mbps for RTLLots of IO-exits per packet

Decided to implement a modern e1000Advantages:

All code in userspace (qemu) All existing drivers recognise device

IRQ coalescingOnly 2-3 IO-exits per packetGoes in excess of 800 Mbps

Page 12: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Virtio Net

Shared memory between host and guestTwo queues: recv and sendRing buffer within each queue'available' pointer controlled by guest'used' pointer controlled by host

Page 13: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Virtio-net on KVM

Guest kernel

BLK NET

Virtio PCI

QEMU

Linux

SharedMemory

User-space

Page 14: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Ideas

Shared memory between host and guest via virtio-pciShared directory between host and guest using virtio + fuseVMGL (OpenGL for Virtual Machines) supporthttp://kvm.qumranet.com/kvmwiki/TODO

Page 15: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

KVM Pros

Leverages Linux scheduler, memory management, I/ONo scheduler involvement for I/OFull virtualisation: No changes to the guest necessary

Paravirt drivers available for better performance

Uses existing Linux security modelcan run VM as ordinary user

Uses existing management toolsPower managementGuest memory swappingReal-time scheduling, NUMALeverages Linux development momentum: all new drivers, {cpu, disk} schedulers, file systems, etc supported

Page 16: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Distro / Industry interest

libvirtManaging various guests under a hypervisorSupport for Xen, KVMAPIs between UI, middle layer and virtualisation backend

DistributionsDebianUbuntuRedHat ELSLES

QumranetDekstop Virtualisation

Page 17: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Release Philosophy

Development snapshots every 1-2 weeksRelease early and oftenFeatures introduces quicklyBugs fixed quicklyBugs added quicklyAllows developers and users to track and test the latest and greatest

Stable releases part of Linux 2.6.xWith bugfixes going into Linux 2.6.x.y

Page 18: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Journey

Linux 2.6.20 (4 Feb 2007): Initial releaseLinux 2.6.21 (25 Apr 2007): Stability, suspend/resumeLinux 2.6.22 (8 Jul 2007): Stable ABI

Old userspace, new kernelNew userspace, old kernel

Linux 2.6.23 (9 Oct 2007): SMP, performanceLinux 2.6.24 (24 Jan 2008): In-kernel APIC, preemptibility, virtioLinux 2.6.25 (16 Apr 2008): Guest swapping, paravirt_ops, balloon drvLinux 2.6.26 (soon): PowerPC, s390, IA64, NPT, EPT, more paravirt (mmu), ...

Page 19: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

KVM is Developer-friendly

No need to reboot (usually)Netconsole, oprofile, all the tools workSmall codebaseFriendly community

Page 20: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Future

Consolidate various virtualisation solutions existing in the kernel

Started with move to virt/ from drivers/kvm/

More hardware features supportMore paravirtualisation supportImprove guest scalingBetter support for management layers like libvirtIntel Real Mode Emulation

Page 21: The kvm virtualization way

Copyright © 2007 Qumranet, Inc. All rights reserved.

Do Read

virt/*, arch/[x86|ia64|s390|powerpc]/kvm/*KvmForum2007 wiki page on http://[email protected]@lists.osdl.org

Page 22: The kvm virtualization way

Thank You