Expand description
IOMMU domain and IOVA management.
This module is the architecture-neutral bookkeeping layer between a PCI function and the DMA allocator:
- a
Domainis bound to oneSbdfand owns a sparse IOVA space; - mappings are kept in a
BTreeMapkeyed by IOVA start, somap,unmapandtranslateare O(log n) and overlap checks never scan the whole table; - domains are allocated from a 16-bit bitmap (the VT-d domain-id width) and
handed out as
Arc<Domain>with an explicit logical reference count so hot-unplug can revoke DMA in one place; - hardware programming lives in
crate::arch::iommubehind a [Backend].
Ordering invariant: the global DOMAINS registry lock is always taken
before the DOMAIN_BITMAP lock. A Domain state lock is never taken
while holding the registry lock.
Re-exportsยง
use alloc::collections::BTreeMap;๐use alloc::sync::Arc;๐use alloc::vec::Vec;๐use core::fmt;๐use core::ops::BitAnd;๐use core::ops::BitOr;๐use core::sync::atomic::AtomicBool;๐use core::sync::atomic::AtomicU64;๐use core::sync::atomic::Ordering;๐use crate::sync::FixedQueue;๐use crate::sync::SpinLock;๐
Structsยง
- DmaProt
- DMA access rights for a mapping.
- Domain
- A DMA domain attached to one PCI function.
- Domain
Id - Opaque domain identifier (VT-d uses 16 bits).
- Domain
State ๐ - Domain
Stats - Per-domain counters exported through
/srv/iommu. - Fault
Record - One bounded fault record.
- Iommu
Group - Coarse IOMMU groups derived from the DMAR DRHD scopes.
- Iommu
Stats - Global counters.
- Mapping
- One IOVA -> physical mapping.
- Reserved
Region - A physical range reserved for a device by the firmware.
- Sbdf
- A PCI function identity, including its PCI segment group.
- Translation
- Result of a software translation.
Enumsยง
- Fault
Action - Outcome attached to a queued fault record.
- Fault
Policy - What the kernel should do when a device faults.
- Fault
Reason - Reason reported by the hardware (or by a debug injection).
- Iommu
Error - Errors returned by the IOMMU bookkeeping layer.
- Mapping
Kind - Granularity of one mapping.
Constantsยง
- BITMAP_
WORDS ๐ - FAULT_
BURST - Per-domain burst before records are dropped (rate limit).
- FAULT_
QUEUE_ CAPACITY - Maximum number of fault records kept globally.
- IOMMU_
PAGE_ SIZE - Page granularity of every IOMMU mapping.
- IOMMU_
SUPERPAGE_ 1G - 1 GiB leaf entries.
- IOMMU_
SUPERPAGE_ 2M - Large-page granularities supported by the second-level page tables.
- IOVA_
BASE - First address handed out to drivers in a domain IOVA space.
- MAX_
DOMAIN_ ID - Highest domain id the VT-d context entry can encode.
Staticsยง
- DOMAINS ๐
- DOMAIN_
BITMAP ๐ - FAULTS ๐
- FAULT_
DROPPED ๐ - FAULT_
SEQ ๐ - HARDWARE_
ENABLED ๐ - PANIC_
ON_ ๐INVALID_ RMRR - RESERVED ๐
- STATS ๐
Functionsยง
- activate
- Enable hardware translation.
- allocate_
domain_ ๐id - backend_
error ๐ - create_
domain - Convenience wrapper for segment 0.
- detach
- Detach a domain from its device: quiesce, then tear it down.
- detach_
device - Detach every domain bound to
sbdf(device hot-removal). - domain_
count - Number of live domains, for diagnostics.
- domain_
for - Return the domain bound to
sbdf, creating it on first use. - domain_
for_ owned - Same as
domain_for, but records the owning silo and its fault policy. - enabled
- True when translation is actually programmed.
- faults_
dropped - Number of fault records dropped by the rate limiter or a full queue.
- find_
domain - Find the live domain bound to
sbdf, without taking a logical reference. - firmware_
present - True when the firmware advertised an IOMMU (DMAR or IVRS).
- free_
domain_ ๐id - get_
domain - Look up a live domain by id.
- groups
- Return the coarse IOMMU groups advertised by the firmware.
- init
- Parse the firmware tables and log a short IOMMU summary.
- inject_
fault - Inject a synthetic fault (debug builds and fault-policy tests).
- load_
reserved_ ๐regions - Translate the DMAR RMRR structures into
ReservedRegions. - lookup ๐
- map
- Map an IOVA range into an existing domain, by id.
- map_
super - Map a range with automatic 2 MiB/1 GiB superpage selection.
- next_
fault - Pop the oldest fault record.
- owner_
usage - Number of live domains and mapped bytes owned by a silo.
- quiesce
- Stop accepting new mappings for a domain (hot-unplug preparation).
- refill_
fault_ budget - Refill the per-domain fault burst budget.
- release_
domain - Drop one logical reference, tearing down the domain when it reaches zero.
- reserved_
conflict - Find the reserved region, if any, covering
[start, start + len)forsbdf. - reserved_
regions - Snapshot of the reserved regions, for diagnostics and
/srv/iommu. - resume
- Allow new mappings again.
- revoke_
owner - Destroy every domain owned by
sid(silo death, hot-unplug, fault). - set_
reserved_ regions - Replace the reserved-region set with the firmware description.
- stats
- Snapshot of the global counters.
- teardown
- Destroy a domain unconditionally (hot-unplug, forced teardown).
- translate
- Translate an IOVA through an existing domain, by id.
- unmap
- Remove mappings from an existing domain, by id.
- validate_
range ๐