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

1

9

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:

  • /etc/udev/rules.d/39-usbmuxd.rules
  • /etc/udev/rules.d/60-libgphoto2-6.rules
  • /etc/udev/rules.d/90-libgpod.rules

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?

Rudich answered 2/10, 2018 at 23:13 Comment(10)
I don't know if iPhones and iPads do this, but many Android phones will disconnect and reconnect with different USB IDs, depending on the mode they are in (e.g. charging, media transfer, firmware flashing, etc.). You might want to look to see if your iPads have done this.Symposium
Thanks for the note, but if I watch lsusb output on the host, the IDs seem to stay the same, so I don't think this is it. You might be onto something with mode switching though: I could imagine the iPad disconnecting in order to affect a mode switch and when it comes back online it connects to the host USB subsystem, rather than qemu's. Unfortunately I think that reduces to the same problem: getting the host to really ignore the device and just connect it to pass through.Rudich
By the way, after a lot of fiddling with this, I discovered the real problem with what I was trying to do: I don't get OpenGL in simulators in this VM, which made the whole endeavor pretty much useless for my intended use case. I'll likely delete this question in a bit if there's no other responses so that I'm not polluting SO with non-solutions. Thanks for stopping by to offer your thoughts though.Rudich
Well, you can get virtualized OpenGL with KVM, but I don't think you can do it with a macOS guest. AFAIK only Linux and Windows guests...Symposium
Right. So what I found was that for a MacOS guest you could map a PCI device to the VM, such as a graphics card. Since I was doing this on a laptop that only had the one card, which I needed for the host, it looked like my only option was to get an eGPU. At that point it seemed like I’d lost all benefit to having a VM (since I’d still need two physical pieces of hardware to make it useful), so instead bought a used MBP (can’t stand the keyboards on the new ones) and used VMWare to run Linux as a guest. Kind of a bummer since I prefer VMs for development where practical.Rudich
Hey please don't delete this, I've got the exact same error as yours here when trying to use my iPad as a SPICE redirection device, I saw a kernel patch here discussing it patchwork.kernel.org/patch/10736061 . Others may want to look at this question later.Sleuth
The patch that @MichaelLee mentioned in the comments of the question seems to be merged, but with a different name. It's called "guest-reset". -device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false` It doesn't work for me with this setting either. But perhaps someone else may find this information useful.Anacardiaceous
@Anacardiaceous YOU are the best my friend :DRaeleneraf
Did you ever figure this out? I am trying to get an external drive to show up on a QEMU MacOS VM on Linux.Dromond
Daniel Limas posted an Answer saying "Apparently it's been solved for a couple of years now. https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04585.html"Apodictic
B
0

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.

Bummalo answered 12/1, 2021 at 16:14 Comment(1)
Doesn't sound right - "For changing device permissions you should use udev rules."Greisen

© 2022 - 2024 — McMap. All rights reserved.