Page MenuHomeFreeBSD

AMD IOMMU: fix per-device IOMMU bypass when IR is enabled
ClosedPublic

Authored by jah on Oct 20 2025, 2:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Jan 12, 12:43 PM
Unknown Object (File)
Fri, Jan 2, 10:25 PM
Unknown Object (File)
Dec 29 2025, 11:52 AM
Unknown Object (File)
Dec 11 2025, 3:33 AM
Unknown Object (File)
Dec 10 2025, 8:31 PM
Unknown Object (File)
Dec 6 2025, 6:33 PM
Unknown Object (File)
Nov 9 2025, 3:55 AM
Unknown Object (File)
Nov 7 2025, 2:02 AM
Subscribers

Details

Summary

When interrupt remapping (IR) is enabled, the device table entry
(DTE) for a given device will likely be initialized by
amdiommu_ir_find() during MSI configuration. This function directly
calls amdiommu_get_ctx_for_dev() with id_mapped=false, which means that
any attempt to disable DMA remapping for the device (e.g. by setting
hw.busdma.pciD.B.S.F='bounce' in the loader tunables) will effectively
be ignored as the paging mode field in the DTE will not be set to
0 as required for identity mapping. This will ultimately produce
an unusable device, because busdma will later observe the bounce
configuration through iommu_instantiate_ctx() and will employ the
non-translated 'bounce' busdma methods for the device, while the DTE
remains configured to enable translation.

Fix this by tweaking iommu_instantiate_ctx() to always return the
relevant per-device context object even if translation is disabled,
and adopt it in amdiommu_ir_find() instead of directly calling
amdiommu_get_ctx_for_dev().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jah requested review of this revision.Oct 20 2025, 2:19 AM

There are probably a lot of different ways to do this. Initially I just did the obvious thing and made iommu_bus_dma_is_dev_disabled() non-static and added a call to it in amdiommu_ir_find(), but this approach seems cleaner and perhaps less likely to break if per-device busdma options are changed in the future.

This revision is now accepted and ready to land.Oct 20 2025, 2:27 AM