ECE344 Fall 2026 (Sec 1) Lec 30 - Virtual Machines
Overview
Virtual machines let multiple guest operating systems share one physical machine while a hypervisor controls hardware, schedules virtual CPUs, and isolates memory and devices. Jon Eyolfson explains software virtualization techniques such as trap-and-emulate and binary translation, hardware support including Intel VT-x and AMD-V, and practical mechanisms such as KVM, nested page tables, virtio, and copy-on-write disk images. The lecture concludes by contrasting virtual machines, which run multiple kernels, with containers, which isolate processes on one kernel.
Key takeaways
- A virtual machine virtualizes an entire operating system, so the hypervisor must save and restore a complete vCPU state, including privileged registers, rather than only a process's user-mode registers.
- Hardware support such as Intel VT-x and AMD-V lets guests execute with hardware-managed guest state; VM exits return control to the hypervisor for events it must handle.
- CPU overcommitment can make guest timing unpredictable because the host may deschedule a vCPU, and it can stall guest synchronization when a paused vCPU holds a spin lock.
- Nested page tables translate guest virtual addresses through guest physical addresses to real machine memory; hardware can cache the combined translation in the TLB.
- Virtio improves virtual-device performance by batching guest requests in shared memory and using a hypercall notification instead of exiting for every device-register access.
- Virtual machines isolate multiple kernels, while containers isolate processes that share a kernel, avoiding the need to package a complete guest operating system for each application.
Chapters
- A guest is an operating system running on a virtual machine; the physical machine is its host.
- The hypervisor, also called a virtual machine manager (VMM), creates guests, schedules them, and controls their hardware access.
- Hardware privilege levels include user mode, kernel or supervisor mode, and more privileged hypervisor mode; machine mode runs firmware and boot code.
- Type 1 hypervisors use CPU virtualization support, while type 2 hypervisors run as ordinary user programs; VirtualBox and QEMU can use different approaches depending on hardware support.
- Windows Hyper-V supports Windows Subsystem for Linux, while Xen is another hypervisor example.
- Virtual machines usually run guest instructions on the same instruction set architecture; QEMU can instead emulate another architecture, such as RISC-V on x86, at a performance cost.
- Hypervisors can pause and migrate guests between physical machines, enforce CPU, memory, and network limits, and consolidate lightly used servers.
- A virtual CPU (vCPU) records the entire CPU state, including privileged registers and execution mode, not just the user registers saved for a process.
- A user-mode hypervisor can use trap-and-emulate: a guest's privileged instruction traps, and the hypervisor updates the corresponding virtual CPU state before resuming execution.
- Trap-and-emulate alone fails for some x86 sensitive instructions that do not trap in user mode; POPF, for example, handles interrupt-flag changes differently by CPU mode.
- Binary translation inspects guest kernel instructions and rewrites or emulates sensitive ones before execution.
- VMware used binary translation to make x86 virtualization practical in the 1990s; Jon Eyolfson compares its overhead with Valgrind, which can make programs 30 to 100 times slower.
- Intel introduced VT-x in 2005 and AMD introduced AMD-V in 2006, adding hardware support for guest execution and virtualized CPU state.
- A VM entry restores guest state and runs the guest; a VM exit saves that state and returns control to the hypervisor to handle events such as device access.
- On Linux, KVM runs each vCPU as a thread, while QEMU commonly emulates devices; the special system call enters the guest until an exit occurs.
- Linux checks such as looking for VMX or SVM CPU flags can indicate virtualization support, while systemd-detect-virt can identify a virtualized environment.
- The guest kernel schedules its threads on virtual CPUs, while the host schedules those vCPUs on physical CPUs.
- With KVM, vCPUs are host threads; a host can pin them to separate physical CPUs or context-switch them when resources are overcommitted.
- Overcommitting vCPUs can distort guest timing: a guest expecting a 10-millisecond slice may wait much longer if its vCPU is descheduled.
- A paused vCPU holding a spin lock can prevent other guest CPUs from making progress; Linux reports time lost to virtualization as steal time.
- The guest kernel maps guest virtual addresses to guest physical addresses, then the hypervisor maps guest physical addresses to real machine memory.
- Intel extended page tables and the RISC-V G-stage provide hardware support for this nested translation; the TLB can cache the combined result.
- A TLB miss can require many memory accesses because both page-table structures must be walked; older hypervisors used shadow page tables as an alternative.
- A missing nested-page-table mapping causes a fault handled by the hypervisor, which controls the actual physical allocation.
- Both a guest and its hypervisor can overcommit memory and perform page replacement, creating two layers of memory pressure.
- A balloon driver coordinates reclamation: the host requests memory, and the guest chooses pages to release based on its knowledge of access patterns.
- A hypervisor can hash guest pages to find likely duplicates, verify matching pages byte-for-byte, and map identical pages read-only.
- On a write, copy-on-write gives the guest a private page; Linux Kernel Samepage Merging (KSM) can perform this kind of page sharing.
- Register-by-register device emulation can trigger a VM exit on each access, making devices such as disks slow.
- Virtio is a paravirtual device interface: a guest driver batches requests in shared memory and notifies the hypervisor, reducing exits.
- A hypercall lets a guest kernel request a service from the hypervisor, analogous to a system call from a user process to its kernel.
- Virtio supports virtual disks, networks, and consoles, and its drivers know they are communicating with a hypervisor.
- A virtual disk can be a host file containing partitions and filesystems; a sparse 20 GB image initially may consume almost no physical disk space.
- QEMU's QCOW2 format uses copy-on-write and supports snapshots, so only written blocks need to occupy storage.
- A virtual machine can freeze an application's kernel and library versions, but distributing a whole guest kernel for one application is costly.
- Containers provide a lighter alternative by isolating processes that share one kernel; Docker is introduced as the subject of the next lecture.
Transcript excerpt
1:41 I >> All right. We are at our second last topic, virtual machines. So, we can take our virtualization as we have learned it and go one step further. Oops. So, [snorts] recall all the way back in lecture two. Feels like eons ago. We had our CPU with different modes. I said there's user mode. That's what
2:29 we're all familiar with. All our applications and library run in this mode. Least privileged doesn't have access to change hardware at all. Then we introduced supervisor mode or kernel mode, whatever you want to call it. Generally the same thing. And we said the kernel is the thing that controls the hardware. But I was like there's other privilege levels. Let's not worry about them for now. Below kernel mode, there's something called H mode and that is where virtual machines kind of live that is even more privileged than kernel mode. Get into what that means in this lecture. And then below that is machine mode, which is uh 25 243. That's where you are in machine mode where you've access to all the hardware. That's where boot loader code and firmware code would be.
3:17 So, today we get to run whole kernels. They'll be virtualized. So, each operating system is going to believe it owns the whole machine like with programs. Each program thinks it owns all of memory and is the only thing running on CPU cores. So, we're just going to take virtualization and step it up. So, virtual machines, same idea. It abstracts a whole virtual machine or a whole machine where our goal is to run multiple operating systems on a single machine where each operating system believes it is the only thing running. So, they all think they have exclusive control over the hardware, which they do
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Jon Eyolfson.