QEMU and KVM
Roles
| Component | Role in the lecture’s Linux stack |
|---|---|
| QEMU | Userspace VM setup, machine/device models, lifecycle and migration support |
| KVM | Linux kernel virtualization interface and hardware-assisted guest execution |
| Linux kernel | Host scheduling, memory management, drivers, and supporting infrastructure |
| Guest OS | Kernel and applications running inside the virtual machine |
QEMU can also emulate a whole system across different ISAs. Its user-mode emulation runs an individual foreign-ISA program; system mode supplies a complete machine. KVM acceleration in the lecture requires a compatible host/guest ISA and virtualization hardware.
VM process and vCPU threads
The illustrated VM is backed by a QEMU process. Guest RAM belongs to that process’s address space; each guest vCPU executes through a host thread. A main loop handles events and other threads can perform expensive I/O.
The host scheduler sees host threads, not every guest application thread as a separate schedulable host entity. The guest OS schedules its own work onto its vCPUs.
Lifecycle through /dev/kvm
The slide’s conceptual flow is:
- Open
/dev/kvm. - Create a VM and register guest-memory backing.
- Create vCPUs and map their
kvm_runcommunication structures. - Initialize processor state.
- Call
KVM_RUNto execute. - Handle returned exit reasons where userspace emulation is needed, then resume.
QEMU (root ring 3) -> host syscall -> KVM (root ring 0)
KVM -> VM entry -> guest (non-root kernel/apps)
Guest -> VM exit -> KVM -> handle in kernel or return to QEMUNot every VM exit makes a userspace round trip.
Correction to the schematic code
PDF page 80 / printed slide 85 is not a complete executable example. In the x86 API, KVM_SET_REGS sets general registers including RIP, while KVM_SET_SREGS sets special registers. The slide mixes these categories. Linux KVM API.
Lecture demonstrations
Pages 76-77 compare x64 emulation with -enable-kvm and an ARM64 guest emulated on x86. The supplied Ubuntu 20.04/21.04 downloads and firmware commands are recorded as historical demonstrations, not tested setup instructions. No VM was launched for these notes.
Common mistakes
- Assuming KVM replaces all QEMU responsibilities.
- Assuming hardware acceleration translates arbitrary foreign ISAs.
- Assuming a guest’s ten application threads become ten host threads.
- Copying the schematic API example as working C.
Related: Hypervisor Architectures, Hardware-Assisted Virtualization and VMCS, Libvirt virsh and virt-manager, Virtio Virtqueues and vhost-net.
Source
Lecture 03 PDF pages 71-83 (printed slides 74-88, with gaps). Context: Lecture 03 - Computing Virtualization Technologies and Tools. The diagram and cautionary distinctions are study explanations; the API correction is separately sourced above.