USB-device passthrough setup for virtual machines

Still in draft version

Several options exist for device passthrough

  • Passthrough a complete USB controller
    • and use an USB switch
    • use a second mouse and keyboard
  • virtual devices
  • synergy

Using USB controller to passthrough

lspci -nn | grep USB
01:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:43b9] (rev 02)
06:00.0 USB controller [0c03]: ASMedia Technology Inc. Device [1b21:1343]
0b:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:145c]
check in the iommu groups if one of those has is in a single group
0b:00.3 is in group 18 in my case. -> 0b:00.3

This command can be used to determine which device is in which group (source: arch wiki)

for usb_ctrl in $(find /sys/bus/usb/devices/usb* -maxdepth 0 -type l); do pci_path="$(dirname "$(realpath "${usb_ctrl}")")"; echo "Bus $(cat "${usb_ctrl}/busnum") --> $(basename $pci_path) (IOMMU group $(basename $(realpath $pci_path/iommu_group)))"; lsusb -s "$(cat "${usb_ctrl}/busnum"):"; echo; done

Bus 5 –> 0000:0b:00.3 (IOMMU group 18)
Bus 005 Device 003: ID 046d:c042 Logitech, Inc. G3 Laser Mouse
Bus 005 Device 002: ID 1b1c:1b09 Corsair
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 6 –> 0000:0b:00.3 (IOMMU group 18)
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Passthrough -> 0b:00.3

on the passed though usb-controller you can use either a second set of mouse and keyboard, or an USB switcher like this.

On ubuntu you might have to take care off the apparmor if you want to pass the usb controller.

Edit the /etc/apparmor.d/abstractions/libvirt-qemu file and find the # for usb access section and modify it thusly:

# for usb access
/dev/bus/usb/** rw,
/etc/udev/udev.conf r,
/sys/bus/ r,
/sys/class/ r,
/run/udev/data/* rw,

Virtual Devices

Set them up in the virtual machine manager.


Leave a Reply