Linux check iommu support

check for IOMMU support on linux

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, 2014

Register our DRHD IOMMUs, cross link devices, and provide a base set of attributes for the IOMMU. . On a typical desktop system, this provides the following (pruned):

$ find /sys | grep dmar /sys/devices/virtual/iommu/dmar0 . /sys/class/iommu/dmar0 /sys/class/iommu/dmar1 
/* * Create an IOMMU device and return a pointer to it. IOMMU specific * attributes can be provided as an attribute group, allowing a unique * namespace per IOMMU type. */ struct device *iommu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, . ) 

Registration is done only for enabled IOMMU. DMAR:

if (intel_iommu_enabled) < iommu->iommu_dev = iommu_device_create(NULL, iommu, intel_iommu_groups, "%s", iommu->name); 
static int iommu_init_pci(struct amd_iommu *iommu) < . if (!iommu->dev) return -ENODEV; . iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu, amd_iommu_groups, "ivhd%d", iommu->index); 
int __init intel_iommu_init(void) < . pr_info("Intel(R) Virtualization Technology for Directed I/O\n"); . for_each_active_iommu(iommu, drhd) iommu->iommu_dev = iommu_device_create(NULL, iommu, intel_iommu_groups, "%s", iommu->name); 

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 parsing dmesg output or searching in /var/log/kern.log or /var/log/messages for driver-specific enable messages:

  • drivers/iommu/amd_iommu_init.c, line 1640
  • drivers/iommu/arm-smmu-v3.c, line 2709
  • drivers/iommu/arm-smmu.c, line 2163
  • drivers/iommu/dmar.c, line 1083
  • drivers/iommu/exynos-iommu.c, line 623
  • drivers/iommu/intel-iommu.c, line 4878
  • drivers/iommu/iommu-sysfs.c, line 57
  • drivers/iommu/msm_iommu.c, line 797
  • drivers/iommu/mtk_iommu.c, line 581

Источник

In Linux, check whether vT-D or IOMMU is enabled

Both VT-D and IOMMU actually stand for I/O virtualization, but the former is Intel’s name and the latter is AMD’s name:

  • VT-d The whole is called Intel® Virtualization Technology for Directed I/O
  • IOMMU The whole is called Input/Output Memory Management Unit

This technology allows resources from pCI-E devices to be allocated directly to virtual machines, known as PCI passthrough.

For example, the virtual client has direct access to a physical video card, performs much better than a VMM/Hypervisor virtual video card, and supports graphics acceleration.

Читайте также:  Linux migrate to ssd

Check whether it is enabled in Linux

Generally speaking, the VT-D/IOMMU Settings can be found in the BIOS/UEFI of the mainboard.

But there are special cases, some motherboards can not find the setting, there are two cases:

  • The mainboard hardware or firmware is not supported The I/O virtualization
  • The main board is brushed into the neutered version of the firmware, but in fact VT-d / IOMMU Is enabled

How do I check if it is enabled on Linux?

If VT-D/IOMMU is enabled, Linux will configure DMA remapping during startup, so the easy way is to look for DMAR items in dMESg.

# dmesg | grep DMAR [0.000000] ACPI: DMAR 0x00000000BBECB000 0000A8 (V01 LENOVO TP-R0D 00000930 PTEC 00000002) [0.001000] DMAR: Host address width 39 [0.001000] DMAR: DRHD Base: 0x000000FeD90000 Flags: 0x0 [0.001000] DMAR: DMAR0: Reg_base_addr FED90000 VER 1:0 CAP 1C0000C40660462 ECAP 19e2FF0505E [0.001000] DMAR: DRHD Base: 0x000000FeD91000 FLAGS: 0x1 [0.001000] DMAR: DMAR1: Reg_base_addr FED91000 VER 1:0 CAP D2008C40660462 ECAP F050DA [0.001000] DMAR: RMRR Base: 0x000000BBDD8000 end: 0x000000bbDF7ffF [0.001000] DMAR: RMRR Base: 0x000000BD000000 End: 0x000000Bf7ffffF [0.001000] DMAR-IR: IOAPIC ID 2 under DRHD Base 0xFeD91000 IOMMU 1 [0.001000] Dmar-ir: HPET ID 0 under DRHD Base 0xFeD91000 [0.001000] dmar-ir: Queued Invalidation will be enabled to support X2APIC and INtr-remapping. [0.002000] DMAR-IR: Enabled IRQ remapping in x2apic modeCopy the code

If you look at the last line, you can see something like dmar-ir: Enabled IRQ remapping in XXXXX mode

# dmesg | grep DMAR # Copy the code

No output, i.e., no DMAR related items found

Источник

Check if VT-D / IOMMU has been enabled in the BIOS/UEFI

I couldn’t find a way to check if Intel’s VT-D or AMD’s IOMMU are enabled in the BIOS/UEFI. I need a way to detect if it is enabled or not without having the iommu kernel parameters set ( iommu=1 , amd_iommu=on , intel_iommu=on ). One idea I had was to use rdmsr , but I’m not sure if that would work. Instead of systool I initially wanted to use sudo rdmsr 0x3A , but it didn’t work for me. It always reports:

rdmsr: CPU 0 cannot read MSR 0x0000003a 

rdmsr is part of msr-tools btw. And to be used requires the msr kenel module to be loaded ( sudo modprobe msr ) first. Allegedly sudo rdmsr 0x3A should have returned 3 or 5 to indicate that VT-X/AMD-V is enabled.

Читайте также:  Midnight commander linux запустить

3 Answers 3

If VT-d is enabled, Linux will configure DMA Remapping at boot time. The easiest way to find this is to look in dmesg for DMAR entries. If you don’t see errors, then VT-d is enabled.

[root@localhost ~]# dmesg | grep DMAR [ 0.000000] ACPI: DMAR 0x00000000BBECB000 0000A8 (v01 LENOVO TP-R0D 00000930 PTEC 00000002) [ 0.001000] DMAR: Host address width 39 [ 0.001000] DMAR: DRHD base: 0x000000fed90000 flags: 0x0 [ 0.001000] DMAR: dmar0: reg_base_addr fed90000 ver 1:0 cap 1c0000c40660462 ecap 19e2ff0505e [ 0.001000] DMAR: DRHD base: 0x000000fed91000 flags: 0x1 [ 0.001000] DMAR: dmar1: reg_base_addr fed91000 ver 1:0 cap d2008c40660462 ecap f050da [ 0.001000] DMAR: RMRR base: 0x000000bbdd8000 end: 0x000000bbdf7fff [ 0.001000] DMAR: RMRR base: 0x000000bd000000 end: 0x000000bf7fffff [ 0.001000] DMAR-IR: IOAPIC id 2 under DRHD base 0xfed91000 IOMMU 1 [ 0.001000] DMAR-IR: HPET id 0 under DRHD base 0xfed91000 [ 0.001000] DMAR-IR: Queued invalidation will be enabled to support x2apic and Intr-remapping. [ 0.002000] DMAR-IR: Enabled IRQ remapping in x2apic mode 

Another example with x2apic opt out:

[root@localhost ~]# dmesg | grep DMAR [ 0.000000] ACPI: DMAR 0000000079a20300 000C4 (v01 SUPERM SMCI--MB 00000001 INTL 20091013) [ 0.106389] DMAR: Host address width 46 [ 0.106392] DMAR: DRHD base: 0x000000fbffc000 flags: 0x1 [ 0.106400] DMAR: dmar0: reg_base_addr fbffc000 ver 1:0 cap 8d2078c106f0466 ecap f020de [ 0.106402] DMAR: RMRR base: 0x0000007bb24000 end: 0x0000007bb32fff [ 0.106404] DMAR: ATSR flags: 0x0 [ 0.106407] DMAR: RHSA base: 0x000000fbffc000 proximity domain: 0x0 [ 0.106409] DMAR-IR: IOAPIC id 8 under DRHD base 0xfbffc000 IOMMU 0 [ 0.106411] DMAR-IR: HPET id 0 under DRHD base 0xfbffc000 [ 0.106413] DMAR-IR: x2apic is disabled because BIOS sets x2apic opt out bit. [ 0.106414] DMAR-IR: Use 'intremap=no_x2apic_optout' to override the BIOS setting. [ 0.106591] DMAR-IR: Enabled IRQ remapping in xapic mode 

Either way, you’re looking for that last line, DMAR-IR: Enabled IRQ remapping in mode .

On a system with VT-d disabled, you will either see an error message, or nothing at all.

[root@localhost ~]# dmesg | grep DMAR [root@localhost ~]# 

Источник

Читайте также:  Запрещенные символы имени файла linux

abelardojarab / IOMMU support in Linux kernel.md

ACPI enumerates and lists the different DMA engines in the platform, and device scope relationships between PCI devices and which DMA engine controls them.

Well behaved drivers call pci_map_() calls before sending command to device that needs to perform DMA. Once DMA is completed and mapping is no longer required, device performs a pci_unmap_() calls to unmap the region.

The Intel IOMMU driver allocates a virtual address per domain. Each PCIE device has its own domain (hence protection). Devices under p2p bridges share the virtual address with all devices under the p2p bridge due to transaction id aliasing for p2p bridges.

IOVA generation is pretty generic. We used the same technique as vmalloc() but these are not global address spaces, but separate for each domain. Different DMA engines may support different number of domains.

We also allocate guard pages with each mapping, so we can attempt to catch any overflow that might happen.

Finding DMAR regions in Linux console

$ find /sys | grep dmar /sys/devices/virtual/iommu/dmar0 . /sys/class/iommu/dmar0 /sys/class/iommu/dmar1

ACPI enumerates and lists the different DMA engines in the platform, and device scope relationships between PCI devices and which DMA engine controls them.

Well behaved drivers call pci_map_() calls before sending command to device that needs to perform DMA. Once DMA is completed and mapping is no longer required, device performs a pci_unmap_() calls to unmap the region.

The Intel IOMMU driver allocates a virtual address per domain. Each PCIE device has its own domain (hence protection). Devices under p2p bridges share the virtual address with all devices under the p2p bridge due to transaction id aliasing for p2p bridges.

IOVA generation is pretty generic. We used the same technique as vmalloc() but these are not global address spaces, but separate for each domain. Different DMA engines may support different number of domains.

We also allocate guard pages with each mapping, so we can attempt to catch any overflow that might happen.

Finding DMAR regions in Linux console

$ find /sys | grep dmar /sys/devices/virtual/iommu/dmar0 . /sys/class/iommu/dmar0 /sys/class/iommu/dmar1

Источник

Оцените статью
Adblock
detector