From nobody Wed Nov 5 12:54:59 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 1534961059398742.3467497839791; Wed, 22 Aug 2018 11:04:19 -0700 (PDT) Received: from localhost ([::1]:60280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsXUQ-0008It-8n for importer@patchew.org; Wed, 22 Aug 2018 14:04:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsXTP-0007yu-21 for qemu-devel@nongnu.org; Wed, 22 Aug 2018 14:03:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsXTJ-00081Q-Ts for qemu-devel@nongnu.org; Wed, 22 Aug 2018 14:03:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51924 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fsXTJ-00080l-LV for qemu-devel@nongnu.org; Wed, 22 Aug 2018 14:03:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB0D54021CC1; Wed, 22 Aug 2018 18:03:08 +0000 (UTC) Received: from localhost (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 496E910CD7C7; Wed, 22 Aug 2018 18:03:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2018 20:02:59 +0200 Message-Id: <20180822180259.26365-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 22 Aug 2018 18:03:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 22 Aug 2018 18:03:08 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] RFC: chardev: mark the calls that allow an implicit mux monitor 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: Stefano Stabellini , armbru@redhat.com, Paolo Bonzini , "open list:X86" , Anthony Perard , =?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" This is mostly for readability of the code. Let's make it clear which callers can create an implicit monitor when the chardev is muxed. This will also enforce a safer behaviour, as we don't really support creating monitor anywhere/anytime at the moment. There are documented cases, such as: -serial/-parallel/-virtioconsole and to less extent -debugcon. Less obvious and questionnable ones are -gdb and Xen console. Add a FIXME note for those, but keep the support for now. Other qemu_chr_new() callers either have a fixed parameter/filename string, or do preliminary checks on the string (such as slirp), or do not need it, such as -qtest. On a related note, the list of monitor creation places: - the chardev creators listed above: all from command line (except perhaps Xen console?) - -gdb & hmp gdbserver will create a "GDB monitor command" chardev that is wired to an HMP monitor. - -mon command line option From this short study, I would like to think that a monitor may only be created in the main thread today, though I remain skeptical :) Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/chardev/char.h | 18 +++++++++++++++++- chardev/char.c | 21 +++++++++++++++++---- gdbstub.c | 6 +++++- hw/char/xen_console.c | 5 ++++- vl.c | 8 ++++---- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/chardev/char.h b/include/chardev/char.h index 6f0576e214..be2b9b817e 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -105,6 +105,7 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, * @qemu_chr_new: * * Create a new character backend from a URI. + * Do not implicitely initialize a monitor if the chardev is muxed. * * @label the name of the backend * @filename the URI @@ -113,6 +114,19 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, */ Chardev *qemu_chr_new(const char *label, const char *filename); =20 +/** + * @qemu_chr_new_mux_mon: + * + * Create a new character backend from a URI. + * Implicitely initialize a monitor if the chardev is muxed. + * + * @label the name of the backend + * @filename the URI + * + * Returns: a new character backend + */ +Chardev *qemu_chr_new_mux_mon(const char *label, const char *filename); + /** * @qemu_chr_change: * @@ -138,10 +152,12 @@ void qemu_chr_cleanup(void); * * @label the name of the backend * @filename the URI + * @with_mux_mon if chardev is muxed, initialize a monitor * * Returns: a new character backend */ -Chardev *qemu_chr_new_noreplay(const char *label, const char *filename); +Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, + bool with_mux_mon); =20 /** * @qemu_chr_be_can_write: diff --git a/chardev/char.c b/chardev/char.c index 76d866e6fe..2c295ad676 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -683,7 +683,8 @@ out: return chr; } =20 -Chardev *qemu_chr_new_noreplay(const char *label, const char *filename) +Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, + bool with_mux_mon) { const char *p; Chardev *chr; @@ -702,17 +703,19 @@ Chardev *qemu_chr_new_noreplay(const char *label, con= st char *filename) if (err) { error_report_err(err); } - if (chr && qemu_opt_get_bool(opts, "mux", 0)) { + if (with_mux_mon && chr && qemu_opt_get_bool(opts, "mux", 0)) { monitor_init(chr, MONITOR_USE_READLINE); } qemu_opts_del(opts); return chr; } =20 -Chardev *qemu_chr_new(const char *label, const char *filename) +static Chardev *qemu_chr_new_with_mux_mon(const char *label, + const char *filename, + bool with_mux_mon) { Chardev *chr; - chr =3D qemu_chr_new_noreplay(label, filename); + chr =3D qemu_chr_new_noreplay(label, filename, with_mux_mon); if (chr) { if (replay_mode !=3D REPLAY_MODE_NONE) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_REPLAY); @@ -726,6 +729,16 @@ Chardev *qemu_chr_new(const char *label, const char *f= ilename) return chr; } =20 +Chardev *qemu_chr_new(const char *label, const char *filename) +{ + return qemu_chr_new_with_mux_mon(label, filename, false); +} + +Chardev *qemu_chr_new_mux_mon(const char *label, const char *filename) +{ + return qemu_chr_new_with_mux_mon(label, filename, true); +} + static int qmp_query_chardev_foreach(Object *obj, void *data) { Chardev *chr =3D CHARDEV(obj); diff --git a/gdbstub.c b/gdbstub.c index d6ab95006c..963531ea90 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2038,7 +2038,11 @@ int gdbserver_start(const char *device) sigaction(SIGINT, &act, NULL); } #endif - chr =3D qemu_chr_new_noreplay("gdb", device); + /* + * FIXME: it's a bit weird to allow using a mux chardev here + * and setup implicitely a monitor. We may want to break this. + */ + chr =3D qemu_chr_new_noreplay("gdb", device, true); if (!chr) return -1; } diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 8b4b4bf523..6a231d487b 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -207,7 +207,10 @@ static int con_init(struct XenDevice *xendev) } else { snprintf(label, sizeof(label), "xencons%d", con->xendev.dev); qemu_chr_fe_init(&con->chr, - qemu_chr_new(label, output), &error_abort); + /* + * FIXME: should it support implicit muxed monito= rs? + */ + qemu_chr_new_mux_mon(label, output), &error_abort= ); } =20 xenstore_store_pv_console_info(con->xendev.dev, diff --git a/vl.c b/vl.c index 16b913f9d5..20b5f321ec 100644 --- a/vl.c +++ b/vl.c @@ -2425,7 +2425,7 @@ static int serial_parse(const char *devname) snprintf(label, sizeof(label), "serial%d", index); serial_hds =3D g_renew(Chardev *, serial_hds, index + 1); =20 - serial_hds[index] =3D qemu_chr_new(label, devname); + serial_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!serial_hds[index]) { error_report("could not connect serial device" " to character backend '%s'", devname); @@ -2461,7 +2461,7 @@ static int parallel_parse(const char *devname) exit(1); } snprintf(label, sizeof(label), "parallel%d", index); - parallel_hds[index] =3D qemu_chr_new(label, devname); + parallel_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!parallel_hds[index]) { error_report("could not connect parallel device" " to character backend '%s'", devname); @@ -2492,7 +2492,7 @@ static int virtcon_parse(const char *devname) qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort); =20 snprintf(label, sizeof(label), "virtcon%d", index); - virtcon_hds[index] =3D qemu_chr_new(label, devname); + virtcon_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!virtcon_hds[index]) { error_report("could not connect virtio console" " to character backend '%s'", devname); @@ -2508,7 +2508,7 @@ static int debugcon_parse(const char *devname) { QemuOpts *opts; =20 - if (!qemu_chr_new("debugcon", devname)) { + if (!qemu_chr_new_mux_mon("debugcon", devname)) { exit(1); } opts =3D qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NUL= L); --=20 2.18.0.547.g1d89318c48