Skip to content

Commit 81da66b

Browse files
elmarcocuinutanix
authored andcommitted
monitor: fix crash when leaving qemu with spice audio
RH-Author: Marc-André Lureau <[email protected]> Message-id: <[email protected]> Patchwork-id: 71914 O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH 1/2] monitor: fix crash when leaving qemu with spice audio Bugzilla: 1355704 RH-Acked-by: Thomas Huth <[email protected]> RH-Acked-by: Markus Armbruster <[email protected]> RH-Acked-by: Miroslav Rezanina <[email protected]> Since aa5cb7f, the chardevs are being cleaned up when leaving qemu. However, the monitor has still references to them, which may lead to crashes when running atexit() and trying to send monitor events: #0 0x00007fffdb18f6f5 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54 #1 0x00007fffdb1912fa in __GI_abort () at abort.c:89 #2 0x0000555555c263e7 in error_exit (err=22, msg=0x555555d47980 <__func__.13537> "qemu_mutex_lock") at util/qemu-thread-posix.c:39 #3 0x0000555555c26488 in qemu_mutex_lock (mutex=0x5555567a2420) at util/qemu-thread-posix.c:66 open-power-host-os#4 0x00005555558c52db in qemu_chr_fe_write (s=0x5555567a2420, buf=0x55555740dc40 "{\"timestamp\": {\"seconds\": 1470041716, \"microseconds\": 989699}, \"event\": \"SPICE_DISCONNECTED\", \"data\": {\"server\": {\"port\": \"5900\", \"family\": \"ipv4\", \"host\": \"127.0.0.1\"}, \"client\": {\"port\": \"40272\", \"f"..., len=240) at qemu-char.c:280 open-power-host-os#5 0x0000555555787cad in monitor_flush_locked (mon=0x5555567bd9e0) at /home/elmarco/src/qemu/monitor.c:311 open-power-host-os#6 0x0000555555787e46 in monitor_puts (mon=0x5555567bd9e0, str=0x5555567a44ef "") at /home/elmarco/src/qemu/monitor.c:353 open-power-host-os#7 0x00005555557880fe in monitor_json_emitter (mon=0x5555567bd9e0, data=0x5555567c73a0) at /home/elmarco/src/qemu/monitor.c:401 open-power-host-os#8 0x00005555557882d2 in monitor_qapi_event_emit (event=QAPI_EVENT_SPICE_DISCONNECTED, qdict=0x5555567c73a0) at /home/elmarco/src/qemu/monitor.c:472 open-power-host-os#9 0x000055555578838f in monitor_qapi_event_queue (event=QAPI_EVENT_SPICE_DISCONNECTED, qdict=0x5555567c73a0, errp=0x7fffffffca88) at /home/elmarco/src/qemu/monitor.c:497 open-power-host-os#10 0x0000555555c15541 in qapi_event_send_spice_disconnected (server=0x5555571139d0, client=0x5555570d0db0, errp=0x5555566c0428 <error_abort>) at qapi-event.c:1038 open-power-host-os#11 0x0000555555b11bc6 in channel_event (event=3, info=0x5555570d6c00) at ui/spice-core.c:248 open-power-host-os#12 0x00007fffdcc9983a in adapter_channel_event (event=3, info=0x5555570d6c00) at reds.c:120 open-power-host-os#13 0x00007fffdcc99a25 in reds_handle_channel_event (reds=0x5555567a9d60, event=3, info=0x5555570d6c00) at reds.c:324 open-power-host-os#14 0x00007fffdcc7d4c4 in main_dispatcher_self_handle_channel_event (self=0x5555567b28b0, event=3, info=0x5555570d6c00) at main-dispatcher.c:175 open-power-host-os#15 0x00007fffdcc7d5b1 in main_dispatcher_channel_event (self=0x5555567b28b0, event=3, info=0x5555570d6c00) at main-dispatcher.c:194 open-power-host-os#16 0x00007fffdcca7674 in reds_stream_push_channel_event (s=0x5555570d9910, event=3) at reds-stream.c:354 open-power-host-os#17 0x00007fffdcca749b in reds_stream_free (s=0x5555570d9910) at reds-stream.c:323 open-power-host-os#18 0x00007fffdccb5dad in snd_disconnect_channel (channel=0x5555576a89a0) at sound.c:229 open-power-host-os#19 0x00007fffdccb9e57 in snd_detach_common (worker=0x555557739720) at sound.c:1589 open-power-host-os#20 0x00007fffdccb9f0e in snd_detach_playback (sin=0x5555569fe3f8) at sound.c:1602 open-power-host-os#21 0x00007fffdcca3373 in spice_server_remove_interface (sin=0x5555569fe3f8) at reds.c:3387 open-power-host-os#22 0x00005555558ff6e2 in line_out_fini (hw=0x5555569fe370) at audio/spiceaudio.c:152 open-power-host-os#23 0x00005555558f909e in audio_atexit () at audio/audio.c:1754 open-power-host-os#24 0x00007fffdb1941e8 in __run_exit_handlers (status=0, listp=0x7fffdb5175d8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82 open-power-host-os#25 0x00007fffdb194235 in __GI_exit (status=<optimized out>) at exit.c:104 open-power-host-os#26 0x00007fffdb17b738 in __libc_start_main (main=0x5555558d7874 <main>, argc=67, argv=0x7fffffffcf48, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffcf38) at ../csu/libc-start.c:323 Add a monitor_cleanup() functions to remove all the monitors before cleaning up the chardev. Note that we are "losing" some events that used to be sent during atexit(). Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: Markus Armbruster <[email protected]> (cherry picked from commit 2ef4571) BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1355704 Signed-off-by: Marc-André Lureau <[email protected]> Signed-off-by: Miroslav Rezanina <[email protected]>
1 parent bdf8973 commit 81da66b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Diff for: include/monitor/monitor.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern Monitor *cur_mon;
2020
bool monitor_cur_is_qmp(void);
2121

2222
void monitor_init(CharDriverState *chr, int flags);
23+
void monitor_cleanup(void);
2324

2425
int monitor_suspend(Monitor *mon);
2526
void monitor_resume(Monitor *mon);

Diff for: monitor.c

+20
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,13 @@ static void monitor_data_init(Monitor *mon)
635635

636636
static void monitor_data_destroy(Monitor *mon)
637637
{
638+
if (mon->chr) {
639+
qemu_chr_add_handlers(mon->chr, NULL, NULL, NULL, NULL);
640+
}
641+
if (monitor_is_qmp(mon)) {
642+
json_message_parser_destroy(&mon->qmp.parser);
643+
}
644+
g_free(mon->rs);
638645
QDECREF(mon->outbuf);
639646
qemu_mutex_destroy(&mon->out_lock);
640647
}
@@ -4156,6 +4163,19 @@ void monitor_init(CharDriverState *chr, int flags)
41564163
qemu_mutex_unlock(&monitor_lock);
41574164
}
41584165

4166+
void monitor_cleanup(void)
4167+
{
4168+
Monitor *mon, *next;
4169+
4170+
qemu_mutex_lock(&monitor_lock);
4171+
QLIST_FOREACH_SAFE(mon, &mon_list, entry, next) {
4172+
QLIST_REMOVE(mon, entry);
4173+
monitor_data_destroy(mon);
4174+
g_free(mon);
4175+
}
4176+
qemu_mutex_unlock(&monitor_lock);
4177+
}
4178+
41594179
static void bdrv_password_cb(void *opaque, const char *password,
41604180
void *readline_opaque)
41614181
{

Diff for: vl.c

+1
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,7 @@ int main(int argc, char **argv, char **envp)
46874687
#endif
46884688
net_cleanup();
46894689

4690+
monitor_cleanup();
46904691
qemu_chr_cleanup();
46914692

46924693
return 0;

0 commit comments

Comments
 (0)