Red Hat Training

A Red Hat training course is available for RHEL 8

10.10. 将 PCI 设备附加到 IBM Z 上的虚拟机

使用 vfio-pci 设备驱动程序,您可以将直通模式下的 PCI 设备分配给 IBM Z 主机上的虚拟机(VM)。例如,虚拟机可以使用 NVMe 闪存磁盘来处理数据库。

先决条件

  • 您的主机系统在使用 IBM Z 硬件架构。
  • 目标虚拟机使用 Linux 客户机操作系统。
  • 已在主机上载入了必要的 vfio 内核模块。

    # lsmod | grep vfio

    这个命令的输出必须包含以下模块:

    • vfio_pci
    • vfio_pci_core
    • vfio_iommu_type1

流程

  1. 获取您要使用的设备的 PCI 地址标识符。

    # lspci -nkD
    
    0000:00:00.0 0000: 1014:04ed
    	Kernel driver in use: ism
    	Kernel modules: ism
    0001:00:00.0 0000: 1014:04ed
    	Kernel driver in use: ism
    	Kernel modules: ism
    0002:00:00.0 0200: 15b3:1016
    	Subsystem: 15b3:0062
    	Kernel driver in use: mlx5_core
    	Kernel modules: mlx5_core
    0003:00:00.0 0200: 15b3:1016
    	Subsystem: 15b3:0062
    	Kernel driver in use: mlx5_core
    	Kernel modules: mlx5_core
  2. 打开您要向其附加 PCI 设备的虚拟机的 XML 配置。

    # virsh edit vm-name
  3. 将以下 <hostdev> 配置添加到 XML 文件的 <devices> 部分。

    address 行上的值替换为设备的 PCI 地址。例如,如果设备地址是 0003:00:00.0,请使用以下配置:

    <hostdev mode="subsystem" type="pci" managed="yes">
      <driver name="vfio"/>
       <source>
        <address domain="0x0003" bus="0x00" slot="0x00" function="0x0"/>
       </source>
       <address type="pci"/>
    </hostdev>
  4. 可选: 要修改客户机操作系统如何检测 PCI 设备,您还可以在 <address> 元素中添加 <zpci> 子元素。在 <zpci> 行中,您可以调整 uidfid 值,它修改客户端操作系统中设备的 PCI 地址和功能 ID。

    <hostdev mode="subsystem" type="pci" managed="yes">
      <driver name="vfio"/>
       <source>
        <address domain="0x0003" bus="0x00" slot="0x00" function="0x0"/>
       </source>
       <address type="pci">
         <zpci uid="0x0008" fid="0x001807"/>
       </address>
    </hostdev>

    在本例中:

    • uid="0x0008" 将虚拟机中设备的域 PCI 地址设置为 0008:00:00.0
    • fid="0x001807" 将设备的插槽值设置为 0x001807。因此,虚拟机的文件系统中的设备配置被保存到 /sys/bus/pci/slots/00001087/address 中。

      如果没有指定这些值,libvirt 会自动配置它们。

  5. 保存 XML 配置。
  6. 如果虚拟机正在运行,请将其关闭。

    # virsh shutdown vm-name

验证

  1. 启动虚拟机,并登录到其客户机操作系统。
  2. 在客户端操作系统中,确认是否列出了 PCI 设备。

    例如,如果设备地址是 0003:00:00.0,请使用以下命令:

    # lspci -nkD | grep 0003:00:00.0
    
    0003:00:00.0 8086:9a09 (rev 01)