mirror of
https://github.com/qemu/qemu.git
synced 2024-11-28 22:33:36 +08:00
ba4c735b4f
With certain USB devices passed through via usb-host, a guest attempting to reset a usb-host device can trigger a reset loop that renders the USB device unusable. In my use case, the device was an iPhone XR that was passed through to a Mac OS X Mojave guest. Upon connecting the device, the following happens: 1) Guest recognizes new device, sends reset to emulated USB host 2) QEMU's USB host sends reset to host kernel 3) Host kernel resets device 4) After reset, host kernel determines that some part of the device descriptor has changed ("device firmware changed" in dmesg), so host kernel decides to re-enumerate the device. 5) Re-enumeration causes QEMU to disconnect and reconnect the device in the guest. 6) goto 1) Here's from the host kernel (note the "device firmware changed" lines") [3677704.473050] usb 1-1.3: new high-speed USB device number 53 using ehci-pci [3677704.555594] usb 1-1.3: New USB device found, idVendor=05ac, idProduct=12a8, bcdDevice=11.08 [3677704.555599] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [3677704.555602] usb 1-1.3: Product: iPhone [3677704.555605] usb 1-1.3: Manufacturer: Apple Inc. [3677704.555607] usb 1-1.3: SerialNumber: [[removed]] [3677709.401040] usb 1-1.3: reset high-speed USB device number 53 using ehci-pci [3677709.479486] usb 1-1.3: device firmware changed [3677709.479842] usb 1-1.3: USB disconnect, device number 53 [3677709.546039] usb 1-1.3: new high-speed USB device number 54 using ehci-pci [3677709.627471] usb 1-1.3: New USB device found, idVendor=05ac, idProduct=12a8, bcdDevice=11.08 [3677709.627476] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [3677709.627479] usb 1-1.3: Product: iPhone [3677709.627481] usb 1-1.3: Manufacturer: Apple Inc. [3677709.627483] usb 1-1.3: SerialNumber: [[removed]] [3677762.320044] usb 1-1.3: reset high-speed USB device number 54 using ehci-pci [3677762.615630] usb 1-1.3: USB disconnect, device number 54 [3677762.787043] usb 1-1.3: new high-speed USB device number 55 using ehci-pci [3677762.869016] usb 1-1.3: New USB device found, idVendor=05ac, idProduct=12a8, bcdDevice=11.08 [3677762.869024] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [3677762.869028] usb 1-1.3: Product: iPhone [3677762.869032] usb 1-1.3: Manufacturer: Apple Inc. [3677762.869035] usb 1-1.3: SerialNumber: [[removed]] [3677815.662036] usb 1-1.3: reset high-speed USB device number 55 using ehci-pci Here's from QEMU: libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/005/022: No such file or directory libusb: error [udev_hotplug_event] ignoring udev action bind libusb: error [udev_hotplug_event] ignoring udev action bind libusb: error [_open_sysfs_attr] open /sys/bus/usb/devices/5-1/bConfigurationValue failed ret=-1 errno=2 libusb: error [_get_usbfs_fd] File doesn't exist, wait 10 ms and try again libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/005/024: No such file or directory libusb: error [udev_hotplug_event] ignoring udev action bind libusb: error [udev_hotplug_event] ignoring udev action bind libusb: error [_open_sysfs_attr] open /sys/bus/usb/devices/5-1/bConfigurationValue failed ret=-1 errno=2 libusb: error [_get_usbfs_fd] File doesn't exist, wait 10 ms and try again libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/005/026: No such file or directory The result of this is that the device remains permanently unusable in the guest. The same problem has been previously reported for an iPad: https://stackoverflow.com/questions/52617634/how-do-i-get-qemu-usb-passthrough-to-work-for-ipad-iphone This problem can be elegantly solved by interrupting step 2) above. Instead of passing through the reset, QEMU simply ignores it. To allow this to be configured on a per-device level, a new parameter "no_guest_reset" is introduced for the usb-host device. I can confirm that the configuration described above (iPhone XS + Mojave guest) works flawlessly with no_guest_reset=True specified. Working command line for my scenario: device_add usb-host,vendorid=0x05ac,productid=0x12a8,no_guest_reset=True,id=iphone Best regards Alexander Signed-off-by: Alexander Kappner <agk@godking.net> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-id: 20190128140027.9448-1-kraxel@redhat.com [ kraxel: rename parameter to "guest-reset" ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> |
||
---|---|---|
.. | ||
9pfs | ||
acpi | ||
adc | ||
alpha | ||
arm | ||
audio | ||
block | ||
bt | ||
char | ||
core | ||
cpu | ||
cris | ||
display | ||
dma | ||
gpio | ||
hppa | ||
hyperv | ||
i2c | ||
i386 | ||
ide | ||
input | ||
intc | ||
ipack | ||
ipmi | ||
isa | ||
lm32 | ||
m68k | ||
mem | ||
microblaze | ||
mips | ||
misc | ||
moxie | ||
net | ||
nios2 | ||
nvram | ||
openrisc | ||
pci | ||
pci-bridge | ||
pci-host | ||
pcmcia | ||
ppc | ||
rdma | ||
riscv | ||
s390x | ||
scsi | ||
sd | ||
sh4 | ||
smbios | ||
sparc | ||
sparc64 | ||
ssi | ||
timer | ||
tpm | ||
tricore | ||
unicore32 | ||
usb | ||
vfio | ||
virtio | ||
watchdog | ||
xen | ||
xenpv | ||
xtensa | ||
Makefile.objs |