Show Table of Contents
附录 G. 为 PCI 透传配置一个主机
通过启用 PCI 透传(PCI passthrough)功能,一个虚拟机可以象使用直接附加到这个虚拟机上的设备一样使用主机的设备。 为了启用 PCI 透传功能,您需要启用虚拟化扩展和 IOMMU 功能。以下步骤需要重新引导主机。如果这个主机已被附加到 Manager,请在执行以下操作时把主机设置为维护状态。
先决条件
- 确认主机硬件满足 PCI 设备透传以及分配的要求。详情请参阅 第 2.2.4 节 “PCI 设备要求”。
过程 G.1. 为 PCI 透传配置一个主机
- 在 BIOS 中启用虚拟化扩展(例如,VT-d 或 AMD-Vi)。请参阅 Red Hat Enterprise Linux Virtualization and Administration Guide 中的 Enabling Intel VT-x and AMD-V virtualization hardware extensions in BIOS。
- 编辑 grub 配置文件来启用 IOMMU。
注意
如果使用 IBM POWER8 硬件,则不需这一步,因为它已被默认启用。- 对于 Intel 系统,引导机器,把
intel_iommu=on添加到grub配置文件的GRUB_CMDLINE_LINUX一行的最后。# vi /etc/default/grub ... GRUB_CMDLINE_LINUX="nofb splash=quiet console=tty0 ... intel_iommu=on ...
- 对于 AMD 系统,引导机器,把
amd_iommu=on添加到grub配置文件的GRUB_CMDLINE_LINUX一行的最后。# vi /etc/default/grub ... GRUB_CMDLINE_LINUX="nofb splash=quiet console=tty0 ... amd_iommu=on ...
注意
如果intel_iommu=on或amd_iommu=on设置可以正常工作,您可以尝试把它们替换为intel_iommu=pt或amd_iommu=pt。pt选项只为使用透传功能的设备启用 IOMMU,并可以提供更好的功能。但不是所有硬件都支持这个选项。如果pt选项在您的主机上无法正常工作,请转换回使用前面的选项。如果因为硬件不支持中断重映射(interrupt remapping)导致透传失败,您可以在信任虚拟机的情况下启用allow_unsafe_interrupts选项。因为启用allow_unsafe_interrupts选项可能会存在通过虚拟机对主机进行 MSI 攻击的可能,因此这个选项在默认情况下没有被启用。使用以下方法启用这个选项:# vi /etc/modprobe.d options vfio_iommu_type1 allow_unsafe_interrupts=1
- 刷新
grub.cfg文件并重启主机使这些改变生效:# grub2-mkconfig -o /boot/grub2/grub.cfg
# reboot
对于 GPU 透传功能,您需要在主机和虚拟机系统上都进行额外的配置。相关信息,请参阅管理指南中的 Preparing Host and Guest Systems for GPU Passthrough。
如果需要启用 SR-IOV 并为虚拟机分配专门的虚拟网卡,请参阅 https://access.redhat.com/articles/2335291。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.