bash 检查 BIOS/UEFI 中是否启用了 VT-D/IOMMU

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51261999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:58:23  来源:igfitidea点击:

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

linuxbashvirtual-machinekvmiommu

提问by Forivin

To check if Intel's VT-X or AMD's AMD-V is enabled in the BIOS/UEFI, I use:

要检查 BIOS/UEFI 中是否启用了 Intel 的 VT-X 或 AMD 的 AMD-V,我使用:

if systool -m kvm_amd -v &> /dev/null || systool -m kvm_intel -v &> /dev/null ; then
    echo "AMD-V / VT-X is enabled in the BIOS/UEFI."
else
    echo "AMD-V / VT-X is not enabled in the BIOS/UEFI"
fi

I couldn't find a way to check if Intel's VT-D or AMD's IOMMU are enabled in the BIOS/UEFI.

我找不到检查 BIOS/UEFI 中是否启用了 Intel 的 VT-D 或 AMD 的 IOMMU 的方法。

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).

我需要一种方法来检测它是否已启用而无需设置 iommu 内核参数 ( 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 systoolI initially wanted to use sudo rdmsr 0x3A, but it didn't work for me. It always reports:

我的一个想法是使用rdmsr,但我不确定这是否可行。而不是systool我最初想使用sudo rdmsr 0x3A,但它对我不起作用。它总是报告:

rdmsr: CPU 0 cannot read MSR 0x0000003a

rdmsris part of msr-toolsbtw. And to be used requires the msrkenel module to be loaded (sudo modprobe msr) first.

rdmsrmsr-tools顺便说一句的一部分。并且要使用需要msr先加载 kenel 模块 ( sudo modprobe msr)。

Allegedly sudo rdmsr 0x3Ashould have returned 3or 5to indicate that VT-X/AMD-V is enabled...

据称sudo rdmsr 0x3A应该返回35表明启用了 VT-X/AMD-V...

回答by Michael Hampton

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

如果启用了 VT-d,Linux 将在启动时配置 DMA 重映射。找到它的最简单方法是查找dmesgDMAR 条目。如果您没有看到错误,则 VT-d 已启用。

For example:

例如:

[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:

x2apic 退出的另一个示例:

[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 <whichever> mode.

无论哪种方式,您都在寻找最后一行,DMAR-IR: Enabled IRQ remapping in <whichever> mode.

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

在禁用 VT-d 的系统上,您将看到一条错误消息,或者什么也没有。

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

回答by Forivin

I just found another way that seems to work even if the iommu kernel parameters have not been set:

我刚刚找到了另一种即使尚未设置 iommu 内核参数似乎也有效的方法:

if compgen -G "/sys/kernel/iommu_groups/*/devices/*" > /dev/null; then
    echo "AMD's IOMMU / Intel's VT-D is enabled in the BIOS/UEFI."
else
    echo "AMD's IOMMU / Intel's VT-D is not enabled in the BIOS/UEFI"
fi

回答by Ehsan Tadayon

Building on Jo-Erlend Schinstad's answer:

基于 Jo-Erlend Schinstad 的回答:

Install cpu-checker

安装 CPU 检查器

$ sudo apt-get update
$ sudo apt-get install cpu-checker

Then check:

然后检查:

$ kvm-ok

If the CPU is enabled, you should see something like:

如果启用了 CPU,您应该会看到如下内容:

INFO: /dev/kvm exists
KVM acceleration can be used

Otherwise, you might see something like:

否则,您可能会看到类似以下内容:

INFO: /dev/kvm does not exist
HINT:   sudo modprobe kvm_intel
INFO: Your CPU supports KVM extensions
INFO: KVM (vmx) is disabled by your BIOS
HINT: Enter your BIOS setup and enable Virtualization Technology (VT),
      and then hard poweroff/poweron your system
KVM acceleration can NOT be used