Skip to content
systemcoding.dev
Virtualization

Paravirtualization vs Full Virtualization

Full virtualization runs an unmodified guest, while paravirtualization gives the guest drivers that call the hypervisor. See where virtio and kvmclock fit.

6 min read
Summarize in AI
Flat illustration of guest machines running on a hypervisor over hardware, with the QEMU, RISC-V and Docker logos.

The two terms describe how much the guest knows it is a guest. In full virtualization the guest operating system is unmodified and unaware, and the hypervisor provides an environment indistinguishable from real hardware. In paravirtualization the guest is changed, or at least equipped with drivers, so it can call the hypervisor directly instead of poking at hardware that is not there. Real systems use both at once, and the interesting question is which parts of a guest deserve which treatment. This post compares them with Linux 6.12 and QEMU 9.2 examples, using the Xen history for context. For the broader model, see the complete guide to virtualization for systems programmers.

Full virtualization

A fully virtualized guest runs a stock operating system image. It executes privileged instructions, reads and writes device registers and probes hardware exactly as it would on a physical machine. The hypervisor catches each of those actions and emulates the effect. Before hardware support this needed binary translation, and since VT-x and AMD-V it uses VM exits.

The big advantage is compatibility. Any operating system that runs on the hardware runs in the VM, including closed-source ones and ones that are decades old. You do not need the guest vendor's cooperation. The cost is every operation that traps. Emulated devices are the worst case: a classic emulated network card is programmed by many register writes per packet, and each write is a VM exit that the VMM handles in software.

Paravirtualization

The term came out of the Xen project, which in its first form ran guest kernels that were modified to replace privileged operations with explicit calls into the hypervisor, called hypercalls. A paravirtualized guest does not try to execute CLI or write to the page-table base register. It asks the hypervisor to do the equivalent. The benefit was good performance on hardware that could not virtualize x86 efficiently, and the cost was that every guest operating system needed a port.

Today the pure form is rare on x86 because hardware support made it unnecessary for the CPU. What survives, and matters, is paravirtualization of devices and a few CPU services. A guest kernel that knows it is in a VM can use interfaces designed for VMs where those beat emulating hardware.

Where each is used on Linux

On a KVM host with a Linux guest, the picture is a hybrid:

ComponentModeMechanism
CPU instructionsFullHardware VT-x or AMD-V, no guest changes
Memory translationFullEPT or NPT in hardware
DiskParavirtualvirtio-blk or virtio-scsi
NetworkParavirtualvirtio-net
ConsoleParavirtualvirtio-console or serial
ClockParavirtualkvm-clock
Idle and spinlocksParavirtualPV spinlocks, HLT handling
Memory reclaimParavirtualvirtio-balloon

The guest kernel detects the hypervisor through CPUID leaf 0x40000000, where KVM places its signature KVMKVMKVM, and then enables the paravirtual features it finds. You can see the result from inside a guest:

Shell
dmesg | grep -i -E 'hypervisor|kvm-clock|paravirt'
Text
[    0.000000] Hypervisor detected: KVM
[    0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[    0.000000] Booting paravirtualized kernel on KVM

The timestamps and exact wording vary by kernel version, but those three themes are the evidence. "Booting paravirtualized kernel on KVM" is a statement that the guest uses paravirtual operations where they exist.

Virtio, the standard paravirtual device interface

Virtio is the reason the hybrid works across hypervisors. It is a specification, maintained by OASIS, that defines a family of devices (block, network, console, balloon, file system, and more) and a transport. A device is described by feature bits and a set of virtqueues, rings in shared memory through which the guest driver posts buffers and the device consumes them. The Virtual I/O Device specification 1.2 is the primary source.

The efficiency comes from batching. A guest driver can add many buffer descriptors to the available ring and notify the device once. The device processes them, writes to the used ring, and signals completion with an interrupt, which can also be suppressed or coalesced. Compare that with an emulated device where each register touch is an exit.

You choose it on the QEMU command line. This guest uses virtio for disk and network:

Shell
qemu-system-x86_64 -enable-kvm -cpu host -m 2G -nographic \
  -drive file=root.qcow2,if=virtio,format=qcow2 \
  -netdev user,id=net0 -device virtio-net-pci,netdev=net0

Inside the guest you can confirm it by listing the PCI devices; virtio devices carry vendor ID 1af4:

Shell
lspci -nn | grep -i virtio
Text
00:03.0 Ethernet controller [0200]: Red Hat, Inc. Virtio network device [1af4:1041]
00:04.0 SCSI storage controller [0100]: Red Hat, Inc. Virtio block device [1af4:1042]

Device IDs 1041 and 1042 are the modern, non-transitional virtio IDs for network and block devices, derived by adding 0x1040 to the device type number defined in the specification.

The clock is the best small example

Time shows why paravirtualization still matters even with perfect CPU virtualization. A guest wants to read the time cheaply and accurately, but the hardware time-stamp counter changes under it when the vCPU moves between host cores or the guest migrates to a different host. Reading hardware timers through emulated devices means an exit per read, which is expensive for software that timestamps constantly.

KVM's paravirtual clock fixes this. The host writes a structure into shared memory with a scale and offset, updated whenever the TSC relationship changes, and the guest computes the time by reading the TSC and applying that structure, with no exit. The guest finds it by writing the structure's address to a model-specific register, the two MSRs named in the dmesg line above. It is a small interface that gives a large win, and it is typical: a few well-chosen paravirtual hooks cover the cases hardware virtualization leaves expensive.

You can see which clock source a guest uses:

Shell
cat /sys/devices/system/clocksource/clocksource0/current_clocksource
Text
kvm-clock

Modern kernels may prefer tsc when the host advertises a stable, invariant TSC, so seeing tsc is also fine. The paravirtual clock exists for hosts that cannot promise it.

Trade-offs

QuestionFull virtualizationParavirtualization
Guest changes neededNoneDrivers or kernel support
Works with closed-source guestsYesOnly if drivers exist for them
Device I/O costHigh with emulated devicesLow, batched through queues
Portability across hypervisorsSame hardware modelStandardized by virtio, otherwise per hypervisor
Attack surfaceLarge emulated device codeSmaller, if the device list is short
DebuggabilityHardware-like, familiarNeeds the right driver in the guest

The drivers are not free of cost. A guest that boots from a virtio disk needs the virtio driver in its initial ramdisk or kernel, or it cannot find its root file system, a classic first-boot failure when migrating a physical machine image into a VM. Windows guests need the virtio drivers supplied separately at install time. If you cannot supply drivers, the compatibility fallback is an emulated device such as an IDE disk or an e1000 network card, which every OS understands and which is slow.

Decision rule

For a Linux guest you control, use virtio for everything it covers and -cpu host with KVM, and keep the emulated devices for the cases where you cannot install a driver. For a guest OS you do not control, begin with emulated devices to get it installed, then add paravirtual drivers and switch. For hostile-guest isolation, shorter is safer: use virtio and drop every emulated device you do not need, because emulated controllers have been the source of many VM escape bugs.

When it stops mattering

If the guest is CPU-bound and does little I/O, device paravirtualization changes little, and the CPU runs natively either way. If you are emulating a foreign architecture with TCG, the devices are not the bottleneck, translation is. And if the guest uses a passthrough device through VFIO, it talks to real hardware and the question of emulated versus paravirtual does not apply to that device.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the C, FreeBSD and Linux logos.
Systems Programming

How argc and argv Reach main in a C Program

The kernel copies argc and argv onto the new process's stack on execve, then startup code hands them to main. See the layout and measure it with a program.

6 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.