[PATCH 09/12] hw/s390x/css-bridge: Realize sysbus device before accessing it

Philippe Mathieu-Daudé posted 12 patches 1 year, 1 month ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Richard Henderson <richard.henderson@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Peter Xu <peterx@redhat.com>, Jason Wang <jasowang@redhat.com>, Sergio Lopez <slp@redhat.com>, Song Gao <gaosong@loongson.cn>, Beniamino Galvani <b.galvani@gmail.com>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Huacai Chen <chenhuacai@kernel.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>
There is a newer version of this series
[PATCH 09/12] hw/s390x/css-bridge: Realize sysbus device before accessing it
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
sysbus_mmio_map() should not be called on unrealized device.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/s390x/css-bridge.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index 4017081d49..15d26efc95 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -95,7 +95,6 @@ static const TypeInfo virtual_css_bus_info = {
 
 VirtualCssBus *virtual_css_bus_init(void)
 {
-    VirtualCssBus *cbus;
     BusState *bus;
     DeviceState *dev;
 
@@ -103,19 +102,19 @@ VirtualCssBus *virtual_css_bus_init(void)
     dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE);
     object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
                               OBJECT(dev));
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Create bus on bridge device */
     bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
-    cbus = VIRTUAL_CSS_BUS(bus);
 
     /* Enable hotplugging */
     qbus_set_hotplug_handler(bus, OBJECT(dev));
 
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+
     css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
                              0, &error_abort);
 
-    return cbus;
+    return VIRTUAL_CSS_BUS(bus);
  }
 
 /***************** Virtual-css Bus Bridge Device ********************/
-- 
2.41.0


Re: [PATCH 09/12] hw/s390x/css-bridge: Realize sysbus device before accessing it
Posted by Thomas Huth 1 year, 1 month ago
On 18/10/2023 16.11, Philippe Mathieu-Daudé wrote:
> sysbus_mmio_map() should not be called on unrealized device.

Can you elaborate? I don't see a sysbus_mmio_map() in this code here...?

  Thomas


> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/s390x/css-bridge.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
> index 4017081d49..15d26efc95 100644
> --- a/hw/s390x/css-bridge.c
> +++ b/hw/s390x/css-bridge.c
> @@ -95,7 +95,6 @@ static const TypeInfo virtual_css_bus_info = {
>   
>   VirtualCssBus *virtual_css_bus_init(void)
>   {
> -    VirtualCssBus *cbus;
>       BusState *bus;
>       DeviceState *dev;
>   
> @@ -103,19 +102,19 @@ VirtualCssBus *virtual_css_bus_init(void)
>       dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE);
>       object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
>                                 OBJECT(dev));
> -    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>   
>       /* Create bus on bridge device */
>       bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
> -    cbus = VIRTUAL_CSS_BUS(bus);
>   
>       /* Enable hotplugging */
>       qbus_set_hotplug_handler(bus, OBJECT(dev));
>   
> +    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> +
>       css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
>                                0, &error_abort);
>   
> -    return cbus;
> +    return VIRTUAL_CSS_BUS(bus);
>    }
>   
>   /***************** Virtual-css Bus Bridge Device ********************/


Re: [PATCH 09/12] hw/s390x/css-bridge: Realize sysbus device before accessing it
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
On 18/10/23 17:06, Thomas Huth wrote:
> On 18/10/2023 16.11, Philippe Mathieu-Daudé wrote:
>> sysbus_mmio_map() should not be called on unrealized device.
> 
> Can you elaborate? I don't see a sysbus_mmio_map() in this code here...?

I meant 's/sysbus_mmio_map/qbus_new'. Sorry, long day.

> 
>   Thomas
> 
> 
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/s390x/css-bridge.c | 7 +++----
>>   1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
>> index 4017081d49..15d26efc95 100644
>> --- a/hw/s390x/css-bridge.c
>> +++ b/hw/s390x/css-bridge.c
>> @@ -95,7 +95,6 @@ static const TypeInfo virtual_css_bus_info = {
>>   VirtualCssBus *virtual_css_bus_init(void)
>>   {
>> -    VirtualCssBus *cbus;
>>       BusState *bus;
>>       DeviceState *dev;
>> @@ -103,19 +102,19 @@ VirtualCssBus *virtual_css_bus_init(void)
>>       dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE);
>>       object_property_add_child(qdev_get_machine(), 
>> TYPE_VIRTUAL_CSS_BRIDGE,
>>                                 OBJECT(dev));
>> -    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>>       /* Create bus on bridge device */
>>       bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
>> -    cbus = VIRTUAL_CSS_BUS(bus);
>>       /* Enable hotplugging */
>>       qbus_set_hotplug_handler(bus, OBJECT(dev));
>> +    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
>> +
>>       css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
>>                                0, &error_abort);
>> -    return cbus;
>> +    return VIRTUAL_CSS_BUS(bus);
>>    }
>>   /***************** Virtual-css Bus Bridge Device ********************/
>