
Recall first from Mixed criticality and real-time vCPUs
- Guest and host schedulers make independent scheduling decisions.
- PREEMPT_RT reduces host kernel scheduling delays, while FIFO policy and CPU reservation address competition for host CPU time.
- vCPU pinning restricts where a vCPU can run. Reserving that CPU also requires controlling what else can run there.
Why direct device ownership changes I/O latency
3 min readThe last lesson tuned the vCPU for latency. This lesson answers the IOMMU, which prevents a device's DMA from reading arbitrary host memory.
A network controller can transfer received data directly into RAM. The driver gives it receive buffers and tells it to start receiving. The controller then writes incoming data to those buffers without asking the CPU to copy each byte. Linux's DMA mapping guide describes this use of DMA and distinguishes the address the driver uses to access a buffer from the address it gives the device. When that driver runs inside a guest, the host needs a way to enforce which memory the controller may access.
With an emulated controller, the guest driver operates a software model of the device. A write that starts an operation can cause a VM exit and require the device model to run before the I/O proceeds. That work adds time to the operation. If the software handling the request has to wait for a host CPU, the added time can vary from one request to the next. The emulated controller still has a practical advantage. The guest can keep using the same device model and driver when the host uses a different physical controller. The host can also share a physical resource among several guests through software.
With direct assignment, the guest owns the operation of the real controller. For the normal data path of a directly mapped device, the guest's native driver can submit requests to hardware and the hardware can transfer data to guest memory without software emulating those operations. The host still controls assignment and DMA permissions. Removing emulation from that path removes one source of latency and jitter. The hardware can still wait for access to memory, and the guest must still run to process completions. Measure the time from submission to completion under the expected workload if the design has a deadline. Direct assignment alone gives no worst-case latency bound.
That choice also changes what the host can do with the controller. While an entire controller belongs to one guest, the host and other guests give up ordinary use of it. The guest needs a driver for the physical device, and moving the VM to another host becomes harder because its I/O depends on real hardware and device state. A dedicated controller can be a reasonable choice for a guest with an I/O deadline. An emulated controller can be a better fit when multiple guests need a common interface and the added latency fits the workload.
How the IOMMU restricts device DMA
4 min reada transfer in which a device reads or writes memory on its own behalf begins after the driver supplies a buffer address. The address might be stored in a descriptor in RAM, so the device may perform a DMA read to fetch the descriptor before it writes to the receive buffer. Both requests need permission. A guest CPU store to a descriptor goes through the CPU's address translation. The device's later read of that descriptor and write to the receive buffer are separate transactions. CPU page-table permissions govern the guest's CPU accesses. An IOMMU applies permissions to the transactions initiated by the device.
Without effective DMA isolation, a DMA-capable device can issue reads or writes to arbitrary host memory addresses that its bus can reach. A faulty guest driver could program the wrong address. A device read could then disclose data belonging to the host or another guest, and a write could corrupt that memory. The IOMMU, or input/output memory management unit, enforces a host-controlled mapping for devices whose transactions pass through it. Arm calls its implementation the System Memory Management Unit, or SMMU. On x86, Intel VT-d and AMD-Vi name the corresponding DMA remapping technologies.
an address issued by a device for translation through an IOMMU has meaning within a translation context. The host associates the device with an IOMMU domain and installs I/O page-table mappings for the guest memory the device may use. Each mapping associates an IOVA range with host physical memory and permissions. VM implementations can arrange for DMA addresses to match guest physical addresses numerically. The device transaction still needs an I/O mapping to reach the corresponding host page. Two domains can use the same IOVA and map it to different host pages.
Consider a receive queue whose descriptor page is mapped for device reads and whose receive buffer is mapped for device writes. A device read of a descriptor can proceed. A write into the receive buffer can also proceed. A write to an unmapped IOVA or to an IOVA mapped only for reads faults under the active translation policy. Stopping a request at that point keeps it from reaching the intended destination. A different error, such as writing into the wrong buffer within a writable mapping, can still damage guest data. The IOMMU checks the translation and permissions for the request. It has no knowledge of which buffer the driver intended.
Going deeperStream selection, page-table walks, and faults
In an Arm SMMUv3, an incoming transaction carries a StreamID. The SMMU uses that ID to select a Stream Table Entry, or STE. The STE holds the stream's translation configuration. For stage-2-only translation, the STE supplies the stage-2 configuration, including the table base, directly. When stage 1 is enabled, the STE also identifies the Context Descriptor structure, and the selected Context Descriptor, or CD, supplies the stage-1 context. With both stages enabled, stage 1 translates the input address to an intermediate physical address and stage 2 translates that address to a host physical address. Stage 2 supplies the host-controlled restriction in this configuration.
An IOMMU can cache translations in an I/O translation lookaside buffer, or IOTLB. When it needs a translation that is absent from the cache, the hardware walks the configured I/O page tables. It follows table entries to a mapping and checks the requested access against its permissions. If the host revokes a mapping, it must also arrange for stale cached translations to be invalidated before relying on the revocation. The walk and any associated memory traffic can contribute to latency even when the guest uses the device directly.
An unmapped address or a permissions violation can cause the IOMMU to reject the transaction and report an event. On an SMMUv3, fault information can identify the stream and the address involved. The precise report depends on the hardware and kernel driver. Fault containment protects memory from the rejected access. The device can still fail the operation, stop processing its queue, or need recovery. For a write that spans multiple mappings, an earlier valid access may already have completed before a later access faults.
What Linux can show about isolation
3 min readLinux exposes IOMMU groups because the hardware topology determines how finely the host can isolate devices. A group is the smallest set of devices Linux can isolate from other devices on that system. For example, devices may share an identity for transactions, or a PCI topology may allow peer transactions to reach another device without going through the IOMMU. Separate PCI addresses alone give insufficient evidence that two devices can be isolated. Devices sharing a group must be assigned together as one ownership unit. A group member can be left idle under that ownership decision. Splitting active members between mutually untrusted owners defeats the isolation assumption.
On the Ubuntu host, inspect the current kernel log and enumerate the group members. The first command may require elevated privileges to read the kernel buffer. The second displays the device links under each numbered group. For PCI devices, the name of each link is the PCI address, so it can be matched to a known endpoint. Group numbers are local to the running system.
sudo dmesg | grep -Ei 'DMAR|AMD-Vi|IOMMU|SMMU'
find /sys/kernel/iommu_groups -path '*/devices/*' -type l -print
Read the relevant boot messages for successful IOMMU initialization and for errors or disabled translation. A match can come from firmware discovery or an error message, so read the line in context. Group entries establish that Linux has enumerated devices into groups. They do not show which DMA permissions apply to your selected device. A device in an identity or bypass configuration may have far broader reach than a device attached to a restricted translation domain. A VM or WSL2 only exposes what its virtual platform provides, and its output cannot establish how the physical host configured a device. Record the result as unavailable if your environment exposes neither usable boot evidence nor groups.
To verify containment, use a prepared lab endpoint whose test driver can submit a controlled DMA write while the endpoint is attached to a restricted domain. The fixture needs a writable test buffer and a separate sacrificial buffer that can be inspected from the host. Use a successful write to the mapped test buffer to establish that the device is active and the test can detect a change. For the fault trial, the fixture must provide an IOVA it has deliberately left unmapped in that domain, with a known protected buffer for its before-and-after integrity check. The protected memory has no writable mapping through the domain during the test. Use the fixture's supplied address and its supported test operation.
Record the endpoint identity and the fault-trial IOVA before submitting the write. Compare the kernel log before and after the trial. The expected evidence is a new translation fault that matches the test requester and address, plus an unchanged protected buffer. Depending on the platform, the log may identify the requester by PCI address, requester ID, or StreamID. Use the fixture's identity information to correlate those fields. Also record the result reported by the endpoint, which may signal an error or time out. A timeout can happen without any transaction reaching the IOMMU, and an unchanged buffer has the same ambiguity. The successful control write, matching fault, and unchanged buffer together support a conclusion about the tested transaction. If the fault record is missing or cannot be matched, record the live verification as inconclusive.
The next lesson, VFIO device passthrough, shows how Linux makes a real device available to a guest through VFIO and how that assignment uses the group and DMA isolation rules established here.
Key takeaways
- Direct assignment removes the software device model from the normal I/O path and gives the guest operational control of the physical device.
- The IOMMU uses host-controlled I/O page tables to restrict device DMA to permitted memory.
- Linux treats the IOMMU group as the minimum unit of secure device ownership.
- A matched translation fault and an unchanged protected buffer provide evidence that a specific DMA write was contained.
Reflect
- Explain to a colleague, in two sentences: compare the latency and ownership tradeoffs of emulated and directly assigned devices.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel documentationDynamic DMA mapping Guide: CPU, physical, and DMA addresses
- Kernel documentationVFIO: Direct device access and IOMMU groups
Official documentation first. Links checked when the lesson was published.