Skip to content

Commit 394642a

Browse files
dagrhkraxel
authored andcommitted
usbredir: Prevent recursion in usbredir_write
I've got a case where usbredir_write manages to call back into itself via spice; this patch causes the recursion to fail (0 bytes) the write; this seems to avoid the deadlock I was previously seeing. I can't say I fully understand the interaction of usbredir and spice; but there are a few similar guards in spice and usbredir to catch other cases especially onces also related to spice_server_char_device_wakeup This case seems to be triggered by repeated migration+repeated reconnection of the viewer; but my debugging suggests the migration finished before this hits. The backtrace of the hang looks like: reds_handle_ticket reds_handle_other_links reds_channel_do_link red_channel_connect spicevmc_connect usbredir_create_parser usbredirparser_do_write usbredir_write qemu_chr_fe_write qemu_chr_write qemu_chr_write_buffer spice_chr_write spice_server_char_device_wakeup red_char_device_wakeup red_char_device_write_to_device vmc_write usbredirparser_do_write usbredir_write qemu_chr_fe_write qemu_chr_write qemu_chr_write_buffer qemu_mutex_lock_impl and we fail as we lang through qemu_chr_write_buffer's lock twice. Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1752320 Signed-off-by: Dr. David Alan Gilbert <[email protected]> Message-Id: <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent 32187f3 commit 394642a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

hw/usb/redirect.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct USBRedirDevice {
114114
CharBackend cs;
115115
bool enable_streams;
116116
bool suppress_remote_wake;
117+
bool in_write;
117118
uint8_t debug;
118119
int32_t bootindex;
119120
char *filter_str;
@@ -291,6 +292,13 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
291292
return 0;
292293
}
293294

295+
/* Recursion check */
296+
if (dev->in_write) {
297+
DPRINTF("usbredir_write recursion\n");
298+
return 0;
299+
}
300+
dev->in_write = true;
301+
294302
r = qemu_chr_fe_write(&dev->cs, data, count);
295303
if (r < count) {
296304
if (!dev->watch) {
@@ -301,6 +309,7 @@ static int usbredir_write(void *priv, uint8_t *data, int count)
301309
r = 0;
302310
}
303311
}
312+
dev->in_write = false;
304313
return r;
305314
}
306315

0 commit comments

Comments
 (0)