Received: from eggs.gnu.org ([2001:4830:134:3::10]:60635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIa0b-00043G-JQ for qemu-devel@nongnu.org; Fri, 24 Jul 2015 06:15:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIa0Y-0000OL-65 for qemu-devel@nongnu.org; Fri, 24 Jul 2015 06:15:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIZy8-0007b3-Oc for qemu-devel@nongnu.org; Fri, 24 Jul 2015 06:12:44 -0400 From: Paolo Bonzini Date: Fri, 24 Jul 2015 12:12:40 +0200 Message-Id: <1437732760-20095-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] main-loop: fix qemu_notify_event for aio_notify optimization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org aio_notify can be optimized away, and in fact almost always will. However, qemu_notify_event is used in places where this is incorrect---most notably, when handling SIGTERM. When aio_notify is optimized away, it is possible that QEMU enters a blocking ppoll immediately afterwards and stays there, without reaching main_loop_should_exit(). Fix this by using a bottom half. The bottom half can be optimized too, but it will cause the ppoll not to block. The hang is thus avoided. Reported-by: Peter Maydell Signed-off-by: Paolo Bonzini --- main-loop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main-loop.c b/main-loop.c index 82875a4..9d93478 100644 --- a/main-loop.c +++ b/main-loop.c @@ -114,6 +114,11 @@ static int qemu_signal_init(void) #endif static AioContext *qemu_aio_context; +static QEMUBH *qemu_notify_bh; + +static void notify_event_cb(void *opaque) +{ +} AioContext *qemu_get_aio_context(void) { @@ -125,7 +130,7 @@ void qemu_notify_event(void) if (!qemu_aio_context) { return; } - aio_notify(qemu_aio_context); + qemu_bh_schedule(qemu_notify_bh); } static GArray *gpollfds; @@ -144,6 +149,7 @@ int qemu_init_main_loop(Error **errp) } qemu_aio_context = aio_context_new(&local_error); + qemu_notify_bh = qemu_bh_new(notify_event_cb, NULL); if (!qemu_aio_context) { error_propagate(errp, local_error); return -EMFILE; -- 2.4.3