Virtualization
IOMMU Explained: DMA Remapping, VFIO Passthrough and VM Security
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيMost discussions of virtualization focus on the CPU and memory: how vCPUs are scheduled and how guest memory is mapped. But there is a third player that can read and write memory on its own, without the CPU's involvement: devices. Network cards, NVMe drives, and GPUs all use Direct Memory Access (DMA) to move data. If a device can write anywhere in physical memory, it can bypass every protection the CPU enforces. The IOMMU is the hardware that closes this gap. This article explains what it does, how it enables device passthrough with VFIO, and why it matters for the security of every virtual server.
The problem: DMA bypasses the CPU's memory protection
Without DMA, the CPU would have to copy every byte between a device and RAM, which is far too slow for modern I/O. With DMA, the driver tells the device "write incoming packets to this physical address," and the device does it directly over the PCIe bus.
The CPU's Memory Management Unit (MMU) enforces which memory a process can touch, but DMA traffic never passes through the MMU. On a machine without an IOMMU, a device programmed with a wrong address, a buggy firmware, or a malicious peripheral (for example, a hostile Thunderbolt device) can read or overwrite any physical memory, including the kernel. In virtualization, this becomes a showstopper: if you hand a device to a guest, the guest driver programs DMA addresses, and those addresses are guest-physical, not host-physical. Without translation, the device would write to the wrong memory, and a malicious guest could deliberately target host memory.
What an IOMMU is
An Input-Output Memory Management Unit is to devices what the MMU is to the CPU. It sits between devices and main memory and translates every DMA address through its own page tables. On x86, the implementations are Intel VT-d and AMD-Vi (AMD IOMMU). ARM systems use the SMMU.
DMA remapping
Each device, identified by its PCI requester ID, is associated with an I/O address space. When the device issues a DMA to an address, the IOMMU looks it up in that device's page tables:
- If a mapping exists, the access is redirected to the correct physical page.
- If not, the access is blocked and a fault is logged.
This gives two benefits. Isolation: a device can only reach memory explicitly mapped for it. Translation: a guest can program its device with guest-physical addresses, and the IOMMU maps them to the real host pages backing that guest's memory.
Interrupt remapping
Devices also signal interrupts by writing to special memory addresses (MSI/MSI-X). A device assigned to a guest could forge interrupts aimed at other CPUs or vectors. Interrupt remapping lets the IOMMU validate and route these messages, and it is required for safe passthrough on modern kernels.
Device passthrough with VFIO
On Linux, VFIO (Virtual Function I/O) is the framework that exposes a device to user space, such as QEMU, under IOMMU protection. The flow is:
- The host unbinds the device from its normal driver and binds it to
vfio-pci. - QEMU opens the device through
/dev/vfio/<group>and maps the guest's memory into the device's IOMMU domain. - The guest sees a real PCI device and loads its native driver.
This is how GPUs are given to VMs for compute or rendering, how NVMe drives are passed through for raw storage speed, and how SR-IOV virtual functions reach guests. For the networking case, see our article on SR-IOV.
IOMMU groups
The IOMMU can only isolate devices that it can tell apart. Devices behind a PCIe bridge without Access Control Services (ACS) may be able to talk to each other directly, bypassing the IOMMU, so the kernel puts them in the same IOMMU group. The rule is simple: all devices in a group must be assigned together, to the same VM. Server motherboards usually provide clean groups; consumer boards sometimes do not.
Security benefits and limits
The IOMMU protects the host from malicious or compromised guests that own passthrough devices, from buggy device firmware, and from external DMA attacks on laptops and desktops (Linux and Windows both use the IOMMU for Thunderbolt protection).
It is not a complete answer, though. Mappings are only as tight as the driver makes them; a device's own firmware, if compromised, can still misuse memory it legitimately has access to; and a passthrough device keeps state across VM reassignment unless it is properly reset. Providers that offer passthrough must reset devices between tenants and keep firmware updated.
What this means for your VPS
Standard VPS instances usually rely on virtio devices, which do not need an IOMMU inside the guest. On the host side, however, the IOMMU is what makes any passthrough feature safe. On a Linux machine you control, you can check its status:
# Is the IOMMU active?
sudo dmesg | grep -i -E 'DMAR|IOMMU|AMD-Vi'
ls /sys/kernel/iommu_groups/ | wc -l
# Show devices per IOMMU group
for g in /sys/kernel/iommu_groups/*; do
echo "Group ${g##*/}:"
for d in "$g"/devices/*; do lspci -nns "${d##*/}"; done
doneIf nothing appears, enable VT-d or AMD-Vi in the firmware, then add kernel parameters such as intel_iommu=on iommu=pt (Intel) to GRUB_CMDLINE_LINUX. On AMD the IOMMU is enabled by default on most current kernels. Then bind a device to VFIO:
sudo modprobe vfio-pci
echo 0000:03:00.0 | sudo tee /sys/bus/pci/devices/0000:03:00.0/driver/unbind
echo vfio-pci | sudo tee /sys/bus/pci/devices/0000:03:00.0/driver_override
echo 0000:03:00.0 | sudo tee /sys/bus/pci/drivers_probeiommu=pt keeps host-owned devices in passthrough mode for performance while still isolating devices given to guests. If you need a server for workloads that do not require special hardware, you can launch one directly from /deploy.
FAQ
Do I need an IOMMU to run virtual machines?
No. CPU virtualization (Intel VT-x or AMD-V) is enough to run VMs with emulated or virtio devices. The IOMMU is required only when you want to assign physical devices, such as GPUs, NVMe drives, or SR-IOV functions, directly to a guest.
Does enabling the IOMMU slow down my system?
Translation adds a small cost, mostly in mapping and unmapping buffers for heavy I/O. Modern hardware caches translations in an IOTLB, and the iommu=pt option avoids translation for devices the host keeps for itself, so the impact is usually negligible.
Can I see IOMMU groups from inside a VPS?
Typically no. A regular VPS guest does not have an emulated IOMMU, so /sys/kernel/iommu_groups is empty. IOMMU groups are a host-side concept, managed by the provider when assigning passthrough devices.