Description
Description
QEMU usb passthrough rabbit hole
Okay, so I went down this rabbit hole to see how doable it is to implement USB passthrough.
Let's go step by step:
-
Lima talks to QEMU through QMP (QEMU Machine Protocol). It uses a lib made by DigitalOcean, go-qemu, which has a function DeviceAdd [1] that seems to be autogenerated. From the qemu qmp ref docs [2] we can see that it accepts device, bus and id. However, according to [3], it should accept other kinds of args as well. In our case, device would be usb-host, and then we would require vendorid and productid.
-
Trying on the qemu monitor, I see this error:
(qemu) device_add usb-host,vendorid=0x1235,productid=0x8211
libusb_detach_kernel_driver: -3 [ACCESS]
libusb_detach_kernel_driver: -3 [ACCESS]
libusb_detach_kernel_driver: -3 [ACCESS]
libusb_detach_kernel_driver: -3 [ACCESS]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
libusb_kernel_driver_active: -5 [NOT_FOUND]
-
The whole bus could be connected, according to [4]
-
From my tests, if the device_add syntax is wrong or device is inexistent, it freezes the whole instance, seems to be a qemu bug.
More info at [5] and [6]
References
[1] https://pkg.go.dev/github.com/digitalocean/[email protected]/qmp/raw#Monitor.DeviceAdd
[2] https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html#qapidoc-2506
[3] https://qemu-project.gitlab.io/qemu/system/devices/usb.html
[4] #1317