qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFE: add usbredir device reset blacklist options support to allow ma


From: Michael Lee
Subject: Re: RFE: add usbredir device reset blacklist options support to allow macOS guest to iOS device usbredir
Date: Tue, 7 Apr 2020 10:52:23 +0800

From ec02df3bb9027691957218e5ea07c4febb007cec Mon Sep 17 00:00:00 2001
From: michaellee8 <address@hidden>
Date: Tue, 7 Apr 2020 10:19:27 +0800
Subject: [PATCH] usbredir: introduce new parameters to configure guest reset
 behavior for usbredir device

This patch solves the same problem of usb device reset loop as mentioned in ba4c735b4fc7,
but for usbredir device instead. This allows my iPad device to be redirected to my
Mac OS X Catalina guest via SPICE.

However, this patch does not solve everything, it will require further work on the
client-side spice viewers to be useful. I have already opened issues in different
components that will require changes in order to make this patch useful.

Cross-references:
- https://bugzilla.redhat.com/show_bug.cgi?id=1821518
- https://bugzilla.redhat.com/show_bug.cgi?id=1821517
- https://gitlab.freedesktop.org/spice/usbredir/-/issues/10
- https://bugs.launchpad.net/bugs/1871270

Signed-off-by: michaellee8 <address@hidden>
---
 hw/usb/redirect.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 45d8b76218..1cb04cebf6 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -115,6 +115,8 @@ struct USBRedirDevice {
     bool enable_streams;
     bool suppress_remote_wake;
     bool in_write;
+    bool allow_one_guest_reset;
+    bool allow_all_guest_resets;
     uint8_t debug;
     int32_t bootindex;
     char *filter_str;
@@ -516,6 +518,13 @@ static void usbredir_handle_reset(USBDevice *udev)
 {
     USBRedirDevice *dev = USB_REDIRECT(udev);
 
+    if (!dev->allow_one_guest_reset && !dev->allow_all_guest_resets) {
+        return;
+    }
+    if (!dev->allow_all_guest_resets && udev->addr == 0) {
+        return;
+    }
+
     DPRINTF("reset device\n");
     usbredirparser_send_reset(dev->parser);
     usbredirparser_do_write(dev->parser);
@@ -2564,6 +2573,10 @@ static Property usbredir_properties[] = {
     DEFINE_PROP_BOOL("streams", USBRedirDevice, enable_streams, true),
     DEFINE_PROP_BOOL("suppress-remote-wake", USBRedirDevice,
                      suppress_remote_wake, true),
+    DEFINE_PROP_BOOL("guest-reset", USBRedirDevice,
+                     allow_one_guest_reset, true),
+    DEFINE_PROP_BOOL("guest-resets-all", USBRedirDevice,
+                     allow_all_guest_resets, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
--
2.17.1

On Tue, 7 Apr 2020 at 09:35, Michael Lee <address@hidden> wrote:
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.

cross-references:
- https://bugzilla.redhat.com/show_bug.cgi?id=1821518
- https://bugzilla.redhat.com/show_bug.cgi?id=1821517
- https://gitlab.freedesktop.org/spice/usbredir/-/issues/10

reply via email to

[Prev in Thread] Current Thread [Next in Thread]