[PATCH 7/7] hw/acpi: generic_event_device: Don't call qdev_get_machine in soc init

alistair23@gmail.com posted 7 patches 3 weeks, 5 days ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Jean-Christophe Dubois <jcd@tribudubois.net>, Andrey Smirnov <andrew.smirnov@gmail.com>, Bernhard Beschow <shentey@gmail.com>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
[PATCH 7/7] hw/acpi: generic_event_device: Don't call qdev_get_machine in soc init
Posted by alistair23@gmail.com 3 weeks, 5 days ago
From: Alistair Francis <alistair.francis@wdc.com>

Calling qdev_get_machine() in the soc_init function would result in
the following assert

    ../hw/core/qdev.c:858: qdev_get_machine: Assertion `dev' failed.

when trying to run

    ./qemu-system-aarch64 -S -display none -M virt -device acpi-ged,help

as the machine wasn't created yet. We call qdev_get_machine() to obtain
the ram slots of the machine. So instead of initialising the GED in
the init let's instead do it in the realise where the machine
will exist.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 hw/acpi/generic_event_device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index 30dab43a00..9e9416d406 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -506,6 +506,9 @@ static void acpi_ged_realize(DeviceState *dev, Error **errp)
     uint32_t ged_events;
     int i;
 
+    acpi_memory_hotplug_init(&s->container_memhp, OBJECT(dev),
+                             &s->memhp_state, 0);
+
     if (pcihp_state->use_acpi_hotplug_bridge) {
         s->ged_event_bitmap |= ACPI_GED_PCI_HOTPLUG_EVT;
     }
@@ -568,8 +571,6 @@ static void acpi_ged_initfn(Object *obj)
     memory_region_init(&s->container_memhp, OBJECT(dev), "memhp container",
                        MEMORY_HOTPLUG_IO_LEN);
     sysbus_init_mmio(sbd, &s->container_memhp);
-    acpi_memory_hotplug_init(&s->container_memhp, OBJECT(dev),
-                             &s->memhp_state, 0);
 
     memory_region_init_io(&ged_st->regs, obj, &ged_regs_ops, ged_st,
                           TYPE_ACPI_GED "-regs", ACPI_GED_REG_COUNT);
-- 
2.53.0
Re: [PATCH 7/7] hw/acpi: generic_event_device: Don't call qdev_get_machine in soc init
Posted by Thomas Huth 3 weeks, 5 days ago
On 12/03/2026 05.31, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
> 
> Calling qdev_get_machine() in the soc_init function would result in

soc_init sounds wrong for this device?

Maybe replace this with:

Calling qdev_get_machine() in acpi_ged_initfn() (via 
acpi_memory_hotplug_init()) results in the following assert

?

With that fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>


> the following assert
> 
>      ../hw/core/qdev.c:858: qdev_get_machine: Assertion `dev' failed.
> 
> when trying to run
> 
>      ./qemu-system-aarch64 -S -display none -M virt -device acpi-ged,help
> 
> as the machine wasn't created yet. We call qdev_get_machine() to obtain
> the ram slots of the machine. So instead of initialising the GED in
> the init let's instead do it in the realise where the machine
> will exist.
> 
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>   hw/acpi/generic_event_device.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index 30dab43a00..9e9416d406 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -506,6 +506,9 @@ static void acpi_ged_realize(DeviceState *dev, Error **errp)
>       uint32_t ged_events;
>       int i;
>   
> +    acpi_memory_hotplug_init(&s->container_memhp, OBJECT(dev),
> +                             &s->memhp_state, 0);
> +
>       if (pcihp_state->use_acpi_hotplug_bridge) {
>           s->ged_event_bitmap |= ACPI_GED_PCI_HOTPLUG_EVT;
>       }
> @@ -568,8 +571,6 @@ static void acpi_ged_initfn(Object *obj)
>       memory_region_init(&s->container_memhp, OBJECT(dev), "memhp container",
>                          MEMORY_HOTPLUG_IO_LEN);
>       sysbus_init_mmio(sbd, &s->container_memhp);
> -    acpi_memory_hotplug_init(&s->container_memhp, OBJECT(dev),
> -                             &s->memhp_state, 0);
>   
>       memory_region_init_io(&ged_st->regs, obj, &ged_regs_ops, ged_st,
>                             TYPE_ACPI_GED "-regs", ACPI_GED_REG_COUNT);