I'd like to verify on any given Linux machine if PCI passthrough is supported. After a bit of googling, I found that I should rather check if IOMMU is supported, and I did so by running:
dmesg | grep IOMMU
If it supports IOMMU (and not IOMMUv2), I would get:
IOMMU
[ 0.000000] DMAR: IOMMU enabled
[ 0.049734] DMAR-IR: IOAPIC id 8 under DRHD base 0xfbffc000 IOMMU 0
[ 0.049735] DMAR-IR: IOAPIC id 9 under DRHD base 0xfbffc000 IOMMU 0
[ 1.286567] AMD IOMMUv2 driver by Joerg Roedel <jroedel@suse.de>
[ 1.286568] AMD IOMMUv2 functionality not available on this system
...where DMAR: IOMMU enabled
is what I'm looking for.
Now, if the machine has been running for days without a reboot, that first message [ 0.000000] DMAR: IOMMU enabled
might not appear any more in the log with the previous command.
Is there any way to check for IOMMU support when that message disappears from the log?
Since 2014 enabled iommu are registered in /sys (sysfs) special file system as class
iommu
(documented at ABI/testing/sysfs-class-iommu): https://patchwork.kernel.org/patch/4345491/ "[2/3] iommu/intel: Make use of IOMMU sysfs support" - June 12, 2014The code is
iommu_device_create
(http://elixir.free-electrons.com/linux/v4.5/ident/iommu_device_create, around 4.5) oriommu_device_sysfs_add
(http://elixir.free-electrons.com/linux/v4.11/ident/iommu_device_sysfs_add) in more recent kernels.Registration is done only for enabled IOMMU. DMAR:
AMD IOMMU:
Intel:
With 4.11 linux kernel version
iommu_device_sysfs_add
is referenced in many IOMMU drivers, so checking /sys/class/iommu is better (more universal) way to programmatically detect enabled IOMMU than parsingdmesg
output or searching in/var/log/kern.log
or/var/log/messages
for driver-specific enable messages: