Fix crashes with introspection of ARM devices
Subsystems (6)
v3 cover Fix crashes with introspection of ARM devices
As discovered recently, you can crash QEMU with a lot of devices that do not get the reference counting of child objects right. You just have to run 'device-list-properties' and call 'info qtree' afterwards.
This patch series fixes these problems in the ARM code. When all patches have been applied, I now do not get any more hangs or crashes when I add a hmp("info qtree") to the device-introspect-test.
Please have a look at patch #1, #15 and #16, they still need reviews.
v3:
- Reworked object_initialize_child according to Paolos suggestions (patch 1)
- Added prototype description in the 2nd patch (as suggested by Eduardo)
- Replaced the xlnx_dp "realize" patch with the one from Paolo
- Added a patch for the "stm32f205_soc" device (surprisingly this was already the last one that caused trouble - I originally expected more)
v2:
- Updated the first patch according to the review feedback from v1
- Added more patches with additional fixes
Paolo Bonzini (1):
hw/display/xlnx_dp: Move problematic code from instance_init to
realize
Thomas Huth (16):
qom/object: Add a new function object_initialize_child() hw/core/sysbus: Add a function for creating and attaching an object hw/arm/bcm2836: Fix crash with device_add bcm2837 on unsupported
machines
hw/arm/armv7: Fix crash when introspecting the "iotkit" device hw/cpu/a15mpcore: Fix introspection problem with the a15mpcore_priv
device
hw/arm/msf2-soc: Fix introspection problem with the "msf2-soc" device hw/cpu/a9mpcore: Fix introspection problems with the "a9mpcore_priv"
device
hw/arm/fsl-imx6: Fix introspection problems with the "fsl,imx6" device hw/arm/fsl-imx7: Fix introspection problems with the "fsl,imx7" device hw/arm/fsl-imx25: Fix introspection problem with the "fsl,imx25"
device
hw/arm/fsl-imx31: Fix introspection problem with the "fsl,imx31"
device
hw/cpu/arm11mpcore: Fix introspection problem with 'arm11mpcore_priv' hw/*/realview: Fix introspection problem with 'realview_mpcore' &
'realview_gic'
hw/arm/allwinner-a10: Fix introspection problem with 'allwinner-a10' hw/arm/stm32f205_soc: Fix introspection problem with 'stm32f205-soc'
device
hw/arm/xlnx-zynqmp: Fix crash when introspecting the "xlnx,zynqmp"
device
hw/arm/allwinner-a10.c | 19 +++++----- hw/arm/armv7m.c | 7 ++-- hw/arm/bcm2836.c | 18 +++------ hw/arm/fsl-imx25.c | 30 +++++++-------- hw/arm/fsl-imx31.c | 26 ++++++------- hw/arm/fsl-imx6.c | 56 ++++++++++------------------ hw/arm/fsl-imx7.c | 97 ++++++++++++++++-------------------------------- hw/arm/iotkit.c | 74 ++++++++++++++++-------------------- hw/arm/msf2-soc.c | 15 ++++---- hw/arm/stm32f205_soc.c | 28 ++++++-------- hw/arm/xlnx-zynqmp.c | 61 ++++++++++++++---------------- hw/core/sysbus.c | 8 ++++ hw/cpu/a15mpcore.c | 8 ++-- hw/cpu/a9mpcore.c | 18 ++++----- hw/cpu/arm11mpcore.c | 14 +++---- hw/cpu/realview_mpcore.c | 8 ++-- hw/display/xlnx_dp.c | 8 +++- hw/intc/armv7m_nvic.c | 5 +-- hw/intc/realview_gic.c | 7 +--- hw/misc/auxbus.c | 18 ++++++--- include/hw/misc/auxbus.h | 14 ++++++- include/hw/sysbus.h | 17 +++++++++ include/qom/object.h | 45 +++++++++++++++++++++- qom/object.c | 54 +++++++++++++++++++++++++++ 24 files changed, 355 insertions(+), 300 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 2/17 hw/core/sysbus: Add a function for creating and attaching an object
A lot of functions are initializing an object and attach it immediately afterwards to the system bus. Provide a common function for this, which also uses object_initialize_child() to make sure that the reference counter is correctly initialized to 1 afterwards.
--- hw/core/sysbus.c | 8 ++++++++ include/hw/sysbus.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+)
hw/core/sysbus.c +8 -0
@@ -376,6 +376,14 @@ BusState *sysbus_get_default(void)return main_system_bus; } +void sysbus_init_child_obj (Object *parent,const char *childname,void *child, +size_t childsize,const char *childtype) +{ +object_initialize_child (parent, childname, child, childsize, childtype, + &error_abort,NULL ); +qdev_set_parent_bus (DEVICE (child),sysbus_get_default ()); +} +static void sysbus_register_types (void ) {type_register_static (&system_bus_info);
include/hw/sysbus.h +17 -0
@@ -96,6 +96,23 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr, MemoryRegion *mem);MemoryRegion *sysbus_address_space (SysBusDevice *dev); +/** +* sysbus_init_child_obj: +* @parent: The parent object +* @childname: Used as name of the "child<>" property in the parent +* @child: A pointer to the memory to be used for the object. +* @childsize: The maximum size available at @child for the object. +* @childtype: The name of the type of the object to instantiate. +* +* This function will initialize an object and attach it to the main system +* bus. The memory for the object should have already been allocated. The +* object will then be added as child to the given parent. The returned object +* has a reference count of 1 (for the "child<...>" property from the parent), +* so the object will be finalized automatically when the parent gets removed. +*/ +void sysbus_init_child_obj (Object *parent,const char *childname,void *child, +size_t childsize,const char *childtype); +/* Call func for every dynamically created sysbus device in the system */ void foreach_dynamic_sysbus_device (FindSysbusDeviceFunc *func,void *opaque);
Signature · 1 line
1.8.3.1
PATCH v3 3/17 hw/arm/bcm2836: Fix crash with device_add bcm2837 on unsupported machines
In reply to Thomas HuthWhen trying to "device_add bcm2837" on a machine that is not suitable for this device, you can quickly crash QEMU afterwards, e.g. with "info qtree":
echo "{'execute':'qmp_capabilities'} {'execute':'device_add', " \
"'arguments':{'driver':'bcm2837'}} {'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
aarch64-softmmu/qemu-system-aarch64 -M integratorcp,accel=qtest -S -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2},
"package": "build-all"}, "capabilities": []}}
{"return": {}}
{"error": {"class": "GenericError", "desc": "Device 'bcm2837' can not be
hotplugged on this machine"}}
Segmentation fault (core dumped)
The qdev_set_parent_bus() from instance_init adds a link to the child devices which is not valid anymore after the bcm2837 instance has been destroyed. Unfortunately, the child devices do not get destroyed / unlinked correctly because both object_initialize() and object_property_add_child() increase the reference count of the child objects by one, but only one reference is dropped when the parent gets removed. So let's use the new functions object_initialize_child() and sysbus_init_child_obj() instead to create the objects, which will take care of creating the child objects with the correct reference count of one.
--- hw/arm/bcm2836.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
hw/arm/bcm2836.c +6 -12
@@ -51,25 +51,19 @@ static void bcm2836_init(Object *obj)int n;for (n =0 ; n <BCM283X_NCPUS ; n++) { -object_initialize (&s->cpus[n],sizeof (s->cpus[n]), - info->cpu_type); -object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), - &error_abort); +object_initialize_child (obj,"cpu[*]" , &s->cpus[n],sizeof (s->cpus[n]), + info->cpu_type, &error_abort,NULL ); } -object_initialize (&s->control,sizeof (s->control),TYPE_BCM2836_CONTROL ); -object_property_add_child (obj,"control" ,OBJECT (&s->control),NULL ); -qdev_set_parent_bus (DEVICE (&s->control),sysbus_get_default ()); +sysbus_init_child_obj (obj,"control" , &s->control,sizeof (s->control), +TYPE_BCM2836_CONTROL ); -object_initialize (&s->peripherals,sizeof (s->peripherals), -TYPE_BCM2835_PERIPHERALS ); -object_property_add_child (obj,"peripherals" ,OBJECT (&s->peripherals), - &error_abort); +sysbus_init_child_obj (obj,"peripherals" , &s->peripherals, +sizeof (s->peripherals),TYPE_BCM2835_PERIPHERALS );object_property_add_alias (obj,"board-rev" ,OBJECT (&s->peripherals),"board-rev" , &error_abort);object_property_add_alias (obj,"vcram-size" ,OBJECT (&s->peripherals),"vcram-size" , &error_abort); -qdev_set_parent_bus (DEVICE (&s->peripherals),sysbus_get_default ()); }static void bcm2836_realize (DeviceState *dev,Error **errp)
Signature · 1 line
1.8.3.1
PATCH v3 1/17 qom/object: Add a new function object_initialize_child()
In reply to Thomas HuthA lot of code is using the object_initialize() function followed by a call to object_property_add_child() to add the newly initialized object as a child of the current object. Both functions increase the reference counter of the new object, but many spots that call these two functions then forget to drop one of the superfluous references. So the newly created object is often not cleaned up correctly when the parent is destroyed. In the worst case, this can cause crashes, e.g. because device objects are not correctly removed from their parent_bus.
Since this is a common pattern between many code spots, let's introduce a new function that takes care of calling all three required initialization functions, first object_initialize(), then object_property_add_child() and finally object_unref(). And since the function does a similar job like object_new_with_props(), also allow to set additional properties via varargs, and use user_creatable_complete() to make sure that the functions can be used similarly.
And while we're at object.h, also fix some copy-n-paste errors in the comments there ("to store the area" --> "to store the error").
--- include/qom/object.h | 45 +++++++++++++++++++++++++++++++++++++++++-- qom/object.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-)
include/qom/object.h +43 -2
@@ -749,6 +749,47 @@ int object_set_propv(Object *obj,void object_initialize (void *obj,size_t size,const char *typename);/** +* object_initialize_child: +* @parentobj: The parent object to add a property to +* @propname: The name of the property +* @childobj: A pointer to the memory to be used for the object. +* @size: The maximum size available at @childobj for the object. +* @type: The name of the type of the object to instantiate. +* @errp: If an error occurs, a pointer to an area to store the error +* @...: list of property names and values +* +* This function will initialize an object. The memory for the object should +* have already been allocated. The object will then be added as child property +* to a parent with object_property_add_child() function. The returned object +* has a reference count of 1 (for the "child<...>" property from the parent), +* so the object will be finalized automatically when the parent gets removed. +* +* The variadic parameters are a list of pairs of (propname, propvalue) +* strings. The propname of %NULL indicates the end of the property list. +* If the object implements the user creatable interface, the object will +* be marked complete once all the properties have been processed. +*/ +void object_initialize_child(Object *parentobj, const char *propname, + void *childobj, size_t size, const char *type, + Error **errp, ...) QEMU_SENTINEL; + +/** +* object_initialize_childv: +* @parentobj: The parent object to add a property to +* @propname: The name of the property +* @childobj: A pointer to the memory to be used for the object. +* @size: The maximum size available at @childobj for the object. +* @type: The name of the type of the object to instantiate. +* @errp: If an error occurs, a pointer to an area to store the error +* @vargs: list of property names and values +* +* See object_initialize_child() for documentation. +*/ +void object_initialize_childv (Object *parentobj,const char *propname, +void *childobj,size_t size,const char *type, +Error **errp,va_list vargs); + +/** * object_dynamic_cast: * @obj: The object to cast. * @typename: The @typename to cast to.
@@ -1382,7 +1423,7 @@ Object *object_resolve_path_component(Object *parent, const gchar *part);* @obj: the object to add a property to * @name: the name of the property * @child: the child object -* @errp: if an error occurs, a pointer to an area to store the area +* @errp: if an error occurs, a pointer to an area to store the error * * Child properties form the composition tree. All objects need to be a child * of another object. Objects can only be a child of one object.
@@ -1420,7 +1461,7 @@ void object_property_allow_set_link(const Object *, const char *,* @child: a pointer to where the link object reference is stored * @check: callback to veto setting or NULL if the property is read-only * @flags: additional options for the link -* @errp: if an error occurs, a pointer to an area to store the area +* @errp: if an error occurs, a pointer to an area to store the error * * Links establish relationships between objects. Links are unidirectional * although two links can be combined to form a bidirectional relationship
qom/object.c +54 -0
60 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 4/17 hw/arm/armv7: Fix crash when introspecting the "iotkit" device
In reply to Thomas HuthQEMU currently crashes when introspecting the "iotkit" device and runnint "info qtree" afterwards, e.g. when running QEMU like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'iotkit'}}" "{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
Use the new functions object_initialize_child() and sysbus_init_child_obj() to make sure that all objects get cleaned up correctly when the instances are destroyed.
--- hw/arm/armv7m.c | 7 +++-- hw/arm/iotkit.c | 74 ++++++++++++++++++++++----------------------------- hw/intc/armv7m_nvic.c | 5 ++-- 3 files changed, 37 insertions(+), 49 deletions(-)
hw/arm/armv7m.c +3 -4
@@ -134,14 +134,13 @@ static void armv7m_instance_init(Object *obj)memory_region_init (&s->container, obj,"armv7m-container" ,UINT64_MAX ); -object_initialize (&s->nvic,sizeof (s->nvic),TYPE_NVIC ); -qdev_set_parent_bus (DEVICE (&s->nvic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"nvnic" , &s->nvic,sizeof (s->nvic),TYPE_NVIC );object_property_add_alias (obj,"num-irq" ,OBJECT (&s->nvic),"num-irq" , &error_abort);for (i =0 ; i <ARRAY_SIZE (s->bitband); i++) { -object_initialize (&s->bitband[i],sizeof (s->bitband[i]),TYPE_BITBAND ); -qdev_set_parent_bus (DEVICE (&s->bitband[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"bitband[*]" , &s->bitband[i], +sizeof (s->bitband[i]),TYPE_BITBAND ); } }
hw/arm/iotkit.c +32 -42
100 lines not on this page · raw message
hw/intc/armv7m_nvic.c +2 -3
@@ -2296,9 +2296,8 @@ static void armv7m_nvic_instance_init(Object *obj)NVICState *nvic =NVIC (obj);SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -object_initialize (&nvic->systick[M_REG_NS ], -sizeof (nvic->systick[M_REG_NS ]),TYPE_SYSTICK ); -qdev_set_parent_bus (DEVICE (&nvic->systick[M_REG_NS ]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"systick-reg-ns" , &nvic->systick[M_REG_NS ], +sizeof (nvic->systick[M_REG_NS ]),TYPE_SYSTICK );/* We can't initialize the secure systick here, as we don't know * yet if we need it. */
Signature · 1 line
1.8.3.1
PATCH v3 5/17 hw/cpu/a15mpcore: Fix introspection problem with the a15mpcore_priv device
In reply to Thomas HuthThere is a memory management problem when introspecting the a15mpcore_priv device. It can be seen with valgrind when running QEMU like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'a15mpcore_priv'}}"\
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2},
"package": "build-all"}, "capabilities": []}}
{"return": {}}
{"return": [{"name": "num-cpu", "type": "uint32"}, {"name": "num-irq",
"type": "uint32"}, {"name": "a15mp-priv-container[0]", "type":
"child<qemu:memory-region>"}]}
==24978== Invalid read of size 8
==24978== at 0x618EBA: qdev_print (qdev-monitor.c:686)
==24978== by 0x618EBA: qbus_print (qdev-monitor.c:719)
[...]
Use the new sysbus_init_child_obj() function to make sure that we get the reference counting of the child objects right.
--- hw/cpu/a15mpcore.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/cpu/a15mpcore.c +3 -5
@@ -35,15 +35,13 @@ static void a15mp_priv_initfn(Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);A15MPPrivState *s =A15MPCORE_PRIV (obj); -DeviceState *gicdev;memory_region_init (&s->container, obj,"a15mp-priv-container" ,0x8000 );sysbus_init_mmio (sbd, &s->container); -object_initialize (&s->gic,sizeof (s->gic),gic_class_name ()); - gicdev =DEVICE (&s->gic); -qdev_set_parent_bus (gicdev,sysbus_get_default ()); -qdev_prop_set_uint32 (gicdev,"revision" ,2 ); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +gic_class_name ()); +qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,2 ); }static void a15mp_priv_realize (DeviceState *dev,Error **errp)
Signature · 1 line
1.8.3.1
PATCH v3 6/17 hw/arm/msf2-soc: Fix introspection problem with the "msf2-soc" device
In reply to Thomas HuthValgrind currently reports a problem when running QEMU like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'msf2-soc'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==23097== Invalid read of size 8
==23097== at 0x6192AA: qdev_print (qdev-monitor.c:686)
==23097== by 0x6192AA: qbus_print (qdev-monitor.c:719)
[...]
Use the new sysbus_init_child_obj() function to make sure that the child objects are cleaned up correctly when the parent gets destroyed.
--- hw/arm/msf2-soc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
hw/arm/msf2-soc.c +7 -8
@@ -68,19 +68,18 @@ static void m2sxxx_soc_initfn(Object *obj)MSF2State *s =MSF2_SOC (obj);int i; -object_initialize (&s->armv7m,sizeof (s->armv7m),TYPE_ARMV7M ); -qdev_set_parent_bus (DEVICE (&s->armv7m),sysbus_get_default ()); +sysbus_init_child_obj (obj,"armv7m" , &s->armv7m,sizeof (s->armv7m), +TYPE_ARMV7M ); -object_initialize (&s->sysreg,sizeof (s->sysreg),TYPE_MSF2_SYSREG ); -qdev_set_parent_bus (DEVICE (&s->sysreg),sysbus_get_default ()); +sysbus_init_child_obj (obj,"sysreg" , &s->sysreg,sizeof (s->sysreg), +TYPE_MSF2_SYSREG ); -object_initialize (&s->timer,sizeof (s->timer),TYPE_MSS_TIMER ); -qdev_set_parent_bus (DEVICE (&s->timer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"timer" , &s->timer,sizeof (s->timer), +TYPE_MSS_TIMER );for (i =0 ; i <MSF2_NUM_SPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]), +sysbus_init_child_obj (obj,"spi[*]" , &s->spi[i],sizeof (s->spi[i]),TYPE_MSS_SPI ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); } }
Signature · 1 line
1.8.3.1
PATCH v3 7/17 hw/cpu/a9mpcore: Fix introspection problems with the "a9mpcore_priv" device
In reply to Thomas HuthRunning QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'a9mpcore_priv'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==30996== Invalid read of size 8
==30996== at 0x6185DA: qdev_print (qdev-monitor.c:686) ==30996== by 0x6185DA: qbus_print (qdev-monitor.c:719) ==30996== by 0x452B38: handle_hmp_command (monitor.c:3446)
[...]
Use the new sysbus_init_child_obj() function to make sure that the objects are cleaned up correctly when the parent gets destroyed.
--- hw/cpu/a9mpcore.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
hw/cpu/a9mpcore.c +8 -10
@@ -27,20 +27,18 @@ static void a9mp_priv_initfn(Object *obj)memory_region_init (&s->container, obj,"a9mp-priv-container" ,0x2000 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->container); -object_initialize (&s->scu,sizeof (s->scu),TYPE_A9_SCU ); -qdev_set_parent_bus (DEVICE (&s->scu),sysbus_get_default ()); +sysbus_init_child_obj (obj,"scu" , &s->scu,sizeof (s->scu),TYPE_A9_SCU ); -object_initialize (&s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -object_initialize (&s->gtimer,sizeof (s->gtimer),TYPE_A9_GTIMER ); -qdev_set_parent_bus (DEVICE (&s->gtimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gtimer" , &s->gtimer,sizeof (s->gtimer), +TYPE_A9_GTIMER ); -object_initialize (&s->mptimer,sizeof (s->mptimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->mptimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"mptimer" , &s->mptimer,sizeof (s->mptimer), +TYPE_ARM_MPTIMER ); -object_initialize (&s->wdt,sizeof (s->wdt),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->wdt),sysbus_get_default ()); +sysbus_init_child_obj (obj,"wdt" , &s->wdt,sizeof (s->wdt), +TYPE_ARM_MPTIMER ); }static void a9mp_priv_realize (DeviceState *dev,Error **errp)
Signature · 1 line
1.8.3.1
PATCH v3 8/17 hw/arm/fsl-imx6: Fix introspection problems with the "fsl, imx6" device
In reply to Thomas HuthRunning QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'fsl,imx6'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==32417== Invalid read of size 8
==32417== at 0x618A7A: qdev_print (qdev-monitor.c:686) ==32417== by 0x618A7A: qbus_print (qdev-monitor.c:719) ==32417== by 0x452B38: handle_hmp_command (monitor.c:3446)
[...]
Use the new sysbus_init_child_obj() and object_initialize_child() to make sure that the objects are removed correctly when the parent gets destroyed.
--- hw/arm/fsl-imx6.c | 56 ++++++++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 36 deletions(-)
hw/arm/fsl-imx6.c +20 -36
@@ -38,73 +38,57 @@ static void fsl_imx6_init(Object *obj)int i;for (i =0 ; i <MIN (smp_cpus,FSL_IMX6_NUM_CPUS ); i++) { -object_initialize (&s->cpu[i],sizeof (s->cpu[i]), -"cortex-a9-" TYPE_ARM_CPU );snprintf (name,NAME_SIZE ,"cpu%d" , i); -object_property_add_child (obj, name,OBJECT (&s->cpu[i]),NULL ); +object_initialize_child (obj, name, &s->cpu[i],sizeof (s->cpu[i]), +"cortex-a9-" TYPE_ARM_CPU , &error_abort,NULL ); } -object_initialize (&s->a9mpcore,sizeof (s->a9mpcore),TYPE_A9MPCORE_PRIV ); -qdev_set_parent_bus (DEVICE (&s->a9mpcore),sysbus_get_default ()); -object_property_add_child (obj,"a9mpcore" ,OBJECT (&s->a9mpcore),NULL ); +sysbus_init_child_obj (obj,"a9mpcore" , &s->a9mpcore,sizeof (s->a9mpcore), +TYPE_A9MPCORE_PRIV ); -object_initialize (&s->ccm,sizeof (s->ccm),TYPE_IMX6_CCM ); -qdev_set_parent_bus (DEVICE (&s->ccm),sysbus_get_default ()); -object_property_add_child (obj,"ccm" ,OBJECT (&s->ccm),NULL ); +sysbus_init_child_obj (obj,"ccm" , &s->ccm,sizeof (s->ccm),TYPE_IMX6_CCM ); -object_initialize (&s->src,sizeof (s->src),TYPE_IMX6_SRC ); -qdev_set_parent_bus (DEVICE (&s->src),sysbus_get_default ()); -object_property_add_child (obj,"src" ,OBJECT (&s->src),NULL ); +sysbus_init_child_obj (obj,"src" , &s->src,sizeof (s->src),TYPE_IMX6_SRC );for (i =0 ; i <FSL_IMX6_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_IMX_SERIAL ); -qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"uart%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->uart[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->uart[i],sizeof (s->uart[i]), +TYPE_IMX_SERIAL ); } -object_initialize (&s->gpt,sizeof (s->gpt),TYPE_IMX6_GPT ); -qdev_set_parent_bus (DEVICE (&s->gpt),sysbus_get_default ()); -object_property_add_child (obj,"gpt" ,OBJECT (&s->gpt),NULL ); +sysbus_init_child_obj (obj,"gpt" , &s->gpt,sizeof (s->gpt),TYPE_IMX6_GPT );for (i =0 ; i <FSL_IMX6_NUM_EPITS ; i++) { -object_initialize (&s->epit[i],sizeof (s->epit[i]),TYPE_IMX_EPIT ); -qdev_set_parent_bus (DEVICE (&s->epit[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"epit%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->epit[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->epit[i],sizeof (s->epit[i]), +TYPE_IMX_EPIT ); }for (i =0 ; i <FSL_IMX6_NUM_I2CS ; i++) { -object_initialize (&s->i2c[i],sizeof (s->i2c[i]),TYPE_IMX_I2C ); -qdev_set_parent_bus (DEVICE (&s->i2c[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"i2c%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->i2c[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->i2c[i],sizeof (s->i2c[i]), +TYPE_IMX_I2C ); }for (i =0 ; i <FSL_IMX6_NUM_GPIOS ; i++) { -object_initialize (&s->gpio[i],sizeof (s->gpio[i]),TYPE_IMX_GPIO ); -qdev_set_parent_bus (DEVICE (&s->gpio[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"gpio%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->gpio[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->gpio[i],sizeof (s->gpio[i]), +TYPE_IMX_GPIO ); }for (i =0 ; i <FSL_IMX6_NUM_ESDHCS ; i++) { -object_initialize (&s->esdhc[i],sizeof (s->esdhc[i]),TYPE_IMX_USDHC ); -qdev_set_parent_bus (DEVICE (&s->esdhc[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"sdhc%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->esdhc[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->esdhc[i],sizeof (s->esdhc[i]), +TYPE_IMX_USDHC ); }for (i =0 ; i <FSL_IMX6_NUM_ECSPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]),TYPE_IMX_SPI ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"spi%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->spi[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->spi[i],sizeof (s->spi[i]), +TYPE_IMX_SPI ); } -object_initialize (&s->eth,sizeof (s->eth),TYPE_IMX_ENET ); -qdev_set_parent_bus (DEVICE (&s->eth),sysbus_get_default ()); -object_property_add_child (obj,"eth" ,OBJECT (&s->eth),NULL ); +sysbus_init_child_obj (obj,"eth" , &s->eth,sizeof (s->eth),TYPE_IMX_ENET ); }static void fsl_imx6_realize (DeviceState *dev,Error **errp)
Signature · 1 line
1.8.3.1
PATCH v3 9/17 hw/arm/fsl-imx7: Fix introspection problems with the "fsl, imx7" device
In reply to Thomas HuthRunning QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'fsl,imx7'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==27284== Invalid read of size 8
==27284== at 0x618F7A: qdev_print (qdev-monitor.c:686) ==27284== by 0x618F7A: qbus_print (qdev-monitor.c:719) ==27284== by 0x452B38: handle_hmp_command (monitor.c:3446)
[...]
Use the new sysbus_init_child_obj() and object_initialize_child() to make sure that the objects are removed correctly when the parent gets destroyed.
--- hw/arm/fsl-imx7.c | 97 +++++++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 64 deletions(-)
hw/arm/fsl-imx7.c +33 -64
@@ -30,157 +30,126 @@static void fsl_imx7_init (Object *obj) { -BusState *sysbus =sysbus_get_default ();FslIMX7State *s =FSL_IMX7 (obj);char name[NAME_SIZE ];int i;for (i =0 ; i <MIN (smp_cpus,FSL_IMX7_NUM_CPUS ); i++) { -object_initialize (&s->cpu[i],sizeof (s->cpu[i]), -ARM_CPU_TYPE_NAME ("cortex-a7" ));snprintf (name,NAME_SIZE ,"cpu%d" , i); -object_property_add_child (obj, name,OBJECT (&s->cpu[i]), - &error_fatal); +object_initialize_child (obj, name, &s->cpu[i],sizeof (s->cpu[i]), +ARM_CPU_TYPE_NAME ("cortex-a7" ), &error_abort, +NULL ); }/* * A7MPCORE */ -object_initialize (&s->a7mpcore,sizeof (s->a7mpcore),TYPE_A15MPCORE_PRIV ); -qdev_set_parent_bus (DEVICE (&s->a7mpcore), sysbus); -object_property_add_child (obj,"a7mpcore" , -OBJECT (&s->a7mpcore), &error_fatal); +sysbus_init_child_obj (obj,"a7mpcore" , &s->a7mpcore,sizeof (s->a7mpcore), +TYPE_A15MPCORE_PRIV );/* * GPIOs 1 to 7 */ for (i =0 ; i <FSL_IMX7_NUM_GPIOS ; i++) { -object_initialize (&s->gpio[i],sizeof (s->gpio[i]), -TYPE_IMX_GPIO ); -qdev_set_parent_bus (DEVICE (&s->gpio[i]), sysbus);snprintf (name,NAME_SIZE ,"gpio%d" , i); -object_property_add_child (obj, name, -OBJECT (&s->gpio[i]), &error_fatal); +sysbus_init_child_obj (obj, name, &s->gpio[i],sizeof (s->gpio[i]), +TYPE_IMX_GPIO ); }/* * GPT1, 2, 3, 4 */ for (i =0 ; i <FSL_IMX7_NUM_GPTS ; i++) { -object_initialize (&s->gpt[i],sizeof (s->gpt[i]),TYPE_IMX7_GPT ); -qdev_set_parent_bus (DEVICE (&s->gpt[i]), sysbus);snprintf (name,NAME_SIZE ,"gpt%d" , i); -object_property_add_child (obj, name,OBJECT (&s->gpt[i]), - &error_fatal); +sysbus_init_child_obj (obj, name, &s->gpt[i],sizeof (s->gpt[i]), +TYPE_IMX7_GPT ); }/* * CCM */ -object_initialize (&s->ccm,sizeof (s->ccm),TYPE_IMX7_CCM ); -qdev_set_parent_bus (DEVICE (&s->ccm), sysbus); -object_property_add_child (obj,"ccm" ,OBJECT (&s->ccm), &error_fatal); +sysbus_init_child_obj (obj,"ccm" , &s->ccm,sizeof (s->ccm),TYPE_IMX7_CCM );/* * Analog */ -object_initialize (&s->analog,sizeof (s->analog),TYPE_IMX7_ANALOG ); -qdev_set_parent_bus (DEVICE (&s->analog), sysbus); -object_property_add_child (obj,"analog" ,OBJECT (&s->analog), &error_fatal); +sysbus_init_child_obj (obj,"analog" , &s->analog,sizeof (s->analog), +TYPE_IMX7_ANALOG );/* * GPCv2 */ -object_initialize (&s->gpcv2,sizeof (s->gpcv2),TYPE_IMX_GPCV2 ); -qdev_set_parent_bus (DEVICE (&s->gpcv2), sysbus); -object_property_add_child (obj,"gpcv2" ,OBJECT (&s->gpcv2), &error_fatal); +sysbus_init_child_obj (obj,"gpcv2" , &s->gpcv2,sizeof (s->gpcv2), +TYPE_IMX_GPCV2 );for (i =0 ; i <FSL_IMX7_NUM_ECSPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]),TYPE_IMX_SPI ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"spi%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->spi[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->spi[i],sizeof (s->spi[i]), +TYPE_IMX_SPI ); }for (i =0 ; i <FSL_IMX7_NUM_I2CS ; i++) { -object_initialize (&s->i2c[i],sizeof (s->i2c[i]),TYPE_IMX_I2C ); -qdev_set_parent_bus (DEVICE (&s->i2c[i]),sysbus_get_default ());snprintf (name,NAME_SIZE ,"i2c%d" , i +1 ); -object_property_add_child (obj, name,OBJECT (&s->i2c[i]),NULL ); +sysbus_init_child_obj (obj, name, &s->i2c[i],sizeof (s->i2c[i]), +TYPE_IMX_I2C ); }/* * UART */ for (i =0 ; i <FSL_IMX7_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_IMX_SERIAL ); -qdev_set_parent_bus (DEVICE (&s->uart[i]), sysbus);snprintf (name,NAME_SIZE ,"uart%d" , i); -object_property_add_child (obj, name,OBJECT (&s->uart[i]), - &error_fatal); +sysbus_init_child_obj (obj, name, &s->uart[i],sizeof (s->uart[i]), +TYPE_IMX_SERIAL ); }/* * Ethernet */ for (i =0 ; i <FSL_IMX7_NUM_ETHS ; i++) { -object_initialize (&s->eth[i],sizeof (s->eth[i]),TYPE_IMX_ENET ); -qdev_set_parent_bus (DEVICE (&s->eth[i]), sysbus);snprintf (name,NAME_SIZE ,"eth%d" , i); -object_property_add_child (obj, name,OBJECT (&s->eth[i]), - &error_fatal); +sysbus_init_child_obj (obj, name, &s->eth[i],sizeof (s->eth[i]), +TYPE_IMX_ENET ); }/* * SDHCI */ for (i =0 ; i <FSL_IMX7_NUM_USDHCS ; i++) { -object_initialize (&s->usdhc[i],sizeof (s->usdhc[i]), -TYPE_IMX_USDHC ); -qdev_set_parent_bus (DEVICE (&s->usdhc[i]), sysbus);snprintf (name,NAME_SIZE ,"usdhc%d" , i); -object_property_add_child (obj, name,OBJECT (&s->usdhc[i]), - &error_fatal); +sysbus_init_child_obj (obj, name, &s->usdhc[i],sizeof (s->usdhc[i]), +TYPE_IMX_USDHC ); }/* * SNVS */ -object_initialize (&s->snvs,sizeof (s->snvs),TYPE_IMX7_SNVS ); -qdev_set_parent_bus (DEVICE (&s->snvs), sysbus); -object_property_add_child (obj,"snvs" ,OBJECT (&s->snvs), &error_fatal); +sysbus_init_child_obj (obj,"snvs" , &s->snvs,sizeof (s->snvs), +TYPE_IMX7_SNVS );/* * Watchdog */ for (i =0 ; i <FSL_IMX7_NUM_WDTS ; i++) { -object_initialize (&s->wdt[i],sizeof (s->wdt[i]),TYPE_IMX2_WDT ); -qdev_set_parent_bus (DEVICE (&s->wdt[i]), sysbus);snprintf (name,NAME_SIZE ,"wdt%d" , i); -object_property_add_child (obj, name,OBJECT (&s->wdt[i]), - &error_fatal); +sysbus_init_child_obj (obj, name, &s->wdt[i],sizeof (s->wdt[i]), +TYPE_IMX2_WDT ); }/* * GPR */ -object_initialize (&s->gpr,sizeof (s->gpr),TYPE_IMX7_GPR ); -qdev_set_parent_bus (DEVICE (&s->gpr), sysbus); -object_property_add_child (obj,"gpr" ,OBJECT (&s->gpr), &error_fatal); +sysbus_init_child_obj (obj,"gpr" , &s->gpr,sizeof (s->gpr),TYPE_IMX7_GPR ); -object_initialize (&s->pcie,sizeof (s->pcie),TYPE_DESIGNWARE_PCIE_HOST ); -qdev_set_parent_bus (DEVICE (&s->pcie), sysbus); -object_property_add_child (obj,"pcie" ,OBJECT (&s->pcie), &error_fatal); +sysbus_init_child_obj (obj,"pcie" , &s->pcie,sizeof (s->pcie), +TYPE_DESIGNWARE_PCIE_HOST );for (i =0 ; i <FSL_IMX7_NUM_USBS ; i++) { -object_initialize (&s->usb[i], -sizeof (s->usb[i]),TYPE_CHIPIDEA ); -qdev_set_parent_bus (DEVICE (&s->usb[i]), sysbus);snprintf (name,NAME_SIZE ,"usb%d" , i); -object_property_add_child (obj, name, -OBJECT (&s->usb[i]), &error_fatal); +sysbus_init_child_obj (obj, name, &s->usb[i],sizeof (s->usb[i]), +TYPE_CHIPIDEA ); } }
Signature · 1 line
1.8.3.1
PATCH v3 10/17 hw/arm/fsl-imx25: Fix introspection problem with the "fsl, imx25" device
In reply to Thomas HuthRunning QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'fsl,imx25'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==26724== Invalid read of size 8
==26724== at 0x6190DA: qdev_print (qdev-monitor.c:686)
==26724== by 0x6190DA: qbus_print (qdev-monitor.c:719)
[...]
Use the new sysbus_init_child_obj() to make sure that the objects are cleaned up correctly when the parent gets destroyed.
--- hw/arm/fsl-imx25.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
hw/arm/fsl-imx25.c +14 -16
@@ -39,38 +39,36 @@ static void fsl_imx25_init(Object *obj)object_initialize (&s->cpu,sizeof (s->cpu),"arm926-" TYPE_ARM_CPU ); -object_initialize (&s->avic,sizeof (s->avic),TYPE_IMX_AVIC ); -qdev_set_parent_bus (DEVICE (&s->avic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"avic" , &s->avic,sizeof (s->avic), +TYPE_IMX_AVIC ); -object_initialize (&s->ccm,sizeof (s->ccm),TYPE_IMX25_CCM ); -qdev_set_parent_bus (DEVICE (&s->ccm),sysbus_get_default ()); +sysbus_init_child_obj (obj,"ccm" , &s->ccm,sizeof (s->ccm),TYPE_IMX25_CCM );for (i =0 ; i <FSL_IMX25_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_IMX_SERIAL ); -qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"uart[*]" , &s->uart[i],sizeof (s->uart[i]), +TYPE_IMX_SERIAL ); }for (i =0 ; i <FSL_IMX25_NUM_GPTS ; i++) { -object_initialize (&s->gpt[i],sizeof (s->gpt[i]),TYPE_IMX25_GPT ); -qdev_set_parent_bus (DEVICE (&s->gpt[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gpt[*]" , &s->gpt[i],sizeof (s->gpt[i]), +TYPE_IMX25_GPT ); }for (i =0 ; i <FSL_IMX25_NUM_EPITS ; i++) { -object_initialize (&s->epit[i],sizeof (s->epit[i]),TYPE_IMX_EPIT ); -qdev_set_parent_bus (DEVICE (&s->epit[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"epit[*]" , &s->epit[i],sizeof (s->epit[i]), +TYPE_IMX_EPIT ); } -object_initialize (&s->fec,sizeof (s->fec),TYPE_IMX_FEC ); -qdev_set_parent_bus (DEVICE (&s->fec),sysbus_get_default ()); +sysbus_init_child_obj (obj,"fec" , &s->fec,sizeof (s->fec),TYPE_IMX_FEC );for (i =0 ; i <FSL_IMX25_NUM_I2CS ; i++) { -object_initialize (&s->i2c[i],sizeof (s->i2c[i]),TYPE_IMX_I2C ); -qdev_set_parent_bus (DEVICE (&s->i2c[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"i2c[*]" , &s->i2c[i],sizeof (s->i2c[i]), +TYPE_IMX_I2C ); }for (i =0 ; i <FSL_IMX25_NUM_GPIOS ; i++) { -object_initialize (&s->gpio[i],sizeof (s->gpio[i]),TYPE_IMX_GPIO ); -qdev_set_parent_bus (DEVICE (&s->gpio[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gpio[*]" , &s->gpio[i],sizeof (s->gpio[i]), +TYPE_IMX_GPIO ); } }
Signature · 1 line
1.8.3.1
PATCH v3 11/17 hw/arm/fsl-imx31: Fix introspection problem with the "fsl, imx31" device
In reply to Thomas HuthRunning QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'fsl,imx31'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==26172== Invalid read of size 8
==26172== at 0x6191FA: qdev_print (qdev-monitor.c:686)
==26172== by 0x6191FA: qbus_print (qdev-monitor.c:719)
[...]
Use the new sysbus_init_child_obj() to make sure that the objects are cleaned up correctly when the parent gets destroyed.
--- hw/arm/fsl-imx31.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
hw/arm/fsl-imx31.c +12 -14
@@ -36,33 +36,31 @@ static void fsl_imx31_init(Object *obj)object_initialize (&s->cpu,sizeof (s->cpu),"arm1136-" TYPE_ARM_CPU ); -object_initialize (&s->avic,sizeof (s->avic),TYPE_IMX_AVIC ); -qdev_set_parent_bus (DEVICE (&s->avic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"avic" , &s->avic,sizeof (s->avic), +TYPE_IMX_AVIC ); -object_initialize (&s->ccm,sizeof (s->ccm),TYPE_IMX31_CCM ); -qdev_set_parent_bus (DEVICE (&s->ccm),sysbus_get_default ()); +sysbus_init_child_obj (obj,"ccm" , &s->ccm,sizeof (s->ccm),TYPE_IMX31_CCM );for (i =0 ; i <FSL_IMX31_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_IMX_SERIAL ); -qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"uart[*]" , &s->uart[i],sizeof (s->uart[i]), +TYPE_IMX_SERIAL ); } -object_initialize (&s->gpt,sizeof (s->gpt),TYPE_IMX31_GPT ); -qdev_set_parent_bus (DEVICE (&s->gpt),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gpt" , &s->gpt,sizeof (s->gpt),TYPE_IMX31_GPT );for (i =0 ; i <FSL_IMX31_NUM_EPITS ; i++) { -object_initialize (&s->epit[i],sizeof (s->epit[i]),TYPE_IMX_EPIT ); -qdev_set_parent_bus (DEVICE (&s->epit[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"epit[*]" , &s->epit[i],sizeof (s->epit[i]), +TYPE_IMX_EPIT ); }for (i =0 ; i <FSL_IMX31_NUM_I2CS ; i++) { -object_initialize (&s->i2c[i],sizeof (s->i2c[i]),TYPE_IMX_I2C ); -qdev_set_parent_bus (DEVICE (&s->i2c[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"i2c[*]" , &s->i2c[i],sizeof (s->i2c[i]), +TYPE_IMX_I2C ); }for (i =0 ; i <FSL_IMX31_NUM_GPIOS ; i++) { -object_initialize (&s->gpio[i],sizeof (s->gpio[i]),TYPE_IMX_GPIO ); -qdev_set_parent_bus (DEVICE (&s->gpio[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gpio[*]" , &s->gpio[i],sizeof (s->gpio[i]), +TYPE_IMX_GPIO ); } }
Signature · 1 line
1.8.3.1
PATCH v3 12/17 hw/cpu/arm11mpcore: Fix introspection problem with 'arm11mpcore_priv'
In reply to Thomas HuthValgrind reports an error here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'arm11mpcore_priv'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==3145== Invalid read of size 8
==3145== at 0x61873A: qdev_print (qdev-monitor.c:686)
==3145== by 0x61873A: qbus_print (qdev-monitor.c:719)
[...]
Use sysbus_init_child_obj() to fix it.
--- hw/cpu/arm11mpcore.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
hw/cpu/arm11mpcore.c +6 -8
@@ -121,19 +121,17 @@ static void mpcore_priv_initfn(Object *obj) "mpcore-priv-container", 0x2000);sysbus_init_mmio (sbd, &s->container); -object_initialize (&s->scu,sizeof (s->scu),TYPE_ARM11_SCU ); -qdev_set_parent_bus (DEVICE (&s->scu),sysbus_get_default ()); +sysbus_init_child_obj (obj,"scu" , &s->scu,sizeof (s->scu),TYPE_ARM11_SCU ); -object_initialize (&s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic),TYPE_ARM_GIC );/* Request the legacy 11MPCore GIC behaviour: */ qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,0 ); -object_initialize (&s->mptimer,sizeof (s->mptimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->mptimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"mptimer" , &s->mptimer,sizeof (s->mptimer), +TYPE_ARM_MPTIMER ); -object_initialize (&s->wdtimer,sizeof (s->wdtimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->wdtimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"wdtimer" , &s->wdtimer,sizeof (s->wdtimer), +TYPE_ARM_MPTIMER ); }static Property mpcore_priv_properties[] = {
Signature · 1 line
1.8.3.1
PATCH v3 14/17 hw/arm/allwinner-a10: Fix introspection problem with 'allwinner-a10'
In reply to Thomas HuthValgrind complains:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'allwinner-a10'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==32519== Invalid read of size 8
==32519== at 0x61869A: qdev_print (qdev-monitor.c:686) ==32519== by 0x61869A: qbus_print (qdev-monitor.c:719) ==32519== by 0x452B38: handle_hmp_command (monitor.c:3446)
[...]
Use object_initialize_child() and sysbus_init_child_obj() to fix the issue.
--- hw/arm/allwinner-a10.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
hw/arm/allwinner-a10.c +9 -10
@@ -27,20 +27,19 @@ static void aw_a10_init(Object *obj) {AwA10State *s =AW_A10 (obj); -object_initialize (&s->cpu,sizeof (s->cpu),"cortex-a8-" TYPE_ARM_CPU ); -object_property_add_child (obj,"cpu" ,OBJECT (&s->cpu),NULL ); +object_initialize_child (obj,"cpu" , &s->cpu,sizeof (s->cpu), +"cortex-a8-" TYPE_ARM_CPU , &error_abort,NULL ); -object_initialize (&s->intc,sizeof (s->intc),TYPE_AW_A10_PIC ); -qdev_set_parent_bus (DEVICE (&s->intc),sysbus_get_default ()); +sysbus_init_child_obj (obj,"intc" , &s->intc,sizeof (s->intc), +TYPE_AW_A10_PIC ); -object_initialize (&s->timer,sizeof (s->timer),TYPE_AW_A10_PIT ); -qdev_set_parent_bus (DEVICE (&s->timer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"timer" , &s->timer,sizeof (s->timer), +TYPE_AW_A10_PIT ); -object_initialize (&s->emac,sizeof (s->emac),TYPE_AW_EMAC ); -qdev_set_parent_bus (DEVICE (&s->emac),sysbus_get_default ()); +sysbus_init_child_obj (obj,"emac" , &s->emac,sizeof (s->emac),TYPE_AW_EMAC ); -object_initialize (&s->sata,sizeof (s->sata),TYPE_ALLWINNER_AHCI ); -qdev_set_parent_bus (DEVICE (&s->sata),sysbus_get_default ()); +sysbus_init_child_obj (obj,"sata" , &s->sata,sizeof (s->sata), +TYPE_ALLWINNER_AHCI ); }static void aw_a10_realize (DeviceState *dev,Error **errp)
Signature · 1 line
1.8.3.1
PATCH v3 13/17 hw/*/realview: Fix introspection problem with 'realview_mpcore' & 'realview_gic'
In reply to Thomas Huthecho "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'realview_mpcore'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==2654== Invalid read of size 8
==2654== at 0x61878A: qdev_print (qdev-monitor.c:686) ==2654== by 0x61878A: qbus_print (qdev-monitor.c:719) ==2654== by 0x452B38: handle_hmp_command (monitor.c:3446) ==2654== by 0x452D70: qmp_human_monitor_command (monitor.c:821)
[...]
Use sysbus_init_child_obj() to fix it.
--- hw/cpu/realview_mpcore.c | 8 ++++---- hw/intc/realview_gic.c | 7 ++----- 2 files changed, 6 insertions(+), 9 deletions(-)
hw/cpu/realview_mpcore.c +4 -4
@@ -101,14 +101,14 @@ static void mpcore_rirq_init(Object *obj)SysBusDevice *privbusdev;int i; -object_initialize (&s->priv,sizeof (s->priv),TYPE_ARM11MPCORE_PRIV ); -qdev_set_parent_bus (DEVICE (&s->priv),sysbus_get_default ()); +sysbus_init_child_obj (obj,"a11priv" , &s->priv,sizeof (s->priv), +TYPE_ARM11MPCORE_PRIV ); privbusdev =SYS_BUS_DEVICE (&s->priv);sysbus_init_mmio (sbd,sysbus_mmio_get_region (privbusdev,0 ));for (i =0 ; i <4 ; i++) { -object_initialize (&s->gic[i],sizeof (s->gic[i]),TYPE_REALVIEW_GIC ); -qdev_set_parent_bus (DEVICE (&s->gic[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic[*]" , &s->gic[i],sizeof (s->gic[i]), +TYPE_REALVIEW_GIC ); } }
hw/intc/realview_gic.c +2 -5
@@ -54,16 +54,13 @@ static void realview_gic_init(Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);RealViewGICState *s =REALVIEW_GIC (obj); -DeviceState *gicdev;memory_region_init (&s->container,OBJECT (s),"realview-gic-container" ,0x2000 );sysbus_init_mmio (sbd, &s->container); -object_initialize (&s->gic,sizeof (s->gic),TYPE_ARM_GIC ); - gicdev =DEVICE (&s->gic); -qdev_set_parent_bus (gicdev,sysbus_get_default ()); -qdev_prop_set_uint32 (gicdev,"num-cpu" ,1 ); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic),TYPE_ARM_GIC ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-cpu" ,1 ); }static void realview_gic_class_init (ObjectClass *oc,void *data)
Signature · 1 line
1.8.3.1
PATCH v3 15/17 hw/arm/stm32f205_soc: Fix introspection problem with 'stm32f205-soc' device
In reply to Thomas HuthValgrind complains:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'stm32f205-soc'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==28531== Invalid read of size 8
==28531== at 0x6185BA: qdev_print (qdev-monitor.c:686) ==28531== by 0x6185BA: qbus_print (qdev-monitor.c:719) ==28531== by 0x452B38: handle_hmp_command (monitor.c:3446)
[...]
Fix it with the new sysbus_init_child_obj() function.
--- hw/arm/stm32f205_soc.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
hw/arm/stm32f205_soc.c +12 -16
@@ -49,36 +49,32 @@ static void stm32f205_soc_initfn(Object *obj)STM32F205State *s =STM32F205_SOC (obj);int i; -object_initialize (&s->armv7m,sizeof (s->armv7m),TYPE_ARMV7M ); -qdev_set_parent_bus (DEVICE (&s->armv7m),sysbus_get_default ()); +sysbus_init_child_obj (obj,"armv7m" , &s->armv7m,sizeof (s->armv7m), +TYPE_ARMV7M ); -object_initialize (&s->syscfg,sizeof (s->syscfg),TYPE_STM32F2XX_SYSCFG ); -qdev_set_parent_bus (DEVICE (&s->syscfg),sysbus_get_default ()); +sysbus_init_child_obj (obj,"syscfg" , &s->syscfg,sizeof (s->syscfg), +TYPE_STM32F2XX_SYSCFG );for (i =0 ; i <STM_NUM_USARTS ; i++) { -object_initialize (&s->usart[i],sizeof (s->usart[i]), -TYPE_STM32F2XX_USART ); -qdev_set_parent_bus (DEVICE (&s->usart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"usart[*]" , &s->usart[i], +sizeof (s->usart[i]),TYPE_STM32F2XX_USART ); }for (i =0 ; i <STM_NUM_TIMERS ; i++) { -object_initialize (&s->timer[i],sizeof (s->timer[i]), -TYPE_STM32F2XX_TIMER ); -qdev_set_parent_bus (DEVICE (&s->timer[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"timer[*]" , &s->timer[i], +sizeof (s->timer[i]),TYPE_STM32F2XX_TIMER ); } s->adc_irqs =OR_IRQ (object_new (TYPE_OR_IRQ ));for (i =0 ; i <STM_NUM_ADCS ; i++) { -object_initialize (&s->adc[i],sizeof (s->adc[i]), -TYPE_STM32F2XX_ADC ); -qdev_set_parent_bus (DEVICE (&s->adc[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"adc[*]" , &s->adc[i],sizeof (s->adc[i]), +TYPE_STM32F2XX_ADC ); }for (i =0 ; i <STM_NUM_SPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]), -TYPE_STM32F2XX_SPI ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"spi[*]" , &s->spi[i],sizeof (s->spi[i]), +TYPE_STM32F2XX_SPI ); } }
Signature · 1 line
1.8.3.1
PATCH v3 16/17 hw/display/xlnx_dp: Move problematic code from instance_init to realize
In reply to Thomas HuthFrom: Paolo Bonzini <[email protected]>
aux_create_slave() calls qdev_init_nofail() which in turn "realizes" the corresponding object. This is unlike qdev_create(), and it is wrong because qdev_init_nofail() must not be called from an instance_init function. Move qdev_init_nofail() and the subsequent aux_map_slave into the caller's realize function.
There are two more bugs that needs to be fixed here, too, where the objects are created but not added as children. Therefore when you call object_unparent on them, nothing happens.
In particular dpcd and edid give you an infinite loop in bus_unparent, because device_unparent is not called and does not remove them from the list of devices on the bus.
--- hw/display/xlnx_dp.c | 8 +++++++- hw/misc/auxbus.c | 18 ++++++++++++------ include/hw/misc/auxbus.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-)
hw/display/xlnx_dp.c +7 -1
@@ -1234,9 +1234,12 @@ static void xlnx_dp_init(Object *obj)/* * Initialize DPCD and EDID.. */ - s->dpcd =DPCD (aux_create_slave (s->aux_bus,"dpcd" ,0x00000 )); + s->dpcd =DPCD (aux_create_slave (s->aux_bus,"dpcd" )); +object_property_add_child (OBJECT (s),"dpcd" ,OBJECT (s->dpcd),NULL ); + s->edid =I2CDDC (qdev_create (BUS (aux_get_i2c_bus (s->aux_bus)),"i2c-ddc" ));i2c_set_slave_address (I2C_SLAVE (s->edid),0x50 ); +object_property_add_child (OBJECT (s),"edid" ,OBJECT (s->edid),NULL );fifo8_create (&s->rx_fifo,16 );fifo8_create (&s->tx_fifo,16 );
@@ -1248,6 +1251,9 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)DisplaySurface *surface;struct audsettings as; +qdev_init_nofail (DEVICE (s->dpcd)); +aux_map_slave (AUX_SLAVE (s->dpcd),0x0000 ); + s->console =graphic_console_init (dev,0 , &xlnx_dp_gfx_ops, s); surface =qemu_console_surface (s->console); xlnx_dpdma_set_host_data_location(s->dpdma, DP_GRAPHIC_DMA_CHANNEL,
hw/misc/auxbus.c +12 -6
@@ -32,6 +32,7 @@#include "hw/misc/auxbus.h" #include "hw/i2c/i2c.h" #include "monitor/monitor.h" +#include "qapi/error.h" #ifndef DEBUG_AUX #define DEBUG_AUX 0
@@ -63,9 +64,14 @@ static void aux_bus_class_init(ObjectClass *klass, void *data)AUXBus *aux_init_bus (DeviceState *parent,const char *name) {AUXBus *bus; +Object *auxtoi2c; bus =AUX_BUS (qbus_create (TYPE_AUX_BUS , parent, name)); - bus->bridge =AUXTOI2C (qdev_create (BUS (bus),TYPE_AUXTOI2C )); + auxtoi2c =object_new_with_props (TYPE_AUXTOI2C ,OBJECT (bus),"i2c" , + &error_abort,NULL ); +qdev_set_parent_bus (DEVICE (auxtoi2c),BUS (bus)); + + bus->bridge =AUXTOI2C (auxtoi2c);/* Memory related. */ bus->aux_io =g_malloc (sizeof (*bus->aux_io));
@@ -74,9 +80,11 @@ AUXBus *aux_init_bus(DeviceState *parent, const char *name)return bus; } -static void aux_bus_map_device (AUXBus *bus,AUXSlave *dev,hwaddr addr) +void aux_map_slave (AUXSlave *aux_dev,hwaddr addr) { -memory_region_add_subregion (bus->aux_io, addr, dev->mmio); +DeviceState *dev =DEVICE (aux_dev); +AUXBus *bus =AUX_BUS (qdev_get_parent_bus (dev)); +memory_region_add_subregion (bus->aux_io, addr, aux_dev->mmio); }static bool aux_bus_is_bridge (AUXBus *bus,DeviceState *dev)
@@ -260,15 +268,13 @@ static void aux_slave_dev_print(Monitor *mon, DeviceState *dev, int indent) memory_region_size(s->mmio)); } -DeviceState *aux_create_slave (AUXBus *bus,const char *type,uint32_t addr) +DeviceState *aux_create_slave (AUXBus *bus,const char *type) {DeviceState *dev; dev =DEVICE (object_new (type));assert (dev);qdev_set_parent_bus (dev, &bus->qbus); -qdev_init_nofail (dev); -aux_bus_map_device (AUX_BUS (qdev_get_parent_bus (dev)),AUX_SLAVE (dev), addr);return dev; }
include/hw/misc/auxbus.h +13 -1
@@ -123,6 +123,18 @@ I2CBus *aux_get_i2c_bus(AUXBus *bus);*/ void aux_init_mmio (AUXSlave *aux_slave,MemoryRegion *mmio); -DeviceState *aux_create_slave (AUXBus *bus,const char *name,uint32_t addr); +/* aux_create_slave: Create a new device on an AUX bus +* +* @bus The AUX bus for the new device. +* @name The type of the device to be created. +*/ +DeviceState *aux_create_slave (AUXBus *bus,const char *name); + +/* aux_map_slave: Map the mmio for an AUX slave on the bus. +* +* @dev The AUX slave. +* @addr The address for the slave's mmio. +*/ +void aux_map_slave (AUXSlave *dev,hwaddr addr);#endif /* HW_MISC_AUXBUS_H */
Signature · 1 line
1.8.3.1
PATCH v3 17/17 hw/arm/xlnx-zynqmp: Fix crash when introspecting the "xlnx, zynqmp" device
In reply to Thomas HuthQEMU currently crashes when e.g. doing something like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'xlnx,zynqmp'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" \
| aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
Use the new object_initialize_child() and sysbus_init_child_obj() functions to get the refernce counting of the child objects right, so that they are properly cleaned up when the parent gets destroyed.
--- hw/arm/xlnx-zynqmp.c | 61 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 33 deletions(-)
hw/arm/xlnx-zynqmp.c +28 -33
@@ -166,64 +166,59 @@ static void xlnx_zynqmp_init(Object *obj)int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS );for (i =0 ; i < num_apus; i++) { -object_initialize (&s->apu_cpu[i],sizeof (s->apu_cpu[i]), -"cortex-a53-" TYPE_ARM_CPU ); -object_property_add_child (obj,"apu-cpu[*]" ,OBJECT (&s->apu_cpu[i]), - &error_abort); +object_initialize_child (obj,"apu-cpu[*]" , &s->apu_cpu[i], +sizeof (s->apu_cpu[i]), +"cortex-a53-" TYPE_ARM_CPU , &error_abort,NULL ); } -object_initialize (&s->gic,sizeof (s->gic),gic_class_name ()); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +gic_class_name ());for (i =0 ; i <XLNX_ZYNQMP_NUM_GEMS ; i++) { -object_initialize (&s->gem[i],sizeof (s->gem[i]),TYPE_CADENCE_GEM ); -qdev_set_parent_bus (DEVICE (&s->gem[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gem[*]" , &s->gem[i],sizeof (s->gem[i]), +TYPE_CADENCE_GEM ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_CADENCE_UART ); -qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"uart[*]" , &s->uart[i],sizeof (s->uart[i]), +TYPE_CADENCE_UART ); } -object_initialize (&s->sata,sizeof (s->sata),TYPE_SYSBUS_AHCI ); -qdev_set_parent_bus (DEVICE (&s->sata),sysbus_get_default ()); +sysbus_init_child_obj (obj,"sata" , &s->sata,sizeof (s->sata), +TYPE_SYSBUS_AHCI );for (i =0 ; i <XLNX_ZYNQMP_NUM_SDHCI ; i++) { -object_initialize (&s->sdhci[i],sizeof (s->sdhci[i]), -TYPE_SYSBUS_SDHCI ); -qdev_set_parent_bus (DEVICE (&s->sdhci[i]), -sysbus_get_default ()); +sysbus_init_child_obj (obj,"sdhci[*]" , &s->sdhci[i], +sizeof (s->sdhci[i]),TYPE_SYSBUS_SDHCI ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_SPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]), -TYPE_XILINX_SPIPS ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"spi[*]" , &s->spi[i],sizeof (s->spi[i]), +TYPE_XILINX_SPIPS ); } -object_initialize (&s->qspi,sizeof (s->qspi),TYPE_XLNX_ZYNQMP_QSPIPS ); -qdev_set_parent_bus (DEVICE (&s->qspi),sysbus_get_default ()); +sysbus_init_child_obj (obj,"qspi" , &s->qspi,sizeof (s->qspi), +TYPE_XLNX_ZYNQMP_QSPIPS ); -object_initialize (&s->dp,sizeof (s->dp),TYPE_XLNX_DP ); -qdev_set_parent_bus (DEVICE (&s->dp),sysbus_get_default ()); +sysbus_init_child_obj (obj,"xxxdp" , &s->dp,sizeof (s->dp),TYPE_XLNX_DP ); -object_initialize (&s->dpdma,sizeof (s->dpdma),TYPE_XLNX_DPDMA ); -qdev_set_parent_bus (DEVICE (&s->dpdma),sysbus_get_default ()); +sysbus_init_child_obj (obj,"dp-dma" , &s->dpdma,sizeof (s->dpdma), +TYPE_XLNX_DPDMA ); -object_initialize (&s->ipi,sizeof (s->ipi),TYPE_XLNX_ZYNQMP_IPI ); -qdev_set_parent_bus (DEVICE (&s->ipi),sysbus_get_default ()); +sysbus_init_child_obj (obj,"ipi" , &s->ipi,sizeof (s->ipi), +TYPE_XLNX_ZYNQMP_IPI ); -object_initialize (&s->rtc,sizeof (s->rtc),TYPE_XLNX_ZYNQMP_RTC ); -qdev_set_parent_bus (DEVICE (&s->rtc),sysbus_get_default ()); +sysbus_init_child_obj (obj,"rtc" , &s->rtc,sizeof (s->rtc), +TYPE_XLNX_ZYNQMP_RTC );for (i =0 ; i <XLNX_ZYNQMP_NUM_GDMA_CH ; i++) { -object_initialize (&s->gdma[i],sizeof (s->gdma[i]),TYPE_XLNX_ZDMA ); -qdev_set_parent_bus (DEVICE (&s->gdma[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gdma[*]" , &s->gdma[i],sizeof (s->gdma[i]), +TYPE_XLNX_ZDMA ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_ADMA_CH ; i++) { -object_initialize (&s->adma[i],sizeof (s->adma[i]),TYPE_XLNX_ZDMA ); -qdev_set_parent_bus (DEVICE (&s->adma[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"adma[*]" , &s->adma[i],sizeof (s->adma[i]), +TYPE_XLNX_ZDMA ); } }
Signature · 1 line
1.8.3.1
Re: [Qemu-arm] [PATCH v3 15/17] hw/arm/stm32f205_soc: Fix introspection problem with 'stm32f205-soc' device
In reply to Thomas HuthQuoted 12 lines · Thomas Huth
Valgrind complains:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'stm32f205-soc'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==28531== Invalid read of size 8==28531== at 0x6185BA: qdev_print (qdev-monitor.c:686) ==28531== by 0x6185BA: qbus_print (qdev-monitor.c:719) ==28531== by 0x452B38: handle_hmp_command (monitor.c:3446)
Quoted 6 lines
[...]
Fix it with the new
sysbus_init_child_obj()function.Signed-off-by Thomas Huth <[email protected]>---
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 16/17] hw/display/xlnx_dp: Move problematic code from instance_init to realize
In reply to Thomas HuthQuoted 16 lines · Thomas Huth
From: Paolo Bonzini <[email protected]>
aux_create_slave()callsqdev_init_nofail()which in turn "realizes" the corresponding object. This is unlikeqdev_create(), and it is wrong becauseqdev_init_nofail()must not be called from aninstance_initfunction. Moveqdev_init_nofail()and the subsequentaux_map_slaveinto the caller's realize function.There are two more bugs that needs to be fixed here, too, where the objects are created but not added as children. Therefore when you call
object_unparenton them, nothing happens.In particular dpcd and edid give you an infinite loop in
bus_unparent, becausedevice_unparentis not called and does not remove them from the list of devices on the bus.
Quoted 5 lines
Reported-by Thomas Huth <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>[thuth: Added Paolo's fixup for the dpcd and edid unparenting]Signed-off-by Thomas Huth <[email protected]>---
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 01/17] qom/object: Add a new function object_initialize_child()
In reply to Thomas HuthQuoted 133 lines · Thomas Huth
A lot of code is using the
object_initialize()function followed by a call toobject_property_add_child()to add the newly initialized object as a child of the current object. Both functions increase the reference counter of the new object, but many spots that call these two functions then forget to drop one of the superfluous references. So the newly created object is often not cleaned up correctly when the parent is destroyed. In the worst case, this can cause crashes, e.g. because device objects are not correctly removed from theirparent_bus.Since this is a common pattern between many code spots, let's introduce a new function that takes care of calling all three required initialization functions, first
object_initialize(), thenobject_property_add_child()and finallyobject_unref(). And since the function does a similar job likeobject_new_with_props(), also allow to set additional properties via varargs, and useuser_creatable_complete()to make sure that the functions can be used similarly.And while we're at
object.h, also fix some copy-n-paste errors in the comments there ("to store the area" --> "to store the error").Signed-off-by Thomas Huth <[email protected]>--- include/qom/object.h | 45 +++++++++++++++++++++++++++++++++++++++++-- qom/object.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-)include/qom/object.h +43
-2@@ -749,6 +749,47 @@ int object_set_propv(Object *obj,void object_initialize (void *obj,size_t size,const char *typename);/** +* object_initialize_child: +* @parentobj: The parent object to add a property to +* @propname: The name of the property +* @childobj: A pointer to the memory to be used for the object. +* @size: The maximum size available at @childobj for the object. +* @type: The name of the type of the object to instantiate. +* @errp: If an error occurs, a pointer to an area to store the error +* @...: list of property names and values +* +* This function will initialize an object. The memory for the object should +* have already been allocated. The object will then be added as child property +* to a parent with object_property_add_child() function. The returned object +* has a reference count of 1 (for the "child<...>" property from the parent), +* so the object will be finalized automatically when the parent gets removed. +* +* The variadic parameters are a list of pairs of (propname, propvalue) +* strings. The propname of %NULL indicates the end of the property list. +* If the object implements the user creatable interface, the object will +* be marked complete once all the properties have been processed. +*/ +void object_initialize_child(Object *parentobj, const char *propname, + void *childobj, size_t size, const char *type, + Error **errp, ...) QEMU_SENTINEL; + +/** +* object_initialize_childv: +* @parentobj: The parent object to add a property to +* @propname: The name of the property +* @childobj: A pointer to the memory to be used for the object. +* @size: The maximum size available at @childobj for the object. +* @type: The name of the type of the object to instantiate. +* @errp: If an error occurs, a pointer to an area to store the error +* @vargs: list of property names and values +* +* See object_initialize_child() for documentation. +*/ +void object_initialize_childv (Object *parentobj,const char *propname, +void *childobj,size_t size,const char *type, +Error **errp,va_list vargs); + +/** * object_dynamic_cast: * @obj: The object to cast. * @typename: The @typename to cast to. @@ -1382,7 +1423,7 @@ Object *object_resolve_path_component(Object *parent, const gchar *part);* @obj: the object to add a property to * @name: the name of the property * @child: the child object -* @errp: if an error occurs, a pointer to an area to store the area +* @errp: if an error occurs, a pointer to an area to store the error * * Child properties form the composition tree. All objects need to be a child * of another object. Objects can only be a child of one object. @@ -1420,7 +1461,7 @@ void object_property_allow_set_link(const Object *, const char *,* @child: a pointer to where the link object reference is stored * @check: callback to veto setting or NULL if the property is read-only * @flags: additional options for the link -* @errp: if an error occurs, a pointer to an area to store the area +* @errp: if an error occurs, a pointer to an area to store the error * * Links establish relationships between objects. Links are unidirectional * although two links can be combined to form a bidirectional relationship qom/object.c +29
-0@@ -392,6 +392,60 @@ void object_initialize(void *data, size_t size, const char *typename)object_initialize_with_type (data, size, type); } +void object_initialize_child (Object *parentobj,const char *propname, +void *childobj,size_t size,const char *type, +Error **errp, ...) +{ +va_list vargs; + +va_start (vargs, errp); +object_initialize_childv (parentobj, propname, childobj, size, type, errp, + vargs); +va_end (vargs); +} + +void object_initialize_childv (Object *parentobj,const char *propname, +void *childobj,size_t size,const char *type, +Error **errp,va_list vargs) +{ +Error *local_err =NULL ; +Object *obj; + +object_initialize (childobj, size, type); + obj =OBJECT (childobj); + +object_set_propv (obj, &local_err, vargs); +if (local_err) { + goto out; + } + +object_property_add_child (parentobj, propname, obj, &local_err); +if (local_err) {
qom/object.c void object_initialize(void *data, size_t size, const char *typename) · line 433
Quoted 10 lines
qom/object.c +10
-0+ goto out; + } + +if (object_dynamic_cast (obj,TYPE_USER_CREATABLE )) { +user_creatable_complete (obj, &local_err); +if (local_err) { +object_unparent (obj); + goto out; + } + }
I don't like adding TYPE_USER_CREATABLE-specific hacks to QOM core, but well, at least this is consistent with object_new_with_propv().
Quoted 21 lines
qom/object.c +15
-0+ +/* +* Since object_property_add_child added a reference to the child object, +* we can drop the reference added by object_initialize(), so the child +* property will own the only reference to the object. +*/ +object_unref (obj); + +out: +if (local_err) { +error_propagate (errp, local_err); +object_unref (obj); + } +} +static inline bool object_property_is_child (ObjectProperty *prop) {return strstart (prop->type,"child<" ,NULL );Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-arm] [PATCH v3 15/17] hw/arm/stm32f205_soc: Fix introspection problem with 'stm32f205-soc' device
In reply to Thomas HuthQuoted 9 lines · Thomas Huth
Valgrind complains:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'stm32f205-soc'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==28531== Invalid read of size 8
Quoted 8 lines
==28531== at 0x6185BA: qdev_print (qdev-monitor.c:686) ==28531== by 0x6185BA: qbus_print (qdev-monitor.c:719) ==28531== by 0x452B38: handle_hmp_command (monitor.c:3446)[...]
Fix it with the new
sysbus_init_child_obj()function.Signed-off-by Thomas Huth <[email protected]>
Signature · 1 line
Eduardo
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 02/17] hw/core/sysbus: Add a function for creating and attaching an object
In reply to Thomas HuthQuoted 9 lines · Thomas Huth
A lot of functions are initializing an object and attach it immediately afterwards to the system bus. Provide a common function for this, which also uses
object_initialize_child()to make sure that the reference counter is correctly initialized to 1 afterwards.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 56 lines
--- hw/core/sysbus.c | 8 ++++++++ include/hw/sysbus.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+)hw/core/sysbus.c +8
-0@@ -376,6 +376,14 @@ BusState *sysbus_get_default(void)return main_system_bus; } +void sysbus_init_child_obj (Object *parent,const char *childname,void *child, +size_t childsize,const char *childtype) +{ +object_initialize_child (parent, childname, child, childsize, childtype, + &error_abort,NULL ); +qdev_set_parent_bus (DEVICE (child),sysbus_get_default ()); +} +static void sysbus_register_types (void ) {type_register_static (&system_bus_info);include/hw/sysbus.h +17
-1@@ -96,6 +96,23 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr, MemoryRegion *mem);MemoryRegion *sysbus_address_space (SysBusDevice *dev); +/** +* sysbus_init_child_obj: +* @parent: The parent object +* @childname: Used as name of the "child<>" property in the parent +* @child: A pointer to the memory to be used for the object. +* @childsize: The maximum size available at @child for the object. +* @childtype: The name of the type of the object to instantiate. +* +* This function will initialize an object and attach it to the main system +* bus. The memory for the object should have already been allocated. The +* object will then be added as child to the given parent. The returned object +* has a reference count of 1 (for the "child<...>" property from the parent), +* so the object will be finalized automatically when the parent gets removed. +*/ +void sysbus_init_child_obj (Object *parent,const char *childname,void *child, +size_t childsize,const char *childtype); +/* Call func for every dynamically created sysbus device in the system */ void foreach_dynamic_sysbus_device (FindSysbusDeviceFunc *func,void *opaque); --1.8.3.1
Re: [Qemu-devel] [PATCH v3 05/17] hw/cpu/a15mpcore: Fix introspection problem with the a15mpcore_priv device
In reply to Thomas HuthQuoted 19 lines · Thomas Huth
There is a memory management problem when introspecting the
a15mpcore_privdevice. It can be seen with valgrind when running QEMU like this:echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'a15mpcore_priv'}}"\
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2},
"package": "build-all"}, "capabilities": []}}
{"return": {}}
{"return": [{"name": "num-cpu", "type": "uint32"}, {"name": "num-irq",
"type": "uint32"}, {"name": "a15mp-priv-container[0]", "type":
"child<qemu:memory-region>"}]}
==24978== Invalid read of size 8
==24978== at0x618EBA:qdev_print(qdev-monitor.c:686)
==24978== by0x618EBA:qbus_print(qdev-monitor.c:719)
[...]
Quoted 7 lines
Use the new
sysbus_init_child_obj()function to make sure that we get the reference counting of the child objects right.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 31 lines
--- hw/cpu/a15mpcore.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)hw/cpu/a15mpcore.c +3
-6@@ -35,15 +35,13 @@ static void a15mp_priv_initfn(Object *obj) {SysBusDevice *sbd =SYS_BUS_DEVICE (obj);A15MPPrivState *s =A15MPCORE_PRIV (obj); -DeviceState *gicdev;memory_region_init (&s->container, obj,"a15mp-priv-container" ,0x8000 );sysbus_init_mmio (sbd, &s->container); -object_initialize (&s->gic,sizeof (s->gic),gic_class_name ()); - gicdev =DEVICE (&s->gic); -qdev_set_parent_bus (gicdev,sysbus_get_default ()); -qdev_prop_set_uint32 (gicdev,"revision" ,2 ); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +gic_class_name ()); +qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,2 ); }static void a15mp_priv_realize (DeviceState *dev,Error **errp) --1.8.3.1
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 04/17] hw/arm/armv7: Fix crash when introspecting the "iotkit" device
In reply to Thomas HuthQuoted 8 lines · Thomas Huth
QEMU currently crashes when introspecting the "iotkit" device and runnint "info qtree" afterwards, e.g. when running QEMU like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'iotkit'}}" "{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
Quoted 8 lines
Use the new functions
object_initialize_child()andsysbus_init_child_obj()to make sure that all objects get cleaned up correctly when the instances are destroyed.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 154 lines
--- hw/arm/armv7m.c | 7 +++-- hw/arm/iotkit.c | 74 ++++++++++++++++++++++----------------------------- hw/intc/armv7m_nvic.c | 5 ++-- 3 files changed, 37 insertions(+), 49 deletions(-)hw/arm/armv7m.c +3
-4@@ -134,14 +134,13 @@ static void armv7m_instance_init(Object *obj)memory_region_init (&s->container, obj,"armv7m-container" ,UINT64_MAX ); -object_initialize (&s->nvic,sizeof (s->nvic),TYPE_NVIC ); -qdev_set_parent_bus (DEVICE (&s->nvic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"nvnic" , &s->nvic,sizeof (s->nvic),TYPE_NVIC );object_property_add_alias (obj,"num-irq" ,OBJECT (&s->nvic),"num-irq" , &error_abort);for (i =0 ; i <ARRAY_SIZE (s->bitband); i++) { -object_initialize (&s->bitband[i],sizeof (s->bitband[i]),TYPE_BITBAND ); -qdev_set_parent_bus (DEVICE (&s->bitband[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"bitband[*]" , &s->bitband[i], +sizeof (s->bitband[i]),TYPE_BITBAND ); } }hw/arm/iotkit.c +32
-42@@ -30,15 +30,6 @@ static void make_alias(IoTKit *s, MemoryRegion *mr, const char *name,memory_region_add_subregion_overlap (&s->container, base, mr,-1500 ); } -static void init_sysbus_child (Object *parent,const char *childname, -void *child,size_t childsize, -const char *childtype) -{ -object_initialize (child, childsize, childtype); -object_property_add_child (parent, childname,OBJECT (child), &error_abort); -qdev_set_parent_bus (DEVICE (child),sysbus_get_default ()); -} -static void irq_status_forwarder (void *opaque,int n,int level) {qemu_irq destirq = opaque;@@ -119,53 +110,52 @@ static void iotkit_init(Object *obj)memory_region_init (&s->container, obj,"iotkit-container" ,UINT64_MAX ); -init_sysbus_child (obj,"armv7m" , &s->armv7m,sizeof (s->armv7m), -TYPE_ARMV7M ); +sysbus_init_child_obj (obj,"armv7m" , &s->armv7m,sizeof (s->armv7m), +TYPE_ARMV7M );qdev_prop_set_string (DEVICE (&s->armv7m),"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m33" )); -init_sysbus_child (obj,"secctl" , &s->secctl,sizeof (s->secctl), -TYPE_IOTKIT_SECCTL ); -init_sysbus_child (obj,"apb-ppc0" , &s->apb_ppc0,sizeof (s->apb_ppc0), -TYPE_TZ_PPC ); -init_sysbus_child (obj,"apb-ppc1" , &s->apb_ppc1,sizeof (s->apb_ppc1), -TYPE_TZ_PPC ); -init_sysbus_child (obj,"mpc" , &s->mpc,sizeof (s->mpc),TYPE_TZ_MPC ); -object_initialize (&s->mpc_irq_orgate,sizeof (s->mpc_irq_orgate), -TYPE_OR_IRQ ); -object_property_add_child (obj,"mpc-irq-orgate" , -OBJECT (&s->mpc_irq_orgate), &error_abort); +sysbus_init_child_obj (obj,"secctl" , &s->secctl,sizeof (s->secctl), +TYPE_IOTKIT_SECCTL ); +sysbus_init_child_obj (obj,"apb-ppc0" , &s->apb_ppc0,sizeof (s->apb_ppc0), +TYPE_TZ_PPC ); +sysbus_init_child_obj (obj,"apb-ppc1" , &s->apb_ppc1,sizeof (s->apb_ppc1), +TYPE_TZ_PPC ); +sysbus_init_child_obj (obj,"mpc" , &s->mpc,sizeof (s->mpc),TYPE_TZ_MPC ); +object_initialize_child (obj,"mpc-irq-orgate" , &s->mpc_irq_orgate, +sizeof (s->mpc_irq_orgate),TYPE_OR_IRQ , + &error_abort,NULL ); +for (i =0 ; i <ARRAY_SIZE (s->mpc_irq_splitter); i++) {char *name =g_strdup_printf ("mpc-irq-splitter-%d" , i);SplitIRQ *splitter = &s->mpc_irq_splitter[i]; -object_initialize (splitter,sizeof (*splitter),TYPE_SPLIT_IRQ ); -object_property_add_child (obj, name,OBJECT (splitter), &error_abort); +object_initialize_child (obj, name, splitter,sizeof (*splitter), +TYPE_SPLIT_IRQ , &error_abort,NULL );g_free (name); } -init_sysbus_child (obj,"timer0" , &s->timer0,sizeof (s->timer0), -TYPE_CMSDK_APB_TIMER ); -init_sysbus_child (obj,"timer1" , &s->timer1,sizeof (s->timer1), -TYPE_CMSDK_APB_TIMER ); -init_sysbus_child (obj,"dualtimer" , &s->dualtimer,sizeof (s->dualtimer), -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize (&s->ppc_irq_orgate,sizeof (s->ppc_irq_orgate), -TYPE_OR_IRQ ); -object_property_add_child (obj,"ppc-irq-orgate" , -OBJECT (&s->ppc_irq_orgate), &error_abort); -object_initialize (&s->sec_resp_splitter,sizeof (s->sec_resp_splitter), -TYPE_SPLIT_IRQ ); -object_property_add_child (obj,"sec-resp-splitter" , -OBJECT (&s->sec_resp_splitter), &error_abort); +sysbus_init_child_obj (obj,"timer0" , &s->timer0,sizeof (s->timer0), +TYPE_CMSDK_APB_TIMER ); +sysbus_init_child_obj (obj,"timer1" , &s->timer1,sizeof (s->timer1), +TYPE_CMSDK_APB_TIMER ); +sysbus_init_child_obj (obj,"dualtimer" , &s->dualtimer,sizeof (s->dualtimer), +TYPE_UNIMPLEMENTED_DEVICE ); +object_initialize_child (obj,"ppc-irq-orgate" , &s->ppc_irq_orgate, +sizeof (s->ppc_irq_orgate),TYPE_OR_IRQ , + &error_abort,NULL ); +object_initialize_child (obj,"sec-resp-splitter" , &s->sec_resp_splitter, +sizeof (s->sec_resp_splitter),TYPE_SPLIT_IRQ , + &error_abort,NULL );for (i =0 ; i <ARRAY_SIZE (s->ppc_irq_splitter); i++) {char *name =g_strdup_printf ("ppc-irq-splitter-%d" , i);SplitIRQ *splitter = &s->ppc_irq_splitter[i]; -object_initialize (splitter,sizeof (*splitter),TYPE_SPLIT_IRQ ); -object_property_add_child (obj, name,OBJECT (splitter), &error_abort); +object_initialize_child (obj, name, splitter,sizeof (*splitter), +TYPE_SPLIT_IRQ , &error_abort,NULL ); +g_free (name); } -init_sysbus_child (obj,"s32ktimer" , &s->s32ktimer,sizeof (s->s32ktimer), -TYPE_UNIMPLEMENTED_DEVICE ); +sysbus_init_child_obj (obj,"s32ktimer" , &s->s32ktimer,sizeof (s->s32ktimer), +TYPE_UNIMPLEMENTED_DEVICE ); }static void iotkit_exp_irq (void *opaque,int n,int level)hw/intc/armv7m_nvic.c +2
-4@@ -2296,9 +2296,8 @@ static void armv7m_nvic_instance_init(Object *obj)NVICState *nvic =NVIC (obj);SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -object_initialize (&nvic->systick[M_REG_NS ], -sizeof (nvic->systick[M_REG_NS ]),TYPE_SYSTICK ); -qdev_set_parent_bus (DEVICE (&nvic->systick[M_REG_NS ]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"systick-reg-ns" , &nvic->systick[M_REG_NS ], +sizeof (nvic->systick[M_REG_NS ]),TYPE_SYSTICK );/* We can't initialize the secure systick here, as we don't know * yet if we need it. */ --1.8.3.1
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 15/17] hw/arm/stm32f205_soc: Fix introspection problem with 'stm32f205-soc' device
In reply to Thomas HuthQuoted 9 lines · Thomas Huth
Valgrind complains:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'stm32f205-soc'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==28531== Invalid read of size 8
Quoted 8 lines
==28531== at 0x6185BA: qdev_print (qdev-monitor.c:686) ==28531== by 0x6185BA: qbus_print (qdev-monitor.c:719) ==28531== by 0x452B38: handle_hmp_command (monitor.c:3446)[...]
Fix it with the new
sysbus_init_child_obj()function.Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 61 lines
--- hw/arm/stm32f205_soc.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)hw/arm/stm32f205_soc.c +12
-17@@ -49,36 +49,32 @@ static void stm32f205_soc_initfn(Object *obj)STM32F205State *s =STM32F205_SOC (obj);int i; -object_initialize (&s->armv7m,sizeof (s->armv7m),TYPE_ARMV7M ); -qdev_set_parent_bus (DEVICE (&s->armv7m),sysbus_get_default ()); +sysbus_init_child_obj (obj,"armv7m" , &s->armv7m,sizeof (s->armv7m), +TYPE_ARMV7M ); -object_initialize (&s->syscfg,sizeof (s->syscfg),TYPE_STM32F2XX_SYSCFG ); -qdev_set_parent_bus (DEVICE (&s->syscfg),sysbus_get_default ()); +sysbus_init_child_obj (obj,"syscfg" , &s->syscfg,sizeof (s->syscfg), +TYPE_STM32F2XX_SYSCFG );for (i =0 ; i <STM_NUM_USARTS ; i++) { -object_initialize (&s->usart[i],sizeof (s->usart[i]), -TYPE_STM32F2XX_USART ); -qdev_set_parent_bus (DEVICE (&s->usart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"usart[*]" , &s->usart[i], +sizeof (s->usart[i]),TYPE_STM32F2XX_USART ); }for (i =0 ; i <STM_NUM_TIMERS ; i++) { -object_initialize (&s->timer[i],sizeof (s->timer[i]), -TYPE_STM32F2XX_TIMER ); -qdev_set_parent_bus (DEVICE (&s->timer[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"timer[*]" , &s->timer[i], +sizeof (s->timer[i]),TYPE_STM32F2XX_TIMER ); } s->adc_irqs =OR_IRQ (object_new (TYPE_OR_IRQ ));for (i =0 ; i <STM_NUM_ADCS ; i++) { -object_initialize (&s->adc[i],sizeof (s->adc[i]), -TYPE_STM32F2XX_ADC ); -qdev_set_parent_bus (DEVICE (&s->adc[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"adc[*]" , &s->adc[i],sizeof (s->adc[i]), +TYPE_STM32F2XX_ADC ); }for (i =0 ; i <STM_NUM_SPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]), -TYPE_STM32F2XX_SPI ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"spi[*]" , &s->spi[i],sizeof (s->spi[i]), +TYPE_STM32F2XX_SPI ); } } --1.8.3.1
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 07/17] hw/cpu/a9mpcore: Fix introspection problems with the "a9mpcore_priv" device
In reply to Thomas HuthQuoted 14 lines · Thomas Huth
Running QEMU with valgrind indicates a problem here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'a9mpcore_priv'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==30996== Invalid read of size 8==30996== at 0x6185DA: qdev_print (qdev-monitor.c:686) ==30996== by 0x6185DA: qbus_print (qdev-monitor.c:719) ==30996== by 0x452B38: handle_hmp_command (monitor.c:3446)[...]
Quoted 7 lines
Use the new
sysbus_init_child_obj()function to make sure that the objects are cleaned up correctly when the parent gets destroyed.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 41 lines
--- hw/cpu/a9mpcore.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)hw/cpu/a9mpcore.c +8
-11@@ -27,20 +27,18 @@ static void a9mp_priv_initfn(Object *obj)memory_region_init (&s->container, obj,"a9mp-priv-container" ,0x2000 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->container); -object_initialize (&s->scu,sizeof (s->scu),TYPE_A9_SCU ); -qdev_set_parent_bus (DEVICE (&s->scu),sysbus_get_default ()); +sysbus_init_child_obj (obj,"scu" , &s->scu,sizeof (s->scu),TYPE_A9_SCU ); -object_initialize (&s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -object_initialize (&s->gtimer,sizeof (s->gtimer),TYPE_A9_GTIMER ); -qdev_set_parent_bus (DEVICE (&s->gtimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gtimer" , &s->gtimer,sizeof (s->gtimer), +TYPE_A9_GTIMER ); -object_initialize (&s->mptimer,sizeof (s->mptimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->mptimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"mptimer" , &s->mptimer,sizeof (s->mptimer), +TYPE_ARM_MPTIMER ); -object_initialize (&s->wdt,sizeof (s->wdt),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->wdt),sysbus_get_default ()); +sysbus_init_child_obj (obj,"wdt" , &s->wdt,sizeof (s->wdt), +TYPE_ARM_MPTIMER ); }static void a9mp_priv_realize (DeviceState *dev,Error **errp) --1.8.3.1
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 16/17] hw/display/xlnx_dp: Move problematic code from instance_init to realize
In reply to Thomas HuthQuoted 12 lines · Thomas Huth
From: Paolo Bonzini <[email protected]>
aux_create_slave()callsqdev_init_nofail()which in turn "realizes" the corresponding object. This is unlikeqdev_create(), and it is wrong becauseqdev_init_nofail()must not be called from aninstance_initfunction. Moveqdev_init_nofail()and the subsequentaux_map_slaveinto the caller's realize function.There are two more bugs that needs to be fixed here, too, where the objects are created but not added as children. Therefore when you call
object_unparenton them, nothing happens.
Quoted 8 lines
In particular dpcd and edid give you an infinite loop in
bus_unparent, becausedevice_unparentis not called and does not remove them from the list of devices on the bus.Reported-by Thomas Huth <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>[thuth: Added Paolo's fixup for the dpcd and edid unparenting]Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 121 lines
--- hw/display/xlnx_dp.c | 8 +++++++- hw/misc/auxbus.c | 18 ++++++++++++------ include/hw/misc/auxbus.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-)hw/display/xlnx_dp.c +7
-1@@ -1234,9 +1234,12 @@ static void xlnx_dp_init(Object *obj)/* * Initialize DPCD and EDID.. */ - s->dpcd =DPCD (aux_create_slave (s->aux_bus,"dpcd" ,0x00000 )); + s->dpcd =DPCD (aux_create_slave (s->aux_bus,"dpcd" )); +object_property_add_child (OBJECT (s),"dpcd" ,OBJECT (s->dpcd),NULL ); + s->edid =I2CDDC (qdev_create (BUS (aux_get_i2c_bus (s->aux_bus)),"i2c-ddc" ));i2c_set_slave_address (I2C_SLAVE (s->edid),0x50 ); +object_property_add_child (OBJECT (s),"edid" ,OBJECT (s->edid),NULL );fifo8_create (&s->rx_fifo,16 );fifo8_create (&s->tx_fifo,16 );@@ -1248,6 +1251,9 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)DisplaySurface *surface;struct audsettings as; +qdev_init_nofail (DEVICE (s->dpcd)); +aux_map_slave (AUX_SLAVE (s->dpcd),0x0000 ); + s->console =graphic_console_init (dev,0 , &xlnx_dp_gfx_ops, s); surface =qemu_console_surface (s->console); xlnx_dpdma_set_host_data_location(s->dpdma, DP_GRAPHIC_DMA_CHANNEL,hw/misc/auxbus.c +12
-6@@ -32,6 +32,7 @@#include "hw/misc/auxbus.h" #include "hw/i2c/i2c.h" #include "monitor/monitor.h" +#include "qapi/error.h" #ifndef DEBUG_AUX #define DEBUG_AUX 0@@ -63,9 +64,14 @@ static void aux_bus_class_init(ObjectClass *klass, void *data)AUXBus *aux_init_bus (DeviceState *parent,const char *name) {AUXBus *bus; +Object *auxtoi2c; bus =AUX_BUS (qbus_create (TYPE_AUX_BUS , parent, name)); - bus->bridge =AUXTOI2C (qdev_create (BUS (bus),TYPE_AUXTOI2C )); + auxtoi2c =object_new_with_props (TYPE_AUXTOI2C ,OBJECT (bus),"i2c" , + &error_abort,NULL ); +qdev_set_parent_bus (DEVICE (auxtoi2c),BUS (bus)); + + bus->bridge =AUXTOI2C (auxtoi2c);/* Memory related. */ bus->aux_io =g_malloc (sizeof (*bus->aux_io));@@ -74,9 +80,11 @@ AUXBus *aux_init_bus(DeviceState *parent, const char *name)return bus; } -static void aux_bus_map_device (AUXBus *bus,AUXSlave *dev,hwaddr addr) +void aux_map_slave (AUXSlave *aux_dev,hwaddr addr) { -memory_region_add_subregion (bus->aux_io, addr, dev->mmio); +DeviceState *dev =DEVICE (aux_dev); +AUXBus *bus =AUX_BUS (qdev_get_parent_bus (dev)); +memory_region_add_subregion (bus->aux_io, addr, aux_dev->mmio); }static bool aux_bus_is_bridge (AUXBus *bus,DeviceState *dev)@@ -260,15 +268,13 @@ static void aux_slave_dev_print(Monitor *mon, DeviceState *dev, int indent) memory_region_size(s->mmio)); } -DeviceState *aux_create_slave (AUXBus *bus,const char *type,uint32_t addr) +DeviceState *aux_create_slave (AUXBus *bus,const char *type) {DeviceState *dev; dev =DEVICE (object_new (type));assert (dev);qdev_set_parent_bus (dev, &bus->qbus); -qdev_init_nofail (dev); -aux_bus_map_device (AUX_BUS (qdev_get_parent_bus (dev)),AUX_SLAVE (dev), addr);return dev; }include/hw/misc/auxbus.h +13
-2@@ -123,6 +123,18 @@ I2CBus *aux_get_i2c_bus(AUXBus *bus);*/ void aux_init_mmio (AUXSlave *aux_slave,MemoryRegion *mmio); -DeviceState *aux_create_slave (AUXBus *bus,const char *name,uint32_t addr); +/* aux_create_slave: Create a new device on an AUX bus +* +* @bus The AUX bus for the new device. +* @name The type of the device to be created. +*/ +DeviceState *aux_create_slave (AUXBus *bus,const char *name); + +/* aux_map_slave: Map the mmio for an AUX slave on the bus. +* +* @dev The AUX slave. +* @addr The address for the slave's mmio. +*/ +void aux_map_slave (AUXSlave *dev,hwaddr addr);#endif /* HW_MISC_AUXBUS_H */ --1.8.3.1
Re: [Qemu-devel] [PATCH v3 12/17] hw/cpu/arm11mpcore: Fix introspection problem with 'arm11mpcore_priv'
In reply to Thomas HuthQuoted 13 lines · Thomas Huth
Valgrind reports an error here:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'arm11mpcore_priv'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
valgrind -q aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
[...]
==3145== Invalid read of size 8
==3145== at0x61873A:qdev_print(qdev-monitor.c:686)
==3145== by0x61873A:qbus_print(qdev-monitor.c:719)
[...]
Quoted 6 lines
Use
sysbus_init_child_obj()to fix it.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 38 lines
--- hw/cpu/arm11mpcore.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)hw/cpu/arm11mpcore.c +6
-9@@ -121,19 +121,17 @@ static void mpcore_priv_initfn(Object *obj) "mpcore-priv-container", 0x2000);sysbus_init_mmio (sbd, &s->container); -object_initialize (&s->scu,sizeof (s->scu),TYPE_ARM11_SCU ); -qdev_set_parent_bus (DEVICE (&s->scu),sysbus_get_default ()); +sysbus_init_child_obj (obj,"scu" , &s->scu,sizeof (s->scu),TYPE_ARM11_SCU ); -object_initialize (&s->gic,sizeof (s->gic),TYPE_ARM_GIC ); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic),TYPE_ARM_GIC );/* Request the legacy 11MPCore GIC behaviour: */ qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,0 ); -object_initialize (&s->mptimer,sizeof (s->mptimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->mptimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"mptimer" , &s->mptimer,sizeof (s->mptimer), +TYPE_ARM_MPTIMER ); -object_initialize (&s->wdtimer,sizeof (s->wdtimer),TYPE_ARM_MPTIMER ); -qdev_set_parent_bus (DEVICE (&s->wdtimer),sysbus_get_default ()); +sysbus_init_child_obj (obj,"wdtimer" , &s->wdtimer,sizeof (s->wdtimer), +TYPE_ARM_MPTIMER ); }static Property mpcore_priv_properties[] = { --1.8.3.1
Re: [Qemu-arm] [Qemu-devel] [PATCH v3 17/17] hw/arm/xlnx-zynqmp: Fix crash when introspecting the "xlnx, zynqmp" device
In reply to Thomas HuthQuoted 8 lines · Thomas Huth
QEMU currently crashes when e.g. doing something like this:
echo "{'execute':'qmp_capabilities'} {'execute':'device-list-properties'," \
"'arguments':{'typename':'xlnx,zynqmp'}}" \
"{'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" \
| aarch64-softmmu/qemu-system-aarch64 -M none,accel=qtest -qmp stdio
Quoted 8 lines
Use the new
object_initialize_child()andsysbus_init_child_obj()functions to get the refernce counting of the child objects right, so that they are properly cleaned up when the parent gets destroyed.Reviewed-by Richard Henderson <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 105 lines
--- hw/arm/xlnx-zynqmp.c | 61 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 33 deletions(-)hw/arm/xlnx-zynqmp.c +28
-34@@ -166,64 +166,59 @@ static void xlnx_zynqmp_init(Object *obj)int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS );for (i =0 ; i < num_apus; i++) { -object_initialize (&s->apu_cpu[i],sizeof (s->apu_cpu[i]), -"cortex-a53-" TYPE_ARM_CPU ); -object_property_add_child (obj,"apu-cpu[*]" ,OBJECT (&s->apu_cpu[i]), - &error_abort); +object_initialize_child (obj,"apu-cpu[*]" , &s->apu_cpu[i], +sizeof (s->apu_cpu[i]), +"cortex-a53-" TYPE_ARM_CPU , &error_abort,NULL ); } -object_initialize (&s->gic,sizeof (s->gic),gic_class_name ()); -qdev_set_parent_bus (DEVICE (&s->gic),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +gic_class_name ());for (i =0 ; i <XLNX_ZYNQMP_NUM_GEMS ; i++) { -object_initialize (&s->gem[i],sizeof (s->gem[i]),TYPE_CADENCE_GEM ); -qdev_set_parent_bus (DEVICE (&s->gem[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gem[*]" , &s->gem[i],sizeof (s->gem[i]), +TYPE_CADENCE_GEM ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_UARTS ; i++) { -object_initialize (&s->uart[i],sizeof (s->uart[i]),TYPE_CADENCE_UART ); -qdev_set_parent_bus (DEVICE (&s->uart[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"uart[*]" , &s->uart[i],sizeof (s->uart[i]), +TYPE_CADENCE_UART ); } -object_initialize (&s->sata,sizeof (s->sata),TYPE_SYSBUS_AHCI ); -qdev_set_parent_bus (DEVICE (&s->sata),sysbus_get_default ()); +sysbus_init_child_obj (obj,"sata" , &s->sata,sizeof (s->sata), +TYPE_SYSBUS_AHCI );for (i =0 ; i <XLNX_ZYNQMP_NUM_SDHCI ; i++) { -object_initialize (&s->sdhci[i],sizeof (s->sdhci[i]), -TYPE_SYSBUS_SDHCI ); -qdev_set_parent_bus (DEVICE (&s->sdhci[i]), -sysbus_get_default ()); +sysbus_init_child_obj (obj,"sdhci[*]" , &s->sdhci[i], +sizeof (s->sdhci[i]),TYPE_SYSBUS_SDHCI ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_SPIS ; i++) { -object_initialize (&s->spi[i],sizeof (s->spi[i]), -TYPE_XILINX_SPIPS ); -qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"spi[*]" , &s->spi[i],sizeof (s->spi[i]), +TYPE_XILINX_SPIPS ); } -object_initialize (&s->qspi,sizeof (s->qspi),TYPE_XLNX_ZYNQMP_QSPIPS ); -qdev_set_parent_bus (DEVICE (&s->qspi),sysbus_get_default ()); +sysbus_init_child_obj (obj,"qspi" , &s->qspi,sizeof (s->qspi), +TYPE_XLNX_ZYNQMP_QSPIPS ); -object_initialize (&s->dp,sizeof (s->dp),TYPE_XLNX_DP ); -qdev_set_parent_bus (DEVICE (&s->dp),sysbus_get_default ()); +sysbus_init_child_obj (obj,"xxxdp" , &s->dp,sizeof (s->dp),TYPE_XLNX_DP ); -object_initialize (&s->dpdma,sizeof (s->dpdma),TYPE_XLNX_DPDMA ); -qdev_set_parent_bus (DEVICE (&s->dpdma),sysbus_get_default ()); +sysbus_init_child_obj (obj,"dp-dma" , &s->dpdma,sizeof (s->dpdma), +TYPE_XLNX_DPDMA ); -object_initialize (&s->ipi,sizeof (s->ipi),TYPE_XLNX_ZYNQMP_IPI ); -qdev_set_parent_bus (DEVICE (&s->ipi),sysbus_get_default ()); +sysbus_init_child_obj (obj,"ipi" , &s->ipi,sizeof (s->ipi), +TYPE_XLNX_ZYNQMP_IPI ); -object_initialize (&s->rtc,sizeof (s->rtc),TYPE_XLNX_ZYNQMP_RTC ); -qdev_set_parent_bus (DEVICE (&s->rtc),sysbus_get_default ()); +sysbus_init_child_obj (obj,"rtc" , &s->rtc,sizeof (s->rtc), +TYPE_XLNX_ZYNQMP_RTC );for (i =0 ; i <XLNX_ZYNQMP_NUM_GDMA_CH ; i++) { -object_initialize (&s->gdma[i],sizeof (s->gdma[i]),TYPE_XLNX_ZDMA ); -qdev_set_parent_bus (DEVICE (&s->gdma[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"gdma[*]" , &s->gdma[i],sizeof (s->gdma[i]), +TYPE_XLNX_ZDMA ); }for (i =0 ; i <XLNX_ZYNQMP_NUM_ADMA_CH ; i++) { -object_initialize (&s->adma[i],sizeof (s->adma[i]),TYPE_XLNX_ZDMA ); -qdev_set_parent_bus (DEVICE (&s->adma[i]),sysbus_get_default ()); +sysbus_init_child_obj (obj,"adma[*]" , &s->adma[i],sizeof (s->adma[i]), +TYPE_XLNX_ZDMA ); } } --1.8.3.1
Quoted 9 lines · Thomas Huth
As discovered recently, you can crash QEMU with a lot of devices that do not get the reference counting of child objects right. You just have to run 'device-list-properties' and call 'info qtree' afterwards.
This patch series fixes these problems in the ARM code. When all patches have been applied, I now do not get any more hangs or crashes when I add ahmp("info qtree")to the device-introspect-test.Please have a look at patch #1, #15 and #16, they still need reviews.
Everything seems to have got review now, so I'm going to apply this set to master for rc1. Thanks very much for digging into what was going on here and cleaning up our APIs.
-- PMM