notes

AMD-Vi: confining DMA on an AMD machine

Name: provisional (lane amd-vi, provisional milestone 764 (AMD-Vi confines device DMA on x86_64)). An architect names things.

An AMD PC has no DMAR. Until this lane the x86_64 kernel looked only for one, printed skipped, no DMAR, and ran every driver unconfined: the NVMe driver tracked the fact honestly, the xHCI driver refused to start, and nothing else noticed. AMD's IOMMU is AMD-Vi, described by the ACPI IVRS. This note is how the kernel drives it, what QEMU does differently from the specification, and what was proved where. The code is kernel/src/arch/x86_64/amd_vi.rs; its header and BUGS are the detail.

Every format here is from AMD document 48882 revision 2.62 (February 2015), read for this work. That revision predates several features (newer IVHD types, a 5-level walk on more parts), none of which this driver uses. QEMU's model is hw/i386/amd_iommu.c at QEMU 11.1.1, the version .qemu-version pinned when it was read. The pin moved to 11.1.2 on 2026-10-10 (UTC), and the model was not re-read.

How it fits behind the seam VT-d already uses

The four confine callers (NVMe, e1000e, xHCI, virtio) call crate::iommu::confine and crate::iommu::scope_of, and nothing in them changed. kernel/src/arch/x86_64/iommu.rs is still the module the seam reaches; each public entry point there asks amd_vi::is_active() first and hands the call over. The file was not split into a dispatcher and a VT-d driver because its path is cited across design/ as where x86's IOMMU lives, and a lane may not edit those citations.

Two seam changes were forced by the hardware, and both reach the other architectures:

The device table, and the one entry that denies everything

AMD-Vi is driven through memory: one 256-bit entry per 16-bit device id, a command ring, an event log. init fills every entry with the blocked entry before setting IommuEn: valid, translating, four levels, rooted at one all-zero table, read and write both clear. A device nobody confined walks to a not-present entry, is target-aborted, and is logged. The table is sized to the highest device id the IVRS names; the hardware target-aborts any id past its end (section 2.2.2).

The blocked entry is also ยง163 (where a confined device's IOMMU fault is delivered)'s quarantine: amd_vi::quarantine writes it. Milestone 102 (what a confined device's fault reaches) is the caller, on every architecture.

Table 7 offers a simpler blocking entry, Mode 0 with IR = IW = 0. It was refused because QEMU does not implement it (next section), and an entry that blocks on silicon and passes everything under QEMU is a default-deny claim no test here could check.

No cache maintenance is needed, unlike VT-d on a unit with ECAP.C clear. Device-table reads are snooped while Control.Coherent is 1, its reset value. Page-table walks are snooped while a device's SD bit is 0, and the command ring is always read coherently.

Where QEMU 11.1.1 differs from the specification

Each of these was read in QEMU's source, and the last two were found by a test failing.

What The specification QEMU 11.1.1 What this tree does
Translation at all always, once IommuEn is set only with -device amd-iommu,dma-remap=on; otherwise every device bypasses the unit the runner sets it
When a device starts being translated at enable only after INVALIDATE_DEVTAB_ENTRY names it init invalidates every entry, as Linux does
Mode 0 entry access controlled by IR/IW pass-through, IR/IW ignored the blocked entry uses a four-level walk
Translation cache tagged by domain id keyed by device id and page changing an entry flushes the domain it leaves
Event record address the faulting address always zero in this build (a shift of 64, fixed upstream in 4adfb431c0, not in 11.1.2) Fault::addr is None; tests use the requester id
Event record device id bus:dev.fn devfn only harmless while every QEMU device is on bus 0

The stale translation was a real escape under QEMU. The virtio escape test failed on its first AMD-Vi run with a fault at address 0. QEMU's own trace showed why. An earlier registration of the same disk had mapped a frame that the allocator later handed to the test as its victim, and QEMU's cache still held that mapping under the device's id. The device read the victim; the fault at 0 was the next access. Section 2.4.2 says INVALIDATE_DEVTAB_ENTRY does not flush translations and that software should flush the domain, and the driver now flushes the one a device leaves on every change to its entry. On silicon the stale entry would have been unreachable (the cache is tagged by domain), but it would still have been sitting there.

What was proved, and where

All on patagonia, QEMU 11.1.1, q35 under TCG. NIFE_IOMMU=amd (provisional) is the runner knob.

Boot Result
script/test --arch x86_64, which now also boots both test images on the AMD-Vi machine kernel suite 129 passed, 5 skipped; system suite 237 passed, 44 skipped, the same 44 the VT-d machine skips
the virtio DMA-escape test, AMD-Vi passes
the NVMe DMA-escape test (run_dma_escape, confinement_attackers), AMD-Vi passes: fault for the controller, canary intact
the same suite on the default (VT-d) machine unchanged
the boot tour with NIFE_IOMMU=none boots, and says iommu : NONE: ... no device's DMA is confined
amd_vi::tests, AMD-Vi, provisional milestone 767 (AMD-Vi hardening before the first AMD boot) the exclusion registers read zero after boot and a range the test sets is cleared; two ids behind the runner's pci-bridge never share its alias; a quarantine blocks the alias too
virtio::tests::a_device_write_to_the_read_only_shadow_is_refused, every IOMMU passes: the device's write into its shadow page does not land

The falsification turns translating_dte's Mode from 4 to 0, keeping IR and IW: the device reaches everything, untranslated. With it applied, on the AMD-Vi machine:

The exclusion range and aliases

An exclusion range is a window of device addresses the unit does not translate. With Allow set in the Exclusion Base register, every device's access inside [base, limit] goes straight to memory, untranslated and unchecked, whatever its device table entry says (section 3.3.1, MMIO 0020h and 0028h; section 2.1.4.4 for translation requests into the range). Firmware sets one to keep a region it DMAs into reachable, and nothing clears it at reset. A range left in force would be a hole in the default deny that no entry the driver writes can close. So clear_exclusion_range zeroes both registers, ExEn and Allow with them, and Unit cannot be built without the record it returns. A range the firmware still needs is not lost: an IVMD with ExclusionRange set is mapped into the named devices' domains as a read-write identity region instead, as Linux does. A range set with no IVMD naming it is firmware's alone, and the boot line says it was cleared, in capitals.

QEMU 11.1.1 stores the limit register and drops every write to the base register (amdvi_mmio_write has no case for MMIO 0020h), and no walk consults either. Its firmware sets no range. So under QEMU the test proves the limit half of the programming and that the boot left both registers zero. The base half and the effect on a device's DMA are provable only on silicon. The range the test writes is the last 4 KiB of the 52-bit address space, which no machine backs with memory, so on silicon the moment between the write and the clear excludes nothing.

A device behind a PCIe-to-PCI bridge is translated under its alias's id, so attach writes the device's own entry and its alias's, as Linux does (clone_aliases, from memory). Two functions behind one bridge reach the unit under one id, so no pair of entries can confine them apart. The second attach therefore fails closed: every entry either device's DMA arrives under is set to the blocked entry, and the boot prints the pair in capitals. Both devices stop doing DMA. Giving such a pair one shared domain on purpose would be an alias group, which the BUGS below say is not built.

What a first AMD board should show

A boot on silicon is the outstanding piece. Read these lines:

BUGS