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)
Sun, Nov 9, 3:55 AM
Unknown Object (File)
Fri, Nov 7, 2:02 AM
Unknown Object (File)
Oct 30 2025, 4:01 PM
Unknown Object (File)
Oct 29 2025, 4:25 PM
Unknown Object (File)
Oct 27 2025, 12:27 AM
Unknown Object (File)
Oct 27 2025, 12:27 AM
Unknown Object (File)
Oct 27 2025, 12:27 AM
Unknown Object (File)
Oct 27 2025, 12:24 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