Native KVM Tool

Asias He Beihang University, Beijing, China Aug 15, 2011 Agenda z What is it? z A brief history z Who is developing it? z Features z Features in the future z How to use it? z Demos z Q&A What is it? (1/2) z Native Linux KVM Tool is a clean, from-scratch, lightweight KVM host tool implementation z Source Code z 15K lines of clean C code z From scratch and lightweight z Great learning tool z Integrate more tightly with the kernel source tree z Care about both Desktop and Server users z Usability ƒ As little configuration as possible z Performance ƒ Multi-threaded and para-virtualized device model What is it? (2/2) z Young, only 1 year and 5 months old z Still under heavy development z Already have some cool features z SMP z Up to 254 VCPUs per VM z Devices z Minimal legacy devices emulation z Rely heavily on virtio devices z Disk, Network, Serial, Mouse and Keyboard, RTC, VESA, SDL and VNC support z More features and improve usability & performance A brief history Who is developing it? (1/2) z Developers (17 people) z Pekka Enberg (326) z Special thanks to z Sasha Levin (153) z Avi Kivity z Asias He (120) z Cyrill Gorcunov (110) z KVM internal z Prasad Joshi (29) z Aneesh Kumar K.V (18) z Ingo Molnar z Ingo Molnar (11) z All around support z Liming Wang (7) z John Floren (6) z Encouragement z Amos Kong (4) z Amerigo Wang (2) z Giuseppe Calderaro (2) z Anton Vorontsov (1) z David Ahern (1) z Emil Renner Berthing (1) z Konstantin Khlebnikov (1) z Paul Bolle (1) Who is developing it? (2/2) z Mail List z [email protected] z IRC z #pvm @ freenode z Git Repo z git://github.com/penberg/linux-kvm.git z We need you! z Patches and ideas are more than welcome ;-) Features (1/12) z User Interface support z Command line user interface z Very similar CLI interface like git and . z Text Console z Serial console z Virtio console z GUI Framebuffer z SDL z VNC Features (2/12) z SMP support z Up to 254 VCPUS per VM z KVM_CAP_NR_VCPUS 64 z KVM_CAP_MAX_VCPUS 254 ƒ [PATCH] x86: Raise the hard VCPU count limit by Sasha Levin z Implement MPtable specification z Easier than ACPI specification z Implement the minimum needed for smp Features (3/12) z Disk support z Disk image support z Raw disk images z QCOW/QCOW2 disk images (experimental) z Raw block devices (e.g. /dev/sdb7) z Boot a directory as a root filesystem. z Plain directory which contains root filesystem Features (4/12) z Network support z TAP Mode z NAT z Bridge z Special privilege (CAP_NET_ADMIN) z Setup z UIP Mode (User mode TCP/IP) z No special privilege z From scratch and no ancient slirp code ƒ qemu.git$ cat slirp/*.{c,h} net/slirp.{c,h} | wc -l -> 11790 LOC -> 11.7 KLOC ƒ tools/kvm$ cat net/uip/*.{c,h} include/kvm/uip.h | wc -l -> 1588 LOC -> 1.5 KLOC ƒ 1588 / 11790 = 13.5% z Protocols ƒ ARP, ICMP, IP, TCP, UDP DHCP ƒ Up layer: HTTP, FTP, SSH, DNS z Zero configuration network ƒ Built-in DHCP server ƒ No setup in host side z Multi-threaded ƒ UDP thread ƒ Per Connect TCP thread z Performance ƒ Almost achieves the the same TCP and UDP performance as in host Features (5/12) z Device emulation z Two type of devices z Virtio devices z Legacy devices z Device emulation infrastructures z PIO and MMIO ƒ KVM_EXIT ƒ KVM_IOEVENTFD z Interrupt ƒ KVM_IRQ_LINE Features (6/12) z virtio pci z Simple PCI controller z PCI configuration space z PCI_CONFIG_ADDRESS 0xcf8 z PCI_CONFIG_DATA 0xcfc z PCI discovery/configuration z VENDOR_ID ƒ PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 z DEVICE_ID ƒ PCI_DEVICE_ID_VIRTIO_NET 0x1000 ƒ PCI_DEVICE_ID_VIRTIO_BLK 0x1001 ƒ PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003 ƒ PCI_DEVICE_ID_VIRTIO_RNG 0x1004 ƒ PCI_DEVICE_ID_VIRTIO_BLN 0x1005 ƒ PCI_DEVICE_ID_VIRTIO_9P 0x1009 z SUBSYSTEM_ID ƒ VIRTIO_ID_NET 1 ƒ VIRTIO_ID_BLOCK 2 ƒ VIRTIO_ID_CONSOLE 3 ƒ VIRTIO_ID_RNG 4 ƒ VIRTIO_ID_BALLOON 5 ƒ VIRTIO_ID_9P 9 z BAR[0] ƒ IO space ƒ Virtio configuration Features (7/12)

z virtio blk Guest OS QUEUE_NOTIFY z Process multiple virtio- KVM_EXIT KVM_IOEVENTFD blk requests in parallel Virtio Block Device z Process multiple virtio- virtio_blk_do_io()

blk devices in parallel Request #1 Request #2 Request #N

z Backends disk_image_read() Handle Handle disk_image_write() Handle z Raw block device Request Request disk_image_flush() Request z Raw disk image KVM_IRQ_LINE KVM_IRQ_LINE KVM_IRQ_LINE z QCOW image Interrupt Interrupt Interrupt z QCOW2 image Guest Guest Guest

Thread/Job Pool Features (8/12)

z virtio net Guest OS QUEUE_NOTIFY z Multi-thread KVM_EXIT KVM_IOEVENTFD z TX thread Virtio Net Device virtio_net_handle_callback() z RX thread VIRTIO_NET_TX_QUEUE VIRTIO_NET_RX_QUEUE z Backends virtio_net_tx_thread() virtio_net_tx_thread() z TAP Mode z UIP Mode Handle Request Handle Request

TAP_MODE UIP_MODE TAP_MODE UIP_MODE

TX TX RX RX tap_ops_tx uip_ops_tx tap_ops_rx uip_ops_rx

Interrupt Interrupt Guest Guest Features (9/12) z virtio z 9p: Plan 9 Filesystem Protocol z Transport: Named pipe, TCP connection, File descriptor, RDMA channel, virito z No network setup is needed z Share files between host and guest z kvm run -k ./bzImage -d ./disk.img -9p ./dir_to_share z mount -t 9p -otrans=virtio -oversion=9p2000.u kvm_9p /mnt z Boot a directory as a guest root filesystem using 9p z kvm run -k ./bzImage -d ./guest_rootfs Features (10/12) z virtio console z /dev/hvc0 z virtio rng z /dev/urandom z /dev/hwrng z virtio balloon z kvm balloon inflate/deflate size instance Features (11/12) z Legacy device emulation z Serial device 16550 z Guest console z PS/2 Keyboard and Mouse i8042 z SDL and VNC z VESA z SDL and VNC z RTC z Real time clock Features (12/12) z BIOS emulation z Very tiny and lightweight BIOS layer z No external BIOS dependency z Functions z e820 memory map z real-mode interrupt vector table z mptable Features in the future(1/2) z Vhost net/blk z Macvtap Mode z Virtio-scsi virtio-based SCSI HBA z IO bandwidth limits z More disk image format support (e.g. vmdk, vdi, etc.) z 9p + overlayfs for COW filesystem layer for guest z Boot disk images without external linux kernel image. z Grub support z External BIOS support (e.g. Seabios) Features in the future(2/2) z Non-Linux OS support z QXL paravirtual graphic card z Integrate with perf for profiling and tracing z Integrate with gdb for debugging z Libvirt support z Live migration How to use it (1/6) z Command line interface z kvm run/stop z kvm pause/resume z kvm list z kvm balloon z kvm debug z kvm help z kvm version How to use it (2/6) z Details for ‘kvm run’ Basic options: --name A name for the guest -c, --cpus Number of CPUs -m, --mem Virtual machine memory size in MiB. -d, --disk Disk image or rootfs directory --balloon Enable virtio balloon --vnc Enable VNC framebuffer --sdl Enable SDL framebuffer --rng Enable virtio Random Number Generator --9p Enable virtio 9p to share files between host and guest --console Console to use --dev KVM How to use it (3/6) z Details for ‘kvm run’ Kernel options: -k, --kernel Kernel to boot in virtual machine -i, --initrd Initial RAM disk image -p, --params Kernel command line arguments How to use it (4/6) z Details for ‘kvm run’

Networking options: -n, --network Network to use --host-ip Assign this address to the host side networking --guest-ip Assign this address to the guest side networking --host-mac Assign this address to the host side NIC --guest-mac Assign this address to the guest side NIC --tapscript