[Spice-devel] [spice-gtk v2] usbredir: fix deadlock on error

Victor Toso victortoso at redhat.com
Tue Jun 20 11:10:43 UTC 2017


From: leaboy <wlbleaboy at 126.com>

The current code deadlocks when a USB error occurs, releasing the
channel lock before the idle is called fixes this problem.

More specifically when an error occurs, we queue a call to device_error
in an idle, and switch to the main context. The device_error() calls
spice_usbredir_channel_disconnect_device() which needs the channel to be
unlocked as it calls spice_usbredir_channel_lock().

Examples:
- Redirect USB Storage device to the guest and copy some big file. While
  copy is ongoing, unplug the USB Storage from the client machine;
- Unplug the usb device from the client machine while the USB Storage
  device is being identified in the guest.
- With the auto-redirection option enabled, plug and unplug the USB
  Storage Device frequently.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1353528
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/channel-usbredir.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index fef62ce..1f791bc 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -927,15 +927,16 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
         err_data.caller = coroutine_self();
         err_data.spice_device = g_boxed_copy(spice_usb_device_get_type(), spice_device);
         err_data.error = err;
+        spice_usbredir_channel_unlock(channel);
         g_idle_add(device_error, &err_data);
         coroutine_yield(NULL);
 
         g_boxed_free(spice_usb_device_get_type(), err_data.spice_device);
 
         g_error_free(err);
+    } else {
+        spice_usbredir_channel_unlock(channel);
     }
-
-    spice_usbredir_channel_unlock(channel);
 }
 
 #endif /* USE_USBREDIR */
-- 
2.13.0



More information about the Spice-devel mailing list