Setting up PCI devices for VFIO pass-through
To set up a PCI device as a VFIO pass-through device you must enable the vfio_pci device driver to handle the PCI device type, and you must assign the specific device to vfio_pci.
Enabling the vfio_pci device driver
For devices that are not managed by libvirt, enable the vfio_pci device driver for specific PCI card types. Proceed according to how your vfio_pci device driver is compiled: as part of the kernel image or as a separate module.
- Module parameter
-
If the vfio_pci device driver is compiled as a separate module, you can use the
ids=
module parameter to specify the PCIe card types.Example: In this example, a PCIe device with function address0001:000:000:0
, vendor code15b3
, and device code1003
is available on the host. The specification for theids=
module parameter makes this card type eligible for the vfio_pci device driver.# lspci -n 0001:000:000:0 15b3:1003 # modprobe vfio_pci ids=15b3:1003
- Kernel parameter
-
If the vfio_pci device driver is compiled into the kernel, you can use the
vfio_pci.ids=
kernel parameter to specify the PCIe card types.Example: The following specification for thevfio_pci.ids=
kernel parameter makes the card type eligible for the vfio_pci device driver.vfio_pci.ids=15b3:1003
On a running host, you can use the /sys/bus/pci/drivers/vfio-pci/new_id sysfs attribute to enable the vfio_pci device driver to control a particular PCIe card type. Write the vendor code and device code, separated by a blank, to the attribute.
15b3
and device code 1003
eligible for the vfio_pci device
driver.# echo 15b3 1003 > /sys/bus/pci/drivers/vfio-pci/new_id
After setting up the vfio_pci device driver for one or more PCIe card types, all cards of these types that are freed from their default device driver are assigned to the vfio_pci device driver.
Assigning a PCI device to the vfio_pci device driver
# echo <function_address> > /sys/bus/pci/drivers/<pci_device_driver>/unbind
# lspci -v
0001:00:00.0 Ethernet controller: Mellanox Technologies MT27500 Family [ConnectX-3]
Subsystem: Mellanox Technologies Device 048d
Physical Slot: 00000015
...
Kernel driver in use: mlx4_core
Kernel modules: mlx4_core
# echo 0001:00:00.0 > /sys/bus/pci/drivers/mlx4_core/unbind