Skip to contentSkip to conversation

qdev: Introduce DEFINE_PROP_LINK

PATCH In review Fam Zheng 3 participants 23 messages Jul 14, 2017 Arm/Zynq architecture

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v4 cover qdev: Introduce DEFINE_PROP_LINK

v4: Add a pointer type param to DEFINE_PROP_LINK, don't change pointer types to

    "Object *". [Paolo]

v3: Include Igor's patch, and fix virtio-crypto too.
Always use qdev_prop_allow_set_link_before_realize and OBJ_PROP_LINK_UNREF_ON_RELEASE.
Include as many applicable devices as possible and some more clean-ups. There are still more left but they use uncommon check and flags parameters, it's better to take care of them in following batches.

v2: Create a new header for link properties. [Paolo]
Don't wrap, use PropertyInfo.create() (much better diffstat, yay!). [Paolo]

Link properties of devices created with object_property_add_link() are not reflected in HMP "info qtree". For example, whether a virtio-blk device has an iothread (i.e. has enabled data plane) can not be introspected easily.

Introduce a new type of qdev property macro to fix that.

Fam Zheng (19):
qdev: Introduce PropertyInfo.create
qdev: Introduce DEFINE_PROP_LINK
qmp: Use ObjectProperty.type if present
qdev: Add const qualifier to PropertyInfo definitions
virtio-blk: Convert to DEFINE_PROP_LINK
virtio-scsi: Convert to DEFINE_PROP_LINK
virtio-rng: Convert to DEFINE_PROP_LINK
virtio-crypto: Convert to DEFINE_PROP_LINK
dimm: Convert to DEFINE_PROP_LINK
ivshmem: Convert to DEFINE_PROP_LINK
armv7m: Convert bitband.source-mamory to DEFINE_PROP_LINK
armv7m: Convert armv7m.memory to DEFINE_PROP_LINK
gicv3: Convert to DEFINE_PROP_LINK
xlnx_zynqmp: Convert to DEFINE_PROP_LINK
xilinx_axienet: Convert to DEFINE_PROP_LINK
xilinx_axidma: Convert to DEFINE_PROP_LINK
mips_cmgcr: Convert to DEFINE_PROP_LINK
cpu: Convert to DEFINE_PROP_LINK
spapr_rng: Convert to DEFINE_PROP_LINK

Igor Mammedov (1):
qom: enforce readonly nature of link's check callback

 exec.c                           | 27 +++++++++--------
 hw/arm/armv7m.c                  | 16 +++-------
 hw/arm/xlnx-zynqmp.c             |  7 ++---
 hw/block/virtio-blk.c            |  6 ++--
 hw/core/qdev-properties-system.c |  8 ++---
 hw/core/qdev-properties.c        | 63 ++++++++++++++++++++++++++--------------
 hw/core/qdev.c                   | 31 ++++++++++++--------
 hw/display/xlnx_dp.c             |  2 +-
 hw/dma/xilinx_axidma.c           | 16 +++-------
 hw/intc/arm_gicv3_its_kvm.c      | 19 +++++-------
 hw/ipmi/ipmi.c                   |  2 +-
 hw/mem/pc-dimm.c                 | 30 +++++--------------
 hw/misc/ivshmem.c                | 24 +++++----------
 hw/misc/mips_cmgcr.c             | 16 +++-------
 hw/net/xilinx_axienet.c          | 16 +++-------
 hw/ppc/spapr_rng.c               |  8 ++---
 hw/s390x/css.c                   |  4 +--
 hw/s390x/s390-pci-bus.c          |  2 +-
 hw/s390x/virtio-ccw.c            |  9 ------
 hw/scsi/virtio-scsi.c            | 13 ++-------
 hw/virtio/virtio-crypto-pci.c    |  2 --
 hw/virtio/virtio-crypto.c        | 27 +++++------------
 hw/virtio/virtio-pci.c           |  6 ----
 hw/virtio/virtio-rng.c           | 12 +-------
 include/hw/qdev-core.h           |  6 ++--
 include/hw/qdev-properties.h     | 62 ++++++++++++++++++++++-----------------
 include/hw/s390x/css.h           |  4 +--
 include/qom/cpu.h                |  1 +
 include/qom/object.h             |  6 ++--
 qmp.c                            |  5 ++--
 qom/cpu.c                        |  1 +
 qom/object.c                     |  8 ++---
 target/i386/cpu.c                |  2 +-
 target/ppc/translate_init.c      |  2 +-
 34 files changed, 193 insertions(+), 270 deletions(-)
Signature · 1 line
2.9.4
author
#1 lore raw

PATCH v4 1/20 qom: enforce readonly nature of link's check callback

From: Igor Mammedov <[email protected]>

link's check callback is supposed to verify/permit setting it, however currently nothing restricts it from misusing it and modifying target object from within.
Make sure that readonly semantics are checked by compiler to prevent callback's misuse.

---
 hw/core/qdev-properties.c    | 3 ++-
 hw/display/xlnx_dp.c         | 2 +-
 hw/ipmi/ipmi.c               | 2 +-
 hw/mem/pc-dimm.c             | 2 +-
 hw/misc/ivshmem.c            | 2 +-
 hw/virtio/virtio-crypto.c    | 2 +-
 include/hw/qdev-properties.h | 3 ++-
 include/qom/object.h         | 6 +++---
 qom/object.c                 | 8 ++++----
 9 files changed, 16 insertions(+), 14 deletions(-)
hw/core/qdev-properties.c +2 -1
index f11d578..113ce7d 100644
@@ -25,7 +25,8 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
     }
 }
 
-void qdev_prop_allow_set_link_before_realize(Object *obj, const char *name,
+void qdev_prop_allow_set_link_before_realize(const Object *obj,
+                                             const char *name,
                                              Object *val, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
hw/display/xlnx_dp.c +1 -1
index a77d7db..561f828 100644
@@ -515,7 +515,7 @@ static void xlnx_dp_aux_set_command(XlnxDPState *s, uint32_t value)
     s->core_registers[DP_INTERRUPT_SIGNAL_STATE] |= 0x04;
 }
 
-static void xlnx_dp_set_dpdma(Object *obj, const char *name, Object *val,
+static void xlnx_dp_set_dpdma(const Object *obj, const char *name, Object *val,
                               Error **errp)
 {
     XlnxDPState *s = XLNX_DP(obj);
hw/ipmi/ipmi.c +1 -1
index afafe14..b27babd 100644
@@ -90,7 +90,7 @@ static TypeInfo ipmi_interface_type_info = {
     .class_init = ipmi_interface_class_init,
 };
 
-static void isa_ipmi_bmc_check(Object *obj, const char *name,
+static void isa_ipmi_bmc_check(const Object *obj, const char *name,
                                Object *val, Error **errp)
 {
     IPMIBmc *bmc = IPMI_BMC(val);
hw/mem/pc-dimm.c +1 -1
index b72258e..5e23495 100644
@@ -367,7 +367,7 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
     visit_type_uint64(v, name, &value, errp);
 }
 
-static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
+static void pc_dimm_check_memdev_is_busy(const Object *obj, const char *name,
                                       Object *val, Error **errp)
 {
     Error *local_err = NULL;
hw/misc/ivshmem.c +1 -1
index 2f0819d..97beaf6 100644
@@ -1009,7 +1009,7 @@ static const TypeInfo ivshmem_common_info = {
     .class_init    = ivshmem_common_class_init,
 };
 
-static void ivshmem_check_memdev_is_busy(Object *obj, const char *name,
+static void ivshmem_check_memdev_is_busy(const Object *obj, const char *name,
                                          Object *val, Error **errp)
 {
     if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
hw/virtio/virtio-crypto.c +1 -1
index 0353eb6..2590893 100644
@@ -889,7 +889,7 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data)
 }
 
 static void
-virtio_crypto_check_cryptodev_is_used(Object *obj, const char *name,
+virtio_crypto_check_cryptodev_is_used(const Object *obj, const char *name,
                                       Object *val, Error **errp)
 {
     if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(val))) {
include/hw/qdev-properties.h +2 -1
index 0604c33..9edded2 100644
@@ -272,7 +272,8 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
  * This function should be used as the check() argument to
  * object_property_add_link().
  */
-void qdev_prop_allow_set_link_before_realize(Object *obj, const char *name,
+void qdev_prop_allow_set_link_before_realize(const Object *obj,
+                                             const char *name,
                                              Object *val, Error **errp);
 
 #endif
include/qom/object.h +3 -3
index abaeb8c..1b82899 100644
@@ -764,7 +764,7 @@ ObjectClass *object_get_class(Object *obj);
  *
  * Returns: The QOM typename of @obj.
  */
-const char *object_get_typename(Object *obj);
+const char *object_get_typename(const Object *obj);
 
 /**
  * type_register_static:
@@ -1319,7 +1319,7 @@ typedef enum {
  * callback function.  It allows the link property to be set and never returns
  * an error.
  */
-void object_property_allow_set_link(Object *, const char *,
+void object_property_allow_set_link(const Object *, const char *,
                                     Object *, Error **);
 
 /**
@@ -1352,7 +1352,7 @@ void object_property_allow_set_link(Object *, const char *,
  */
 void object_property_add_link(Object *obj, const char *name,
                               const char *type, Object **child,
-                              void (*check)(Object *obj, const char *name,
+                              void (*check)(const Object *obj, const char *name,
                                             Object *val, Error **errp),
                               ObjectPropertyLinkFlags flags,
                               Error **errp);
qom/object.c +4 -4
index 5f6fdfa..dfdbd50 100644
@@ -740,7 +740,7 @@ out:
     return ret;
 }
 
-const char *object_get_typename(Object *obj)
+const char *object_get_typename(const Object *obj)
 {
     return obj->class->type->name;
 }
@@ -1428,7 +1428,7 @@ out:
     g_free(type);
 }
 
-void object_property_allow_set_link(Object *obj, const char *name,
+void object_property_allow_set_link(const Object *obj, const char *name,
                                     Object *val, Error **errp)
 {
     /* Allow the link to be set, always */
@@ -1436,7 +1436,7 @@ void object_property_allow_set_link(Object *obj, const char *name,
 
 typedef struct {
     Object **child;
-    void (*check)(Object *, const char *, Object *, Error **);
+    void (*check)(const Object *, const char *, Object *, Error **);
     ObjectPropertyLinkFlags flags;
 } LinkProperty;
 
@@ -1552,7 +1552,7 @@ static void object_release_link_property(Object *obj, const char *name,
 
 void object_property_add_link(Object *obj, const char *name,
                               const char *type, Object **child,
-                              void (*check)(Object *, const char *,
+                              void (*check)(const Object *, const char *,
                                             Object *, Error **),
                               ObjectPropertyLinkFlags flags,
                               Error **errp)
Signature · 1 line
2.9.4
author
#2 lore raw

PATCH v4 2/20 qdev: Introduce PropertyInfo.create

In reply to Fam Zheng

This allows property implementation to provide a specialized property creation method.

Update conditions guarding property types accordingly.

---
 hw/core/qdev.c         | 31 +++++++++++++++++++------------
 include/hw/qdev-core.h |  1 +
 qmp.c                  |  2 +-
 3 files changed, 21 insertions(+), 13 deletions(-)
hw/core/qdev.c +19 -12
index 849952a..ec63fe0 100644
@@ -744,6 +744,10 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
         return;
     }
 
+    if (prop->info->create) {
+        return;
+    }
+
     name = g_strdup_printf("legacy-%s", prop->name);
     object_property_add(OBJECT(dev), name, "str",
                         prop->info->print ? qdev_get_legacy_property : prop->info->get,
@@ -770,20 +774,23 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
     Error *local_err = NULL;
     Object *obj = OBJECT(dev);
 
-    /*
-     * TODO qdev_prop_ptr does not have getters or setters.  It must
-     * go now that it can be replaced with links.  The test should be
-     * removed along with it: all static properties are read/write.
-     */
-    if (!prop->info->get && !prop->info->set) {
-        return;
+    if (prop->info->create) {
+        prop->info->create(obj, prop, &local_err);
+    } else {
+        /*
+         * TODO qdev_prop_ptr does not have getters or setters.  It must
+         * go now that it can be replaced with links.  The test should be
+         * removed along with it: all static properties are read/write.
+         */
+        if (!prop->info->get && !prop->info->set) {
+            return;
+        }
+        object_property_add(obj, prop->name, prop->info->name,
+                            prop->info->get, prop->info->set,
+                            prop->info->release,
+                            prop, &local_err);
     }
 
-    object_property_add(obj, prop->name, prop->info->name,
-                        prop->info->get, prop->info->set,
-                        prop->info->release,
-                        prop, &local_err);
-
     if (local_err) {
         error_propagate(errp, local_err);
         return;
include/hw/qdev-core.h +1 -0
index 9d7c1c0..33518ee 100644
@@ -241,6 +241,7 @@ struct PropertyInfo {
     const char * const *enum_table;
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
     void (*set_default_value)(Object *obj, const Property *prop);
+    void (*create)(Object *obj, Property *prop, Error **errp);
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
     ObjectPropertyRelease *release;
qmp.c +1 -1
index 7ee9bcf..133fdfc 100644
@@ -490,7 +490,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
              * for removal.  This conditional should be removed along with
              * it.
              */
-            if (!prop->info->set) {
+            if (!prop->info->set && !prop->info->create) {
                 return NULL;           /* no way to set it, don't show */
             }
 
Signature · 1 line
2.9.4
author
#3 lore raw

PATCH v4 3/20 qdev: Introduce DEFINE_PROP_LINK

In reply to Fam Zheng

This property can be used to replace the object_property_add_link in device code, to add a link to other objects, which is a common pattern.

---
 hw/core/qdev-properties.c    | 18 ++++++++++++++++++
 include/hw/qdev-core.h       |  1 +
 include/hw/qdev-properties.h |  9 +++++++++
 3 files changed, 28 insertions(+)
hw/core/qdev-properties.c +18 -0
index 113ce7d..5429c63 100644
@@ -1214,3 +1214,21 @@ PropertyInfo qdev_prop_size = {
     .set = set_size,
     .set_default_value = set_default_value_uint,
 };
+
+/* --- object link property --- */
+
+static void create_link_property(Object *obj, Property *prop, Error **errp)
+{
+    Object **child = qdev_get_prop_ptr(DEVICE(obj), prop);
+
+    object_property_add_link(obj, prop->name, prop->link_type,
+                             child,
+                             qdev_prop_allow_set_link_before_realize,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
+                             errp);
+}
+
+PropertyInfo qdev_prop_link = {
+    .name = "link",
+    .create = create_link_property,
+};
include/hw/qdev-core.h +1 -0
index 33518ee..08d1d2c 100644
@@ -233,6 +233,7 @@ struct Property {
     int          arrayoffset;
     PropertyInfo *arrayinfo;
     int          arrayfieldsize;
+    const char   *link_type;
 };
 
 struct PropertyInfo {
include/hw/qdev-properties.h +9 -0
index 9edded2..876ba2e 100644
@@ -30,6 +30,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 extern PropertyInfo qdev_prop_blocksize;
 extern PropertyInfo qdev_prop_pci_host_devaddr;
 extern PropertyInfo qdev_prop_arraylen;
+extern PropertyInfo qdev_prop_link;
 
 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
         .name      = (_name),                                    \
@@ -117,6 +118,14 @@ extern PropertyInfo qdev_prop_arraylen;
         .arrayoffset = offsetof(_state, _arrayfield),                   \
         }
 
+#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) {     \
+        .name = (_name),                                                \
+        .info = &(qdev_prop_link),                                      \
+        .offset = offsetof(_state, _field)                              \
+            + type_check(_ptr_type, typeof_field(_state, _field)),      \
+        .link_type  = _type,                                            \
+        }
+
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
     DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
Signature · 1 line
2.9.4
author
#4 lore raw

PATCH v4 4/20 qmp: Use ObjectProperty.type if present

In reply to Fam Zheng

The dynamic value is more informative in the case of link property, otherwise it is the same.

---
 qmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qmp.c +2 -1
index 133fdfc..9f8a167 100644
@@ -496,7 +496,8 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
 
             info = g_malloc0(sizeof(*info));
             info->name = g_strdup(prop->name);
-            info->type = g_strdup(prop->info->name);
+            info->type = default_type ? g_strdup(default_type)
+                                      : g_strdup(prop->info->name);
             info->has_description = !!prop->info->description;
             info->description = g_strdup(prop->info->description);
             return info;
Signature · 1 line
2.9.4
author
#5 lore raw

PATCH v4 5/20 qdev: Add const qualifier to PropertyInfo definitions

In reply to Fam Zheng

The remaining non-const ones are in e1000e which modifies description at runtime. They can be addressed separatedly.

---
 hw/core/qdev-properties-system.c |  8 +++----
 hw/core/qdev-properties.c        | 44 +++++++++++++++++-----------------
 hw/s390x/css.c                   |  4 ++--
 hw/s390x/s390-pci-bus.c          |  2 +-
 include/hw/qdev-core.h           |  4 ++--
 include/hw/qdev-properties.h     | 52 ++++++++++++++++++++--------------------
 include/hw/s390x/css.h           |  4 ++--
 target/i386/cpu.c                |  2 +-
 target/ppc/translate_init.c      |  2 +-
 9 files changed, 61 insertions(+), 61 deletions(-)
hw/core/qdev-properties-system.c +4 -4
index 3bef419..ec10da7 100644
@@ -159,7 +159,7 @@ static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
     set_pointer(obj, v, opaque, parse_drive, name, errp);
 }
 
-PropertyInfo qdev_prop_drive = {
+const PropertyInfo qdev_prop_drive = {
     .name  = "str",
     .description = "Node name or ID of a block device to use as a backend",
     .get   = get_drive,
@@ -228,7 +228,7 @@ static void release_chr(Object *obj, const char *name, void *opaque)
     qemu_chr_fe_deinit(be, false);
 }
 
-PropertyInfo qdev_prop_chr = {
+const PropertyInfo qdev_prop_chr = {
     .name  = "str",
     .description = "ID of a chardev to use as a backend",
     .get   = get_chr,
@@ -313,7 +313,7 @@ out:
     g_free(str);
 }
 
-PropertyInfo qdev_prop_netdev = {
+const PropertyInfo qdev_prop_netdev = {
     .name  = "str",
     .description = "ID of a netdev to use as a backend",
     .get   = get_netdev,
@@ -393,7 +393,7 @@ static void set_vlan(Object *obj, Visitor *v, const char *name, void *opaque,
     *ptr = hubport;
 }
 
-PropertyInfo qdev_prop_vlan = {
+const PropertyInfo qdev_prop_vlan = {
     .name  = "int32",
     .description = "Integer VLAN id to connect to",
     .print = print_vlan,
hw/core/qdev-properties.c +22 -22

176 lines not on this page · raw message

hw/s390x/css.c +2 -2
index d67fffa..cd0b776 100644
@@ -2095,7 +2095,7 @@ out:
     g_free(str);
 }
 
-PropertyInfo css_devid_propinfo = {
+const PropertyInfo css_devid_propinfo = {
     .name = "str",
     .description = "Identifier of an I/O device in the channel "
                    "subsystem, example: fe.1.23ab",
@@ -2103,7 +2103,7 @@ PropertyInfo css_devid_propinfo = {
     .set = set_css_devid,
 };
 
-PropertyInfo css_devid_ro_propinfo = {
+const PropertyInfo css_devid_ro_propinfo = {
     .name = "str",
     .description = "Read-only identifier of an I/O device in the channel "
                    "subsystem, example: fe.1.23ab",
hw/s390x/s390-pci-bus.c +1 -1
index 5651483..061e0c6 100644
@@ -1018,7 +1018,7 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
     zpci->fid_defined = true;
 }
 
-static PropertyInfo s390_pci_fid_propinfo = {
+static const PropertyInfo s390_pci_fid_propinfo = {
     .name = "zpci_fid",
     .get = s390_pci_get_fid,
     .set = s390_pci_set_fid,
include/hw/qdev-core.h +2 -2
index 08d1d2c..5348815 100644
@@ -223,7 +223,7 @@ struct BusState {
 
 struct Property {
     const char   *name;
-    PropertyInfo *info;
+    const PropertyInfo *info;
     ptrdiff_t    offset;
     uint8_t      bitnr;
     union {
@@ -231,7 +231,7 @@ struct Property {
         uint64_t u;
     } defval;
     int          arrayoffset;
-    PropertyInfo *arrayinfo;
+    const PropertyInfo *arrayinfo;
     int          arrayfieldsize;
     const char   *link_type;
 };
include/hw/qdev-properties.h +26 -26

58 lines not on this page · raw message

include/hw/s390x/css.h +2 -2
index eb0e26f..dc1001b 100644
@@ -112,7 +112,7 @@ typedef struct CssDevId {
     bool valid;
 } CssDevId;
 
-extern PropertyInfo css_devid_propinfo;
+extern const PropertyInfo css_devid_propinfo;
 
 #define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
@@ -196,7 +196,7 @@ int css_do_rchp(uint8_t cssid, uint8_t chpid);
 bool css_present(uint8_t cssid);
 #endif
 
-extern PropertyInfo css_devid_ro_propinfo;
+extern const PropertyInfo css_devid_ro_propinfo;
 
 #define DEFINE_PROP_CSS_DEV_ID_RO(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, css_devid_ro_propinfo, CssDevId)
target/i386/cpu.c +1 -1
index c571772..1b089c5 100644
@@ -1961,7 +1961,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, const char *name,
     cpu->hyperv_spinlock_attempts = value;
 }
 
-static PropertyInfo qdev_prop_spinlocks = {
+static const PropertyInfo qdev_prop_spinlocks = {
     .name  = "int",
     .get   = x86_get_hv_spinlocks,
     .set   = x86_set_hv_spinlocks,
target/ppc/translate_init.c +1 -1
index 783bf98..ae25faf 100644
@@ -8435,7 +8435,7 @@ static void getset_compat_deprecated(Object *obj, Visitor *v, const char *name,
     visit_type_null(v, name, NULL);
 }
 
-static PropertyInfo ppc_compat_deprecated_propinfo = {
+static const PropertyInfo ppc_compat_deprecated_propinfo = {
     .name = "str",
     .description = "compatibility mode (deprecated)",
     .get = getset_compat_deprecated,
Signature · 1 line
2.9.4
author
#6 lore raw

PATCH v4 6/20 virtio-blk: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/block/virtio-blk.c  | 6 ++----
 hw/s390x/virtio-ccw.c  | 2 --
 hw/virtio/virtio-pci.c | 2 --
 3 files changed, 2 insertions(+), 8 deletions(-)
hw/block/virtio-blk.c +2 -4
index c0bd247..b750bd8 100644
@@ -983,10 +983,6 @@ static void virtio_blk_instance_init(Object *obj)
 {
     VirtIOBlock *s = VIRTIO_BLK(obj);
 
-    object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
-                             (Object **)&s->conf.iothread,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
     device_add_bootindex_property(obj, &s->conf.conf.bootindex,
                                   "bootindex", "/disk@0,0",
                                   DEVICE(obj), NULL);
@@ -1014,6 +1010,8 @@ static Property virtio_blk_properties[] = {
     DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0,
                     true),
     DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1),
+    DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
+                     IOThread *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/s390x/virtio-ccw.c +0 -2
index e18fd26..a0437d1 100644
@@ -867,8 +867,6 @@ static void virtio_ccw_blk_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_BLK);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
-                              &error_abort);
     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
                               "bootindex", &error_abort);
 }
hw/virtio/virtio-pci.c +0 -2
index 93480a7..94f72f3 100644
@@ -2000,8 +2000,6 @@ static void virtio_blk_pci_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_BLK);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
-                              &error_abort);
     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
                               "bootindex", &error_abort);
 }
Signature · 1 line
2.9.4
author
#7 lore raw

PATCH v4 7/20 virtio-scsi: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/s390x/virtio-ccw.c  |  2 --
 hw/scsi/virtio-scsi.c  | 13 ++-----------
 hw/virtio/virtio-pci.c |  2 --
 3 files changed, 2 insertions(+), 15 deletions(-)
hw/s390x/virtio-ccw.c +0 -2
index a0437d1..c5e0606 100644
@@ -950,8 +950,6 @@ static void virtio_ccw_scsi_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_SCSI);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
-                              &error_abort);
 }
 
 #ifdef CONFIG_VHOST_SCSI
hw/scsi/virtio-scsi.c +2 -11
index d076fe7..eb63944 100644
@@ -898,16 +898,6 @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
     virtio_scsi_dataplane_setup(s, errp);
 }
 
-static void virtio_scsi_instance_init(Object *obj)
-{
-    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(obj);
-
-    object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
-                             (Object **)&vs->conf.iothread,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
-}
-
 void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -935,6 +925,8 @@ static Property virtio_scsi_properties[] = {
                                            VIRTIO_SCSI_F_HOTPLUG, true),
     DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features,
                                                 VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_PROP_LINK("iothread", VirtIOSCSI, parent_obj.conf.iothread,
+                     TYPE_IOTHREAD, IOThread *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -989,7 +981,6 @@ static const TypeInfo virtio_scsi_info = {
     .name = TYPE_VIRTIO_SCSI,
     .parent = TYPE_VIRTIO_SCSI_COMMON,
     .instance_size = sizeof(VirtIOSCSI),
-    .instance_init = virtio_scsi_instance_init,
     .class_init = virtio_scsi_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
hw/virtio/virtio-pci.c +0 -2
index 94f72f3..cc69fe3 100644
@@ -2069,8 +2069,6 @@ static void virtio_scsi_pci_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_SCSI);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
-                              &error_abort);
 }
 
 static const TypeInfo virtio_scsi_pci_info = {
Signature · 1 line
2.9.4
author
#8 lore raw

PATCH v4 8/20 virtio-rng: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/s390x/virtio-ccw.c  |  2 --
 hw/virtio/virtio-pci.c |  2 --
 hw/virtio/virtio-rng.c | 12 +-----------
 3 files changed, 1 insertion(+), 15 deletions(-)
hw/s390x/virtio-ccw.c +0 -2
index c5e0606..a492d0f 100644
@@ -1548,8 +1548,6 @@ static void virtio_ccw_rng_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
-                              "rng", &error_abort);
 }
 
 static Property virtio_ccw_rng_properties[] = {
hw/virtio/virtio-pci.c +0 -2
index cc69fe3..5d14bd6 100644
@@ -2463,8 +2463,6 @@ static void virtio_rng_initfn(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng",
-                              &error_abort);
 }
 
 static const TypeInfo virtio_rng_pci_info = {
hw/virtio/virtio-rng.c +1 -11
index a6ee501..289bbca 100644
@@ -246,6 +246,7 @@ static Property virtio_rng_properties[] = {
      */
     DEFINE_PROP_UINT64("max-bytes", VirtIORNG, conf.max_bytes, INT64_MAX),
     DEFINE_PROP_UINT32("period", VirtIORNG, conf.period_ms, 1 << 16),
+    DEFINE_PROP_LINK("rng", VirtIORNG, conf.rng, TYPE_RNG_BACKEND, RngBackend *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -262,21 +263,10 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data)
     vdc->get_features = get_features;
 }
 
-static void virtio_rng_initfn(Object *obj)
-{
-    VirtIORNG *vrng = VIRTIO_RNG(obj);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&vrng->conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
-}
-
 static const TypeInfo virtio_rng_info = {
     .name = TYPE_VIRTIO_RNG,
     .parent = TYPE_VIRTIO_DEVICE,
     .instance_size = sizeof(VirtIORNG),
-    .instance_init = virtio_rng_initfn,
     .class_init = virtio_rng_class_init,
 };
 
Signature · 1 line
2.9.4
author
#9 lore raw

PATCH v4 9/20 virtio-crypto: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng

Unlike other object_property_add_link() occurrences in virtio devices, virtio-crypto checks the "in use" state of the linked backend object in addition to qdev_prop_allow_set_link_before_realize. To convert it without needing to specialize DEFINE_PROP_LINK which always uses the qdev callback, move the "in use" check to device realize time.

---
 hw/s390x/virtio-ccw.c         |  3 ---
 hw/virtio/virtio-crypto-pci.c |  2 --
 hw/virtio/virtio-crypto.c     | 27 +++++++--------------------
 3 files changed, 7 insertions(+), 25 deletions(-)
hw/s390x/virtio-ccw.c +0 -3
index a492d0f..c07ddb1 100644
@@ -1594,9 +1594,6 @@ static void virtio_ccw_crypto_instance_init(Object *obj)
     ccw_dev->force_revision_1 = true;
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_CRYPTO);
-
-    object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
-                              "cryptodev", &error_abort);
 }
 
 static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
hw/virtio/virtio-crypto-pci.c +0 -2
index 422aca3..bf64996 100644
@@ -62,8 +62,6 @@ static void virtio_crypto_initfn(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_CRYPTO);
-    object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
-                              "cryptodev", &error_abort);
 }
 
 static const TypeInfo virtio_crypto_pci_info = {
hw/virtio/virtio-crypto.c +7 -20
index 2590893..19c82e0 100644
@@ -781,6 +781,11 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
     if (vcrypto->cryptodev == NULL) {
         error_setg(errp, "'cryptodev' parameter expects a valid object");
         return;
+    } else if (cryptodev_backend_is_used(vcrypto->cryptodev)) {
+        char *path = object_get_canonical_path_component(OBJECT(vcrypto->conf.cryptodev));
+        error_setg(errp, "can't use already used cryptodev backend: %s", path);
+        g_free(path);
+        return;
     }
 
     vcrypto->max_queues = MAX(vcrypto->cryptodev->conf.peers.queues, 1);
@@ -845,6 +850,8 @@ static const VMStateDescription vmstate_virtio_crypto = {
 };
 
 static Property virtio_crypto_properties[] = {
+    DEFINE_PROP_LINK("cryptodev", VirtIOCrypto, conf.cryptodev,
+                     TYPE_CRYPTODEV_BACKEND, CryptoDevBackend *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -888,20 +895,6 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data)
     vdc->reset = virtio_crypto_reset;
 }
 
-static void
-virtio_crypto_check_cryptodev_is_used(const Object *obj, const char *name,
-                                      Object *val, Error **errp)
-{
-    if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(val))) {
-        char *path = object_get_canonical_path_component(val);
-        error_setg(errp,
-            "can't use already used cryptodev backend: %s", path);
-        g_free(path);
-    } else {
-        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
-    }
-}
-
 static void virtio_crypto_instance_init(Object *obj)
 {
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj);
@@ -911,12 +904,6 @@ static void virtio_crypto_instance_init(Object *obj)
      * Can be overriden with virtio_crypto_set_config_size.
      */
     vcrypto->config_size = sizeof(struct virtio_crypto_config);
-
-    object_property_add_link(obj, "cryptodev",
-                             TYPE_CRYPTODEV_BACKEND,
-                             (Object **)&vcrypto->conf.cryptodev,
-                             virtio_crypto_check_cryptodev_is_used,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
 }
 
 static const TypeInfo virtio_crypto_info = {
Signature · 1 line
2.9.4
author
#10 lore raw

PATCH v4 10/20 dimm: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng

Unlike the usual object_property_add_link() invocations in other devices, dimm checks the "is mapped" state of the backend in addition to qdev_prop_allow_set_link_before_realize. To convert it without specializing DEFINE_PROP_LINK which always uses the qdev general check callback, move the extra check to device realize time.

---
 hw/mem/pc-dimm.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)
hw/mem/pc-dimm.c +7 -23
index 5e23495..ea67b46 100644
@@ -350,6 +350,8 @@ static Property pc_dimm_properties[] = {
     DEFINE_PROP_UINT32(PC_DIMM_NODE_PROP, PCDIMMDevice, node, 0),
     DEFINE_PROP_INT32(PC_DIMM_SLOT_PROP, PCDIMMDevice, slot,
                       PC_DIMM_UNASSIGNED_SLOT),
+    DEFINE_PROP_LINK(PC_DIMM_MEMDEV_PROP, PCDIMMDevice, hostmem,
+                     TYPE_MEMORY_BACKEND, HostMemoryBackend *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -367,33 +369,10 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
     visit_type_uint64(v, name, &value, errp);
 }
 
-static void pc_dimm_check_memdev_is_busy(const Object *obj, const char *name,
-                                      Object *val, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
-        char *path = object_get_canonical_path_component(val);
-        error_setg(&local_err, "can't use already busy memdev: %s", path);
-        g_free(path);
-    } else {
-        qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err);
-    }
-
-    error_propagate(errp, local_err);
-}
-
 static void pc_dimm_init(Object *obj)
 {
-    PCDIMMDevice *dimm = PC_DIMM(obj);
-
     object_property_add(obj, PC_DIMM_SIZE_PROP, "uint64", pc_dimm_get_size,
                         NULL, NULL, NULL, &error_abort);
-    object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND,
-                             (Object **)&dimm->hostmem,
-                             pc_dimm_check_memdev_is_busy,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
 }
 
 static void pc_dimm_realize(DeviceState *dev, Error **errp)
@@ -404,6 +383,11 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
     if (!dimm->hostmem) {
         error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
         return;
+    } else if (host_memory_backend_is_mapped(dimm->hostmem)) {
+        char *path = object_get_canonical_path_component(OBJECT(dimm->hostmem));
+        error_setg(errp, "can't use already busy memdev: %s", path);
+        g_free(path);
+        return;
     }
     if (((nb_numa_nodes > 0) && (dimm->node >= nb_numa_nodes)) ||
         (!nb_numa_nodes && dimm->node)) {
Signature · 1 line
2.9.4
author
#11 lore raw

PATCH v4 11/20 ivshmem: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng

Unlike the usual object_property_add_link() invocations in other devices, ivshmem checks the "is mapped" state of the backend in addition to qdev_prop_allow_set_link_before_realize. To convert it without specializing DEFINE_PROP_LINK which always uses the qdev callback, move the extra check to device realize time.

---
 hw/misc/ivshmem.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
hw/misc/ivshmem.c +7 -17
index 97beaf6..4b38248 100644
@@ -1009,18 +1009,6 @@ static const TypeInfo ivshmem_common_info = {
     .class_init    = ivshmem_common_class_init,
 };
 
-static void ivshmem_check_memdev_is_busy(const Object *obj, const char *name,
-                                         Object *val, Error **errp)
-{
-    if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
-        char *path = object_get_canonical_path_component(val);
-        error_setg(errp, "can't use already busy memdev: %s", path);
-        g_free(path);
-    } else {
-        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
-    }
-}
-
 static const VMStateDescription ivshmem_plain_vmsd = {
     .name = TYPE_IVSHMEM_PLAIN,
     .version_id = 0,
@@ -1037,6 +1025,8 @@ static const VMStateDescription ivshmem_plain_vmsd = {
 
 static Property ivshmem_plain_properties[] = {
     DEFINE_PROP_ON_OFF_AUTO("master", IVShmemState, master, ON_OFF_AUTO_OFF),
+    DEFINE_PROP_LINK("memdev", IVShmemState, hostmem, TYPE_MEMORY_BACKEND,
+                     HostMemoryBackend *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -1044,11 +1034,6 @@ static void ivshmem_plain_init(Object *obj)
 {
     IVShmemState *s = IVSHMEM_PLAIN(obj);
 
-    object_property_add_link(obj, "memdev", TYPE_MEMORY_BACKEND,
-                             (Object **)&s->hostmem,
-                             ivshmem_check_memdev_is_busy,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
     s->not_legacy_32bit = 1;
 }
 
@@ -1059,6 +1044,11 @@ static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
     if (!s->hostmem) {
         error_setg(errp, "You must specify a 'memdev'");
         return;
+    } else if (host_memory_backend_is_mapped(s->hostmem)) {
+        char *path = object_get_canonical_path_component(OBJECT(s->hostmem));
+        error_setg(errp, "can't use already busy memdev: %s", path);
+        g_free(path);
+        return;
     }
 
     ivshmem_common_realize(dev, errp);
Signature · 1 line
2.9.4
author
#12 lore raw

PATCH v4 12/20 armv7m: Convert bitband.source-mamory to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/arm/armv7m.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/arm/armv7m.c +2 -6
index c8a11f2..8efc4e8 100644
@@ -97,12 +97,6 @@ static void bitband_init(Object *obj)
     BitBandState *s = BITBAND(obj);
     SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
-    object_property_add_link(obj, "source-memory",
-                             TYPE_MEMORY_REGION,
-                             (Object **)&s->source_memory,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
     memory_region_init_io(&s->iomem, obj, &bitband_ops, s,
                           "bitband", 0x02000000);
     sysbus_init_mmio(dev, &s->iomem);
@@ -349,6 +343,8 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
 
 static Property bitband_properties[] = {
     DEFINE_PROP_UINT32("base", BitBandState, base, 0),
+    DEFINE_PROP_LINK("source-memory", BitBandState, source_memory,
+                     TYPE_MEMORY_REGION, MemoryRegion *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
author
#13 lore raw

PATCH v4 13/20 armv7m: Convert armv7m.memory to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/arm/armv7m.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/arm/armv7m.c +2 -6
index 8efc4e8..1c837da 100644
@@ -132,12 +132,6 @@ static void armv7m_instance_init(Object *obj)
 
     /* Can't init the cpu here, we don't yet know which model to use */
 
-    object_property_add_link(obj, "memory",
-                             TYPE_MEMORY_REGION,
-                             (Object **)&s->board_memory,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
     memory_region_init(&s->container, obj, "armv7m-container", UINT64_MAX);
 
     object_initialize(&s->nvic, sizeof(s->nvic), "armv7m_nvic");
@@ -248,6 +242,8 @@ static void armv7m_realize(DeviceState *dev, Error **errp)
 
 static Property armv7m_properties[] = {
     DEFINE_PROP_STRING("cpu-model", ARMv7MState, cpu_model),
+    DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
author
#14 lore raw

PATCH v4 14/20 gicv3: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/intc/arm_gicv3_its_kvm.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
hw/intc/arm_gicv3_its_kvm.c +7 -12
index 1f8991b..39903d5 100644
@@ -120,17 +120,6 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
     qemu_add_vm_change_state_handler(vm_change_state_handler, s);
 }
 
-static void kvm_arm_its_init(Object *obj)
-{
-    GICv3ITSState *s = KVM_ARM_ITS(obj);
-
-    object_property_add_link(obj, "parent-gicv3",
-                             "kvm-arm-gicv3", (Object **)&s->gicv3,
-                             object_property_allow_set_link,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-}
-
 /**
  * kvm_arm_its_pre_save - handles the saving of ITS registers.
  * ITS tables are flushed into guest RAM separately and earlier,
@@ -205,12 +194,19 @@ static void kvm_arm_its_post_load(GICv3ITSState *s)
                       GITS_CTLR, &s->ctlr, true, &error_abort);
 }
 
+static Property kvm_arm_its_props[] = {
+    DEFINE_PROP_LINK("parent-gicv3", GICv3ITSState, gicv3, "kvm-arm-gicv3",
+                     GICv3State *),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void kvm_arm_its_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     GICv3ITSCommonClass *icc = ARM_GICV3_ITS_COMMON_CLASS(klass);
 
     dc->realize = kvm_arm_its_realize;
+    dc->props   = kvm_arm_its_props;
     icc->send_msi = kvm_its_send_msi;
     icc->pre_save = kvm_arm_its_pre_save;
     icc->post_load = kvm_arm_its_post_load;
@@ -220,7 +216,6 @@ static const TypeInfo kvm_arm_its_info = {
     .name = TYPE_KVM_ARM_ITS,
     .parent = TYPE_ARM_GICV3_ITS_COMMON,
     .instance_size = sizeof(GICv3ITSState),
-    .instance_init = kvm_arm_its_init,
     .class_init = kvm_arm_its_class_init,
 };
 
Signature · 1 line
2.9.4
author
#15 lore raw

PATCH v4 15/20 xlnx_zynqmp: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/arm/xlnx-zynqmp.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/arm/xlnx-zynqmp.c +2 -5
index 64f52f8..cd8a4aa 100644
@@ -140,11 +140,6 @@ static void xlnx_zynqmp_init(Object *obj)
                                   &error_abort);
     }
 
-    object_property_add_link(obj, "ddr-ram", TYPE_MEMORY_REGION,
-                             (Object **)&s->ddr_ram,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
-
     object_initialize(&s->gic, sizeof(s->gic), gic_class_name());
     qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
 
@@ -434,6 +429,8 @@ static Property xlnx_zynqmp_props[] = {
     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
     DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
     DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
+    DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
     DEFINE_PROP_END_OF_LIST()
 };
 
Signature · 1 line
2.9.4
author
#16 lore raw

PATCH v4 16/20 xilinx_axienet: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/net/xilinx_axienet.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
hw/net/xilinx_axienet.c +4 -12
index b670184..05344b4 100644
@@ -991,18 +991,6 @@ static void xilinx_enet_init(Object *obj)
     XilinxAXIEnet *s = XILINX_AXI_ENET(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-    object_property_add_link(obj, "axistream-connected", TYPE_STREAM_SLAVE,
-                             (Object **) &s->tx_data_dev,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-    object_property_add_link(obj, "axistream-control-connected",
-                             TYPE_STREAM_SLAVE,
-                             (Object **) &s->tx_control_dev,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-
     object_initialize(&s->rx_data_dev, sizeof(s->rx_data_dev),
                       TYPE_XILINX_AXI_ENET_DATA_STREAM);
     object_initialize(&s->rx_control_dev, sizeof(s->rx_control_dev),
@@ -1023,6 +1011,10 @@ static Property xilinx_enet_properties[] = {
     DEFINE_PROP_UINT32("rxmem", XilinxAXIEnet, c_rxmem, 0x1000),
     DEFINE_PROP_UINT32("txmem", XilinxAXIEnet, c_txmem, 0x1000),
     DEFINE_NIC_PROPERTIES(XilinxAXIEnet, conf),
+    DEFINE_PROP_LINK("axistream-connected", XilinxAXIEnet,
+                     tx_data_dev, TYPE_STREAM_SLAVE, StreamSlave *),
+    DEFINE_PROP_LINK("axistream-control-connected", XilinxAXIEnet,
+                     tx_control_dev, TYPE_STREAM_SLAVE, StreamSlave *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
author
#17 lore raw

PATCH v4 17/20 xilinx_axidma: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/dma/xilinx_axidma.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
hw/dma/xilinx_axidma.c +4 -12
index 6065689..4f68f50 100644
@@ -564,18 +564,6 @@ static void xilinx_axidma_init(Object *obj)
     XilinxAXIDMA *s = XILINX_AXI_DMA(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-    object_property_add_link(obj, "axistream-connected", TYPE_STREAM_SLAVE,
-                             (Object **)&s->tx_data_dev,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-    object_property_add_link(obj, "axistream-control-connected",
-                             TYPE_STREAM_SLAVE,
-                             (Object **)&s->tx_control_dev,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-
     object_initialize(&s->rx_data_dev, sizeof(s->rx_data_dev),
                       TYPE_XILINX_AXI_DMA_DATA_STREAM);
     object_initialize(&s->rx_control_dev, sizeof(s->rx_control_dev),
@@ -595,6 +583,10 @@ static void xilinx_axidma_init(Object *obj)
 
 static Property axidma_properties[] = {
     DEFINE_PROP_UINT32("freqhz", XilinxAXIDMA, freqhz, 50000000),
+    DEFINE_PROP_LINK("axistream-connected", XilinxAXIDMA,
+                     tx_data_dev, TYPE_STREAM_SLAVE, StreamSlave *),
+    DEFINE_PROP_LINK("axistream-control-connected", XilinxAXIDMA,
+                     tx_control_dev, TYPE_STREAM_SLAVE, StreamSlave *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
author
#18 lore raw

PATCH v4 18/20 mips_cmgcr: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/misc/mips_cmgcr.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
hw/misc/mips_cmgcr.c +4 -12
index a1edb53..211f609 100644
@@ -181,18 +181,6 @@ static void mips_gcr_init(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     MIPSGCRState *s = MIPS_GCR(obj);
 
-    object_property_add_link(obj, "gic", TYPE_MEMORY_REGION,
-                             (Object **)&s->gic_mr,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-
-    object_property_add_link(obj, "cpc", TYPE_MEMORY_REGION,
-                             (Object **)&s->cpc_mr,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
-
     memory_region_init_io(&s->iomem, OBJECT(s), &gcr_ops, s,
                           "mips-gcr", GCR_ADDRSPACE_SZ);
     sysbus_init_mmio(sbd, &s->iomem);
@@ -227,6 +215,10 @@ static Property mips_gcr_properties[] = {
     DEFINE_PROP_INT32("num-vp", MIPSGCRState, num_vps, 1),
     DEFINE_PROP_INT32("gcr-rev", MIPSGCRState, gcr_rev, 0x800),
     DEFINE_PROP_UINT64("gcr-base", MIPSGCRState, gcr_base, GCR_BASE_ADDR),
+    DEFINE_PROP_LINK("gic", MIPSGCRState, gic_mr, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
+    DEFINE_PROP_LINK("cpc", MIPSGCRState, cpc_mr, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
author
#19 lore raw

PATCH v4 19/20 cpu: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 exec.c            | 27 +++++++++++++++------------
 include/qom/cpu.h |  1 +
 qom/cpu.c         |  1 +
 3 files changed, 17 insertions(+), 12 deletions(-)
exec.c +15 -12
index a083ff8..385c2d0 100644
@@ -27,6 +27,7 @@
 #include "exec/target_page.h"
 #include "tcg.h"
 #include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
 #if !defined(CONFIG_USER_ONLY)
 #include "hw/boards.h"
 #include "hw/xen/xen.h"
@@ -735,6 +736,20 @@ void cpu_exec_unrealizefn(CPUState *cpu)
     }
 }
 
+Property cpu_common_props[] = {
+#ifndef CONFIG_USER_ONLY
+    /* Create a memory property for softmmu CPU object,
+     * so users can wire up its memory. (This can't go in qom/cpu.c
+     * because that file is compiled only once for both user-mode
+     * and system builds.) The default if no link is set up is to use
+     * the system address space.
+     */
+    DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
+#endif
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 void cpu_exec_initfn(CPUState *cpu)
 {
     cpu->as = NULL;
@@ -742,18 +757,6 @@ void cpu_exec_initfn(CPUState *cpu)
 
 #ifndef CONFIG_USER_ONLY
     cpu->thread_id = qemu_get_thread_id();
-
-    /* This is a softmmu CPU object, so create a property for it
-     * so users can wire up its memory. (This can't go in qom/cpu.c
-     * because that file is compiled only once for both user-mode
-     * and system builds.) The default if no link is set up is to use
-     * the system address space.
-     */
-    object_property_add_link(OBJECT(cpu), "memory", TYPE_MEMORY_REGION,
-                             (Object **)&cpu->memory,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
-                             &error_abort);
     cpu->memory = system_memory;
     object_ref(OBJECT(cpu->memory));
 #endif
include/qom/cpu.h +1 -0
index 7bfd50c..e456cef 100644
@@ -1015,6 +1015,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
 
 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
+extern Property cpu_common_props[];
 void cpu_exec_initfn(CPUState *cpu);
 void cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
qom/cpu.c +1 -0
index 8757f03..a39ff6c 100644
@@ -458,6 +458,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_CPU, dc->categories);
     dc->realize = cpu_common_realizefn;
     dc->unrealize = cpu_common_unrealizefn;
+    dc->props = cpu_common_props;
     /*
      * Reason: CPUs still need special care by board code: wiring up
      * IRQs, adding reset handlers, halting non-first CPUs, ...
Signature · 1 line
2.9.4
author
#20 lore raw

PATCH v4 20/20 spapr_rng: Convert to DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/ppc/spapr_rng.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/ppc/spapr_rng.c +2 -6
index 80515eb..d2acd61 100644
@@ -96,17 +96,11 @@ static target_ulong h_random(PowerPCCPU *cpu, sPAPRMachineState *spapr,
 
 static void spapr_rng_instance_init(Object *obj)
 {
-    sPAPRRngState *rngstate = SPAPR_RNG(obj);
-
     if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL) != NULL) {
         error_report("spapr-rng can not be instantiated twice!");
         return;
     }
 
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&rngstate->backend,
-                             object_property_allow_set_link,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
     object_property_set_description(obj, "rng",
                                     "ID of the random number generator backend",
                                     NULL);
@@ -163,6 +157,8 @@ int spapr_rng_populate_dt(void *fdt)
 
 static Property spapr_rng_properties[] = {
     DEFINE_PROP_BOOL("use-kvm", sPAPRRngState, use_kvm, false),
+    DEFINE_PROP_LINK("rng", sPAPRRngState, backend, TYPE_RNG_BACKEND,
+                     RngBackend *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.9.4
#21 lore raw
In reply to Fam Zheng
Quoted 71 lines · Fam Zheng

v4: Add a pointer type param to DEFINE_PROP_LINK, don't change pointer types to

    "Object *". [Paolo]

v3: Include Igor's patch, and fix virtio-crypto too.
Always use qdev_prop_allow_set_link_before_realize and OBJ_PROP_LINK_UNREF_ON_RELEASE.
Include as many applicable devices as possible and some more clean-ups. There are still more left but they use uncommon check and flags parameters, it's better to take care of them in following batches.

v2: Create a new header for link properties. [Paolo]
Don't wrap, use PropertyInfo.create() (much better diffstat, yay!). [Paolo]

Link properties of devices created with object_property_add_link() are not reflected in HMP "info qtree". For example, whether a virtio-blk device has an iothread (i.e. has enabled data plane) can not be introspected easily.

Introduce a new type of qdev property macro to fix that.

Fam Zheng (19):
qdev: Introduce PropertyInfo.create
qdev: Introduce DEFINE_PROP_LINK
qmp: Use ObjectProperty.type if present
qdev: Add const qualifier to PropertyInfo definitions
virtio-blk: Convert to DEFINE_PROP_LINK
virtio-scsi: Convert to DEFINE_PROP_LINK
virtio-rng: Convert to DEFINE_PROP_LINK
virtio-crypto: Convert to DEFINE_PROP_LINK
dimm: Convert to DEFINE_PROP_LINK
ivshmem: Convert to DEFINE_PROP_LINK
armv7m: Convert bitband.source-mamory to DEFINE_PROP_LINK
armv7m: Convert armv7m.memory to DEFINE_PROP_LINK
gicv3: Convert to DEFINE_PROP_LINK
xlnx_zynqmp: Convert to DEFINE_PROP_LINK
xilinx_axienet: Convert to DEFINE_PROP_LINK
xilinx_axidma: Convert to DEFINE_PROP_LINK
mips_cmgcr: Convert to DEFINE_PROP_LINK
cpu: Convert to DEFINE_PROP_LINK
spapr_rng: Convert to DEFINE_PROP_LINK

Igor Mammedov (1):
qom: enforce readonly nature of link's check callback

 exec.c                           | 27 +++++++++--------
 hw/arm/armv7m.c                  | 16 +++-------
 hw/arm/xlnx-zynqmp.c             |  7 ++---
 hw/block/virtio-blk.c            |  6 ++--
 hw/core/qdev-properties-system.c |  8 ++---
 hw/core/qdev-properties.c        | 63 ++++++++++++++++++++++++++--------------
 hw/core/qdev.c                   | 31 ++++++++++++--------
 hw/display/xlnx_dp.c             |  2 +-
 hw/dma/xilinx_axidma.c           | 16 +++-------
 hw/intc/arm_gicv3_its_kvm.c      | 19 +++++-------
 hw/ipmi/ipmi.c                   |  2 +-
 hw/mem/pc-dimm.c                 | 30 +++++--------------
 hw/misc/ivshmem.c                | 24 +++++----------
 hw/misc/mips_cmgcr.c             | 16 +++-------
 hw/net/xilinx_axienet.c          | 16 +++-------
 hw/ppc/spapr_rng.c               |  8 ++---
 hw/s390x/css.c                   |  4 +--
 hw/s390x/s390-pci-bus.c          |  2 +-
 hw/s390x/virtio-ccw.c            |  9 ------
 hw/scsi/virtio-scsi.c            | 13 ++-------
 hw/virtio/virtio-crypto-pci.c    |  2 --
 hw/virtio/virtio-crypto.c        | 27 +++++------------
 hw/virtio/virtio-pci.c           |  6 ----
 hw/virtio/virtio-rng.c           | 12 +-------
 include/hw/qdev-core.h           |  6 ++--
 include/hw/qdev-properties.h     | 62 ++++++++++++++++++++++-----------------
 include/hw/s390x/css.h           |  4 +--
Quoted 9 lines
 include/qom/cpu.h                |  1 +
 include/qom/object.h             |  6 ++--
 qmp.c                            |  5 ++--
 qom/cpu.c                        |  1 +
 qom/object.c                     |  8 ++---
 target/i386/cpu.c                |  2 +-
 target/ppc/translate_init.c      |  2 +-
 34 files changed, 193 insertions(+), 270 deletions(-)

I'm leaving the ARM patches to Peter and respinning my pull request with the others.

Thanks,

Paolo

#22 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Fam Zheng

v4: Add a pointer type param to DEFINE_PROP_LINK, don't change pointer types to

    "Object *". [Paolo]

v3: Include Igor's patch, and fix virtio-crypto too.
Always use qdev_prop_allow_set_link_before_realize and OBJ_PROP_LINK_UNREF_ON_RELEASE.
Include as many applicable devices as possible and some more clean-ups. There are still more left but they use uncommon check and flags parameters, it's better to take care of them in following batches.

v2: Create a new header for link properties. [Paolo]
Don't wrap, use PropertyInfo.create() (much better diffstat, yay!). [Paolo]

Quoted 8 lines
Quoted 5 lines

Link properties of devices created with object_property_add_link() are not reflected in HMP "info qtree". For example, whether a virtio-blk device has an iothread (i.e. has enabled data plane) can not be introspected easily.

Introduce a new type of qdev property macro to fix that.

I'm leaving the ARM patches to Peter and respinning my pull request with the others.

OK. Fam, you'll need to send a patchset with whatever the stuff I need to pick up is, then (and it'll need to get to me by monday given the freeze date is tuesday).

thanks
-- PMM