Preparing PCI pass-through devices

To make a PCIe device eligible as a VFIO pass-through device, you must bring it under control of the vfio_pci device driver.

Before you begin

PCI devices can be configured for automatic management by libvirt, as described in Configuring pass-through PCI devices. This management includes a dynamic host preparation. Perform the steps that follow only for devices that are not managed by libvirt.

Procedure

  1. Free the intended pass-through PCI devices from the applicable PCI device driver by writing their function address to /sys/bus/pci/drivers/<pci_device_driver>/unbind.
    # echo <function_address> > /sys/bus/pci/drivers/<pci_device_driver>/unbind
    In the path, <pci_device_driver> is the name of the device driver that handles the particular PCI device, for example mlx4_core for 10 GbE RoCE Express devices.
    Tip: Issue lspci -v to find out which device driver controls the device.
  2. Configure the vfio-pci device driver.
    You must ensure that the vfio-pci device driver is operational and configured to control the intended PCI card types. You need to specify the applicable vendor code and device code to configure a specific card type.
    Tip: Issue lspci -n to display the vendor and device codes for your PCI devices in the format <vendor_code>:<device_code>.
    • Configure the card types through sysfs.
      1. Unless it is compiled into the kernel, load the vfio-pci device driver.
        # modprobe vfio_pci
      2. Set the PCI card types to be controlled by the vfio-pci device driver by writing the vendor and device code to /sys/bus/pci/drivers/vfio-pci/new_id.
        # echo <vendor_code> <device_code> > /sys/bus/pci/drivers/vfio-pci/new_id
        Separate the vendor code and the device code with a blank. Repeat the command to specify multiple card types.
    • If the vfio-pci device driver is compiled as a separate module, you can configure the card types with the ids= module parameter.
      # modprobe vfio_pci ids=<vendor_code>:<device_code>
      You can specify multiple card types as a comma-separated value.
    • If the vfio-pci device driver is compiled into the kernel, you can configure the card types with the vfio_pci.ids= module parameter.
      vfio_pci.ids=<vendor_code>:<device_code>
      You can specify multiple card types as a comma-separated value.

Example

To make a 10 GbE RoCE Express device with function address 0001:000:000:0 eligible for KVM guests:
# lspci -n
0001:000:000:0 15b3:1003
# echo 0001:000:000:0 > /sys/bus/pci/drivers/mlx4_core/unbind
# modprobe vfio_pci ids=15b3:1003

What to do next

You can now configure a virtual PCI device as a pass-through device that is based on the device at function address 0001:000:000:0. For more information, see Configuring pass-through PCI devices.