Skip to contentSkip to conversation

qdev: Validate class name for -device <class>, help

PATCH Applied Eduardo Habkost 3 participants 12 messages Nov 1, 2014 – Nov 4, 2014

lore
Share & tools
lore
#0 lore raw

cover qdev: Validate class name for -device <class>, help

This fixes the following crashes:

   $ qemu-system-x86_64 -device x86_64-cpu,help
   **
   ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
   Aborted (core dumped)
   $ qemu-system-x86_64 -device host-x86_64-cpu,help
   qemu-system-x86_64: /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
   Aborted (core dumped)
Cc Stefan Hajnoczi <[email protected]>
Cc Gonglei <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Andreas Färber <[email protected]>
Cc Paolo Bonzini <[email protected]>

Eduardo Habkost (3):
qdev: Create qdev_get_device_class() function
qdev: Move error printing to the end of qdev_device_help()
qdev: Use qdev_device_add_get_class() for -device <type>,help

 qdev-monitor.c | 88 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 51 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/3 qdev: Create qdev_get_device_class() function

Extract the DeviceClass lookup from qdev_device_add() to a separate function.

---
 qdev-monitor.c | 70 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 28 deletions(-)
qdev-monitor.c +42 -28
index fac7d17..982f3f4 100644
@@ -180,6 +180,44 @@ static const char *find_typename_by_alias(const char *alias)
     return NULL;
 }
 
+static DeviceClass *qdev_get_device_class(const char **driver, Error **errp)
+{
+    ObjectClass *oc;
+    DeviceClass *dc;
+
+    oc = object_class_by_name(*driver);
+    if (!oc) {
+        const char *typename = find_typename_by_alias(*driver);
+
+        if (typename) {
+            *driver = typename;
+            oc = object_class_by_name(*driver);
+        }
+    }
+
+    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
+        error_setg(errp, "'%s' is not a valid device model name", *driver);
+        return NULL;
+    }
+
+    if (object_class_is_abstract(oc)) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+                  "non-abstract device type");
+        return NULL;
+    }
+
+    dc = DEVICE_CLASS(oc);
+    if (dc->cannot_instantiate_with_device_add_yet ||
+        (qdev_hotplug && !dc->hotpluggable)) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+                  "pluggable device type");
+        return NULL;
+    }
+
+    return dc;
+}
+
+
 int qdev_device_help(QemuOpts *opts)
 {
     Error *local_err = NULL;
@@ -455,7 +493,6 @@ static BusState *qbus_find(const char *path)
 
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
-    ObjectClass *oc;
     DeviceClass *dc;
     const char *driver, *path, *id;
     DeviceState *dev;
@@ -469,33 +506,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     /* find driver */
-    oc = object_class_by_name(driver);
-    if (!oc) {
-        const char *typename = find_typename_by_alias(driver);
-
-        if (typename) {
-            driver = typename;
-            oc = object_class_by_name(driver);
-        }
-    }
-
-    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
-        qerror_report(ERROR_CLASS_GENERIC_ERROR,
-                      "'%s' is not a valid device model name", driver);
-        return NULL;
-    }
-
-    if (object_class_is_abstract(oc)) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
-                      "non-abstract device type");
-        return NULL;
-    }
-
-    dc = DEVICE_CLASS(oc);
-    if (dc->cannot_instantiate_with_device_add_yet ||
-        (qdev_hotplug && !dc->hotpluggable)) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
-                      "pluggable device type");
+    dc = qdev_get_device_class(&driver, &err);
+    if (err) {
+        qerror_report_err(err);
+        error_free(err);
         return NULL;
     }
 
Signature · 1 line
1.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] qdev: Create qdev_get_device_class() function

Hi,

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 13 lines

Extract the DeviceClass lookup from qdev_device_add() to a separate function.

---
 qdev-monitor.c | 70 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 28 deletions(-)
qdev-monitor.c +0 -0
index fac7d17..982f3f4 100644

qdev-monitor.c static const char *find_typename_by_alias(const char *alias) · line 183

Quoted 4 lines
qdev-monitor.c +1 -0
@@ -180,6 +180,44 @@ static const char *find_typename_by_alias(const char *alias)
     return NULL;
 }
 
+static DeviceClass *qdev_get_device_class(const char **driver, Error **errp)

Since this does nothing qdev-specific, what about device_get_class_by_name()? The only that's not generically suitable for hw/core/ is the "driver" naming in the error handling; otherwise it looks very similar to the CPUClass hooks I added a while back.

Quoted 15 lines
qdev-monitor.c +15 -0
+{
+    ObjectClass *oc;
+    DeviceClass *dc;
+
+    oc = object_class_by_name(*driver);
+    if (!oc) {
+        const char *typename = find_typename_by_alias(*driver);
+
+        if (typename) {
+            *driver = typename;
+            oc = object_class_by_name(*driver);
+        }
+    }
+
+    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {

qdev-monitor.c static const char *find_typename_by_alias(const char *alias) · line 208

Quoted 10 lines
qdev-monitor.c +10 -0
+        error_setg(errp, "'%s' is not a valid device model name", *driver);
+        return NULL;
+    }
+
+    if (object_class_is_abstract(oc)) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+                  "non-abstract device type");
+        return NULL;
+    }
+

See 3/3 for whether we may want to return here.

Quoted 51 lines
qdev-monitor.c +12 -25
+    dc = DEVICE_CLASS(oc);
+    if (dc->cannot_instantiate_with_device_add_yet ||
+        (qdev_hotplug && !dc->hotpluggable)) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+                  "pluggable device type");
+        return NULL;
+    }
+
+    return dc;
+}
+
+
 int qdev_device_help(QemuOpts *opts)
 {
     Error *local_err = NULL;
@@ -455,7 +493,6 @@ static BusState *qbus_find(const char *path)
 
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
-    ObjectClass *oc;
     DeviceClass *dc;
     const char *driver, *path, *id;
     DeviceState *dev;
@@ -469,33 +506,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     /* find driver */
-    oc = object_class_by_name(driver);
-    if (!oc) {
-        const char *typename = find_typename_by_alias(driver);
-
-        if (typename) {
-            driver = typename;
-            oc = object_class_by_name(driver);
-        }
-    }
-
-    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
-        qerror_report(ERROR_CLASS_GENERIC_ERROR,
-                      "'%s' is not a valid device model name", driver);
-        return NULL;
-    }
-
-    if (object_class_is_abstract(oc)) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
-                      "non-abstract device type");
-        return NULL;
-    }
-
-    dc = DEVICE_CLASS(oc);
-    if (dc->cannot_instantiate_with_device_add_yet ||

qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 515

Quoted 10 lines
qdev-monitor.c +4 -3
-        (qdev_hotplug && !dc->hotpluggable)) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
-                      "pluggable device type");
+    dc = qdev_get_device_class(&driver, &err);
+    if (err) {
+        qerror_report_err(err);
+        error_free(err);
         return NULL;
     }
 

Otherwise looks good.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] qdev: Create qdev_get_device_class() function

Quoted 19 lines · Andreas Färber

Hi,

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 16 lines

Extract the DeviceClass lookup from qdev_device_add() to a separate function.

---
 qdev-monitor.c | 70 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 28 deletions(-)
qdev-monitor.c +0 -0
index fac7d17..982f3f4 100644
@@ -180,6 +180,44 @@ static const char *find_typename_by_alias(const char *alias)
     return NULL;
 }
 
Quoted 6 lines

qdev-monitor.c static const char *find_typename_by_alias(const char *alias) · line 183

Quoted 1 line
qdev-monitor.c +1 -0
+static DeviceClass *qdev_get_device_class(const char **driver, Error **errp)

Since this does nothing qdev-specific, what about device_get_class_by_name()? The only that's not generically suitable for hw/core/ is the "driver" naming in the error handling; otherwise it looks very similar to the CPUClass hooks I added a while back.

Well, I don't know where's the line that divides "qdev-specific" from "DeviceState-specific". The distinction seems arbitrary to me, and I won't see any problem if somebody moves all qdev-*.c files inside hw/core. :)

I assume that at least qdev_alias_table (which is used by both qdev_device_add() and qdev_device_help()) can be considered qdev-specific (but just because the table is currently inside qdev-monitor.c).

Anyway, the only point of this function is to reduce code duplication between qdev_device_add() and qdev_device_help() while fixing the "-device ,help" crashes. If somebody wants to move any of the existing qdev-*.c logic to hw/core later, I won't complain (but I wouldn't want to do that after hard freeze).

Quoted 20 lines
Quoted 20 lines
qdev-monitor.c +19 -0
+{
+    ObjectClass *oc;
+    DeviceClass *dc;
+
+    oc = object_class_by_name(*driver);
+    if (!oc) {
+        const char *typename = find_typename_by_alias(*driver);
+
+        if (typename) {
+            *driver = typename;
+            oc = object_class_by_name(*driver);
+        }
+    }
+
+    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
+        error_setg(errp, "'%s' is not a valid device model name", *driver);
+        return NULL;
+    }
+
Quoted 8 lines

qdev-monitor.c static const char *find_typename_by_alias(const char *alias) · line 208

Quoted 6 lines
qdev-monitor.c +6 -0
+    if (object_class_is_abstract(oc)) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
+                  "non-abstract device type");
+        return NULL;
+    }
+

See 3/3 for whether we may want to return here.

The point of this function is to allow reuse of checks that are necessary on both qdev_device_add() and qdev_device_help(), and both functions need to reject abstract and cannot_instantiate_with_device_add_yet classes.

Signature · 1 line
Eduardo
#4 lore raw

PATCH 2/3 qdev: Move error printing to the end of qdev_device_help()

In reply to Eduardo Habkost
---
 qdev-monitor.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
qdev-monitor.c +6 -3
index 982f3f4..a9702d8 100644
@@ -245,9 +245,7 @@ int qdev_device_help(QemuOpts *opts)
 
     prop_list = qmp_device_list_properties(driver, &local_err);
     if (local_err) {
-        error_printf("%s\n", error_get_pretty(local_err));
-        error_free(local_err);
-        return 1;
+        goto error;
     }
 
     for (prop = prop_list; prop; prop = prop->next) {
@@ -263,6 +261,11 @@ int qdev_device_help(QemuOpts *opts)
 
     qapi_free_DevicePropertyInfoList(prop_list);
     return 1;
+
+error:
+    error_printf("%s\n", error_get_pretty(local_err));
+    error_free(local_err);
+    return 1;
 }
 
 static Object *qdev_get_peripheral(void)
Signature · 1 line
1.9.3
#5 lore raw

PATCH 3/3 qdev: Use qdev_device_add_get_class() for -device <type>, help

In reply to Eduardo Habkost

Make sure we try to list properties from classes that can be safely used with "-device".

Fixes the following crashes:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  **
  ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
  Aborted (core dumped)
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
  Aborted (core dumped)

After applying this patch:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  Parameter 'driver' expects non-abstract device type
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  Parameter 'driver' expects pluggable device type
---
 qdev-monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
qdev-monitor.c +3 -6
index a9702d8..ebfa701 100644
@@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
 
-    if (!object_class_by_name(driver)) {
-        const char *typename = find_typename_by_alias(driver);
-
-        if (typename) {
-            driver = typename;
-        }
+    qdev_get_device_class(&driver, &local_err);
+    if (local_err) {
+        goto error;
     }
 
     prop_list = qmp_device_list_properties(driver, &local_err);
Signature · 1 line
1.9.3
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device <type>, help

Hi Eduardo,

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 35 lines

Make sure we try to list properties from classes that can be safely used with "-device".

Fixes the following crashes:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  **
  ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
  Aborted (core dumped)
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
  Aborted (core dumped)

After applying this patch:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  Parameter 'driver' expects non-abstract device type
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  Parameter 'driver' expects pluggable device type
---
 qdev-monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
qdev-monitor.c +0 -2
index a9702d8..ebfa701 100644
@@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
 
-    if (!object_class_by_name(driver)) {
-        const char *typename = find_typename_by_alias(driver);

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 243

Quoted 10 lines
qdev-monitor.c +3 -4
-
-        if (typename) {
-            driver = typename;
-        }
+    qdev_get_device_class(&driver, &local_err);
+    if (local_err) {
+        goto error;
     }
 
     prop_list = qmp_device_list_properties(driver, &local_err);

Is dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && !dc->hotpluggable) really relevant here? Or should that rather remain outside the common function in 1/3?

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device <type>, help

Quoted 47 lines · Andreas Färber

Hi Eduardo,

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 44 lines

Make sure we try to list properties from classes that can be safely used with "-device".

Fixes the following crashes:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  **
  ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
  Aborted (core dumped)
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
  Aborted (core dumped)

After applying this patch:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  Parameter 'driver' expects non-abstract device type
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  Parameter 'driver' expects pluggable device type
---
 qdev-monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
qdev-monitor.c +3 -6
index a9702d8..ebfa701 100644
@@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
 
-    if (!object_class_by_name(driver)) {
-        const char *typename = find_typename_by_alias(driver);
-
-        if (typename) {
-            driver = typename;
-        }
+    qdev_get_device_class(&driver, &local_err);
+    if (local_err) {
+        goto error;
     }
 
Quoted 5 lines

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 243

Quoted 1 line
qdev-monitor.c +0 -0
     prop_list = qmp_device_list_properties(driver, &local_err);

Is dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && !dc->hotpluggable) really relevant here? Or should that rather remain outside the common function in 1/3?

cannot_instantiate_with_device_add_yet makes sure we won't try to instantiate classes that are not device_add-safe yet (like X86CPU, that has lots of assumptions and side-effects inside instance_init()).

Signature · 1 line
Eduardo
#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device <type>, help

Am 01.11.2014 um 17:45 schrieb Eduardo Habkost:

Quoted 52 lines · Andreas Färber
Quoted 45 lines

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 44 lines

Make sure we try to list properties from classes that can be safely used with "-device".

Fixes the following crashes:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  **
  ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
  Aborted (core dumped)
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
  Aborted (core dumped)

After applying this patch:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  Parameter 'driver' expects non-abstract device type
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  Parameter 'driver' expects pluggable device type
---
 qdev-monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
qdev-monitor.c +3 -6
index a9702d8..ebfa701 100644
@@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
 
-    if (!object_class_by_name(driver)) {
-        const char *typename = find_typename_by_alias(driver);
-
-        if (typename) {
-            driver = typename;
-        }
+    qdev_get_device_class(&driver, &local_err);
+    if (local_err) {
+        goto error;
     }
 
Quoted 5 lines

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 243

Quoted 1 line
qdev-monitor.c +0 -0
     prop_list = qmp_device_list_properties(driver, &local_err);

Is dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && !dc->hotpluggable) really relevant here? Or should that rather remain outside the common function in 1/3?

Quoted 3 lines

cannot_instantiate_with_device_add_yet makes sure we won't try to instantiate classes that are not device_add-safe yet (like X86CPU, that has lots of assumptions and side-effects inside instance_init()).

Maybe I'm misunderstanding? Does this code path apply only to device_add (then you are right) or does it also apply to -device?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device <type>, help

Quoted 53 lines · Andreas Färber

Am 01.11.2014 um 17:45 schrieb Eduardo Habkost:

Quoted 52 lines · Andreas Färber
Quoted 50 lines

Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:

Quoted 35 lines

Make sure we try to list properties from classes that can be safely used with "-device".

Fixes the following crashes:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  **
  ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
  Aborted (core dumped)
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  qemu-system-x86_64: [...]/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
  Aborted (core dumped)

After applying this patch:

  $ qemu-system-x86_64 -device x86_64-cpu,help
  Parameter 'driver' expects non-abstract device type
  $ qemu-system-x86_64 -device host-x86_64-cpu,help
  Parameter 'driver' expects pluggable device type
---
 qdev-monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
qdev-monitor.c +0 -2
index a9702d8..ebfa701 100644
@@ -235,12 +235,9 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
 
-    if (!object_class_by_name(driver)) {
-        const char *typename = find_typename_by_alias(driver);

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 243

Quoted 10 lines
qdev-monitor.c +3 -4
-
-        if (typename) {
-            driver = typename;
-        }
+    qdev_get_device_class(&driver, &local_err);
+    if (local_err) {
+        goto error;
     }
 
     prop_list = qmp_device_list_properties(driver, &local_err);

Is dc->cannot_instantiate_with_device_add_yet || (qdev_hotplug && !dc->hotpluggable) really relevant here? Or should that rather remain outside the common function in 1/3?

Quoted 6 lines
Quoted 3 lines

cannot_instantiate_with_device_add_yet makes sure we won't try to instantiate classes that are not device_add-safe yet (like X86CPU, that has lots of assumptions and side-effects inside instance_init()).

Maybe I'm misunderstanding? Does this code path apply only to device_add (then you are right) or does it also apply to -device?

It applies to both -device and device_add, and both reject cannot_instantiate_with_device_add_yet classes.

The question here is whether it is safe to blindly call object_new() on the class or not. I assume that a non-hotpluggable or cannot_instantiate_with_device_add_yet class indicates it is not safe to do that.

I am being conservative because I don't know how many classes have side-effects on instance_init today. I believe the next steps could be:

1) Moving the dc->hotpluggable check to qdev_device_add(). Preferably after ensuring all (!hotpluggable && !cannot_instantiate_with_device_add_yet) classes have no side-effects on instance_init.
2) Moving the cannot_instantiate_with_device_add_yet check to qdev_device_add(). Preferably after ensuring all classes have no side-effects on instance_init.

Or we could just move directly to (1) or (2), and live with the possibility of having QEMU crashing or misbehaving when using "-device ...,help" or "device_add ...,help" with some class names.

Signature · 1 line
Eduardo
#10 lore raw
In reply to Eduardo Habkost
Quoted 11 lines · Eduardo Habkost

This fixes the following crashes:

   $ qemu-system-x86_64 -device x86_64-cpu,help
   **
   ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
   Aborted (core dumped)
   $ qemu-system-x86_64 -device host-x86_64-cpu,help
   qemu-system-x86_64: /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
   Aborted (core dumped)
Cc Stefan Hajnoczi <[email protected]>

Haven't reviewed in detail but thanks for fixing this.

#11 lore raw

Am 03.11.2014 um 16:14 schrieb Stefan Hajnoczi:

Quoted 11 lines · Eduardo Habkost
Quoted 10 lines

This fixes the following crashes:

   $ qemu-system-x86_64 -device x86_64-cpu,help
   **
   ERROR:qom/object.c:336:object_initialize_with_type: assertion failed: (type->abstract == false)
   Aborted (core dumped)
   $ qemu-system-x86_64 -device host-x86_64-cpu,help
   qemu-system-x86_64: /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:1329: host_x86_cpu_initfn: Assertion `(kvm_allowed)' failed.
   Aborted (core dumped)
Quoted 3 lines
Quoted 1 line
Cc Stefan Hajnoczi <[email protected]>

Haven't reviewed in detail but thanks for fixing this.

Thanks, applied to qom-next as is:
https://github.com/afaerber/qemu-cpu/commits/qom-next

Andreas

Signature · 2 lines
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 21284 AG Nürnberg