From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E11BC433EF for ; Tue, 24 May 2022 20:03:10 +0000 (UTC) Received: from localhost ([::1]:35292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntakH-0005cN-8X for qemu-devel@archiver.kernel.org; Tue, 24 May 2022 16:03:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntagM-0000aK-SM for qemu-devel@nongnu.org; Tue, 24 May 2022 15:59:06 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:45720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ntagK-0000OA-V7 for qemu-devel@nongnu.org; Tue, 24 May 2022 15:59:06 -0400 Received: by mail-ej1-x62b.google.com with SMTP id jx22so24059046ejb.12 for ; Tue, 24 May 2022 12:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fcmGoVeCwMq16X+e2i/CqaMP15k0DqIDqmrdyS90K8w=; b=fkcOMHmHUdNZAjzPsm3co+FDt7gECnArZYPGLa6QNNJO78hcR2pGF3ErKRhpCBTXo9 qNbTEIhRqNANpSNMkVgqR8a+6DVkgRMM2tZ6z6TIz+0RCeWPC8MGHKTN3PkW+9sqtxXn dtCSO+0EUt9PLJoAEBBguZmj+DrmW9Vzs2ua45VGnljwZZqsz9Jw4KFI3jm1Wst9jIxQ UeHUWedXOIwURSOn0EDRl2chn0m7/iSlRTUIWTQrKsv3NqCOzdeEDkUKIYybh0kcV4d/ JJfJwiCUJGunbfGaCAB4jQEOc8Jg6VefT42WfUt8GYNIUkuKR1AWX8KQqdiKGNs1r1rS bTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fcmGoVeCwMq16X+e2i/CqaMP15k0DqIDqmrdyS90K8w=; b=CKrQdasjqVQ3rJtJUWLlrEOh93ebe2ndLXW9jBjnio8G7mFXuGwceepYU/CKnjmCbb PjPtoDif85p2jsB1p9seHJDx09uVEa6O3Md3esjMo1AdoDYks6/gjCH82ID43lgcUtnY jmdmSz1AsSHi8fz7xHruXHkjk2tWHp7qWzliOz83wUbEihjXrWFVHdSBxRJ0tARugybI Jo4rXjEuqsL8Ice9Q/fUyJK8Aug4eqMCwNRNUn24OFX5UV2T4uEt5cj36bGhxioNMEqy 9JXwArosK2LKk0YrV9NU0D1iM71Hwp8y0ZSXGMfIASYmAO/41CmD+50K9v5A2KDLKvE+ omzA== X-Gm-Message-State: AOAM531tEkBtCHkVUnNYC2zWaJL3T5uz8QYY9imfn1+QAq+F2Wm6RAOj Kyd8aIi3wgjlWPqRoYvoJLKkJgqiAq1YT8IuluRIlw== X-Google-Smtp-Source: ABdhPJyW6W8bSW0OdvALdr/6uQd7QcOSiqN0gUi7LWpxeah0IPbkuB5/Uq43O26uzhPucHVJ8gqFe/afNl93jwGx5mA= X-Received: by 2002:a17:907:9602:b0:6df:e82c:f84 with SMTP id gb2-20020a170907960200b006dfe82c0f84mr25673615ejc.590.1653422343461; Tue, 24 May 2022 12:59:03 -0700 (PDT) MIME-Version: 1.0 References: <20220519153402.41540-1-damien.hedde@greensocs.com> <20220519153402.41540-7-damien.hedde@greensocs.com> In-Reply-To: <20220519153402.41540-7-damien.hedde@greensocs.com> From: Jim Shu Date: Wed, 25 May 2022 03:58:51 +0800 Message-ID: Subject: Re: [PATCH v5 6/6] qapi/device_add: Allow execution in machine initialized phase To: Damien Hedde Cc: "qemu-devel@nongnu.org Developers" , mark.burton@greensocs.com, edgari@xilinx.com, Mirela Grujic , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake , Paolo Bonzini , =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Content-Type: multipart/alternative; boundary="0000000000007239e205dfc763d7" Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=jim.shu@sifive.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000007239e205dfc763d7 Content-Type: text/plain; charset="UTF-8" Tested-by: Jim Shu On Thu, May 19, 2022 at 11:37 PM Damien Hedde wrote: > From: Mirela Grujic > > This commit allows to use the QMP command to add a cold-plugged > device like we can do with the CLI option -device. > > Note: for device_add command in qdev.json adding the 'allow-preconfig' > option has no effect because the command appears to bypass QAPI (see > TODO at qapi/qdev.json:61). The option is added there solely to > document the intent. > For the same reason, the flags have to be explicitly set in > monitor_init_qmp_commands() when the device_add command is registered. > > Signed-off-by: Mirela Grujic > Signed-off-by: Damien Hedde > --- > > v4: > + use phase_until() > + add missing flag in hmp-commands.hx > --- > qapi/qdev.json | 3 ++- > monitor/misc.c | 2 +- > softmmu/qdev-monitor.c | 4 ++++ > hmp-commands.hx | 1 + > 4 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/qapi/qdev.json b/qapi/qdev.json > index 26cd10106b..2e2de41499 100644 > --- a/qapi/qdev.json > +++ b/qapi/qdev.json > @@ -77,7 +77,8 @@ > { 'command': 'device_add', > 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, > 'gen': false, # so we can get the additional arguments > - 'features': ['json-cli', 'json-cli-hotplug'] } > + 'features': ['json-cli', 'json-cli-hotplug'], > + 'allow-preconfig': true } > > ## > # @device_del: > diff --git a/monitor/misc.c b/monitor/misc.c > index 6c5bb82d3b..d3d413d70c 100644 > --- a/monitor/misc.c > +++ b/monitor/misc.c > @@ -233,7 +233,7 @@ static void monitor_init_qmp_commands(void) > qmp_init_marshal(&qmp_commands); > > qmp_register_command(&qmp_commands, "device_add", > - qmp_device_add, 0, 0); > + qmp_device_add, QCO_ALLOW_PRECONFIG, 0); > > QTAILQ_INIT(&qmp_cap_negotiation_commands); > qmp_register_command(&qmp_cap_negotiation_commands, > "qmp_capabilities", > diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c > index 7cbee2b0d8..c53f62be51 100644 > --- a/softmmu/qdev-monitor.c > +++ b/softmmu/qdev-monitor.c > @@ -855,6 +855,10 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, > Error **errp) > QemuOpts *opts; > DeviceState *dev; > > + if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) { > + return; > + } > + > opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp); > if (!opts) { > return; > diff --git a/hmp-commands.hx b/hmp-commands.hx > index 03e6a73d1f..0091b8e2dd 100644 > --- a/hmp-commands.hx > +++ b/hmp-commands.hx > @@ -672,6 +672,7 @@ ERST > .help = "add device, like -device on the command line", > .cmd = hmp_device_add, > .command_completion = device_add_completion, > + .flags = "p", > }, > > SRST > -- > 2.36.1 > > > --0000000000007239e205dfc763d7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Tested-by: Jim Shu <jim.shu@sifive.com>

On Thu, May 19, 2022 at = 11:37 PM Damien Hedde <dam= ien.hedde@greensocs.com> wrote:
From: Mirela Grujic <mirela.grujic@greensocs.com>
This commit allows to use the QMP command to add a cold-plugged
device like we can do with the CLI option -device.

Note: for device_add command in qdev.json adding the 'allow-preconfig&#= 39;
option has no effect because the command appears to bypass QAPI (see
TODO at qapi/qdev.json:61). The option is added there solely to
document the intent.
For the same reason, the flags have to be explicitly set in
monitor_init_qmp_commands() when the device_add command is registered.

Signed-off-by: Mirela Grujic <mirela.grujic@greensocs.com>
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---

v4:
=C2=A0+ use phase_until()
=C2=A0+ add missing flag in hmp-commands.hx
---
=C2=A0qapi/qdev.json=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 3 ++-
=C2=A0monitor/misc.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 2 +-
=C2=A0softmmu/qdev-monitor.c | 4 ++++
=C2=A0hmp-commands.hx=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 1 +
=C2=A04 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/qapi/qdev.json b/qapi/qdev.json
index 26cd10106b..2e2de41499 100644
--- a/qapi/qdev.json
+++ b/qapi/qdev.json
@@ -77,7 +77,8 @@
=C2=A0{ 'command': 'device_add',
=C2=A0 =C2=A0'data': {'driver': 'str', '*bus= 9;: 'str', '*id': 'str'},
=C2=A0 =C2=A0'gen': false, # so we can get the additional arguments=
-=C2=A0 'features': ['json-cli', 'json-cli-hotplug'= ] }
+=C2=A0 'features': ['json-cli', 'json-cli-hotplug'= ],
+=C2=A0 'allow-preconfig': true }

=C2=A0##
=C2=A0# @device_del:
diff --git a/monitor/misc.c b/monitor/misc.c
index 6c5bb82d3b..d3d413d70c 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -233,7 +233,7 @@ static void monitor_init_qmp_commands(void)
=C2=A0 =C2=A0 =C2=A0qmp_init_marshal(&qmp_commands);

=C2=A0 =C2=A0 =C2=A0qmp_register_command(&qmp_commands, "device_ad= d",
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0qmp_device_add, 0, 0);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0qmp_device_add, QCO_ALLOW_PRECONFIG, 0);

=C2=A0 =C2=A0 =C2=A0QTAILQ_INIT(&qmp_cap_negotiation_commands);
=C2=A0 =C2=A0 =C2=A0qmp_register_command(&qmp_cap_negotiation_commands,= "qmp_capabilities",
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 7cbee2b0d8..c53f62be51 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -855,6 +855,10 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp)
=C2=A0 =C2=A0 =C2=A0QemuOpts *opts;
=C2=A0 =C2=A0 =C2=A0DeviceState *dev;

+=C2=A0 =C2=A0 if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+=C2=A0 =C2=A0 }
+
=C2=A0 =C2=A0 =C2=A0opts =3D qemu_opts_from_qdict(qemu_find_opts("devi= ce"), qdict, errp);
=C2=A0 =C2=A0 =C2=A0if (!opts) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 03e6a73d1f..0091b8e2dd 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -672,6 +672,7 @@ ERST
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.help=C2=A0 =C2=A0 =C2=A0 =C2=A0=3D "= ;add device, like -device on the command line",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.cmd=C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D hmp_d= evice_add,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.command_completion =3D device_add_comple= tion,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 .flags=C2=A0 =C2=A0 =C2=A0 =3D "p",<= br> =C2=A0 =C2=A0 =C2=A0},

=C2=A0SRST
--
2.36.1


--0000000000007239e205dfc763d7--