j4m3z0r
j4m3z0r

Reputation: 427

How do I get Qemu USB Passthrough to work for iPad / iPhone?

I'm trying to setup a Mac OS virtual machine to do iPad development. The host system is Ubuntu 18.04, and I'm using the stock qemu packages from the Ubuntu repo.

I've got a Mojave VM up and running using these instructions, and in the script to boot the VM, I've added this line:

  -device usb-host,vendorid=0x05ac,productid=0x12ab \

The devices in question are an iPad Air 2, and an iPad Mini 4, which seem to share the same product ids, according to lsusb.

Here's the issue: when I boot into my Mojave VM, when I plug the iPad in, I see it appear in ioreg -p IOUSB for a few seconds, then it disappears. Other devices (I tried a USB LTE modem and a USB RS232 interface) don't do this; it appears to be specific to iDevices.

On the host side, I see the device appear to connect and disconnect in a loop. Here's what I see in dmesg -w:

[  483.734771] usb 1-2.4.1: new high-speed USB device number 39 using xhci_hcd
[  483.849408] usb 1-2.4.1: New USB device found, idVendor=05ac, idProduct=12ab
[  483.849416] usb 1-2.4.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  483.849420] usb 1-2.4.1: Product: iPad
[  483.849425] usb 1-2.4.1: Manufacturer: Apple Inc.
[  483.849435] usb 1-2.4.1: SerialNumber: <xxx>
[  484.543671] usb 2-2.1.4.1.3.3: reset SuperSpeed USB device number 9 using xhci_hcd
[  488.616849] usb 1-2.4.1: reset high-speed USB device number 39 using xhci_hcd
[  488.732805] usb 1-2.4.1: device firmware changed
[  488.733301] usb 1-2.4.1: USB disconnect, device number 39
[  488.824694] usb 1-2.4.1: new high-speed USB device number 40 using xhci_hcd
[  488.938611] usb 1-2.4.1: New USB device found, idVendor=05ac, idProduct=12ab
[  488.938613] usb 1-2.4.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  488.938614] usb 1-2.4.1: Product: iPad
[  488.938615] usb 1-2.4.1: Manufacturer: Apple Inc.
[  488.938616] usb 1-2.4.1: SerialNumber: <xxx>
[  490.961709] usb 1-2.4.1: reset high-speed USB device number 40 using xhci_hcd
[  491.076908] usb 1-2.4.1: usbfs: process 2557 (gvfs-gphoto2-vo) did not claim interface 0 before use
[  494.579362] usb 2-2.1.4.1.3.3: reset SuperSpeed USB device number 9 using xhci_hcd
[  531.110536] usb 1-2.4.1: USB disconnect, device number 40
[  533.905116] usb 1-2.4.1: new high-speed USB device number 41 using xhci_hcd
[  534.019231] usb 1-2.4.1: New USB device found, idVendor=05ac, idProduct=12ab
[  534.019237] usb 1-2.4.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  534.019241] usb 1-2.4.1: Product: iPad
[  534.019244] usb 1-2.4.1: Manufacturer: Apple Inc.
[  534.019247] usb 1-2.4.1: SerialNumber: <xxx>
[  534.602098] usb 1-2.1.4.4: USB disconnect, device number 17

Note that the above is not me physically connecting and diconnecting -- something is doing it on its own. Also of note, I don't get this connect / disconnect loop if my VM isn't running (or if I remove the line setting up the USB passthrough)

Things I've tried

I've been operating on the assumption that this is something that the host (probably udevd) is doing which is preventing qemu (well, libusb, I presume) from being able to keep hold of the device. To that end I've been going through and disabling any udev rules that look like they might be implicated. Specifically, I've created symlinks to /dev/null for the following udev files:

I also tried disabling the gphoto2 service, like so:

systemctl --user stop gvfs-gphoto2-volume-monitor.service

Despite all of these things, the behavior is essentially the same. Also noteworthy: even after disabling all these things, the kernel is still somehow detecting the iPad when I connect it, and logs its serial number, etc to syslog, and I've reached the limit of my knowledge on how to disable things on Linux!

How can I get my iPad to appear (and stay) in my qemu virtual machine?

Upvotes: 9

Views: 8554

Answers (2)

Grunchy
Grunchy

Reputation: 1

I found a working solution for assigning a USB controller card to the VM from within Ubuntu 24.04.

The xhci_hcd is compiled into the kernel, not as module. So when you put the USB controller id in GRUB_CMDLINE_LINUX_DEFAULT, the USB controller will still bind with xhci_hcd, as it is already inside the kernel. To confirm if your kernel has xhci_hcd compiled within:

modprobe -D xhci_hcd

If your output is:

builtin xhci_hcd

then your kernel contains xhci_hcd.

So you instruct:

sudo apt-get -y install driverctl
sudo driverctl -v set-override 0000:2d:00.3 vfio-pci

The second you execute this command whatever USB device you have plugged into that USB controller card will no longer be accessible to Linux (keyboard, mouse, camera, iPhone, what-have-you). For some reason my MSI B350 PC-Mate (with latest BIOS Sept 2024) puts all of my USB controller cards along with SATA, Ethernet, nVidia GTX 1050 in IOMMU group 15, and IOMMU groups can't be broken apart. It did, however, put MSI motherboard USB 3.0 controller all by itself in IOMMU group 23 (and these are the USB 3.0 ports coming out the I/O shield at the back of the computer). So, whatever. I had the keyboard, mouse, Xbox 360 controller receiver, 3d connexion spacemouse receiver, and web cameras plugged into a hub plugged into the USB 2 sockets: those are connected to IOMMU group 15 and are unchanged.

Upvotes: 0

5h4d
5h4d

Reputation: 1

You need to chown the file corresponding to the bus and device in /dev/bus/usb/[bus]/[device] and maybe also add id=iphone but the main thing is to change the ownership.

Upvotes: 0

Related Questions