Source code:
accel/kvm/kvm-all.c
Links:
I think the key to understand device emulation is first to understand how kernel access devices. The following are the things I know of:
- Legacy x86 ports. Some char devices and other devices still use this port. Writing to IO ports will cause vmexit, and KVM will report such events to QEMU (kvm-all.c)
- PCIe devices. During boot, the kernel can query IO ports to get the list of available PCIe devices. The kernel can also query the ACPI tables to get avaiable PCIe devices. Once get the list, the kernel access PCIe device through Memory-Mapped IO, or MMIO. So I guess this kind of MMIO memory access can be caught by KVM, right?
I'm also aware that virtio is like the "paravirtualization" technique for device drivers. The device drivers in the guest are aware that they are in virtual machines, thus some operations will directly call into the hooks exposed by hypervisor (KVM).
Either way, I want to understand things in this sequence:
- In the early days when there is no hardware-virt support, how VMware emulate devices.
- How Xen emulate devices.
- How QEMU presents a whole machine machine model to the VM.
- How QEMU catches all the MMIO accesses. Without VIRTIO, how it works.
- With VIRTIO, how it works.
Links: