Whether you are running VNF’s in OpenStack or deploying virtual environments within GNS3 or EVE-NG, it is important to understand the different virtualization technologies, such as QEMU and KVM, even for us network engineers.
The differences between QEMU and KVM are not always clear. I mean, are they the same, or are they different? Aren't they both hypervisors? Let’s dive in ...
QEMU is a userland type 2 (i.e runs upon a host OS) hypervisor for performing hardware virtualization (not to be confused with hardware-assisted virtualization), such as disk, network, VGA, PCI, USB, serial/parallel ports, etc. It is flexible in that it can emulate CPUs via dynamic binary translation (DBT) allowing code written for a given processor to be executed on another (i.e ARM on x86, or PPC on ARM). Though QEMU can run on its own and emulate all of the virtual machine’s resources, as all the emulation is performed in software it is extremely slow.
KVM is a Linux kernel module. It is a type 1 hypervisor that is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). But what is full virtualization, you may ask? When a CPU is emulated (vCPU) by the hypervisor, the hypervisor has to translate the instructions meant for the vCPU to the physical CPU. As you can imagine this has a massive performance impact. To overcome this, modern processors support virtualization extensions, such as Intel VT-x and AMD-V. These technologies provide the ability for a slice of the physical CPU to be directly mapped to the vCPU. Therefore the instructions meant for the vCPU can be directly executed on the physical CPU slice.
As previously mentioned, QEMU can run independently, but due to the emulation being performed entirely in software it is extremely slow. To overcome this, QEMU allows you to use KVM as an accelerator so that the physical CPU virtualization extensions can be used. So to conclude: QEMU is a type 2 hypervisor that runs within user space and performs virtual hardware emulation, whereas KVM is a type 1 hypervisor that runs in kernel space, that allows a user space program access to the hardware virtualization features of various processors.
Figure 1 - High-level overview of the KVM/QEMU virtualization environment.
Finally, It is also worth mentioning a little history, which in my opinion has led to some of the confusion around KVM/QEMU. Previously KVM was a fork of QEMU, named qemu-kvm. However, this has now been merged into QEMU upstream and the fork has now been discontinued. Or in other words, as per Linux KVM,
The kernel component of KVM is included in mainline Linux, as of 2.6.20. The userspace component of KVM is included in mainline QEMU, as of 1.3.
"Features/KVM - QEMU." 6 Feb. 2017, https://wiki.qemu.org/Features/KVM. Accessed 9 Jan. 2020. ↩︎
"KVM & Qemu - saravananlinux." 20 Jul. 2015, http://saravananlinux.blogspot.com/2015/07/kvm-qemu.html. Accessed 9 Jan. 2020. ↩︎
"QEMU - Wikipedia." https://en.wikipedia.org/wiki/QEMU. Accessed 9 Jan. 2020. ↩︎
"Kernel-based Virtual Machine - Wikipedia." https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine. Accessed 9 Jan. 2020. ↩︎
"Linux KVM." https://www.linux-kvm.org/page/Main_Page. Accessed 9 Jan. 2020. ↩︎