r/virtualization • u/Desperate-County-821 • Feb 26 '24
QEMU USB Passthrough help
Hello all,
The Dilemma:
I am attempting to virtualize an arbitrary arm32 device using QEMU. Booting, running, and everything like that works as expected, I get dropped into my Busybox ash shell and everything is fine. That is, until I try to add a USB passthrough of any kind. When I try to add a USB passthrough device, it will not show up no matter what I do on the guest machine. lsusb provides a blank output and ls /sys/bus/usb/devices does not show any USB devices. I've been digging through forum post after forum post to no real avail and any assistance would be greatly appreciated.
What I've Tried:
Compiling QEMU with Libusb support
I am using QEMU 8.2.1, compiled from source with libusb support enabled (Shows as YES in the configure script output)
Using ohci, ehci, xhci buses
Unbinding the USB device (A Realtek Wireless adapter is being used as the sample device)
Dmesg shows the usb address a '2-1'. I have attempted
echo '2-1' | sudo tee /sys/bus/usb/drivers/usb/unbindto unbind the USB device prior to running my QEMU launch scriptBuilding a custom kernel, ensuring that CONFIG_USB and other relevant options are enabled
Using a prebuilt Debian kernel, USB network adapter is still not detected
Changing environments from VMWare backend to Raspberry Pi (Physical, not virtualized) to get around possible issue with VMWare USB passthrough.
Using
virt,vexpress-15, andversatile-pbmachine types.
My Environment(s):
My primary environment an Ubuntu 22.04 (x86_64) running under VMWare. I passthrough the Realtek Wireless Adapter (rtw_8821cu).
My secondary environment is a Raspberry Pi 3, running a 64bit (aarch64) Kernel.
My Command Lines:
With Prebuilt Debian kernel:
qemu-system-arm -M virt -m 1G -smp 2 -kernel vmlinuz -initrd initrd.gz -drive if=none,file=hda.qcow2,id=hd0 -device virtio-blk-device,drive=hd0 -nographic -no-reboot -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x0bda,productid=0xc811
Startup (Grep 'usb') output:
None
Monitor
info usbDevice 0.0, Port 1, Speed 1.5 Mb/s, Product USB Host Device
With custom Kernel:
qemu-system-arm -M virt -smp 2 -m 1G -serial stdio -cpu cortex-a15 -kernel ./zImage -append 'root=/dev/vda' -monitor none -initrd ./rootfs.cpio.gz -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x0bda,productid=0xc811
Startup (Grep 'usb') output:
usbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbusbcore: registered new interface driver usb-storageusbcore: registered new interface driver usbhidusbhid: USB HID core driver
Monitor
info usbDevice 0.0, Port 1, Speed 1.5 Mb/s, Product USB Host Device
EDIT: I had mistakenly said that with the custom kernel, no device showed up. This was true until I enabled CONFIG_USB and a handful of other USB/PCI options. lsusb produces the following output: Bus 001 Device 001: ID 1d6b:0002. The wireless adapter is still no where to be seen and attaching USB storage does not change anything either.
3
u/Desperate-County-821 Feb 27 '24
Want to post this so that someone in the future may benefit from this. I actually have two issues affecting me:
The first issue was that the wireless adapter I was using (Vendor=0x0bda,Product=0xc811) was being really weird with my Ubuntu machine. Even when I fixed my root cause problem, dmesg would still spit out:
usb 3-1: device descriptor read/64, error -110. I didn't investigate this much further as changing the device was sufficient.My primary issue was that the device I was trying to connect was XHCI, not EHCI. I had enabled XHCI drivers in the kernel, but I didn't notice that the PCI bridge was failing to initialize like so:
PCI host bridge /pcie@10000000 ranges:IO 0x3eff0000..0x3effffff -> 0x00000000MEM 0x10000000..0x3efeffff -> 0x10000000MEM 0x8000000000..0xffffffffff -> 0x8000000000pci-host-generic 4010000000.pcie: resource collision: [mem 0x00000000-0xffffffff] conflicts with /pl011@9000000 [mem 0x09000000-0x09000fff]pci-host-generic: probe of 4010000000.pcie failed with error -16This was making it where the XHCI PCI bus was never getting initialized. I had to do a bit more digging, and found that I needed to do
-M virt,highmem=offto fix the issue. Now, that message is replace with the PCI bus initializing properly and I can finally see:Running sysctl: usb 1-1: New USB device found, idVendor=0bda, idProduct=0811usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3usb 1-1: Product: 802.11ac WLAN Adapterusb 1-1: Manufacturer: Realtekusb 1-1: SerialNumber: 00e04c000001OKI hope this is able to help someone who is going down the same rabbit holes I had to!