KVM PV DEVICES [email protected] Agenda
Kernel Virtual Machine overview
Paravirtualized drivers intro & brief history
VirtIO
Enhanced VirtIO with KVM support
2 Copyright © 2007 Qumranet, Inc. All rights reserved. Kernel Virtual Machine overview
VM is a regular Linux process. KVM handles cpu & memory virtualization Qemu virtualizes IO devices
3 Copyright © 2007 Qumranet, Inc. All rights reserved. KVM Execution Model
4 Copyright © 2007 Qumranet, Inc. All rights reserved. Evolution of x86 virtualization
5 Copyright © 2007 Qumranet, Inc. All rights reserved. General & history
Fully virtualized devices performs bad 55 Mbps for RTL Lots of io-exits per packet
Decided to implement a modern e1000 Advantage: Only Qemu coding no guest tools involved Irq coalescing Only 2-3 io-exits per packet Can be the base of user-space PV
But then came Ingo…
6 Copyright © 2007 Qumranet, Inc. All rights reserved. PV driver architecture
VM VM VM HVM VMguest HVM guestR PV I R HVMfrontend guest PV N I driver frontend VM G HVMN guestR driver PV G I R frontend PV PV N I driverfrontend backend PV Qemu G N driver driver backend Qemu G driver PV backend PV Qemu driverbackend Qemu driver
Linux kernel & KVM
PV backend KVM driver
7 Copyright © 2007 Qumranet, Inc. All rights reserved. General & history
V0 - leveraging Ingo Molnar’s PV code Make loadable module Add HVM support Add NAPI Add memory barriers and improved ring Keep running after performance & stability Merge to the kernel?
Alternatives Xen Polished drivers Xen specific VirtIO was just published.
8 Copyright © 2007 Qumranet, Inc. All rights reserved. VirtIO
An API for virtual I/O Implements network & block driver logic Written by Rusty Russell
Motivation Many hypervisors of all types Hard to tune and maintain each one Code reuse – The KVM way ;)
Implementations Lguest KVM Possible (Xen, UML, Qemu, VMware?..)
9 Copyright © 2007 Qumranet, Inc. All rights reserved. VirtIO
GuestVM kernel VIRTIO VIRTIO BlK NET
Add_buf Get_buf Sync Detach VM Restart Hypervisor Specifics PV code
Qemu Kick Linux kernel & KVM
PV backend KVM driver
scatterlist sg[] for skb/blk_req data 10 Copyright © 2007 Qumranet, Inc. All rights reserved. VirtIO – Hypervisor specifics
The front end logic is implemented by VirtIO
The backend needs GuestVM kernel VIRTIO VIRTIO BlK NET
Probing & Bus services VM Hypervisor Specifics Enumeration PV code Irq Qemu Parameters (mac,..) Linux kernel & KVM
KVM PV backend Shared memory with remote side driver Hypercalls Host driver/userspace backend
11 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO – Reuse the reuser
Motivation Increase re-use
GuestVM Allow operation with various bus types kernel VIRTIO VIRTIO BlK NET
Make new devices code smallest VM Hypervisor Specifics PV code
Qemu Components Linux kernel & KVM
Shared memory code PV backend KVM driver With per hypervisor I/O hypercalls Bus (pci, virtual bus) Host backend
12 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO
VM Blk Net VIRTIO Net VIRTIO BlK Backend Backend
Guest Enhanced VIRTIO VIRTIO kernel
Shared Virtual Bus Hypercalls mem backend VM
Qemu
Linux kernel & KVM
PV KVM backend driver
13 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO
Status: 162 LOC 195 LOC Interface was enhanced VM Blk Net VIRTIO Net VIRTIO BlK KVM support Backend Backend Guest Enhanced VIRTIO VIRTIO PCI like configuration space kernel Shared added Virtual Bus Hypercalls mem Actually we got re-used… backend VM
Result: Qemu
Makes backend driver tiny Linux kernel & KVM 620 Mbps throughput for network PV HVM Linux guest KVM backend driver Before optimization Userspace backend driver
14 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO – shared memory backend
VirtIO backend Implements VirtIO interface Callbacks to hypervisor and
Code consists of add_buf, get_buf, restart, detach_buf VM Blk Net VIRTIO Net VIRTIO BlK Backend Backend
Only shared memory logic needed Guest Enhanced VIRTIO VIRTIO kernel sync Shared Virtual Bus Hypercalls mem VM Ring logic backend
IO pending hypercall Qemu
be_virtqueue_interrupt handler Linux kernel & KVM
PV KVM backend driver
15 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO – Day in a life of packet
2.Kernel 1.User VM 3.start_xmit Tcp/ip write Blk Net VIRTIO Net VIRTIO BlK Backend Backend 4.add_buf 12. skb_recv_done Guest Enhanced VIRTIO VIRTIO kernel 6.sync 13. get_buf… Shared Virtual Bus Hypercalls mem 5.add_buf backend VM 11.irq 7.sync 8.Notify hcall Qemu
Linux kernel &10.Trigger KVM irq
PV KVM backend driver 9.The pkts travels to tap/backend host device 16 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO – shared memory details
Based on lguest
1-1 shared memory
Data structure Page of descriptors for rx, tx. Available pointers page controlled by guest Used pointers page controlled by host
SG list is currently internal to descriptors Descriptors are chained by next pointer
17 Copyright © 2007 Qumranet, Inc. All rights reserved. Enhanced VirtIO – network be driver
Implements kvm_virtnet_probe for pci bus Creates tx,rx be_new_virtqueue 195 LOC VM Blk Net VIRTIO Net VIRTIO BlK Backend Backend
Guest Enhanced VIRTIO VIRTIO Probes virtnet kernel Shared Virtual Bus Hypercalls mem backend VM
Request_irq Qemu Irq# taken from bus Linux kernel & KVM
PV KVM backend Register hypercall - shared memory pfn driver Device key for enumeration taken from bus
18 Copyright © 2007 Qumranet, Inc. All rights reserved. Further work
Basic Add readv/writev handlers to Qemu Complete the user-space block device VM Complete migration support Blk Net VIRTIO Net VIRTIO BlK Backend Backend
Guest Enhanced VIRTIO VIRTIO Advanced (also simple) kernel Shared Optimize and stabilize Virtual Bus Hypercalls mem backend VM Add host back end drivers Add virtual bus HVM improvements Qemu Test with PV kernel Linux kernel & KVM
PV KVM backend driver
19 Copyright © 2007 Qumranet, Inc. All rights reserved. Q&A
Thank you ;)
20 Copyright © 2007 Qumranet, Inc. All rights reserved.