Skip to contentSkip to conversation

QOM: Can devices having link properties be user-creatable?

Qemu-devel Philippe Mathieu-Daudé 2 participants 4 messages Oct 12, 2018

lore
Share & tools
lore
#0 lore raw

While looking at Mao's series
(https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02519.html) I wondered if devices having link properties can be user-creatable.

Using the following patch (I don't think this is correct to put qdev code into qobject, but I used this as PoC):

-- >8 --

qom/object.c +1 -0
index 547dcf97c3..2dd3a25531 100644
@@ -16,4 +16,5 @@
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qapi/visitor.h"
 #include "qapi/string-input-visitor.h"
@@ -1662,4 +1663,11 @@ void object_property_add_link(Object *obj, const

char *name,

     gchar *full_type;
     ObjectProperty *op;

+ ObjectClass *klass = object_get_class(obj);
+
+ if (klass && object_dynamic_cast(obj, TYPE_DEVICE) &&
+ DEVICE_CLASS(klass)->user_creatable == false) {
+ warn_report("Device type '%s' is user_creatable "
+ "(linked property: '%s')", type, name);
+ }

     prop->child = child;

---

I get:

$ aarch64-softmmu/qemu-system-aarch64 -M virt
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
user_creatable (linked property: 'memory')
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'unnamed-gpio-out[0]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'unnamed-gpio-out[1]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'unnamed-gpio-out[2]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'unnamed-gpio-out[3]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'gicv3-maintenance-interrupt[0]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'pmu-interrupt[0]')
qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
user_creatable (linked property: 'secure-memory')
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'sysbus-irq[0]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'sysbus-irq[1]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'sysbus-irq[2]')
qemu-system-aarch64: warning: Device type 'irq' is user_creatable
(linked property: 'sysbus-irq[3]')

Are we incorrectly using user_creatable = true in those devices/ Am I missing something?

Thanks,

Phil.

#1 lore raw
Quoted 33 lines · Philippe Mathieu-Daudé

While looking at Mao's series
(https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02519.html) I wondered if devices having link properties can be user-creatable.

Using the following patch (I don't think this is correct to put qdev code into qobject, but I used this as PoC):

-- >8 --

qom/object.c +8 -0
index 547dcf97c3..2dd3a25531 100644
@@ -16,4 +16,5 @@
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qapi/visitor.h"
 #include "qapi/string-input-visitor.h"
@@ -1662,4 +1663,11 @@ void object_property_add_link(Object *obj, const
 char *name,
     gchar *full_type;
     ObjectProperty *op;
+    ObjectClass *klass = object_get_class(obj);
+
+    if (klass && object_dynamic_cast(obj, TYPE_DEVICE) &&
+                 DEVICE_CLASS(klass)->user_creatable == false) {
+        warn_report("Device type '%s' is user_creatable "
+                    "(linked property: '%s')", type, name);
+    }
 
     prop->child = child;

---

Quoted 7 lines

I get:

$ aarch64-softmmu/qemu-system-aarch64 -M virt
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
user_creatable (linked property: 'memory')

Is your warning printing the wrong thing? "bus", "irq", etc don't seem like names of devices...

I think whether a device with a link property is user creatable might depend on what the property is for and whether the device has a useful fallback for "link not connected".

thanks
-- PMM

#2 lore raw
Quoted 36 lines · Peter Maydell
Quoted 35 lines · Philippe Mathieu-Daudé

While looking at Mao's series
(https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02519.html) I wondered if devices having link properties can be user-creatable.

Using the following patch (I don't think this is correct to put qdev code into qobject, but I used this as PoC):

-- >8 --

qom/object.c +8 -0
index 547dcf97c3..2dd3a25531 100644
@@ -16,4 +16,5 @@
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qapi/visitor.h"
 #include "qapi/string-input-visitor.h"
@@ -1662,4 +1663,11 @@ void object_property_add_link(Object *obj, const
 char *name,
     gchar *full_type;
     ObjectProperty *op;
+    ObjectClass *klass = object_get_class(obj);
+
+    if (klass && object_dynamic_cast(obj, TYPE_DEVICE) &&
+                 DEVICE_CLASS(klass)->user_creatable == false) {
+        warn_report("Device type '%s' is user_creatable "
+                    "(linked property: '%s')", type, name);
+    }
 
     prop->child = child;

---

I get:

Quoted 8 lines
Quoted 5 lines
$ aarch64-softmmu/qemu-system-aarch64 -M virt
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
user_creatable (linked property: 'memory')

Is your warning printing the wrong thing? "bus", "irq", etc don't seem like names of devices...

Oh indeed I inverted (type, name) :)

Quoted 4 lines

I think whether a device with a link property is user creatable might depend on what the property is for and whether the device has a useful fallback for "link not connected".

OK it now makes sens, reading this example:

    static void bcm2836_realize(DeviceState *dev, Error **errp)
    {
        Object *obj;
        Error *err = NULL;

        obj = object_property_get_link(OBJECT(dev), "ram", &err);
        if (obj == NULL) {
            error_setg(errp, "%s: required ram link not found: %s",
                       __func__, error_get_pretty(err));
            return;
        }
        ...

Thanks!

Phil.

#3 lore raw
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Peter Maydell
Quoted 35 lines · Philippe Mathieu-Daudé

While looking at Mao's series
(https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02519.html) I wondered if devices having link properties can be user-creatable.

Using the following patch (I don't think this is correct to put qdev code into qobject, but I used this as PoC):

-- >8 --

qom/object.c +8 -0
index 547dcf97c3..2dd3a25531 100644
@@ -16,4 +16,5 @@
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qapi/visitor.h"
 #include "qapi/string-input-visitor.h"
@@ -1662,4 +1663,11 @@ void object_property_add_link(Object *obj, const
 char *name,
     gchar *full_type;
     ObjectProperty *op;
+    ObjectClass *klass = object_get_class(obj);
+
+    if (klass && object_dynamic_cast(obj, TYPE_DEVICE) &&
+                 DEVICE_CLASS(klass)->user_creatable == false) {
+        warn_report("Device type '%s' is user_creatable "
+                    "(linked property: '%s')", type, name);
+    }
 
     prop->child = child;

---

I get:

Quoted 8 lines
Quoted 5 lines
$ aarch64-softmmu/qemu-system-aarch64 -M virt
qemu-system-aarch64: warning: Device type 'bus' is user_creatable
(linked property: 'parent_bus')
qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
user_creatable (linked property: 'memory')

Is your warning printing the wrong thing? "bus", "irq", etc don't seem like names of devices...

Quoted 1 line

Oh indeed I inverted (type, name) :)

Yes, but also what we want to know is the type name of the object obj we're adding the link property to (that is the object which is marked user-creatable). The "type" variable here is the type of the thing being linked. So I think printing object_get_typename(obj) would be helpful.

thanks
-- PMM