The IOMMU setting: VT-d or AMD-Vi
Video 093 of 140 in Virtualization Foundations, in the unit “Firmware settings that matter on a virtualization host”. 3:21, with English and Hindi audio.
Sometimes a virtual machine needs a whole network card of its own, for full speed. Done carelessly, that card could reach memory it should never touch. The IOMMU is the firmware setting that prevents this, because it checks every address a device uses. This article explains how the IOMMU works, what the setting is called on Intel and AMD hosts, and how to count the IOMMU groups from Linux.
What you will learn
- The IOMMU checks every address a device uses, so a device cannot write where it was not allowed.
- Intel calls the firmware setting VT-d, and AMD calls it AMD-Vi.
- Handing a whole device to a virtual machine needs the IOMMU on.
- Every device in the same IOMMU group moves with the one you hand over.
- Count the IOMMU groups from Linux before you hand over a device.
Why a virtual machine may need its own card
At Harbor Point, a logistics firm, a busy database virtual machine wants a network card of its own, for full speed. Handing over a card needs the IOMMU on. The hand-over also moves every device in the same group, so the team checks the groups before it moves anything.
If the IOMMU is off, the hand-over fails as the virtual machine starts, and the database waits.
How the IOMMU stops a device writing where it should not
A device such as a network card does not wait for the processor to copy its data. It reads and writes memory directly, using direct memory access, called DMA. Without an IOMMU, nothing checks where that write goes, so a faulty driver or a bad card could write over another machine's memory.
The IOMMU sits between the device and memory. It checks every address the device uses, and it lets the device reach only the memory it was given. The virtual machine gets its own card safely, and it cannot reach memory it was never given.
Two names, one job
- Intel: the firmware setting is called VT-d.
- AMD: the setting is called AMD-Vi, and its menu may simply say IOMMU.
- Linux: it builds IOMMU groups, which are sets of devices that move together.
Count the IOMMU groups from Linux
Linux builds IOMMU groups from the firmware setting. Count them by listing the directory and counting the lines. A number above zero means the IOMMU is working.
ls /sys/kernel/iommu_groups/ | wc -lNote: The count depends on the machine. If the directory is empty, the setting is off, or the platform does not offer it.
Terms
- IOMMU
- The input-output memory management unit: a firmware-controlled checkpoint that limits which memory a device may read and write.
- DMA
- Direct memory access: a way for a device to read and write memory without the processor copying the data.
- IOMMU group
- A set of devices that Linux builds from the IOMMU, and that move together when one of them is handed to a virtual machine.
Check yourself
What does the IOMMU check?
It checks every address a device uses, and it lets the device reach only the memory it was given.
Why do the devices in one IOMMU group matter for a hand-over?
Every device in the same group moves with the card, so the team checks the groups before it moves anything.
What does an empty IOMMU groups directory mean?
The setting is off, or the platform does not offer it.
Previous: Turning on VT-x or AMD-V. Next: SR-IOV in firmware.