Skip to main content

Module iommu

Module iommu 

Source
Expand description

IOMMU domain and IOVA management.

This module is the architecture-neutral bookkeeping layer between a PCI function and the DMA allocator:

  • a Domain is bound to one Sbdf and owns a sparse IOVA space;
  • mappings are kept in a BTreeMap keyed by IOVA start, so map, unmap and translate are 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::iommu behind 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.
DomainId
Opaque domain identifier (VT-d uses 16 bits).
DomainState ๐Ÿ”’
DomainStats
Per-domain counters exported through /srv/iommu.
FaultRecord
One bounded fault record.
IommuGroup
Coarse IOMMU groups derived from the DMAR DRHD scopes.
IommuStats
Global counters.
Mapping
One IOVA -> physical mapping.
ReservedRegion
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ยง

FaultAction
Outcome attached to a queued fault record.
FaultPolicy
What the kernel should do when a device faults.
FaultReason
Reason reported by the hardware (or by a debug injection).
IommuError
Errors returned by the IOMMU bookkeeping layer.
MappingKind
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) for sbdf.
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 ๐Ÿ”’