qemu-e2k/hw
Alexander Kappner ba4c735b4f Introduce new "no_guest_reset" parameter for usb-host device
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>
2019-03-07 10:03:54 +01:00
..
9pfs
acpi qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
adc
alpha
arm hw/arm/stellaris: Implement watchdog timer 2019-03-05 15:55:09 +00:00
audio i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
block block/pflash_cfi02: Fix memory leak and potential use-after-free 2019-03-06 10:37:23 +01:00
bt
char hw/char/pl011: Use '0x' prefix when logging hex numbers 2019-02-21 18:17:46 +00:00
core qdev: Provide qdev_get_bus_hotplug_handler() 2019-03-06 11:51:08 -03:00
cpu
cris
display i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
dma
gpio i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
hppa
hyperv
i2c i2c: Verify that the count passed in to smbus_eeprom_init() is valid 2019-02-27 21:06:08 -06:00
i386 qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
ide hw/ide: drop iov field from IDEDMA 2019-02-22 09:42:13 +00:00
input i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
intc hw/ppc: Use object_initialize_child for correct reference counting 2019-02-26 09:21:25 +11:00
ipack
ipmi
isa i2c: Split smbus into parts 2019-02-27 21:06:08 -06:00
lm32
m68k hw/m68k/mcf5208: Support loading of bios images 2019-02-28 12:18:18 +01:00
mem
microblaze
mips i2c: Split smbus into parts 2019-02-27 21:06:08 -06:00
misc This has been out there long enough, I need to get this in. 2019-03-01 11:20:49 +00:00
moxie
net virtio-net: Allow qemu_announce_self to trigger virtio announcements 2019-03-05 11:27:41 +08:00
nios2
nvram i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
openrisc
pci qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
pci-bridge
pci-host hw/pci-host/bonito.c: Add PCI mem region mapped at the correct address 2019-02-21 19:36:47 +01:00
pcmcia
ppc qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
rdma
riscv
s390x qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
scsi
sd
sh4
smbios hw/smbios: fix offset of type 3 sku field 2019-02-22 10:51:31 -05:00
sparc
sparc64
ssi
timer i2c: have I2C receive operation return uint8_t 2019-02-27 21:06:08 -06:00
tpm tpm_tis: convert tpm_tis_show_buffer() to use trace event 2019-02-24 14:46:14 -05:00
tricore
unicore32
usb Introduce new "no_guest_reset" parameter for usb-host device 2019-03-07 10:03:54 +01:00
vfio s390x updates: 2019-03-04 13:38:54 +00:00
virtio virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT 2019-03-06 10:49:18 +00:00
watchdog hw/arm/stellaris: Implement watchdog timer 2019-03-05 15:55:09 +00:00
xen
xenpv
xtensa
Makefile.objs