Pass-through PCIe USB3 card to KVM guest

To get some usable input devices inside a Windows VM used mainly for gaming i bought a PCIe USB3 card that should be passed through to the guest.

During the boot process the xhci_hcd (usb3) driver of the host system attaches to the card which makes the card unusable with qemu/kvm without unbinding it first. To pass it through the card needs to be claimed by the vfio-pci driver.

To get the vfio-pci driver to claim the USB3 card, create the file /etc/modprobe.d/vfio.conf and add the pci id (get it from lspci -nv) to the list. The id 1912:0014 is the USB3 card. The other two ids are from my GPU. Update the initrd after this change before rebooting.

options vfio-pci ids=10de:11c0,10de:0e0b,1912:0014

After the reboot lspci -v shows that the USB3 card still attached to the xhci_hcd driver:

06:00.0 USB controller: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller (rev 03) (prog-if 30 [XHCI])
	Flags: fast devsel, IRQ 18
	Memory at f7800000 (64-bit, non-prefetchable) [size=8K]
	Capabilities: [50] Power Management version 3
	Capabilities: [70] MSI: Enable- Count=1/8 Maskable- 64bit+
	Capabilities: [90] MSI-X: Enable- Count=8 Masked-
	Capabilities: [a0] Express Endpoint, MSI 00
	Capabilities: [100] Advanced Error Reporting
	Capabilities: [150] Latency Tolerance Reporting
	Kernel driver in use: xhci_hcd

The boot logs show that the xhci_hcd driver is loaded just before the vfio-pci driver and thus comes first to see the USB3 card.

To work around this, define a soft dependency (found here) (also see man modprobe.d) on vfio-pci for xhcd_hcd so that vfio-pci (and its configuration) gets loaded before the xhci_hcd module.

Create /etc/modprobe.d/xhci_hcd.conf, rebuild the initrd and reboot to test.

# load vfio-pci before xhci-hcd else the usb3 orts are claimed by xhci_hcd
softdep xhci_hcd pre: vfio_pci

After the reboot the lspci -v should show that the driver in use for the USB3 card is vfio-pci:

06:00.0 USB controller: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller (rev 03) (prog-if 30 [XHCI])
	Flags: fast devsel, IRQ 18
	Memory at f7800000 (64-bit, non-prefetchable) [size=8K]
	Capabilities: [50] Power Management version 3
	Capabilities: [70] MSI: Enable- Count=1/8 Maskable- 64bit+
	Capabilities: [90] MSI-X: Enable- Count=8 Masked-
	Capabilities: [a0] Express Endpoint, MSI 00
	Capabilities: [100] Advanced Error Reporting
	Capabilities: [150] Latency Tolerance Reporting
	Kernel driver in use: vfio-pci

Using the bus:device.function number the device can then be used by qemu/kvm to be passed through to the guest system.

1 thought on “Pass-through PCIe USB3 card to KVM guest”

Leave a Comment