Bug 1821518 - RFE: add usbredir device reset blacklist options support to allow macOS guest to iOS device usbredir
Summary: RFE: add usbredir device reset blacklist options support to allow macOS guest...
Keywords:
Status: CLOSED DEFERRED
Alias: None
Product: Virtualization Tools
Classification: Community
Component: virt-manager
Version: unspecified
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Cole Robinson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-04-07 01:20 UTC by Michael Lee
Modified: 2020-08-31 18:33 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-08-31 18:33:40 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1871270 0 None None None 2020-04-07 02:16:40 UTC
Red Hat Bugzilla 1821517 0 unspecified NEW RFE: add usbredir device reset blacklist options support to allow macOS guest to iOS device usbredir 2021-02-22 00:41:40 UTC
freedesktop.org Gitlab spice usbredir issues 10 0 None None None 2020-04-07 01:23:55 UTC

Internal Links: 1821517

Description Michael Lee 2020-04-07 01:20:03 UTC
Description of problem:
Currently, when a iOS device is redirected to a macOS VM, it falls into a reset-not-found loop.

Version-Release number of selected component (if applicable):
latest

How reproducible:
100%

Steps to Reproduce:

1. Connect an iOS device to Ubuntu 18.04.2 LTS (I believe it is the same for any distro.)

2. Connect virt-manager/virt-viewer to a macOS VM through SPICE (I am using OSX 10.15 Catalina)

3. Attempt to redirect the iOS device (iPad in my case) to the VM through usb redirection.

Actual results:

For any odd number of attempt, the guest macOS will send a reset to the iOS device which causes the host to reset the USB connection in the host side. In the UI, it will be displayed as a successful connection for a few seconds before it disconnects. After this, the iOS device will reconnect itself, but via a different device name /dev/bus/usb/x/y+1.

For any even number of attempt, when I select the iOS device in the virt-manager/virt-viewer UI, the connection will not success and instead a LIBUSB_ERROR_NOT_FOUND error will be provided. Then the UI will reload and get the new device name of the iOS device, falling into the behavior of the aforementioned odd number of attempt. 

Expected results:

The macOS detects the iOS device and connects to it happily.

Additional info:

It seems that this bug has been first identified as in https://bugs.freedesktop.org/show_bug.cgi?id=100149, for a Samsung Android device, which the developers of SPICE applied a hotfix in https://gitlab.freedesktop.org/spice/usbredir/-/blob/master/usbredirhost/usbredirhost.c#L147. However, there were no settings available for users to fix it. 

A similar bug that also consists of a macOS guest/iOS device pair, but instead of being usbredir, is usb-host, has been identified and patched in https://github.com/qemu/qemu/commit/ba4c735b4fc74e309ce4b2551d258e442ef513a5, which is further modified into https://github.com/qemu/qemu/blame/146aa0f104bb3bf88e43c4082a0bfc4bbda4fbd8/hw/usb/host-libusb.c#L1486. Following such patch, I have attempted to apply such patch at host-side in https://github.com/michaellee8/qemu/blob/master/hw/usb/redirect.c (not correctly formatted currently, pls ignore it atm), however I discovered that this is not enough since it is also a SPICE issue, which resolves to virt-manager/virt-viewer. 

This is probably a cross-project issue between qemu, spice (usbredir) and virt-manager/virt-viewer, which would some effort to coordinate a solution. However a working solution for this problem would probably benefits a lot of users whom relies on connecting a mobile device into a VM, for purposes like easier mobile development. Considering the report for the Samsung Android Device on a PC use case, such issue is probably cross-OS/cross-device.

Comment 1 Cole Robinson 2020-08-31 18:33:40 UTC
Thanks for the report and the information dump. Solving this in an out of the box way would definitely take some cross functional work.

There would ideally be a central database of devices that are known to need the workaround. Maybe udev annotations
usbredir could check that to see if it needs to blacklist the device like is shown in the redir code
users could drop in their own udev additions so usbredir would change behavior dynamically
that could be used to have libvirt + clients coordinate to fix the usb-host case as well

Realistically I can't say whether that work will ever be done though unless someone motivated wants to drive it.
I suspect redhat will never sponsor that work given current engineering priorities

The lowest hanging fruit would be to expose no_guest_reset in libvirt XML. This way users have a supported way
to opt into the workaround for direct USB assignment. Mapping libvirt XML to qemu command line is pretty
straightforward, for a recent commit see this example: https://github.com/libvirt/libvirt/commit/493d2769f2962b7106583bd3a85cadd752d34703

In the mean time you could use qemu commandline passthrough XML to set the workaround but it might be a bit
tricky. There's some discussion about that here: https://www.reddit.com/r/VFIO/comments/gdx0ut/libvirt_xml_arguments_for_hostdev_usb_devices_for/

In the end though this is more than a virt-manager issue, and there's nothing we can do until there's
some amount of support in the lower level componenets. And truthfully even if there was XML support for
this right now, unless there was a way we could make it work automatically transparently for the user
I would likely not expose in the XML knob in the UI because it's a corner case, and if users know they
need it they could set it in the XML directly with the XML editor in recent versions:
https://blog.wikichoon.com/2020/07/virt-manager-xml-editor.html

So for those reasons I'm closing this as DEFERRED. If/when lower levels get more support for this
that we can consume in virt-manager, we can revisit this


Note You need to log in before you can comment on or make changes to this bug.