From nobody Mon May 6 13:17:34 2024 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 154152623457735.42141038325644; Tue, 6 Nov 2018 09:43:54 -0800 (PST) Received: from localhost ([::1]:42367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5OI-00028R-2N for importer@patchew.org; Tue, 06 Nov 2018 12:43:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5L6-0006CI-6m for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK5Kk-0008Na-5j for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34192) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK5Kh-0007IN-UH for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EEBE85A04; Tue, 6 Nov 2018 17:39:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D970560C60; Tue, 6 Nov 2018 17:39:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5D87611385F9; Tue, 6 Nov 2018 18:39:41 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 18:39:39 +0100 Message-Id: <20181106173941.9449-2-armbru@redhat.com> In-Reply-To: <20181106173941.9449-1-armbru@redhat.com> References: <20181106173941.9449-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Nov 2018 17:39:43 +0000 (UTC) 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] [PULL v2 1/3] monitor: guard iothread access by mon->use_io_thread 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: Wolfgang Bumiller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wolfgang Bumiller monitor_resume() and monitor_suspend() both want to "kick" the I/O thread if it is there, but in monitor_suspend() lacked the use_io_thread flag condition. This is required when we later only spawn the thread on first use. Signed-off-by: Wolfgang Bumiller Reviewed-by: Eric Blake Reviewed-by: Peter Xu Message-Id: <20180925081507.11873-2-w.bumiller@proxmox.com> Signed-off-by: Markus Armbruster --- monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index 823b5a1099..66f149c1dc 100644 --- a/monitor.c +++ b/monitor.c @@ -4292,7 +4292,7 @@ int monitor_suspend(Monitor *mon) =20 atomic_inc(&mon->suspend_cnt); =20 - if (monitor_is_qmp(mon)) { + if (monitor_is_qmp(mon) && mon->use_io_thread) { /* * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. --=20 2.17.2 From nobody Mon May 6 13:17:34 2024 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 1541526356583264.02017167660756; Tue, 6 Nov 2018 09:45:56 -0800 (PST) Received: from localhost ([::1]:42379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5QJ-0003WA-Dy for importer@patchew.org; Tue, 06 Nov 2018 12:45:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5L6-0006CQ-AL for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK5Kg-0008HR-MX for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK5Ke-0007Ie-Gc for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:05 -0500 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 5A43658E23; Tue, 6 Nov 2018 17:39:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E280260851; Tue, 6 Nov 2018 17:39:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 624A21138603; Tue, 6 Nov 2018 18:39:41 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 18:39:40 +0100 Message-Id: <20181106173941.9449-3-armbru@redhat.com> In-Reply-To: <20181106173941.9449-1-armbru@redhat.com> References: <20181106173941.9449-1-armbru@redhat.com> 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.39]); Tue, 06 Nov 2018 17:39:43 +0000 (UTC) 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] [PULL v2 2/3] monitor: delay monitor iothread creation 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: Wolfgang Bumiller Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wolfgang Bumiller Commit d32749deb615 moved the call to monitor_init_globals() to before os_daemonize(), making it an unsuitable place to spawn the monitor iothread as it won't be inherited over the fork() in os_daemonize(). We now spawn the thread the first time we instantiate a monitor which actually has use_io_thread =3D=3D true. Instantiation of monitors happens only after os_daemonize(). We still need to create the qmp_dispatcher_bh when not using iothreads, so this now still happens in monitor_init_globals(). Signed-off-by: Wolfgang Bumiller Fixes: d32749deb615 ("monitor: move init global earlier") Message-Id: <20180925081507.11873-3-w.bumiller@proxmox.com> Reviewed-by: Eric Blake Reviewed-by: Peter Xu Tested-by: Peter Xu [This fixes a crash on shutdown with --daemonize] Signed-off-by: Markus Armbruster --- monitor.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/monitor.c b/monitor.c index 66f149c1dc..d39390c2f2 100644 --- a/monitor.c +++ b/monitor.c @@ -708,9 +708,14 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 +static void monitor_iothread_init(void); + static void monitor_data_init(Monitor *mon, bool skip_flush, bool use_io_thread) { + if (use_io_thread && !mon_iothread) { + monitor_iothread_init(); + } memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->mon_lock); qemu_mutex_init(&mon->qmp.qmp_queue_lock); @@ -4461,15 +4466,6 @@ static AioContext *monitor_get_aio_context(void) static void monitor_iothread_init(void) { mon_iothread =3D iothread_create("mon_iothread", &error_abort); - - /* - * The dispatcher BH must run in the main loop thread, since we - * have commands assuming that context. It would be nice to get - * rid of those assumptions. - */ - qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), - monitor_qmp_bh_dispatcher, - NULL); } =20 void monitor_init_globals(void) @@ -4479,7 +4475,15 @@ void monitor_init_globals(void) sortcmdlist(); qemu_mutex_init(&monitor_lock); qemu_mutex_init(&mon_fdsets_lock); - monitor_iothread_init(); + + /* + * The dispatcher BH must run in the main loop thread, since we + * have commands assuming that context. It would be nice to get + * rid of those assumptions. + */ + qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), + monitor_qmp_bh_dispatcher, + NULL); } =20 /* These functions just adapt the readline interface in a typesafe way. We @@ -4624,7 +4628,9 @@ void monitor_cleanup(void) * we need to unregister from chardev below in * monitor_data_destroy(), and chardev is not thread-safe yet */ - iothread_stop(mon_iothread); + if (mon_iothread) { + iothread_stop(mon_iothread); + } =20 /* Flush output buffers and destroy monitors */ qemu_mutex_lock(&monitor_lock); @@ -4639,9 +4645,10 @@ void monitor_cleanup(void) /* QEMUBHs needs to be deleted before destroying the I/O thread */ qemu_bh_delete(qmp_dispatcher_bh); qmp_dispatcher_bh =3D NULL; - - iothread_destroy(mon_iothread); - mon_iothread =3D NULL; + if (mon_iothread) { + iothread_destroy(mon_iothread); + mon_iothread =3D NULL; + } } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.17.2 From nobody Mon May 6 13:17:34 2024 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 1541526285189781.1006330576297; Tue, 6 Nov 2018 09:44:45 -0800 (PST) Received: from localhost ([::1]:42369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5P5-0002eN-TC for importer@patchew.org; Tue, 06 Nov 2018 12:44:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5Ki-0005pC-34 for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK5Kd-00086k-ME for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK5Kc-0007IE-TE for qemu-devel@nongnu.org; Tue, 06 Nov 2018 12:40:03 -0500 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 2D3F9356CD for ; Tue, 6 Nov 2018 17:39:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5FBD611D3; Tue, 6 Nov 2018 17:39:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 66E5D11384D8; Tue, 6 Nov 2018 18:39:41 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 18:39:41 +0100 Message-Id: <20181106173941.9449-4-armbru@redhat.com> In-Reply-To: <20181106173941.9449-1-armbru@redhat.com> References: <20181106173941.9449-1-armbru@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.30]); Tue, 06 Nov 2018 17:39:43 +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] [PULL v2 3/3] vl: Avoid crash when -mon is underspecified 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Eric Blake A quick coredump on an incomplete command line: ./x86_64-softmmu/qemu-system-x86_64 -mon mode=3Dcontrol,pretty=3Don #0 0x00007ffff723d9e4 in g_str_hash () at /lib64/libglib-2.0.so.0 #1 0x00007ffff723ce38 in g_hash_table_lookup () at /lib64/libglib-2.0.so.0 #2 0x0000555555cc0073 in object_class_property_find (klass=3D0x5555566a94= b0, name=3D0x0, errp=3D0x0) at qom/object.c:1135 #3 0x0000555555cc004b in object_class_property_find (klass=3D0x5555566a94= 40, name=3D0x0, errp=3D0x0) at qom/object.c:1129 #4 0x0000555555cbfe6e in object_property_find (obj=3D0x5555568348c0, name= =3D0x0, errp=3D0x0) at qom/object.c:1080 #5 0x0000555555cc183d in object_resolve_path_component (parent=3D0x555556= 8348c0, part=3D0x0) at qom/object.c:1762 #6 0x0000555555d82071 in qemu_chr_find (name=3D0x0) at chardev/char.c:802 #7 0x00005555559d77cb in mon_init_func (opaque=3D0x0, opts=3D0x5555566b65= a0, errp=3D0x0) at vl.c:2291 Fix it to instead fail gracefully. Signed-off-by: Eric Blake Message-Id: <20181023213600.364086-1-eblake@redhat.com> Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Signed-off-by: Markus Armbruster --- vl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vl.c b/vl.c index 03ed215d7b..55bab005b6 100644 --- a/vl.c +++ b/vl.c @@ -2323,6 +2323,10 @@ static int mon_init_func(void *opaque, QemuOpts *opt= s, Error **errp) } =20 chardev =3D qemu_opt_get(opts, "chardev"); + if (!chardev) { + error_report("chardev is required"); + exit(1); + } chr =3D qemu_chr_find(chardev); if (chr =3D=3D NULL) { error_setg(errp, "chardev \"%s\" not found", chardev); --=20 2.17.2