From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091641191932.8142709106107; Tue, 9 Oct 2018 06:27:21 -0700 (PDT) Received: from localhost ([::1]:51503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9s2V-0007dk-UN for importer@patchew.org; Tue, 09 Oct 2018 09:27:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rp8-000628-Fo for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rp6-0002Y2-MI for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rp6-0002WY-F0 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E0BE3082B56 for ; Tue, 9 Oct 2018 13:13:14 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 661EB5B690; Tue, 9 Oct 2018 13:13:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:46 +0400 Message-Id: <20181009131251.721-2-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 09 Oct 2018 13:13:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/6] monitor: inline ambiguous helper functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function were not named with "mon_iothread", or following the AIO vs GMainContext distinction. Inline them instead. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/monitor.c b/monitor.c index b9258a7438..ab60c9f87e 100644 --- a/monitor.c +++ b/monitor.c @@ -4441,16 +4441,6 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } =20 -static GMainContext *monitor_get_io_context(void) -{ - return iothread_get_g_main_context(mon_iothread); -} - -static AioContext *monitor_get_aio_context(void) -{ - return iothread_get_aio_context(mon_iothread); -} - static void monitor_iothread_init(void) { mon_iothread =3D iothread_create("mon_iothread", &error_abort); @@ -4538,7 +4528,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) GMainContext *context; =20 assert(mon->use_io_thread); - context =3D monitor_get_io_context(); + context =3D iothread_get_g_main_context(mon_iothread); assert(context); qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, NULL, mon, context, true); @@ -4590,7 +4580,7 @@ void monitor_init(Chardev *chr, int flags) * since chardev might be running in the monitor I/O * thread. Schedule a bottom half. */ - aio_bh_schedule_oneshot(monitor_get_aio_context(), + aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ return; --=20 2.19.0.271.gfe8321ec05 From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091219136575.0552051827527; Tue, 9 Oct 2018 06:20:19 -0700 (PDT) Received: from localhost ([::1]:51455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rvq-0002Me-0U for importer@patchew.org; Tue, 09 Oct 2018 09:20:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rpL-0006CS-Lr for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rpH-0002fZ-NZ for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60092) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rpH-0002dw-E4 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2573831B333 for ; Tue, 9 Oct 2018 13:13:25 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 329A963B9E; Tue, 9 Oct 2018 13:13:17 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:47 +0400 Message-Id: <20181009131251.721-3-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 09 Oct 2018 13:13:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/6] monitor: accept chardev input from iothread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Chardev backends may not handle safely IO events from concurrent threads. Better to wake up the chardev from the monitor IO thread if it's being used as the chardev context. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index ab60c9f87e..a25514490a 100644 --- a/monitor.c +++ b/monitor.c @@ -4297,6 +4297,13 @@ int monitor_suspend(Monitor *mon) return 0; } =20 +static void monitor_accept_input(void *opaque) +{ + Monitor *mon =3D opaque; + + qemu_chr_fe_accept_input(&mon->chr); +} + void monitor_resume(Monitor *mon) { if (monitor_is_hmp_non_interactive(mon)) { @@ -4310,13 +4317,14 @@ void monitor_resume(Monitor *mon) * let's kick the thread in case it's sleeping. */ if (mon->use_io_thread) { - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothr= ead), + monitor_accept_input, mon); } } else { assert(mon->rs); readline_show_prompt(mon->rs); + monitor_accept_input(mon); } - qemu_chr_fe_accept_input(&mon->chr); } trace_monitor_suspend(mon, -1); } --=20 2.19.0.271.gfe8321ec05 From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091392815271.9499214785975; Tue, 9 Oct 2018 06:23:12 -0700 (PDT) Received: from localhost ([::1]:51475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9ryh-0004gn-OU for importer@patchew.org; Tue, 09 Oct 2018 09:23:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rpV-0006Lc-IF for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rpR-0002nn-Jx for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rpR-0002mH-08 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D97BD52748 for ; Tue, 9 Oct 2018 13:13:34 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5738C1001947; Tue, 9 Oct 2018 13:13:28 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:48 +0400 Message-Id: <20181009131251.721-4-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 09 Oct 2018 13:13:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/6] char: add a QEMU_CHAR_FEATURE_GCONTEXT flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The feature should be set if the chardev is able to switch GMainContext. Callers that want to put a chardev in a different thread context can/should check this capabilities. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/chardev/char.h | 3 +++ chardev/char.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/chardev/char.h b/include/chardev/char.h index 7becd8c80c..014566c3de 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -47,6 +47,9 @@ typedef enum { QEMU_CHAR_FEATURE_FD_PASS, /* Whether replay or record mode is enabled */ QEMU_CHAR_FEATURE_REPLAY, + /* Whether the gcontext can be changed after calling + * qemu_chr_be_update_read_handlers() */ + QEMU_CHAR_FEATURE_GCONTEXT, =20 QEMU_CHAR_FEATURE_LAST, } ChardevFeature; diff --git a/chardev/char.c b/chardev/char.c index e115166995..fa1b74e0d9 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -196,6 +196,8 @@ void qemu_chr_be_update_read_handlers(Chardev *s, s->gcontext =3D context; if (cc->chr_update_read_handler) { cc->chr_update_read_handler(s); + } else if (s->gcontext) { + error_report("switching context isn't supported by this chardev"); } } =20 @@ -240,6 +242,15 @@ static void char_init(Object *obj) =20 chr->logfd =3D -1; qemu_mutex_init(&chr->chr_write_lock); + + /* + * Assume if chr_update_read_handler is implemented it will + * take the updated gcontext into account. + */ + if (CHARDEV_GET_CLASS(chr)->chr_update_read_handler) { + qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT); + } + } =20 static int null_chr_write(Chardev *chr, const uint8_t *buf, int len) --=20 2.19.0.271.gfe8321ec05 From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091792731408.3161467557337; Tue, 9 Oct 2018 06:29:52 -0700 (PDT) Received: from localhost ([::1]:51518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9s59-0001bo-NO for importer@patchew.org; Tue, 09 Oct 2018 09:29:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rpV-0006Li-LT for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rpV-0002qg-1q for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rpU-0002pw-RY for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C39F3001BDD for ; Tue, 9 Oct 2018 13:13:40 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF3591001947; Tue, 9 Oct 2018 13:13:38 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:49 +0400 Message-Id: <20181009131251.721-5-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 09 Oct 2018 13:13:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/6] monitor: check if chardev can switch gcontext for OOB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Note: this patch will conflict with Peter "[PATCH v9 3/6] monitor: remove "x-oob", turn oob on by default", but can be trivially updated. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index a25514490a..c175cf6f0d 100644 --- a/monitor.c +++ b/monitor.c @@ -4550,9 +4550,10 @@ void monitor_init(Chardev *chr, int flags) bool use_oob =3D flags & MONITOR_USE_OOB; =20 if (use_oob) { - if (CHARDEV_IS_MUX(chr)) { + if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT)) { error_report("Monitor out-of-band is not supported with " - "MUX typed chardev backend"); + "%s typed chardev backend", + object_get_typename(OBJECT(chr))); exit(1); } if (use_readline) { --=20 2.19.0.271.gfe8321ec05 From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091391231623.7902124782037; Tue, 9 Oct 2018 06:23:11 -0700 (PDT) Received: from localhost ([::1]:51474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9ryY-0004Z7-5G for importer@patchew.org; Tue, 09 Oct 2018 09:23:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rpj-0006ZA-7Z for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rpf-00030j-8Q for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rpf-000305-2P for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:13:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70AA01152E for ; Tue, 9 Oct 2018 13:13:50 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28C535B68F; Tue, 9 Oct 2018 13:13:43 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:50 +0400 Message-Id: <20181009131251.721-6-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 09 Oct 2018 13:13:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/6] monitor: prevent inserting new monitors after cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a monitor_destroyed global to check if monitor_cleanup() has been already called. In this case, don't insert the new monitor in the list, but free it instead. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index c175cf6f0d..90b7867ed4 100644 --- a/monitor.c +++ b/monitor.c @@ -262,10 +262,11 @@ typedef struct QMPRequest QMPRequest; /* QMP checker flags */ #define QMP_ACCEPT_UNKNOWNS 1 =20 -/* Protects mon_list, monitor_qapi_event_state. */ +/* Protects mon_list, monitor_qapi_event_state, monitor_destroyed. */ static QemuMutex monitor_lock; static GHashTable *monitor_qapi_event_state; static QTAILQ_HEAD(mon_list, Monitor) mon_list; +static bool monitor_destroyed; =20 /* Protects mon_fdsets */ static QemuMutex mon_fdsets_lock; @@ -4526,8 +4527,16 @@ void error_vprintf_unless_qmp(const char *fmt, va_li= st ap) static void monitor_list_append(Monitor *mon) { qemu_mutex_lock(&monitor_lock); - QTAILQ_INSERT_HEAD(&mon_list, mon, entry); + if (!monitor_destroyed) { + QTAILQ_INSERT_HEAD(&mon_list, mon, entry); + mon =3D NULL; + } qemu_mutex_unlock(&monitor_lock); + + if (mon) { + monitor_data_destroy(mon); + g_free(mon); + } } =20 static void monitor_qmp_setup_handlers_bh(void *opaque) @@ -4620,6 +4629,7 @@ void monitor_cleanup(void) =20 /* Flush output buffers and destroy monitors */ qemu_mutex_lock(&monitor_lock); + monitor_destroyed =3D true; QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { QTAILQ_REMOVE(&mon_list, mon, entry); monitor_flush(mon); --=20 2.19.0.271.gfe8321ec05 From nobody Thu Nov 6 01:17:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539091542245557.6016767024942; Tue, 9 Oct 2018 06:25:42 -0700 (PDT) Received: from localhost ([::1]:51492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9s16-0006Zu-JP for importer@patchew.org; Tue, 09 Oct 2018 09:25:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rpv-0006i9-7a for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:14:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rpr-0003F2-8s for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:14:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53382) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rpq-0003Dp-W6 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:14:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53F423001FCD for ; Tue, 9 Oct 2018 13:14:02 +0000 (UTC) Received: from localhost (ovpn-112-31.ams2.redhat.com [10.36.112.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BF7E6A956; Tue, 9 Oct 2018 13:13:54 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 17:12:51 +0400 Message-Id: <20181009131251.721-7-marcandre.lureau@redhat.com> In-Reply-To: <20181009131251.721-1-marcandre.lureau@redhat.com> References: <20181009131251.721-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 09 Oct 2018 13:14:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/6] monitor: avoid potential dead-lock when cleaning up X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster , peterx@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When a monitor is connected to a Spice chardev, the monitor cleanup can dead-lock: #0 0x00007f43446637fd in __lll_lock_wait () at /lib64/libpthread.so.0 #1 0x00007f434465ccf4 in pthread_mutex_lock () at /lib64/libpthread.so.0 #2 0x0000556dd79f22ba in qemu_mutex_lock_impl (mutex=3D0x556dd81c9220 , file=3D0x556dd7ae3648 "/home/elmarco/src/qq/monitor.c", line= =3D645) at /home/elmarco/src/qq/util/qemu-thread-posix.c:66 #3 0x0000556dd7431bd5 in monitor_qapi_event_queue (event=3DQAPI_EVENT_SPI= CE_DISCONNECTED, qdict=3D0x556dd9abc850, errp=3D0x7fffb7bbddd8) at /home/el= marco/src/qq/monitor.c:645 #4 0x0000556dd79d476b in qapi_event_send_spice_disconnected (server=3D0x5= 56dd98ee760, client=3D0x556ddaaa8560, errp=3D0x556dd82180d0 ) = at qapi/qapi-events-ui.c:149 #5 0x0000556dd7870fc1 in channel_event (event=3D3, info=3D0x556ddad1b590)= at /home/elmarco/src/qq/ui/spice-core.c:235 #6 0x00007f434560a6bb in reds_handle_channel_event (reds=3D, event=3D3, info=3D0x556ddad1b590) at reds.c:316 #7 0x00007f43455f393b in main_dispatcher_self_handle_channel_event (info= =3D0x556ddad1b590, event=3D3, self=3D0x556dd9a7d8c0) at main-dispatcher.c:1= 97 #8 0x00007f43455f393b in main_dispatcher_channel_event (self=3D0x556dd9a7= d8c0, event=3Devent@entry=3D3, info=3D0x556ddad1b590) at main-dispatcher.c:= 197 #9 0x00007f4345612833 in red_stream_push_channel_event (s=3Ds@entry=3D0x5= 56ddae2ef40, event=3Devent@entry=3D3) at red-stream.c:414 #10 0x00007f434561286b in red_stream_free (s=3D0x556ddae2ef40) at red-stre= am.c:388 #11 0x00007f43455f9ddc in red_channel_client_finalize (object=3D0x556dd9bb= 21a0) at red-channel-client.c:347 #12 0x00007f434b5f9fb9 in g_object_unref () at /lib64/libgobject-2.0.so.0 #13 0x00007f43455fc212 in red_channel_client_push (rcc=3D0x556dd9bb21a0) a= t red-channel-client.c:1341 #14 0x0000556dd76081ba in spice_port_set_fe_open (chr=3D0x556dd9925e20, fe= _open=3D0) at /home/elmarco/src/qq/chardev/spice.c:241 #15 0x0000556dd796d74a in qemu_chr_fe_set_open (be=3D0x556dd9a37c00, fe_op= en=3D0) at /home/elmarco/src/qq/chardev/char-fe.c:340 #16 0x0000556dd796d4d9 in qemu_chr_fe_set_handlers (b=3D0x556dd9a37c00, fd= _can_read=3D0x0, fd_read=3D0x0, fd_event=3D0x0, be_change=3D0x0, opaque=3D0= x0, context=3D0x0, set_open=3Dtrue) at /home/elmarco/src/qq/chardev/char-fe= .c:280 #17 0x0000556dd796d359 in qemu_chr_fe_deinit (b=3D0x556dd9a37c00, del=3Dfa= lse) at /home/elmarco/src/qq/chardev/char-fe.c:233 #18 0x0000556dd7432240 in monitor_data_destroy (mon=3D0x556dd9a37c00) at /= home/elmarco/src/qq/monitor.c:786 #19 0x0000556dd743b968 in monitor_cleanup () at /home/elmarco/src/qq/monit= or.c:4683 #20 0x0000556dd75ce776 in main (argc=3D3, argv=3D0x7fffb7bbe458, envp=3D0x= 7fffb7bbe478) at /home/elmarco/src/qq/vl.c:4660 Because spice code tries to emit a "disconnected" signal on the monitors. Fix this dead-lock by releasing the monitor lock for flush/destroy. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitor.c b/monitor.c index 90b7867ed4..cb80f39ada 100644 --- a/monitor.c +++ b/monitor.c @@ -4632,8 +4632,10 @@ void monitor_cleanup(void) monitor_destroyed =3D true; QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { QTAILQ_REMOVE(&mon_list, mon, entry); + qemu_mutex_unlock(&monitor_lock); monitor_flush(mon); monitor_data_destroy(mon); + qemu_mutex_lock(&monitor_lock); g_free(mon); } qemu_mutex_unlock(&monitor_lock); --=20 2.19.0.271.gfe8321ec05