Skip to contentSkip to conversation

Fix crashes related to -global option

PATCH In review Eduardo Habkost 4 participants 6 messages Jul 3, 2014 – Jul 7, 2014

lore
Share & tools
lore
#0 lore raw

cover Fix crashes related to -global option

Patch 1 (which was submitted previously but has fallen through the cracks) fixes:

        $ qemu-system-x86_64 -global cpu.xxx=y
        qemu-system-x86_64: Property '.xxx' not found
        Aborted (core dumped)

Patch 2 fixes:

        $ qemu-system-x86_64 -global container.xxx=y
        hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
        Aborted (core dumped)

Eduardo Habkost (2):
qdev: Don't abort() in case globals can't be set
qdev: Fix crash when using non-device class name on -global

 hw/core/qdev-properties-system.c | 3 ++-
 hw/core/qdev.c                   | 8 +++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 qdev: Don't abort() in case globals can't be set

It would be much better if we didn't terminate QEMU inside device_post_init(), but at least exiting cleanly is better than aborting and dumping core.

Before this patch:

    $ qemu-system-x86_64 -global cpu.xxx=y
    qemu-system-x86_64: Property '.xxx' not found
    Aborted (core dumped)

After this patch:

    $ qemu-system-x86_64 -global cpu.xxx=y
    qemu-system-x86_64: Property '.xxx' not found
---
 hw/core/qdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/core/qdev.c +7 -1
index 3bdda8e..da1ba48 100644
@@ -957,7 +957,13 @@ static void device_initfn(Object *obj)
 
 static void device_post_init(Object *obj)
 {
-    qdev_prop_set_globals(DEVICE(obj), &error_abort);
+    Error *err = NULL;
+    qdev_prop_set_globals(DEVICE(obj), &err);
+    if (err) {
+        qerror_report_err(err);
+        error_free(err);
+        exit(EXIT_FAILURE);
+    }
 }
 
 /* Unlink device from bus and free the structure.  */
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/2 qdev: Fix crash when using non-device class name on -global

In reply to Eduardo Habkost

This fixes the following crash:

    $ qemu-system-x86_64 -global container.xxx=y
    hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
    Aborted (core dumped)

New behavior will be to just warn, just like when non-existing clas names are used:

    $ qemu-system-x86_64 -global container.xxx=y
    qemu-system-x86_64: Warning: "-global container.xxx=y" not used
---
 hw/core/qdev-properties-system.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +2 -1
index 8e140af..ae0900f 100644
@@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_by_name(g->driver);
+    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
+                                   TYPE_DEVICE);
     if (oc) {
         DeviceClass *dc = DEVICE_CLASS(oc);
 
Signature · 1 line
1.9.3
Reviewed-by on v1 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH for-2.1 2/2] qdev: Fix crash when using non-device class name on -global

Quoted 7 lines · Eduardo Habkost

This fixes the following crash:

    $ qemu-system-x86_64 -global container.xxx=y
    hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
    Aborted (core dumped)

New behavior will be to just warn, just like when non-existing clas

s/clas/class/

Quoted 15 lines

names are used:

    $ qemu-system-x86_64 -global container.xxx=y
    qemu-system-x86_64: Warning: "-global container.xxx=y" not used
---
 hw/core/qdev-properties-system.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +0 -0
index 8e140af..ae0900f 100644

hw/core/qdev-properties-system.c static int qdev_add_one_global(QemuOpts *opts, void *opaque) · line 400

Quoted 8 lines
hw/core/qdev-properties-system.c +2 -1
@@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_by_name(g->driver);
+    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
+                                   TYPE_DEVICE);
     if (oc) {
         DeviceClass *dc = DEVICE_CLASS(oc);

I'm not an expert on the type system, but this one looks simple enough that I don't mind:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Tested-by
#4 lore raw

Re: [Qemu-devel] [PATCH for-2.1 2/2] qdev: Fix crash when using non-device class name on -global

Quoted 36 lines · Eric Blake
Quoted 7 lines · Eduardo Habkost

This fixes the following crash:

     $ qemu-system-x86_64 -global container.xxx=y
     hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
     Aborted (core dumped)

New behavior will be to just warn, just like when non-existing clas

s/clas/class/

Quoted 15 lines

names are used:

     $ qemu-system-x86_64 -global container.xxx=y
     qemu-system-x86_64: Warning: "-global container.xxx=y" not used
---
  hw/core/qdev-properties-system.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +0 -0
index 8e140af..ae0900f 100644

hw/core/qdev-properties-system.c static int qdev_add_one_global(QemuOpts *opts, void *opaque) · line 400

Quoted 8 lines
hw/core/qdev-properties-system.c +2 -1
@@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
      g->driver   = qemu_opt_get(opts, "driver");
      g->property = qemu_opt_get(opts, "property");
      g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_by_name(g->driver);
+    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
+                                   TYPE_DEVICE);
      if (oc) {
          DeviceClass *dc = DEVICE_CLASS(oc);

I'm not an expert on the type system, but this one looks simple enough that I don't mind:

Quoted 2 lines

Looks good to me also, and it passes my quick tests.

-Don Slutz

Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH for-2.1 2/2] qdev: Fix crash when using non-device class name on -global

In reply to Eduardo Habkost
Quoted 22 lines · On Thu, 3 Jul 2014 16:45:35 -0300 Eduardo Habkost <[email protected]> wrote:

This fixes the following crash:

    $ qemu-system-x86_64 -global container.xxx=y
    hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
    Aborted (core dumped)

New behavior will be to just warn, just like when non-existing clas names are used:

    $ qemu-system-x86_64 -global container.xxx=y
    qemu-system-x86_64: Warning: "-global container.xxx=y" not used
---
 hw/core/qdev-properties-system.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +0 -0
index 8e140af..ae0900f 100644

hw/core/qdev-properties-system.c static int qdev_add_one_global(QemuOpts *opts, void *opaque) · line 401

Quoted 9 lines
hw/core/qdev-properties-system.c +2 -1
@@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_by_name(g->driver);
+    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
+                                   TYPE_DEVICE);
     if (oc) {
         DeviceClass *dc = DEVICE_CLASS(oc);