LINUX KVM FRANCISCO JAVIER VARGAS GARCIA-DONAS CLOUD COMPUTING 2017
LINUX KERNEL-BASED VIRTUAL MACHINE KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V) It consists of a loadable kernel module, kvm.ko Provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko https://www.linux-kvm.org
FULL VIRTUALIZATION Virtualization on bare-metal Architecture (bottom up) Hardware Virtual Machine Monitor (Hypervisor) Virtual Machine Operating System (Guest) So Where does the KVM fit in here? VM (Virtual Machine) OS VMM (Virtual Machine Monitor) HW VM (Virtual Machine) OS
FULL VIRTUALIZATION Architecture realization VM (Virtual Machine) VM (Virtual Machine) OS OS VMM (Virtual Machine Monitor) HW
LINUX KERNEL-BASED VIRTUAL MACHINE KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V) It consists of a loadable kernel module, kvm.ko Provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko https://www.linux-kvm.org
X86 HARDWARE Most popular HW for high end systems The x86 architecture defines 4 privilege levels or rings Resources protected: I/O ports, CPU instructions PROBLEM: Only one kernel can run in ring 0
X86 VIRTUALIZATION EXTENSIONS Solutions: Guest OS in Ring 1 + Binary Translation Modify OS to run in user level (Ring 3) + Hypercalls Modify HW to allow running guest OS in a new Privilege Mode Extensions: Intel VT and AMD-V KVM uses them!! kvm-intel.ko kvm-amd.ko
LINUX KERNEL-BASED VIRTUAL MACHINE KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V) It consists of a loadable kernel module, kvm.ko Provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko https://www.linux-kvm.org
LOADABLE KERNEL MODULE Linux kernel is extensible with modules (built in or loaded in runtime) Any Linux kernel can be turned into a hypervisor with just cloud@cloud-10642:~$ modprobe kvm-intel To see running modules Linux Kernel kvm.ko HW
LOADABLE KERNEL MODULE If offers one interface to the user space (as networking, storage ) Where? In the same place that all the devices interfaces are placed in linux (file descriptors) cloud@cloud-10642:~$ ls /dev/kvm Now manage VM is as simple as issue ioctl() to /dev/kvm Userspace Linux Kernel myvm.c /dev/kvm ioctl() HW
LOADABLE KERNEL MODULE Creating VM they run as threads Open the interface Create a virtual machine Create cpu Create mem ioctl() Userspace myvm.c Linux Kernel /dev/kvm
LINUX KERNEL-BASED VIRTUAL MACHINE KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V) It consists of a loadable kernel module, kvm.ko Provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko
IMPLEMENTATION ASPECTS KVM and Linux Kernel Execution modes Stack Implementation Example
KVM AND LINUX KERNEL Since the developers didn't want to reinvent the wheel, KVM relies on the mechanisms of the kernel to schedule computing power and benefits from the of the box driver support The kernel component of KVM is included in mainline Linux, as of 2.6.20 Currently developed and maintained by Red Hat Linux So, KVM extend the kernel with new functionalities, but it does not change it.
EXECUTION MODES Implementation of the Full Virtualization or Hardware Assisted Virtualization Execution modes User-mode Kener-mode Guest-mode The architecture may be understood under the same vision but the implementation is different
EXECUTION MODES Execution modes User-mode Kernel-mode Guest-mode
BUILDING THE STACK UP We mentioned this And this
LET S USE QEMU! It would be something like this Create VM cloud@cloud-10642:~$ qemu-img create -f qcow2 debian.qcow2 2G cloud@cloud-10642:~$ qemu -enable-kvm -k tr -cdrom debian-504-i386- businesscard.iso -hda debian.qcow2 -boot d cloud@cloud-10642:~$ qemu-img create -f qcow2 -o backing_file=debian.qcow2 actual.qcow2 qemu -enable-kvm -k tr -hda actual.qcow2 -net user -net nic \ -redir tcp:5022::22 \ -redir tcp:9080::80 http://blog.muhuk.com/2010/07/07/how-to-create-a-debian-vm-with-qemu.html#.wmw9pfnhdiv
THE REAL HIGH LEVEL STACK If KVM developers did not reinvented the wheel, neither we have to do it Why use qemu when we already have higher level management tools!! Scripting GUI But who really uses this open source stack?
BME CIRCLE REALIZATION Looking for KVM Looking for QEMU
QUESTIONS? SYN? SYN-ACK!