From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328795882516.2959691867069; Wed, 22 Sep 2021 09:39:55 -0700 (PDT) Received: from localhost ([::1]:34228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5Hm-0007OM-Mi for importer@patchew.org; Wed, 22 Sep 2021 12:39:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uY-0002d5-MI; Wed, 22 Sep 2021 12:15:54 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:38826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uT-0005G8-HT; Wed, 22 Sep 2021 12:15:54 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id F3DEA21CC1; Wed, 22 Sep 2021 16:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VdnVuRz8orSzm80d4V6oo8FtHFI6VLNiM7CokKV1kg0=; b=FUm2HUwzttyCZe+8dhBbh50LnWpTBgfyRBKEmQweI52IibjcVgDn4DK1o5YtxElR7pK3VG FzivmPgZdVq7CIwOWz8C/0JHcJLoWkMZTuJkoIZq/q7EtIWQYR432EE+RLBVUQvkum1SsI 7ZnOmjO/M8NkPARS4NSxeS/ky6/tWQE= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 01/16] rename MachineInitPhase enum constants for QAPI compatibility Date: Wed, 22 Sep 2021 18:13:50 +0200 Message-Id: <20210922161405.140018-2-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328796895100003 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic This commit is a preparation to switch to a QAPI definition of the MachineInitPhase enum. QAPI will generate enumeration constants prefixed with the MACHINE_INIT_PHASE_, so rename values accordingly. Signed-off-by: Mirela Grujic --- include/hw/qdev-core.h | 10 +++++----- hw/core/machine-qmp-cmds.c | 2 +- hw/core/machine.c | 6 +++--- hw/core/qdev.c | 2 +- hw/pci/pci.c | 2 +- hw/usb/core.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- monitor/hmp.c | 2 +- softmmu/qdev-monitor.c | 9 +++++---- softmmu/vl.c | 6 +++--- ui/console.c | 3 ++- 11 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 34c8a7506a..859fd913bb 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -841,30 +841,30 @@ bool qdev_should_hide_device(QemuOpts *opts); =20 typedef enum MachineInitPhase { /* current_machine is NULL. */ - PHASE_NO_MACHINE, + MACHINE_INIT_PHASE_NO_MACHINE, =20 /* current_machine is not NULL, but current_machine->accel is NULL. */ - PHASE_MACHINE_CREATED, + MACHINE_INIT_PHASE_MACHINE_CREATED, =20 /* * current_machine->accel is not NULL, but the machine properties have * not been validated and machine_class->init has not yet been called. */ - PHASE_ACCEL_CREATED, + MACHINE_INIT_PHASE_ACCEL_CREATED, =20 /* * machine_class->init has been called, thus creating any embedded * devices and validating machine properties. Devices created at * this time are considered to be cold-plugged. */ - PHASE_MACHINE_INITIALIZED, + MACHINE_INIT_PHASE_INITIALIZED, =20 /* * QEMU is ready to start CPUs and devices created at this time * are considered to be hot-plugged. The monitor is not restricted * to "preconfig" commands. */ - PHASE_MACHINE_READY, + MACHINE_INIT_PHASE_READY, } MachineInitPhase; =20 extern bool phase_check(MachineInitPhase phase); diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 216fdfaf3a..52168a3771 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -147,7 +147,7 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error = **errp) =20 void qmp_set_numa_node(NumaOptions *cmd, Error **errp) { - if (phase_check(PHASE_MACHINE_INITIALIZED)) { + if (phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { error_setg(errp, "The command is permitted only before the machine= has been created"); return; } diff --git a/hw/core/machine.c b/hw/core/machine.c index 067f42b528..9125c9aad0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1274,7 +1274,7 @@ void machine_run_board_init(MachineState *machine) =20 accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator)); machine_class->init(machine); - phase_advance(PHASE_MACHINE_INITIALIZED); + phase_advance(MACHINE_INIT_PHASE_INITIALIZED); } =20 static NotifierList machine_init_done_notifiers =3D @@ -1283,7 +1283,7 @@ static NotifierList machine_init_done_notifiers =3D void qemu_add_machine_init_done_notifier(Notifier *notify) { notifier_list_add(&machine_init_done_notifiers, notify); - if (phase_check(PHASE_MACHINE_READY)) { + if (phase_check(MACHINE_INIT_PHASE_READY)) { notify->notify(notify, NULL); } } @@ -1306,7 +1306,7 @@ void qdev_machine_creation_done(void) * ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - phase_advance(PHASE_MACHINE_READY); + phase_advance(MACHINE_INIT_PHASE_READY); qdev_assert_realized_properly(); =20 /* TODO: once all bus devices are qdevified, this should be done diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cefc5eaa0a..c5fc704f55 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -904,7 +904,7 @@ static void device_initfn(Object *obj) { DeviceState *dev =3D DEVICE(obj); =20 - if (phase_check(PHASE_MACHINE_READY)) { + if (phase_check(MACHINE_INIT_PHASE_READY)) { dev->hotplugged =3D 1; qdev_hot_added =3D true; } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 23d2ae2ab2..5ed798b480 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1102,7 +1102,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *p= ci_dev, address_space_init(&pci_dev->bus_master_as, &pci_dev->bus_master_container_region, pci_dev->nam= e); =20 - if (phase_check(PHASE_MACHINE_READY)) { + if (phase_check(MACHINE_INIT_PHASE_READY)) { pci_init_bus_master(pci_dev); } pci_dev->irq_state =3D 0; diff --git a/hw/usb/core.c b/hw/usb/core.c index 975f76250a..7a9a81c4fe 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -97,7 +97,7 @@ void usb_wakeup(USBEndpoint *ep, unsigned int stream) USBDevice *dev =3D ep->dev; USBBus *bus =3D usb_bus_from_device(dev); =20 - if (!phase_check(PHASE_MACHINE_READY)) { + if (!phase_check(MACHINE_INIT_PHASE_READY)) { /* * This is machine init cold plug. No need to wakeup anyone, * all devices will be reset anyway. And trying to wakeup can diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 1b23e8e18c..b777a80be2 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -948,7 +948,7 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemoryR= egion *mr, * accept it. Having a different masks is possible but the guest will = use * sub-optimal block sizes, so warn about it. */ - if (phase_check(PHASE_MACHINE_READY)) { + if (phase_check(MACHINE_INIT_PHASE_READY)) { int new_granule =3D ctz64(new_mask); int cur_granule =3D ctz64(cur_mask); =20 diff --git a/monitor/hmp.c b/monitor/hmp.c index d50c3124e1..ad012b0b22 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -216,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd) =20 static bool cmd_available(const HMPCommand *cmd) { - return phase_check(PHASE_MACHINE_READY) || cmd_can_preconfig(cmd); + return phase_check(MACHINE_INIT_PHASE_READY) || cmd_can_preconfig(cmd); } =20 static void help_cmd_dump_one(Monitor *mon, diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 0705f00846..25275984bd 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -262,7 +262,7 @@ static DeviceClass *qdev_get_device_class(const char **= driver, Error **errp) =20 dc =3D DEVICE_CLASS(oc); if (!dc->user_creatable || - (phase_check(PHASE_MACHINE_READY) && !dc->hotpluggable)) { + (phase_check(MACHINE_INIT_PHASE_READY) && !dc->hotpluggable)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver", "a pluggable device type"); return NULL; @@ -649,7 +649,8 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) } } =20 - if (phase_check(PHASE_MACHINE_READY) && bus && !qbus_is_hotpluggable(b= us)) { + if (phase_check(MACHINE_INIT_PHASE_READY) && bus && + !qbus_is_hotpluggable(bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); return NULL; } @@ -663,7 +664,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) dev =3D qdev_new(driver); =20 /* Check whether the hotplug is allowed by the machine */ - if (phase_check(PHASE_MACHINE_READY)) { + if (phase_check(MACHINE_INIT_PHASE_READY)) { if (!qdev_hotplug_allowed(dev, errp)) { goto err_del_dev; } @@ -1011,7 +1012,7 @@ int qemu_global_option(const char *str) =20 bool qmp_command_available(const QmpCommand *cmd, Error **errp) { - if (!phase_check(PHASE_MACHINE_READY) && + if (!phase_check(MACHINE_INIT_PHASE_READY) && !(cmd->options & QCO_ALLOW_PRECONFIG)) { error_setg(errp, "The command '%s' is permitted only after machine= initialization has completed", cmd->name); diff --git a/softmmu/vl.c b/softmmu/vl.c index 55ab70eb97..d2552ba8ac 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2692,7 +2692,7 @@ static void qemu_machine_creation_done(void) =20 void qmp_x_exit_preconfig(Error **errp) { - if (phase_check(PHASE_MACHINE_INITIALIZED)) { + if (phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { error_setg(errp, "The command is permitted only before machine ini= tialization"); return; } @@ -3665,14 +3665,14 @@ void qemu_init(int argc, char **argv, char **envp) qemu_apply_legacy_machine_options(machine_opts_dict); qemu_apply_machine_options(machine_opts_dict); qobject_unref(machine_opts_dict); - phase_advance(PHASE_MACHINE_CREATED); + phase_advance(MACHINE_INIT_PHASE_MACHINE_CREATED); =20 /* * Note: uses machine properties such as kernel-irqchip, must run * after qemu_apply_machine_options. */ configure_accelerators(argv[0]); - phase_advance(PHASE_ACCEL_CREATED); + phase_advance(MACHINE_INIT_PHASE_ACCEL_CREATED); =20 /* * Beware, QOM objects created before this point miss global and diff --git a/ui/console.c b/ui/console.c index eabbbc951c..b09b0f9760 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1353,7 +1353,8 @@ static QemuConsole *new_console(DisplayState *ds, con= sole_type_t console_type, if (QTAILQ_EMPTY(&consoles)) { s->index =3D 0; QTAILQ_INSERT_TAIL(&consoles, s, next); - } else if (console_type !=3D GRAPHIC_CONSOLE || phase_check(PHASE_MACH= INE_READY)) { + } else if (console_type !=3D GRAPHIC_CONSOLE || + phase_check(MACHINE_INIT_PHASE_READY)) { QemuConsole *last =3D QTAILQ_LAST(&consoles); s->index =3D last->index + 1; QTAILQ_INSERT_TAIL(&consoles, s, next); --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632327874198961.2129009768609; Wed, 22 Sep 2021 09:24:34 -0700 (PDT) Received: from localhost ([::1]:43656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT52v-0001zE-4M for importer@patchew.org; Wed, 22 Sep 2021 12:24:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uX-0002Ze-0i; Wed, 22 Sep 2021 12:15:53 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:38880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uU-0005Gn-MX; Wed, 22 Sep 2021 12:15:52 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 6B2F521EB7; Wed, 22 Sep 2021 16:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uO+rxeU8HZHEUI7sNPCnX4N20yxgThgHilFwN01tQgY=; b=4nwd0mKYOh88Bq4/k8c2ah+UaLuLdmXU2GInH88kJxYAg7EbL+YtSjZJK2c1dGQBJKmftg 4vAVxgxK4VmkfrqkOGJ0zDbZ2nOewcMfN23UNSDTJ+uvKx1YBbYpqTbVYD/e/IUguDE62+ uTYcsOtlMDJL+LNvRXe+uEKGS6FD+Ew= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 02/16] qapi: Implement query-machine-phase QMP command Date: Wed, 22 Sep 2021 18:13:51 +0200 Message-Id: <20210922161405.140018-3-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632327875580100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic The command returns current machine initialization phase. From now on, the MachineInitPhase enum is generated from the QAPI schema. Signed-off-by: Mirela Grujic Acked-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qapi/machine.json | 56 ++++++++++++++++++++++++++++++++++++++ include/hw/qdev-core.h | 30 ++------------------ hw/core/machine-qmp-cmds.c | 9 ++++++ hw/core/qdev.c | 5 ++++ 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index 157712f006..969d37fb03 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1312,3 +1312,59 @@ '*cores': 'int', '*threads': 'int', '*maxcpus': 'int' } } + +## +# @MachineInitPhase: +# +# Enumeration of machine initialization phases. +# +# @no-machine: machine does not exist +# +# @machine-created: machine is created, but its accelerator is not +# +# @accel-created: accelerator is created, but the machine properties have = not +# been validated and machine initialization is not done yet +# +# @initialized: machine is initialized, thus creating any embedded devices= and +# validating machine properties. Devices created at this tim= e are +# considered to be cold-plugged. +# +# @ready: QEMU is ready to start CPUs and devices created at this time are +# considered to be hot-plugged. The monitor is not restricted to +# "preconfig" commands. +# +# Since: 6.2 +## +{ 'enum': 'MachineInitPhase', + 'data': [ 'no-machine', 'machine-created', 'accel-created', 'initialized= ', + 'ready' ] } + +## +# @MachineInitPhaseStatus: +# +# Information about machine initialization phase +# +# @phase: the machine initialization phase +# +# Since: 6.2 +## +{ 'struct': 'MachineInitPhaseStatus', + 'data': { 'phase': 'MachineInitPhase' } } + +## +# @query-machine-phase: +# +# Return machine initialization phase +# +# Since: 6.2 +# +# Returns: MachineInitPhaseStatus +# +# Example: +# +# -> { "execute": "query-machine-phase" } +# <- { "return": { "phase": "initialized" } } +# +## +{ 'command': 'query-machine-phase', 'returns': 'MachineInitPhaseStatus', + 'allow-preconfig': true } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 859fd913bb..800eda8f54 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -1,6 +1,7 @@ #ifndef QDEV_CORE_H #define QDEV_CORE_H =20 +#include "qapi/qapi-types-machine.h" #include "qemu/queue.h" #include "qemu/bitmap.h" #include "qemu/rcu.h" @@ -839,35 +840,8 @@ void device_listener_unregister(DeviceListener *listen= er); */ bool qdev_should_hide_device(QemuOpts *opts); =20 -typedef enum MachineInitPhase { - /* current_machine is NULL. */ - MACHINE_INIT_PHASE_NO_MACHINE, - - /* current_machine is not NULL, but current_machine->accel is NULL. */ - MACHINE_INIT_PHASE_MACHINE_CREATED, - - /* - * current_machine->accel is not NULL, but the machine properties have - * not been validated and machine_class->init has not yet been called. - */ - MACHINE_INIT_PHASE_ACCEL_CREATED, - - /* - * machine_class->init has been called, thus creating any embedded - * devices and validating machine properties. Devices created at - * this time are considered to be cold-plugged. - */ - MACHINE_INIT_PHASE_INITIALIZED, - - /* - * QEMU is ready to start CPUs and devices created at this time - * are considered to be hot-plugged. The monitor is not restricted - * to "preconfig" commands. - */ - MACHINE_INIT_PHASE_READY, -} MachineInitPhase; - extern bool phase_check(MachineInitPhase phase); extern void phase_advance(MachineInitPhase phase); +extern MachineInitPhase phase_get(void); =20 #endif diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 52168a3771..d3b9a04855 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -204,3 +204,12 @@ MemdevList *qmp_query_memdev(Error **errp) object_child_foreach(obj, query_memdev, &list); return list; } + +MachineInitPhaseStatus *qmp_query_machine_phase(Error **errp) +{ + MachineInitPhaseStatus *status =3D g_malloc0(sizeof(*status)); + + status->phase =3D phase_get(); + + return status; +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index c5fc704f55..d83f1c029a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -1150,6 +1150,11 @@ void phase_advance(MachineInitPhase phase) machine_phase =3D phase; } =20 +MachineInitPhase phase_get(void) +{ + return machine_phase; +} + static const TypeInfo device_type_info =3D { .name =3D TYPE_DEVICE, .parent =3D TYPE_OBJECT, --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632327763123785.5663445304285; Wed, 22 Sep 2021 09:22:43 -0700 (PDT) Received: from localhost ([::1]:40818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT517-0008V4-Tz for importer@patchew.org; Wed, 22 Sep 2021 12:22:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uX-0002Zh-24; Wed, 22 Sep 2021 12:15:53 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:38906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uV-0005I8-2n; Wed, 22 Sep 2021 12:15:52 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 52F9C21EBA; Wed, 22 Sep 2021 16:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGnYGLYTZlt4UtXZbiZtPB9v0oVww6LTMwGhigIhC4w=; b=UPbC1fzbJrfdLTp7ZSQj2uQcWDXflOXpR/G4vVRGW9kdVFULzUF67xhe1kfuNYSz/JpOy1 wbygKgvKMOyqx7pbbTbb6Y8z+9IiPW9zihN9nMV81AsEGbTgqsQrzORivur2m5ElixWh2H hKLkReYRjURA8IUJP7ZqkVTFDvxTEQs= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 03/16] qapi: Implement x-machine-init QMP command Date: Wed, 22 Sep 2021 18:13:52 +0200 Message-Id: <20210922161405.140018-4-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632327764450100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic The x-machine-init QMP command is available only if the -preconfig option is used and the current machine initialization phase is accel-created. The command triggers QEMU to enter machine initialized phase and wait for the QMP configuration. In future commits, we will add the possiblity to create devices at this point. To exit the initialized phase use the x-exit-preconfig QMP command. Signed-off-by: Mirela Grujic Acked-by: Alistair Francis --- qapi/machine.json | 23 +++++++++++++++++++++++ softmmu/vl.c | 19 +++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index 969d37fb03..56330c0e8e 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1368,3 +1368,26 @@ ## { 'command': 'query-machine-phase', 'returns': 'MachineInitPhaseStatus', 'allow-preconfig': true } + +## +# @x-machine-init: +# +# Enter machine initialized phase +# +# Since: 6.2 +# +# Returns: If successful, nothing +# +# Notes: This command will trigger QEMU to execute initialization steps +# that are required to enter the machine initialized phase. The com= mand +# is available only if the -preconfig command line option was passe= d and +# if the machine is currently in the accel-created phase. To exit t= he +# machine initialized phase use the x-exit-preconfig command. +# +# Example: +# +# -> { "execute": "x-machine-init" } +# <- { "return": {} } +# +## +{ 'command': 'x-machine-init', 'allow-preconfig': true } diff --git a/softmmu/vl.c b/softmmu/vl.c index d2552ba8ac..84c5132ad7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -123,6 +123,7 @@ #include "qapi/qapi-visit-qom.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qdict.h" +#include "qapi/qapi-commands-machine.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" #include "qemu/guest-random.h" @@ -2610,10 +2611,16 @@ static void qemu_init_displays(void) } } =20 -static void qemu_init_board(void) +void qmp_x_machine_init(Error **errp) { MachineClass *machine_class =3D MACHINE_GET_CLASS(current_machine); =20 + if (phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { + error_setg(errp, "The command is permitted only before " + "the machine is initialized"); + return; + } + if (machine_class->default_ram_id && current_machine->ram_size && numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { create_default_memdev(current_machine, mem_path); @@ -2692,12 +2699,16 @@ static void qemu_machine_creation_done(void) =20 void qmp_x_exit_preconfig(Error **errp) { - if (phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { - error_setg(errp, "The command is permitted only before machine ini= tialization"); + if (phase_check(MACHINE_INIT_PHASE_READY)) { + error_setg(errp, "The command is permitted only before " + "the machine is ready"); return; } =20 - qemu_init_board(); + if (!phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { + qmp_x_machine_init(errp); + } + qemu_create_cli_devices(); qemu_machine_creation_done(); =20 --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328292567933.8559376990993; Wed, 22 Sep 2021 09:31:32 -0700 (PDT) Received: from localhost ([::1]:52296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT59f-0008Cu-Ao for importer@patchew.org; Wed, 22 Sep 2021 12:31:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uY-0002bQ-9U; Wed, 22 Sep 2021 12:15:54 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:38948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uV-0005JR-Ex; Wed, 22 Sep 2021 12:15:53 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 16B1021EBD; Wed, 22 Sep 2021 16:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XKa7YpvCaHNP7B/Gx81xxfSEDEFxmlko5ypNT6F1RPs=; b=wtOmf1TGRi5+LsCZ7dTaWkdafLDUIQXjxY7cZKMSJPwbDnsncS8770qaxVmTeU8tVxHdsy 98gXhs3KUKW1OrVqW4NQVrvc+Q9klOB56ADRcupW0/lzsumJ9QGaU1grDQEcXmiK54ZKOs 5X4IsCXiqP+1fadiUoWHXRzy0Q+v+Wo= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 04/16] softmmu/qdev-monitor: add error handling in qdev_set_id Date: Wed, 22 Sep 2021 18:13:53 +0200 Message-Id: <20210922161405.140018-5-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328293333100001 Content-Type: text/plain; charset="utf-8" qdev_set_id() is mostly used when the user adds a device (using -device cli option or device_add qmp command). This commit adds an error parameter to handle the case where the given id is already taken. Also document the function and add a return value in order to be able to capture success/failure: the function now returns the id in case of success, or NULL in case of failure. The commit modifies the 2 calling places (qdev-monitor and xen-legacy-backend) to add the error object parameter. Note that the id is, right now, guaranteed to be unique because all ids came from the "device" QemuOptsList where the id is used as key. This addition is a preparation for a future commit which will relax the uniqueness. Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis --- include/monitor/qdev.h | 25 +++++++++++++++++++++++- hw/xen/xen-legacy-backend.c | 3 ++- softmmu/qdev-monitor.c | 38 +++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index eaa947d73a..23c31f5296 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -9,6 +9,29 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Erro= r **errp); =20 int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); -void qdev_set_id(DeviceState *dev, const char *id); + +/** + * qdev_set_id: parent the device and set its id if provided. + * @dev: device to handle + * @id: id to be given to the device, or NULL. + * + * Returns: the id of the device in case of success; otherwise NULL. + * + * @dev must be unrealized, unparented and must not have an id. + * + * If @id is non-NULL, this function tries to setup @dev qom path as + * "/peripheral/id". If @id is already taken, it fails. If it succeeds, + * the id field of @dev is set to @id (@dev now owns the given @id + * parameter). + * + * If @id is NULL, this function generates a unique name and setups @dev + * qom path as "/peripheral-anon/name". This name is not set as the id + * of @dev. + * + * Upon success, it returns the id/name (generated or provided). The + * returned string is owned by the corresponding child property and must + * not be freed by the caller. + */ +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp); =20 #endif diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c index dd8ae1452d..f541cfa0e9 100644 --- a/hw/xen/xen-legacy-backend.c +++ b/hw/xen/xen-legacy-backend.c @@ -276,7 +276,8 @@ static struct XenLegacyDevice *xen_be_get_xendev(const = char *type, int dom, xendev =3D g_malloc0(ops->size); object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); OBJECT(xendev)->free =3D g_free; - qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev)); + qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev), + &error_fatal); qdev_realize(DEVICE(xendev), xen_sysbus, &error_fatal); object_unref(OBJECT(xendev)); =20 diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 25275984bd..0007698ff3 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -578,22 +578,34 @@ static BusState *qbus_find(const char *path, Error **= errp) return bus; } =20 -void qdev_set_id(DeviceState *dev, const char *id) +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp) { + ObjectProperty *prop; + + assert(!dev->id && !dev->realized); + + /* + * object_property_[try_]add_child() below will assert the device + * has no parent + */ if (id) { - dev->id =3D id; - } - - if (dev->id) { - object_property_add_child(qdev_get_peripheral(), dev->id, - OBJECT(dev)); + prop =3D object_property_try_add_child(qdev_get_peripheral(), id, + OBJECT(dev), NULL); + if (prop) { + dev->id =3D id; + } else { + error_setg(errp, "Duplicate device ID '%s'", id); + return NULL; + } } else { static int anon_count; gchar *name =3D g_strdup_printf("device[%d]", anon_count++); - object_property_add_child(qdev_get_peripheral_anon(), name, - OBJECT(dev)); + prop =3D object_property_add_child(qdev_get_peripheral_anon(), nam= e, + OBJECT(dev)); g_free(name); } + + return prop->name; } =20 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) @@ -677,7 +689,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **e= rrp) } } =20 - qdev_set_id(dev, qemu_opts_id(opts)); + /* + * set dev's parent and register its id. + * If it fails it means the id is already taken. + */ + if (!qdev_set_id(dev, qemu_opts_id(opts), errp)) { + goto err_del_dev; + } =20 /* set properties */ if (qemu_opt_foreach(opts, set_property, dev, errp)) { --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632329398086770.3195345447833; Wed, 22 Sep 2021 09:49:58 -0700 (PDT) Received: from localhost ([::1]:52750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5RU-0004Fl-Jr for importer@patchew.org; Wed, 22 Sep 2021 12:49:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ub-0002iM-39; Wed, 22 Sep 2021 12:15:57 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uY-0005Le-Cy; Wed, 22 Sep 2021 12:15:56 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id F1D0E21EC1; Wed, 22 Sep 2021 16:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jPWHcx8frG0Bxx16IuAMBta1shU2F7IxandpxY+0m3o=; b=R2JacUH5kcSgL3a0GBx59skiUZLwlJrwuwsPCJPKp/jfsGnSFIs+eudHgACISfwNN8yzup PCA4EJ5Gc/WoYe//HHjbUL42WxmqWvbtS6uTYjxX75b2H+nsza1Ny7Oyp1hqgAG32pAcXI W+J++3yJDsAwelYtREZpkVK9EkRGLEc= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 05/16] qdev-monitor: prevent conflicts between qmp/device_add and cli/-device Date: Wed, 22 Sep 2021 18:13:54 +0200 Message-Id: <20210922161405.140018-6-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632329400513100001 Content-Type: text/plain; charset="utf-8" This commit prepares to extend device_add qmp command when using -preconfig option. In order to avoid conflicts with the cli -device option handling, we need to handle some special case with the QemuOpts. The qemu_device_opts is traversed when switching from MACHINE_INIT_PHASE_INITIALIZED to MACHINE_INIT_PHASE_READY in order to create any device specified by cli -device. Until now any device_add qmp command was issued after that point so there was no problem. If we execute the qmp command before the MACHINE_INIT_PHASE_READY phase we need to discard the QemuOpts from the qemu_device_opts in order to avoid the cli -device code to try to create the device again. This commit preserves the opts behavior regarding the devices added in 'ready' phase by the QMP command device_add. Signed-off-by: Damien Hedde --- Although we keep the original behavior for QMP commands issued when the machine is ready (only authorized case so far), we are not sure it is necessary: keeping the opts in the list is not needed anymore to ensure the id uniqueness of devices but it has the 2 following consequences: 1. the device opts stay in the QemuOptsList. Is this list needed after traversing the device cli options? 2. the DeviceState "opts" field is set. Do we need to keep it after the device is realized ? Any information on this will be appreciated. --- softmmu/qdev-monitor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 0007698ff3..834f2b56b5 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -848,6 +848,23 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) if (!dev) { qemu_opts_del(opts); return; + } else if (!phase_check(MACHINE_INIT_PHASE_READY)) { + /* + * Always delete the related opts in case the device was created + * before handling of cli -device arguments: + * We do not want a device added by the qmp command to be handled + * again by the cli -device creation code. This does not break + * the ID uniqueness because it is checked in qdev_device_add(). + * + * Note: We check the phase in order to keep the legacy behavior: + * in the machine ready phase case, the QemuOpts remains in the li= st + * (and the dev->opts field is kept). + * If it happens it was done only to ensure the ID uniqueness and + * the QemuOpts is never used after this point: then we could + * remove QemuOpts in any phase. + */ + dev->opts =3D NULL; + qemu_opts_del(opts); } object_unref(OBJECT(dev)); } --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328107702412.4028249409041; Wed, 22 Sep 2021 09:28:27 -0700 (PDT) Received: from localhost ([::1]:49904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT56g-0006ZQ-Jn for importer@patchew.org; Wed, 22 Sep 2021 12:28:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ua-0002hi-TS; Wed, 22 Sep 2021 12:15:56 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uY-0005Ld-C6; Wed, 22 Sep 2021 12:15:56 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 4B88C21EC3; Wed, 22 Sep 2021 16:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOou7ntZwf6jxxWFcKHppVKqRu0dT3fZc00S/uH+MyA=; b=5bk6PS2OqJmvZzhaI9CocH6KgDJLjQ0sST8dAep+XnkbKqazJzdfin3fRbNcoCFIIJ4LDG GoegIeSg8nXubLp4NmRiWtEy9I5diF4x3MSZmpTdsP6bl5Lp7T8uGdnf7mcsqHi+kAZIk3 qGWjcdZLReG9SyIDa9sXiR3hURGJtcE= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 06/16] qapi: Allow device_add to execute in machine initialized phase Date: Wed, 22 Sep 2021 18:13:55 +0200 Message-Id: <20210922161405.140018-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328108778100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic To configure a machine using QMP we need the device_add command to execute at machine initialized phase. Note: for device_add command in qdev.json adding the 'allow-init-config' 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 Acked-by: Alistair Francis --- The commit is fine, but we may add intermediate commits before this one in order to add or change the condition for a device type to be accepted in the 'initialized' state (see the cover-letter of the series). --- qapi/qdev.json | 3 ++- monitor/misc.c | 2 +- softmmu/qdev-monitor.c | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index b83178220b..ad669ae175 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -67,7 +67,8 @@ ## { 'command': 'device_add', 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, - 'gen': false } # so we can get the additional arguments + 'gen': false, # so we can get the additional arguments + 'allow-preconfig': true } =20 ## # @device_del: diff --git a/monitor/misc.c b/monitor/misc.c index ffe7966870..2c476de316 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -231,7 +231,7 @@ static void monitor_init_qmp_commands(void) qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "device_add", qmp_device_add, - QCO_NO_OPTIONS); + QCO_ALLOW_PRECONFIG); =20 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 834f2b56b5..47ccd90be8 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -824,6 +824,12 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) QemuOpts *opts; DeviceState *dev; =20 + if (!phase_check(MACHINE_INIT_PHASE_INITIALIZED)) { + error_setg(errp, "The command is permitted only after " + "the machine is initialized"); + return; + } + opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp); if (!opts) { return; --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328707193850.880771434173; Wed, 22 Sep 2021 09:38:27 -0700 (PDT) Received: from localhost ([::1]:59030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5GL-0004ka-P8 for importer@patchew.org; Wed, 22 Sep 2021 12:38:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ub-0002jo-J8; Wed, 22 Sep 2021 12:15:57 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uZ-0005Lo-BC; Wed, 22 Sep 2021 12:15:57 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 8859E21EC6; Wed, 22 Sep 2021 16:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327353; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AlcBA0wPhQv7JVjfEB3jyBVlLhydcLHLk7mWNQnkSaw=; b=aNbmKAB3upukJdcXcsuRvB4jG/XeAjvN01JCf7FZfNOuG3Ym0/T3VOHAsNgbv3CyONvpfS mid9Yf6nHZMIKJQ8tXxHLaDcTTsVZesJe5TCDt+J3rfnHcViEzutj1BAJythr3C13zB3oI zK53p1V+hpk5h2HvFJykoc2d/cYBPPw= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 07/16] hw/core/machine: add machine_class_is_dynamic_sysbus_dev_allowed Date: Wed, 22 Sep 2021 18:13:56 +0200 Message-Id: <20210922161405.140018-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328709580100001 Content-Type: text/plain; charset="utf-8" Right now the allowance check for adding a sysbus device using -device cli option (or device_add qmp command) is done well after the device has been created. It is done during the machine init done notifier: machine_init_notify() in hw/core/machine.c This new function will allow us to check if a sysbus device type is allowed to be dynamically created by the machine during the device creation time. Also make device_is_dynamic_sysbus() use the new function. Signed-off-by: Damien Hedde --- In the context of our series, we need to be able to do the check at device creation time to allow doing it depending on the current MACHINE_INIT phase. --- include/hw/boards.h | 17 +++++++++++++++++ hw/core/machine.c | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 463a5514f9..934443c1cd 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -51,6 +51,23 @@ void machine_set_cpu_numa_node(MachineState *machine, */ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *= type); =20 +/** + * machine_class_is_dynamic_sysbus_dev_allowed: Check if type is an allowed + * sysbus device type for the machine class. + * @mc: Machine class + * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE) + * + * Returns: true if @type is a type in the machine's list of + * dynamically pluggable sysbus devices; otherwise false. + * + * Check if the QOM type @type is in the list of allowed sysbus device + * types (see machine_class_allowed_dynamic_sysbus_dev()). + * Note that if @type is a subtype of a type which is in the list, it is + * allowed too. + */ +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, + const char *type); + /** * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device * @mc: Machine class diff --git a/hw/core/machine.c b/hw/core/machine.c index 9125c9aad0..1a18912dc8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -545,18 +545,27 @@ void machine_class_allow_dynamic_sysbus_dev(MachineCl= ass *mc, const char *type) =20 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) { - bool allowed =3D false; - strList *wl; Object *obj =3D OBJECT(dev); =20 if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { return false; } =20 + return machine_class_is_dynamic_sysbus_dev_allowed(mc, + object_get_typename(obj)); +} + +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, + const char *type) +{ + bool allowed =3D false; + strList *wl; + ObjectClass *klass =3D object_class_by_name(type); + for (wl =3D mc->allowed_dynamic_sysbus_devices; !allowed && wl; wl =3D wl->next) { - allowed |=3D !!object_dynamic_cast(obj, wl->value); + allowed |=3D !!object_class_dynamic_cast(klass, wl->value); } =20 return allowed; --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632329890478396.27749049111276; Wed, 22 Sep 2021 09:58:10 -0700 (PDT) Received: from localhost ([::1]:36108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5ZR-0003rg-Ch for importer@patchew.org; Wed, 22 Sep 2021 12:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ud-0002rn-Hx; Wed, 22 Sep 2021 12:15:59 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ub-0005Mq-0J; Wed, 22 Sep 2021 12:15:59 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 73F7B21EC7; Wed, 22 Sep 2021 16:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PKL+1gA6erzUqEOhaWDpJ5h6F3B//VEnmj0ACbfqSX0=; b=GLtOAaaPxTWsl4cHZ/jIm6GfdPz+u/QkndP3ql38H10VNAIkQ1EwIQigKoDRTjU3Cd27wF Z6jKSrHDiHVqytohW3K+04Wi7HCpPSBqociS+H/TTxSa5+XQbb0tINq8trisTlGjDgV8bz b/1Ub1hjekRXgH5VyDRqY1f0lN6lPzM= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 08/16] qdev-monitor: Check sysbus device type before creating it Date: Wed, 22 Sep 2021 18:13:57 +0200 Message-Id: <20210922161405.140018-9-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632329891906100001 Content-Type: text/plain; charset="utf-8" Add an early check to test if the requested sysbus device type is allowed by the current machine before creating the device. This impacts both -device cli option and device_add qmp command. Before this patch, the check was done well after the device has been created (in a machine init done notifier). We can now report the error right away. Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis --- softmmu/qdev-monitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 47ccd90be8..f1c9242855 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -40,6 +40,7 @@ #include "qemu/cutils.h" #include "hw/qdev-properties.h" #include "hw/clock.h" +#include "hw/boards.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -268,6 +269,16 @@ static DeviceClass *qdev_get_device_class(const char *= *driver, Error **errp) return NULL; } =20 + if (object_class_dynamic_cast(oc, TYPE_SYS_BUS_DEVICE)) { + /* sysbus devices need to be allowed by the machine */ + MachineClass *mc =3D MACHINE_CLASS(object_get_class(qdev_get_machi= ne())); + if (!machine_class_is_dynamic_sysbus_dev_allowed(mc, *driver)) { + error_setg(errp, "'%s' is not an allowed pluggable sysbus devi= ce " + " type for the machine", *driver); + return NULL; + } + } + return dc; } =20 --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328023711653.8965396086737; Wed, 22 Sep 2021 09:27:03 -0700 (PDT) Received: from localhost ([::1]:47280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT55K-0004bX-AI for importer@patchew.org; Wed, 22 Sep 2021 12:27:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ue-0002xf-Tq; Wed, 22 Sep 2021 12:16:00 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uc-0005O0-1i; Wed, 22 Sep 2021 12:16:00 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 615DE21EC9; Wed, 22 Sep 2021 16:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PDCjVxFBi4vz75aeR9pd9AbmoW6STuPuMbNBE/FSM7I=; b=ICuAAVCXm0R5uk9SjJ8PoZaJwYoy4CElxlYLonWdbRGOal6uenKQyWFhRGYtaMcpNGrB6U a6eNGZVWTngTm/nJTjQ651qUUGJcEfSF62QKzWyQ8J+LWw+rY7XTtY9hl/Kg9JWezPiQT2 mj0ltS02PcDOghYVnG1qEo0ZJHBn8H4= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 09/16] hw/core/machine: Remove the dynamic sysbus devices type check Date: Wed, 22 Sep 2021 18:13:58 +0200 Message-Id: <20210922161405.140018-10-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328025972100001 Content-Type: text/plain; charset="utf-8" Now that we check sysbus device types during device creation, we can remove the check done in the machine init done notifier. This was the only thing done by this notifier, so we remove the whole sysbus_notifier structure of the MachineState. Note: This notifier was checking all /peripheral and /peripheral-anon sysbus devices. Now we only check those added by -device cli option or device_add qmp command when handling the command/option. So if there are some devices added in one of these containers manually (eg in machine C code), these will not be checked anymore. This use case does not seem to appear apart from hw/xen/xen-legacy-backend.c (it uses qdev_set_id() and in this case, not for a sysbus device, so it's ok). Signed-off-by: Damien Hedde Acked-by: Alistair Francis --- include/hw/boards.h | 1 - hw/core/machine.c | 27 --------------------------- 2 files changed, 28 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 934443c1cd..ccbc40355a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -311,7 +311,6 @@ typedef struct CpuTopology { struct MachineState { /*< private >*/ Object parent_obj; - Notifier sysbus_notifier; =20 /*< public >*/ =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index 1a18912dc8..521438e90a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -571,18 +571,6 @@ bool machine_class_is_dynamic_sysbus_dev_allowed(Machi= neClass *mc, return allowed; } =20 -static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque) -{ - MachineState *machine =3D opaque; - MachineClass *mc =3D MACHINE_GET_CLASS(machine); - - if (!device_is_dynamic_sysbus(mc, DEVICE(sbdev))) { - error_report("Option '-device %s' cannot be handled by this machin= e", - object_class_get_name(object_get_class(OBJECT(sbdev))= )); - exit(1); - } -} - static char *machine_get_memdev(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -598,17 +586,6 @@ static void machine_set_memdev(Object *obj, const char= *value, Error **errp) ms->ram_memdev_id =3D g_strdup(value); } =20 -static void machine_init_notify(Notifier *notifier, void *data) -{ - MachineState *machine =3D MACHINE(qdev_get_machine()); - - /* - * Loop through all dynamically created sysbus devices and check if th= ey are - * all allowed. If a device is not allowed, error out. - */ - foreach_dynamic_sysbus_device(validate_sysbus_device, machine); -} - HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine) { int i; @@ -1030,10 +1007,6 @@ static void machine_initfn(Object *obj) "Table (HMAT)"); } =20 - /* Register notifier when init is done for sysbus sanity checks */ - ms->sysbus_notifier.notify =3D machine_init_notify; - qemu_add_machine_init_done_notifier(&ms->sysbus_notifier); - /* default to mc->default_cpus */ ms->smp.cpus =3D mc->default_cpus; ms->smp.max_cpus =3D mc->default_cpus; --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632330501801467.2531865382489; Wed, 22 Sep 2021 10:08:21 -0700 (PDT) Received: from localhost ([::1]:46442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5jI-0002i9-EG for importer@patchew.org; Wed, 22 Sep 2021 13:08:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ug-00032v-84; Wed, 22 Sep 2021 12:16:02 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uc-0005OV-8A; Wed, 22 Sep 2021 12:16:01 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 4E73021ECB; Wed, 22 Sep 2021 16:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ow5aMrqN/i5D/dv1vm+J5tz7Z/sAyFJH5Io1/i7HEmw=; b=cHbJePzpcvHXQEkqOdmaeWcRNrJ837qUy9Smnwsf4FkYlw79QNCGGyVPvnpY0eWxfDYkrY Gcyfi8h/ljklnuDrFdhj+SC0Q9suuCMFH6X6PkgUXB/DYK4rXoUWqJXJJmrOrjy7EPcEAj CWsJ/7O0ROaTwhJk7Qw6cuIAJX3Xrb8= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 10/16] qdev-monitor: allow adding any sysbus device before machine is ready Date: Wed, 22 Sep 2021 18:13:59 +0200 Message-Id: <20210922161405.140018-11-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632330503269100001 Content-Type: text/plain; charset="utf-8" Skip the sysbus device type per-machine allow-list check before the MACHINE_INIT_PHASE_READY phase. This patch permits adding any sysbus device (it still needs to be user_creatable) when using the -preconfig experimental option. Signed-off-by: Damien Hedde --- This commit is RFC. Depending on the condition to allow a device to be added, it may change. --- softmmu/qdev-monitor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index f1c9242855..73b991adda 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -269,8 +269,13 @@ static DeviceClass *qdev_get_device_class(const char *= *driver, Error **errp) return NULL; } =20 - if (object_class_dynamic_cast(oc, TYPE_SYS_BUS_DEVICE)) { - /* sysbus devices need to be allowed by the machine */ + if (object_class_dynamic_cast(oc, TYPE_SYS_BUS_DEVICE) && + phase_check(MACHINE_INIT_PHASE_READY)) { + /* + * Sysbus devices need to be allowed by the machine. + * We only check that after the machine is ready in order to let + * us add any user_creatable sysbus device during machine creation. + */ MachineClass *mc =3D MACHINE_CLASS(object_get_class(qdev_get_machi= ne())); if (!machine_class_is_dynamic_sysbus_dev_allowed(mc, *driver)) { error_setg(errp, "'%s' is not an allowed pluggable sysbus devi= ce " --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328486749605.0079414158204; Wed, 22 Sep 2021 09:34:46 -0700 (PDT) Received: from localhost ([::1]:55878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5Cn-0002Vi-Ic for importer@patchew.org; Wed, 22 Sep 2021 12:34:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uz-0003Ey-C1; Wed, 22 Sep 2021 12:16:21 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ux-0005Ow-JW; Wed, 22 Sep 2021 12:16:21 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 3C58E21ECD; Wed, 22 Sep 2021 16:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=83vzCH47KASlUcuFQINQpuff64c+MWa6MS19Qg8Yxnk=; b=P7hcyu+pxVIWKnhY3fU1nC0/ApGUVDeZbSeiHxcpgkCZWg35zWms2xJ3anjKnSVUoSAD8c H+qh2umF75EUBiBBC7qMvIrQtuaCSddKC0OjRXsV4MQS+CTdyIeI2BmpDSKe3DXTKRIt0Q VCthFEhyqAq/QRJQzHUCvH2QWSOp70s= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 11/16] softmmu/memory: add memory_region_try_add_subregion function Date: Wed, 22 Sep 2021 18:14:00 +0200 Message-Id: <20210922161405.140018-12-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328487845100003 Content-Type: text/plain; charset="utf-8" It allows to try to add a subregion to a memory region with error handling. Like memory_region_add_subregion_overlap, it handles priority as well. Apart the error handling, the behavior is the same. It can be used to do the simple memory_region_add_subregion() (with no overlap) by setting the priority parameter to 0. This commit is a preparation to further use this function in the context of qmp command which needs error handling support. Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Adding a new function is obviously not ideal. But there is ~900 occurrences of memory_region_add_subregion[_overlap] calls in the code base. We do not really see an alternative here. --- include/exec/memory.h | 22 ++++++++++++++++++++++ softmmu/memory.c | 22 ++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index c3d417d317..422e1eda67 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2162,6 +2162,28 @@ void memory_region_add_subregion_overlap(MemoryRegio= n *mr, MemoryRegion *subregion, int priority); =20 +/** + * memory_region_try_add_subregion: Add a subregion to a container + * with error handling. + * + * Behaves like memory_region_add_subregion_overlap(), but errors are + * reported if the subregion cannot be added. + * + * @mr: the region to contain the new subregion; must be a container + * initialized with memory_region_init(). + * @offset: the offset relative to @mr where @subregion is added. + * @subregion: the subregion to be added. + * @priority: used for resolving overlaps; highest priority wins. + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns: True in case of success, false otherwise. + */ +bool memory_region_try_add_subregion(MemoryRegion *mr, + hwaddr offset, + MemoryRegion *subregion, + int priority, + Error **errp); + /** * memory_region_get_ram_addr: Get the ram address associated with a memory * region diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4d..eac61f8236 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2513,22 +2513,28 @@ done: memory_region_transaction_commit(); } =20 -static void memory_region_add_subregion_common(MemoryRegion *mr, - hwaddr offset, - MemoryRegion *subregion) +bool memory_region_try_add_subregion(MemoryRegion *mr, + hwaddr offset, + MemoryRegion *subregion, + int priority, + Error **errp) { - assert(!subregion->container); + if (subregion->container) { + error_setg(errp, "The memory region is already in another region"); + return false; + } + subregion->priority =3D priority; subregion->container =3D mr; subregion->addr =3D offset; memory_region_update_container_subregions(subregion); + return true; } =20 void memory_region_add_subregion(MemoryRegion *mr, hwaddr offset, MemoryRegion *subregion) { - subregion->priority =3D 0; - memory_region_add_subregion_common(mr, offset, subregion); + memory_region_try_add_subregion(mr, offset, subregion, 0, &error_abort= ); } =20 void memory_region_add_subregion_overlap(MemoryRegion *mr, @@ -2536,8 +2542,8 @@ void memory_region_add_subregion_overlap(MemoryRegion= *mr, MemoryRegion *subregion, int priority) { - subregion->priority =3D priority; - memory_region_add_subregion_common(mr, offset, subregion); + memory_region_try_add_subregion(mr, offset, subregion, priority, + &error_abort); } =20 void memory_region_del_subregion(MemoryRegion *mr, --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632328280119852.7170050961789; Wed, 22 Sep 2021 09:31:20 -0700 (PDT) Received: from localhost ([::1]:52020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT59R-00081D-Iv for importer@patchew.org; Wed, 22 Sep 2021 12:31:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v1-0003Id-H5; Wed, 22 Sep 2021 12:16:24 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39206) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uz-0005RD-LI; Wed, 22 Sep 2021 12:16:23 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 29DC821ECF; Wed, 22 Sep 2021 16:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YFwTgaEumzc2XGbjK4hpWpdj4pZUzdb1skxz4Vmg8i8=; b=J+Wmqk4a8kuzHCMVCeIGgJjNaAhGIf80oYCh+/fvuoSlwd8WukKbcCqGi6wVcYUIS4uQKG /a8dur7Nk0YA6/FfoYgSVEqf/P0POAC01x1RLhg1ZUWOh0CgUNQ4C0nG1dSJsSu+dGdi1N f1rziCvvT/vfiWxVDVTEbOMcSei2Y0c= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 12/16] add x-sysbus-mmio-map qmp command Date: Wed, 22 Sep 2021 18:14:01 +0200 Message-Id: <20210922161405.140018-13-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632328281941100001 Content-Type: text/plain; charset="utf-8" This command allows to map an mmio region of sysbus device onto the system memory. Its behavior mimics the sysbus_mmio_map() function apart from the automatic unmap (the C function unmaps the region if it is already mapped). For the qmp function we consider it is an error to try to map an already mapped function. If unmapping is required, it is probably better to add a sysbus-mmip-unmap function. This command is still experimental (hence the x prefix), as it is related to the sysbus device creation through qmp commands. In future, we expect to have to handle the overlap/priority parameter but also multiple mapping of one mmio. For some devices, one mmio is mapped several times at different addresses on the bus (which is not supported by sysbus_mmio_map() function and requires the use of memory region aliases). Signed-off-by: Damien Hedde --- Note: this qmp command is required to be able to build a machine from scratch as there is no qmp-way of doing a memory mapping today. We've added the command into qapi/qdev.json section. It does not seem to have any really adequate section yet. Any idea ? should we create for example a new one: qapi/sysbus.json or qapi/memory.json ? --- qapi/qdev.json | 21 +++++++++++++++++++++ hw/core/sysbus.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index ad669ae175..dfc1104197 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -125,3 +125,24 @@ ## { 'event': 'DEVICE_DELETED', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @x-sysbus-mmio-map: +# +# Map a sysbus device mmio onto the main system bus. +# +# @device: the device's QOM path +# +# @mmio: The mmio number to be mapped (defaults to 0). +# +# @addr: The base address for the mapping. +# +# Since: 6.2 +# +# Returns: Nothing on success +# +## + +{ 'command': 'x-sysbus-mmio-map', + 'data': {'device': 'str', '*mmio': 'uint8', 'addr': 'uint64'}, + 'allow-preconfig' : true } diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index aaae8e23cc..b0891f37b6 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -23,6 +23,7 @@ #include "hw/sysbus.h" #include "monitor/monitor.h" #include "exec/address-spaces.h" +#include "qapi/qapi-commands-qdev.h" =20 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *sysbus_get_fw_dev_path(DeviceState *dev); @@ -154,6 +155,46 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, = int n, hwaddr addr, } } =20 +void qmp_x_sysbus_mmio_map(const char *device, bool has_mmio, uint8_t mmio, + uint64_t addr, Error **errp) +{ + Object *obj =3D object_resolve_path_type(device, TYPE_SYS_BUS_DEVICE, = NULL); + SysBusDevice *dev; + + if (phase_get() !=3D MACHINE_INIT_PHASE_INITIALIZED) { + error_setg(errp, "The command is permitted only when " + "the machine is in initialized phase"); + return; + } + + if (obj =3D=3D NULL) { + error_setg(errp, "Device '%s' not found", device); + return; + } + + dev =3D SYS_BUS_DEVICE(obj); + if (!has_mmio) { + mmio =3D 0; + } + if (mmio >=3D dev->num_mmio) { + error_setg(errp, "MMIO index '%u' is out of range", mmio); + return; + } + + if (dev->mmio[mmio].addr !=3D (hwaddr)-1) { + error_setg(errp, "MMIO index '%u' is already mapped", mmio); + return; + } + + if (!memory_region_try_add_subregion(get_system_memory(), addr, + dev->mmio[mmio].memory, 0, + errp)) { + return; + } + + dev->mmio[mmio].addr =3D addr; +} + void sysbus_mmio_unmap(SysBusDevice *dev, int n) { assert(n >=3D 0 && n < dev->num_mmio); --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632331643638858.3106713466716; Wed, 22 Sep 2021 10:27:23 -0700 (PDT) Received: from localhost ([::1]:53838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT61i-0000GO-EP for importer@patchew.org; Wed, 22 Sep 2021 13:27:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v2-0003If-93; Wed, 22 Sep 2021 12:16:24 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v0-0005Ro-C6; Wed, 22 Sep 2021 12:16:24 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id B455E21ED2; Wed, 22 Sep 2021 16:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cfebBfH6GVdfSl+a3M3Z0yLytuwrCU0s61tJ+ZXVGyA=; b=4+57fmZZrqqfiMZEPQV/HtYezQjVslO9aiAmXDY9Q9U4w+pBohuF9d/PLrpAJIwjoBNO49 4DN2/DjmOHhL4T4VsHSwLEPNnD/2srj0nVTR7h5YqWSOh3iImVQU3JbPlA8mSUE2Ei2E1r K/SqfsawzVu+ASUu//lxvgY7OHHBmXc= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 13/16] hw/mem/system-memory: add a memory sysbus device Date: Wed, 22 Sep 2021 18:14:02 +0200 Message-Id: <20210922161405.140018-14-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632331645263100003 Content-Type: text/plain; charset="utf-8" This device can be used to create some memories using standard device_add qmp command. This device has one property 'readonly' which allows to choose between a ram or a rom. The device holds the adequate memory region and can be put on the sysbus. Signed-off-by: Damien Hedde --- Should we add a related CONFIG_ variable in the build system ? Depending on the chosen condition to add a device, the commit may change. --- include/hw/mem/sysbus-memory.h | 32 +++++++++++++ hw/mem/sysbus-memory.c | 83 ++++++++++++++++++++++++++++++++++ hw/mem/meson.build | 2 + 3 files changed, 117 insertions(+) create mode 100644 include/hw/mem/sysbus-memory.h create mode 100644 hw/mem/sysbus-memory.c diff --git a/include/hw/mem/sysbus-memory.h b/include/hw/mem/sysbus-memory.h new file mode 100644 index 0000000000..3e1271dbfd --- /dev/null +++ b/include/hw/mem/sysbus-memory.h @@ -0,0 +1,32 @@ +/* + * QEMU memory SysBusDevice + * + * Copyright (c) 2021 Greensocs + * + * Author: + * + Damien Hedde + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_SYSBUS_MEMORY_H +#define HW_SYSBUS_MEMORY_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_SYSBUS_MEMORY "sysbus-memory" +OBJECT_DECLARE_SIMPLE_TYPE(SysBusMemoryState, SYSBUS_MEMORY) + +struct SysBusMemoryState { + /* */ + SysBusDevice parent_obj; + uint64_t size; + bool readonly; + + /* */ + MemoryRegion mem; +}; + +#endif /* HW_SYSBUS_MEMORY_H */ diff --git a/hw/mem/sysbus-memory.c b/hw/mem/sysbus-memory.c new file mode 100644 index 0000000000..897fa154f0 --- /dev/null +++ b/hw/mem/sysbus-memory.c @@ -0,0 +1,83 @@ +/* + * QEMU memory SysBusDevice + * + * Copyright (c) 2021 Greensocs + * + * Author: + * + Damien Hedde + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/mem/sysbus-memory.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" + +static Property sysbus_memory_properties[] =3D { + DEFINE_PROP_UINT64("size", SysBusMemoryState, size, 0), + DEFINE_PROP_BOOL("readonly", SysBusMemoryState, readonly, false), + DEFINE_PROP_END_OF_LIST(), +}; + +static void sysbus_memory_realize(DeviceState *dev, Error **errp) +{ + SysBusMemoryState *s =3D SYSBUS_MEMORY(dev); + gchar *name; + + if (!s->size) { + error_setg(errp, "'size' must be non-zero."); + return; + } + + /* + * We impose having an id (which is unique) because we need to generate + * a unique name for the memory region. + * memory_region_init_ram/rom() will abort() (in qemu_ram_set_idstr() + * function if 2 system-memory devices are created with the same name + * for the memory region). + */ + if (!dev->id) { + error_setg(errp, "system-memory device must have an id."); + return; + } + name =3D g_strdup_printf("%s.region", dev->id); + + if (s->readonly) { + memory_region_init_rom(&s->mem, OBJECT(dev), name, s->size, errp); + } else { + memory_region_init_ram(&s->mem, OBJECT(dev), name, s->size, errp); + } + + g_free(name); + + if (!*errp) { + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mem); + } +} + +static void sysbus_memory_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->user_creatable =3D true; + dc->realize =3D sysbus_memory_realize; + device_class_set_props(dc, sysbus_memory_properties); +} + +static const TypeInfo sysbus_memory_info =3D { + .name =3D TYPE_SYSBUS_MEMORY, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(SysBusMemoryState), + .class_init =3D sysbus_memory_class_init, +}; + +static void sysbus_memory_register_types(void) +{ + type_register_static(&sysbus_memory_info); +} + +type_init(sysbus_memory_register_types) diff --git a/hw/mem/meson.build b/hw/mem/meson.build index 3c8fdef9f9..81e2de1d34 100644 --- a/hw/mem/meson.build +++ b/hw/mem/meson.build @@ -7,3 +7,5 @@ mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'= )) softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss) =20 softmmu_ss.add(when: 'CONFIG_FUZZ', if_true: files('sparse-mem.c')) + +softmmu_ss.add(files('sysbus-memory.c')) --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632332234965753.0145883765474; Wed, 22 Sep 2021 10:37:14 -0700 (PDT) Received: from localhost ([::1]:39824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT6BF-0002G0-Oz for importer@patchew.org; Wed, 22 Sep 2021 13:37:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v4-0003M6-8P; Wed, 22 Sep 2021 12:16:27 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v1-0005S5-AB; Wed, 22 Sep 2021 12:16:26 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 879E321ED3; Wed, 22 Sep 2021 16:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lg6JGGOuMKgOK9bkuvAzYukD8OqEWtmOgbk2hQPItz8=; b=ND0iqKFzTzDcZ27ooxhDOEEEV8AccARG7AJHhC9a02u1e9KnwGeBRww88INrFwYdnUiGLU iWgot6Scekg2EdCjx5zulK0cCIpl/uZhww0kpehf4I9kg6qVmrIhlxI6IZCWAofixBVreB IFn8x3hm1X67NsswL2KN8XfRLNp4fgc= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 14/16] docs/system: add doc about the initialized machine phase and an example Date: Wed, 22 Sep 2021 18:14:03 +0200 Message-Id: <20210922161405.140018-15-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632332235917100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Damien Hedde --- docs/system/managed-startup.rst | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/docs/system/managed-startup.rst b/docs/system/managed-startup.= rst index 9bcf98ea79..af12a10d27 100644 --- a/docs/system/managed-startup.rst +++ b/docs/system/managed-startup.rst @@ -32,4 +32,81 @@ machine, including but not limited to: - ``query-qmp-schema`` - ``query-commands`` - ``query-status`` +- ``x-machine-init`` - ``x-exit-preconfig`` + +In particular these commands allow to advance and stop qemu at different +phases of the VM creation and finally to leave the "preconfig" state. The +accessible phases are: + +- ``accel-created`` +- ``initialized`` +- ``ready`` + +The order of the phases is enforced. It is not possible to go backwards. +Note that other early phases exist, but they are not attainable with +``--preconfig``. Depending on the phase, QMP commands can be issued to mod= ify +some part of the VM creation. + +accel-created phase +------------------- + +Initial phase entered with ``--preconfig``. + +initialized phase +----------------- + +``x-machine-init`` advances to ``initialized`` phase. During this phase, t= he +machine is initialized and populated with buses and devices. The following= QMP +commands are available to manually populate or modify the machine: + +- ``device_add`` +- ``x-sysbus-mmio-map`` +- ``qom-set`` + +ready phase +----------- + +``x-exit-preconfig`` advances to the final phase. When entering this phase, +the VM creation finishes. "preconfig" state is then done and QEMU goes to +normal execution. + +Machine creation example +------------------------ + +The following is an example that shows how to add some devices with qmp +commands, memory map them, and add interrupts:: + + x-machine-init + + device_add driver=3Dsysbus-memory id=3Drom size=3D0x4000 readonly= =3Dtrue + x-sysbus-mmio-map device=3Drom addr=3D32768 + + device_add driver=3Dsysbus-memory id=3Dflash size=3D0x80000 reado= nly=3Dtrue + x-sysbus-mmio-map device=3Dflash addr=3D536870912 + + device_add driver=3Dsysbus-memory id=3Dram size=3D0x10000 + x-sysbus-mmio-map device=3Dram addr=3D268435456 + + device_add driver=3Dibex-plic id=3Dplic + x-sysbus-mmio-map device=3Dplic addr=3D1090584576 + + device_add driver=3Dibex-uart id=3Duart chardev=3Dserial0 + x-sysbus-mmio-map device=3Duart addr=3D1073741824 + qom-set path=3Duart property=3Dsysbus-irq[0] value=3Dplic/unnamed-gpio-i= n[1] + qom-set path=3Duart property=3Dsysbus-irq[1] value=3Dplic/unnamed-gpio-i= n[2] + qom-set path=3Duart property=3Dsysbus-irq[2] value=3Dplic/unnamed-gpio-i= n[3] + qom-set path=3Duart property=3Dsysbus-irq[3] value=3Dplic/unnamed-gpio-i= n[4] + + x-exit-preconfig + +These commands reproduce a subset of the riscv32 opentitan (hw/riscv/opent= itan) +machine. We can start qemu using:: + + qemu-sytem-riscv32 -preconfig -qmp unix:./qmp-sock,server \ + -machine none -cpu lowriscv-ibex -serial mon:stdio ... + +Then we just have to issue the commands, for example using `qmp-shell`. If= the +previous commands were in a file named `machine.qmp`, we could do:: + + qmp-shell ./qmp-sock < machine.qmp --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632332848429186.80275071869244; Wed, 22 Sep 2021 10:47:28 -0700 (PDT) Received: from localhost ([::1]:51918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT6L7-0002p4-NX for importer@patchew.org; Wed, 22 Sep 2021 13:47:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v5-0003Nt-Pn; Wed, 22 Sep 2021 12:16:27 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4v2-0005So-8d; Wed, 22 Sep 2021 12:16:27 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 89D1B21ED5; Wed, 22 Sep 2021 16:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V/wXO8Fw46s42gvXscl9fDzKCmjnZalAaCkoeLW9idc=; b=fzmPX4ObaVsIGjwR4GzoY/SbGumd3hE8zzTj5wQNt93NX3hZr8kYnEk/i6a/ahRb3BcyzH r4OPUKes6fAREsZ6M/d6oRgJNM/rLp/UW1rGVvosF72Xhv4ZT3ZMvT7X96ovqsT8bIwjFg MzDwJiVoSLVcg/Nq1RzI5wAN8p9MecQ= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 15/16] hw/char/ibex_uart: set user_creatable Date: Wed, 22 Sep 2021 18:14:04 +0200 Message-Id: <20210922161405.140018-16-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632332851153100001 Content-Type: text/plain; charset="utf-8" This patch allows to create the device using device_add using -preconfig mode. This sysbus device still needs to be allowed by a machine to be created after preconfig is done. Signed-off-by: Damien Hedde --- Depending on chosen condition for a device to be added, this commit may change. --- hw/char/ibex_uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c index 9b0a817713..b1646422c0 100644 --- a/hw/char/ibex_uart.c +++ b/hw/char/ibex_uart.c @@ -546,6 +546,7 @@ static void ibex_uart_class_init(ObjectClass *klass, vo= id *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; dc->reset =3D ibex_uart_reset; dc->realize =3D ibex_uart_realize; dc->vmsd =3D &vmstate_ibex_uart; --=20 2.33.0 From nobody Fri Nov 29 17:38:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1632331918; cv=none; d=zohomail.com; s=zohoarc; b=ZEByXTbnm2aiPK9yHDQ4XNTbXpIdD60S7GZJ1DylokKn4sk4DJLk6ECObwG33IaQukMPHCYonqeNPRxa8c1tDEp4q8Mj1qk2IuGXUztAXeWW1w/tJKP54JLDoG4TojrBaX5CxNbGZAYjbVYu0KIop19DvqUpH1QKiEHwcRL43Vs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632331918; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=20eMulj3Qy/DZxWmekzYSt42bv07Z1NJC97opChMppc=; b=Ax24ZBqsVIl0EzFGvndcC1ksubz911t3dXU819ViMlAH422oeDryr6AuzcwN+UvXyovnIImBGxZZN0m5toJQveHce1mjMoX45D74jGjIfs5LQ/2Xy8SWomc4eJjumhS7/atdUba9DzFax/QFaQUtG2GYrxa9xgnqWs9Y07NptcM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1632331918708328.1476233801949; Wed, 22 Sep 2021 10:31:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.192961.343709 (Exim 4.92) (envelope-from ) id 1mT65q-0003pG-ND; Wed, 22 Sep 2021 17:31:38 +0000 Received: by outflank-mailman (output) from mailman id 192961.343709; Wed, 22 Sep 2021 17:31:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mT65q-0003p9-Jh; Wed, 22 Sep 2021 17:31:38 +0000 Received: by outflank-mailman (input) for mailman id 192961; Wed, 22 Sep 2021 17:31:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mT65p-0003p3-Uf for xen-devel@lists.xenproject.org; Wed, 22 Sep 2021 17:31:37 +0000 Received: from beetle.greensocs.com (unknown [5.135.226.135]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id efd3b8be-1bca-11ec-b9c0-12813bfff9fa; Wed, 22 Sep 2021 17:31:36 +0000 (UTC) Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 98B7F21ED8; Wed, 22 Sep 2021 16:16:02 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: efd3b8be-1bca-11ec-b9c0-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=20eMulj3Qy/DZxWmekzYSt42bv07Z1NJC97opChMppc=; b=0GTRQNrK+8eC4nSIBI1SyRdVgk/yz3AcWIgo1jZc+3/ixKzyuHi/rbXlOmb7SF5gwUT4je Kafcyz3ZizvLJ94FKvPqVu6mxe7wLyPq9T2y/XORwkJswxh9nvcCQaC5xGv/EED3DiFvN+ S0CxATzuTlW34AF4O/BZxkpylFrb5Mg= From: Damien Hedde To: qemu-devel@nongnu.org Cc: Damien Hedde , Alistair Francis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Gerd Hoffmann , Eric Auger , Stefano Stabellini , Anthony Perard , Paul Durrant , Peter Xu , David Hildenbrand , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake , qemu-riscv@nongnu.org, xen-devel@lists.xenproject.org, mark.burton@greensocs.com, mirela.grujic@greensocs.com, edgari@xilinx.com, Peter Maydell Subject: [RFC PATCH v2 16/16] hw/intc/ibex_plic: set user_creatable Date: Wed, 22 Sep 2021 18:14:05 +0200 Message-Id: <20210922161405.140018-17-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1632331921262100001 Content-Type: text/plain; charset="utf-8" This patch allows to create the device using device_add using -preconfig mode. This sysbus device still needs to be allowed by a machine to be created after preconfig is done. Signed-off-by: Damien Hedde --- Depending on chosen condition for a device to be added, this commit may change. --- hw/intc/ibex_plic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c index edf76e4f61..8abd5ee613 100644 --- a/hw/intc/ibex_plic.c +++ b/hw/intc/ibex_plic.c @@ -291,6 +291,7 @@ static void ibex_plic_class_init(ObjectClass *klass, vo= id *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; dc->reset =3D ibex_plic_reset; device_class_set_props(dc, ibex_plic_properties); dc->realize =3D ibex_plic_realize; --=20 2.33.0