Skip to contentSkip to conversation

Generalize machine compatibility properties

PATCH Superseded Marc-André Lureau 4 participants 47 messages Dec 4, 2018 – Dec 13, 2018 Arm STM32

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Generalize machine compatibility properties

Hi,

During "[PATCH v2 05/10] qom/globals: generalize object_property_set_globals()" review, Eduardo suggested to rework the GlobalProperty handling, so that -global is limited to QDev only and we avoid mixing the machine compats and the user-provided -global properties (instead of generalizing -global to various object kinds, like I proposed in v2).

"qdev: do not mix compat props with global props" patch decouples a bit user-provided -global from machine compat properties. This allows to get rid of "user_provided" and "errp" fields in following patches.

Instead of explcitely calling object_apply_global_props() in the various object post_init, I opted for creating a new TYPE_COMPAT_PROPS interface. The interface approach gives a lot more flexibility on which objects can have compat props. This requires some interface improvments in "qom: teach interfaces to implement post-init".

A new compat property "x-use-canonical-path-for-ramblock-id" is added to hostmem for legacy canonical path names, set to true for -file and -memfd with qemu < 4.0.

(this series was initially titled "[PATCH v2 00/10] hostmem: use object "id" for memory region name with >= 3.1", but its focus is more in refactoring the global and compatilibity properties handling now)

v5:
- replace the SET_COMPAT macros, use normal function instead (suggested by Eduardo)
- replace the TYPE_COMPAT_PROPS interface approach for explicit object_apply_compat_props(), solving post-init ordering issues.
- get back to coupling compat properties with machine, in qdev (although there is still some discussion how to improve this, it can be changed later)
- mark the "arm: replace instance_post_init()" as RFC, since it is not longer required for this series
- change machines version from 3.2 to 4.0
- add some r-b tags

v4:
- fix accel/machine compat props apply order inversion
- split "qdev: do not mix compat props with global props": replace using current_machine by new compat_props global, introduce SET_COMPAT() macro, use GPtrArray.
- add a comment about "qdev-props: call object_apply_global_props()" error reporting
- add "arm: replace instance_post_init()", to solve the post-init ordering issue
- add "hw/arm/virt: add virt-3.2 machine type" for completeness
- commit message improvements
- rebased, add r-b tags

v3:
- GlobalProperties improvements/cleanups
- drop generalizing the -global idea
- "replace" the set_globals flag with a TYPE_COMPAT_PROPS interface
- update hw/i386 machine version to 3.2
- add "qom: make interface types abstract" interface cleanup

v2:
- replace "qom/user-creatable: add a few helper macros" patch for a more optimized "qom: make user_creatable_complete() specific to UserCreatable"
- rename register_global_list() to register_global_properties()
- call object_property_set_globals() after post-init
- add and use a ObjectClass.set_globals flag, instead of dynamically check object class in object_property_set_globals()
- use object "id" in >= 3.1 instead of canonical path, add compat property "x-use-canonical-path-for-ramblock-id" in base hostmem class.

Marc-André Lureau (19):
tests: qdev_prop_check_globals() doesn't return "all_used"
qom: make interface types abstract
qom: make user_creatable_complete() specific to UserCreatable
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests
qom: remove unimplemented class_finalize
hw: apply accel compat properties without touching globals
hw: apply machine compat properties without touching globals
hw: remove SET_MACHINE_COMPAT
qdev: make a separate helper function to apply compat properties
qdev: all globals are now user-provided
qdev-props: convert global_props to GPtrArray
qdev-props: remove errp from GlobalProperty
qdev-props: call object_apply_global_props()
qom: add object_class_get_class_data()
RFC: arm: replace instance_post_init()
hw/i386: add pc-i440fx-4.0 & pc-q35-4.0
hw/arm/virt: add virt-4.0 machine type
hostmem: use object id for memory region name with >= 4.0

 include/hw/acpi/acpi_dev_interface.h |   6 +-
 include/hw/arm/linux-boot-if.h       |   5 +-
 include/hw/boards.h                  |  19 +-
 include/hw/compat.h                  |  11 +
 include/hw/fw-path-provider.h        |   4 +-
 include/hw/hotplug.h                 |   6 +-
 include/hw/i386/pc.h                 |   3 +
 include/hw/intc/intc.h               |   4 +-
 include/hw/ipmi/ipmi.h               |   4 +-
 include/hw/isa/isa.h                 |   4 -
 include/hw/mem/memory-device.h       |   4 +-
 include/hw/nmi.h                     |   4 +-
 include/hw/qdev-core.h               |  21 +-
 include/hw/qdev-properties.h         |  30 --
 include/hw/stream.h                  |   4 +-
 include/hw/timer/m48t59.h            |   4 +-
 include/qom/object.h                 |  19 +-
 include/qom/object_interfaces.h      |  10 +-
 include/sysemu/accel.h               |   4 +-
 include/sysemu/hostmem.h             |   3 +-
 include/sysemu/tpm.h                 |   4 +-
 target/arm/cpu.h                     |   2 +
 target/arm/idau.h                    |   4 +-
 accel/accel.c                        |   7 +-
 backends/hostmem-file.c              |   8 +-
 backends/hostmem-memfd.c             |   2 +-
 backends/hostmem-ram.c               |   9 +-
 backends/hostmem.c                   |  36 ++
 hw/arm/virt.c                        |  70 ++-
 hw/core/machine.c                    |  30 +-
 hw/core/qdev-properties.c            |  73 +---
 hw/core/qdev.c                       |  15 +
 hw/i386/pc_piix.c                    | 607 ++++++++++++++++-----------
 hw/i386/pc_q35.c                     |  88 +++-
 hw/misc/ivshmem.c                    |   2 +-
 hw/ppc/spapr.c                       | 209 +++++----
 hw/s390x/s390-virtio-ccw.c           | 220 +++++-----
 hw/virtio/virtio-rng.c               |   2 +-
 hw/xen/xen-common.c                  |   9 +-
 qom/cpu.c                            |   1 -
 qom/object.c                         |  54 ++-
 qom/object_interfaces.c              |  14 +-
 target/arm/cpu.c                     |  15 +-
 target/arm/cpu64.c                   |  11 +-
 target/i386/cpu.c                    |   1 -
 target/sparc/cpu.c                   |   1 -
 tests/check-qom-interface.c          |   4 +-
 tests/test-qdev-global-props.c       |  79 +---
 vl.c                                 |   4 -
 49 files changed, 963 insertions(+), 787 deletions(-)
Signature · 1 line
2.20.0.rc1
#1 lore raw

PATCH v5 1/19 tests: qdev_prop_check_globals() doesn't return "all_used"

Instead, it returns 1 if an error was detected, which is the case for:

/qdev/properties/dynamic/global/subprocess:
warning: global dynamic-prop-type-bad.prop3 has invalid class name
warning: global nohotplug-type.prop5=105 not used
warning: global nondevice-type.prop6 has invalid class name

Clarify the function return value.

---
 tests/test-qdev-global-props.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/test-qdev-global-props.c +6 -6
index d81b0862d5..ccdf6c57c1 100644
@@ -214,7 +214,7 @@ static void test_dynamic_globalprop_subprocess(void)
         { TYPE_NONDEVICE, "prop6", "106", true },
         {}
     };
-    int all_used;
+    int global_error;
 
     qdev_prop_register_global_list(props);
 
@@ -223,8 +223,8 @@ static void test_dynamic_globalprop_subprocess(void)
 
     g_assert_cmpuint(mt->prop1, ==, 101);
     g_assert_cmpuint(mt->prop2, ==, 102);
-    all_used = qdev_prop_check_globals();
-    g_assert_cmpuint(all_used, ==, 1);
+    global_error = qdev_prop_check_globals();
+    g_assert_cmpuint(global_error, ==, 1);
     g_assert(props[0].used);
     g_assert(props[1].used);
     g_assert(!props[2].used);
@@ -259,7 +259,7 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
         { TYPE_NONDEVICE, "prop6", "106" },
         {}
     };
-    int all_used;
+    int global_error;
 
     qdev_prop_register_global_list(props);
 
@@ -268,8 +268,8 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
 
     g_assert_cmpuint(mt->prop1, ==, 101);
     g_assert_cmpuint(mt->prop2, ==, 102);
-    all_used = qdev_prop_check_globals();
-    g_assert_cmpuint(all_used, ==, 0);
+    global_error = qdev_prop_check_globals();
+    g_assert_cmpuint(global_error, ==, 0);
     g_assert(props[0].used);
     g_assert(props[1].used);
     g_assert(!props[2].used);
Signature · 1 line
2.20.0.rc1
#2 lore raw

PATCH v5 2/19 qom: make interface types abstract

In reply to Marc-André Lureau

Interfaces don't have instance, let's make the interface type really abstract to avoid confusion.

---
 include/hw/acpi/acpi_dev_interface.h | 6 +-----
 include/hw/arm/linux-boot-if.h       | 5 +----
 include/hw/fw-path-provider.h        | 4 +---
 include/hw/hotplug.h                 | 6 +-----
 include/hw/intc/intc.h               | 4 +---
 include/hw/ipmi/ipmi.h               | 4 +---
 include/hw/isa/isa.h                 | 4 ----
 include/hw/mem/memory-device.h       | 4 +---
 include/hw/nmi.h                     | 4 +---
 include/hw/stream.h                  | 4 +---
 include/hw/timer/m48t59.h            | 4 +---
 include/qom/object_interfaces.h      | 6 +-----
 include/sysemu/tpm.h                 | 4 +---
 target/arm/idau.h                    | 4 +---
 tests/check-qom-interface.c          | 4 +---
 15 files changed, 14 insertions(+), 53 deletions(-)
include/hw/acpi/acpi_dev_interface.h +1 -5
index dabf4c4fc9..43ff119179 100644
@@ -25,11 +25,7 @@ typedef enum {
      INTERFACE_CHECK(AcpiDeviceIf, (obj), \
                      TYPE_ACPI_DEVICE_IF)
 
-
-typedef struct AcpiDeviceIf {
-    /* <private> */
-    Object Parent;
-} AcpiDeviceIf;
+typedef struct AcpiDeviceIf AcpiDeviceIf;
 
 void acpi_send_event(DeviceState *dev, AcpiEventStatusBits event);
 
include/hw/arm/linux-boot-if.h +1 -4
index aba4479a14..7bbdfd1cc6 100644
@@ -16,10 +16,7 @@
 #define ARM_LINUX_BOOT_IF(obj) \
     INTERFACE_CHECK(ARMLinuxBootIf, (obj), TYPE_ARM_LINUX_BOOT_IF)
 
-typedef struct ARMLinuxBootIf {
-    /*< private >*/
-    Object parent_obj;
-} ARMLinuxBootIf;
+typedef struct ARMLinuxBootIf ARMLinuxBootIf;
 
 typedef struct ARMLinuxBootIfClass {
     /*< private >*/
include/hw/fw-path-provider.h +1 -3
index 050cb05d92..5df893a3d8 100644
@@ -30,9 +30,7 @@
 #define FW_PATH_PROVIDER(obj) \
      INTERFACE_CHECK(FWPathProvider, (obj), TYPE_FW_PATH_PROVIDER)
 
-typedef struct FWPathProvider {
-    Object parent_obj;
-} FWPathProvider;
+typedef struct FWPathProvider FWPathProvider;
 
 typedef struct FWPathProviderClass {
     InterfaceClass parent_class;
include/hw/hotplug.h +1 -5
index 1a0516a479..6321e292fd 100644
@@ -23,11 +23,7 @@
 #define HOTPLUG_HANDLER(obj) \
      INTERFACE_CHECK(HotplugHandler, (obj), TYPE_HOTPLUG_HANDLER)
 
-
-typedef struct HotplugHandler {
-    /* <private> */
-    Object Parent;
-} HotplugHandler;
+typedef struct HotplugHandler HotplugHandler;
 
 /**
  * hotplug_fn:
include/hw/intc/intc.h +1 -3
index 27d9828943..fb3e8e621f 100644
@@ -15,9 +15,7 @@
     INTERFACE_CHECK(InterruptStatsProvider, (obj), \
                     TYPE_INTERRUPT_STATS_PROVIDER)
 
-typedef struct InterruptStatsProvider {
-    Object parent;
-} InterruptStatsProvider;
+typedef struct InterruptStatsProvider InterruptStatsProvider;
 
 typedef struct InterruptStatsProviderClass {
     InterfaceClass parent;
include/hw/ipmi/ipmi.h +1 -3
index 0affe5a4d8..99661d2bf0 100644
@@ -114,9 +114,7 @@ uint32_t ipmi_next_uuid(void);
 #define IPMI_INTERFACE_GET_CLASS(class) \
      OBJECT_GET_CLASS(IPMIInterfaceClass, (class), TYPE_IPMI_INTERFACE)
 
-typedef struct IPMIInterface {
-    Object parent;
-} IPMIInterface;
+typedef struct IPMIInterface IPMIInterface;
 
 typedef struct IPMIInterfaceClass {
     InterfaceClass parent;
include/hw/isa/isa.h +0 -4
index b9dbab24b4..e62ac91c19 100644
@@ -43,10 +43,6 @@ static inline uint16_t applesmc_port(void)
 #define ISADMA(obj) \
     INTERFACE_CHECK(IsaDma, (obj), TYPE_ISADMA)
 
-struct IsaDma {
-    Object parent;
-};
-
 typedef enum {
     ISADMA_TRANSFER_VERIFY,
     ISADMA_TRANSFER_READ,
include/hw/mem/memory-device.h +1 -3
index e904e194d5..0293a96abb 100644
@@ -25,9 +25,7 @@
 #define MEMORY_DEVICE(obj) \
      INTERFACE_CHECK(MemoryDeviceState, (obj), TYPE_MEMORY_DEVICE)
 
-typedef struct MemoryDeviceState {
-    Object parent_obj;
-} MemoryDeviceState;
+typedef struct MemoryDeviceState MemoryDeviceState;
 
 /**
  * MemoryDeviceClass:
include/hw/nmi.h +1 -3
index d092c684a1..ad857f3832 100644
@@ -34,9 +34,7 @@
 #define NMI(obj) \
      INTERFACE_CHECK(NMI, (obj), TYPE_NMI)
 
-typedef struct NMIState {
-    Object parent_obj;
-} NMIState;
+typedef struct NMIState NMIState;
 
 typedef struct NMIClass {
     InterfaceClass parent_class;
include/hw/stream.h +1 -3
index c370ba0c66..15774f07ab 100644
@@ -14,9 +14,7 @@
 #define STREAM_SLAVE(obj) \
      INTERFACE_CHECK(StreamSlave, (obj), TYPE_STREAM_SLAVE)
 
-typedef struct StreamSlave {
-    Object Parent;
-} StreamSlave;
+typedef struct StreamSlave StreamSlave;
 
 typedef void (*StreamCanPushNotifyFn)(void *opaque);
 
include/hw/timer/m48t59.h +1 -3
index db5e43a8da..6f8db04fce 100644
@@ -13,9 +13,7 @@
 #define NVRAM(obj) \
     INTERFACE_CHECK(Nvram, (obj), TYPE_NVRAM)
 
-typedef struct Nvram {
-    Object parent;
-} Nvram;
+typedef struct Nvram Nvram;
 
 typedef struct NvramClass {
     InterfaceClass parent;
include/qom/object_interfaces.h +1 -5
index 4d513fb329..652a16d2ba 100644
@@ -16,11 +16,7 @@
      INTERFACE_CHECK(UserCreatable, (obj), \
                      TYPE_USER_CREATABLE)
 
-
-typedef struct UserCreatable {
-    /* <private> */
-    Object Parent;
-} UserCreatable;
+typedef struct UserCreatable UserCreatable;
 
 /**
  * UserCreatableClass:
include/sysemu/tpm.h +1 -3
index 17a97ed77a..5b541a71c8 100644
@@ -33,9 +33,7 @@ typedef enum TPMVersion {
 #define TPM_IF(obj)                             \
     INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
 
-typedef struct TPMIf {
-    Object parent_obj;
-} TPMIf;
+typedef struct TPMIf TPMIf;
 
 typedef struct TPMIfClass {
     InterfaceClass parent_class;
target/arm/idau.h +1 -3
index cac27b95fa..7c0e4e3776 100644
@@ -38,9 +38,7 @@
 #define IDAU_INTERFACE_GET_CLASS(obj) \
     OBJECT_GET_CLASS(IDAUInterfaceClass, (obj), TYPE_IDAU_INTERFACE)
 
-typedef struct IDAUInterface {
-    Object parent;
-} IDAUInterface;
+typedef struct IDAUInterface IDAUInterface;
 
 #define IREGION_NOTVALID -1
 
tests/check-qom-interface.c +1 -3
index f87c9aaa8a..2177f0dce5 100644
@@ -23,9 +23,7 @@
 #define TEST_IF(obj) \
      INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
 
-typedef struct TestIf {
-    Object parent_obj;
-} TestIf;
+typedef struct TestIf TestIf;
 
 typedef struct TestIfClass {
     InterfaceClass parent_class;
Signature · 1 line
2.20.0.rc1
#3 lore raw

PATCH v5 3/19 qom: make user_creatable_complete() specific to UserCreatable

In reply to Marc-André Lureau

Instead of accepting any Object*, change user_creatable_complete() to require a UserCreatable*. Modify the callers to pass the appropriate argument, removing redundant dynamic cast checks in object creation.

---
 include/qom/object_interfaces.h |  4 ++--
 hw/misc/ivshmem.c               |  2 +-
 hw/virtio/virtio-rng.c          |  2 +-
 qom/object.c                    | 12 ++++++++----
 qom/object_interfaces.c         | 14 +++-----------
 5 files changed, 15 insertions(+), 19 deletions(-)
include/qom/object_interfaces.h +2 -2
index 652a16d2ba..682ba1d9b0 100644
@@ -51,14 +51,14 @@ typedef struct UserCreatableClass {
 
 /**
  * user_creatable_complete:
- * @obj: the object whose complete() method is called if defined
+ * @uc: the user-creatable object whose complete() method is called if defined
  * @errp: if an error occurs, a pointer to an area to store the error
  *
  * Wrapper to call complete() method if one of types it's inherited
  * from implements USER_CREATABLE interface, otherwise the call does
  * nothing.
  */
-void user_creatable_complete(Object *obj, Error **errp);
+void user_creatable_complete(UserCreatable *uc, Error **errp);
 
 /**
  * user_creatable_can_be_deleted:
hw/misc/ivshmem.c +1 -1
index ecfd10a29a..8213659602 100644
@@ -1280,7 +1280,7 @@ static void desugar_shm(IVShmemState *s)
     object_property_add_child(OBJECT(s), "internal-shm-backend", obj,
                               &error_abort);
     object_unref(obj);
-    user_creatable_complete(obj, &error_abort);
+    user_creatable_complete(USER_CREATABLE(obj), &error_abort);
     s->hostmem = MEMORY_BACKEND(obj);
 }
 
hw/virtio/virtio-rng.c +1 -1
index 855f1b41d1..30493a2586 100644
@@ -191,7 +191,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
     if (vrng->conf.rng == NULL) {
         vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
 
-        user_creatable_complete(OBJECT(vrng->conf.default_backend),
+        user_creatable_complete(USER_CREATABLE(vrng->conf.default_backend),
                                 &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
qom/object.c +8 -4
index 547dcf97c3..eb770dbf7f 100644
@@ -417,6 +417,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
 {
     Error *local_err = NULL;
     Object *obj;
+    UserCreatable *uc;
 
     object_initialize(childobj, size, type);
     obj = OBJECT(childobj);
@@ -431,8 +432,9 @@ void object_initialize_childv(Object *parentobj, const char *propname,
         goto out;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
-        user_creatable_complete(obj, &local_err);
+    uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
+    if (uc) {
+        user_creatable_complete(uc, &local_err);
         if (local_err) {
             object_unparent(obj);
             goto out;
@@ -590,6 +592,7 @@ Object *object_new_with_propv(const char *typename,
     Object *obj;
     ObjectClass *klass;
     Error *local_err = NULL;
+    UserCreatable *uc;
 
     klass = object_class_by_name(typename);
     if (!klass) {
@@ -612,8 +615,9 @@ Object *object_new_with_propv(const char *typename,
         goto error;
     }
 
-    if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
-        user_creatable_complete(obj, &local_err);
+    uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
+    if (uc) {
+        user_creatable_complete(uc, &local_err);
         if (local_err) {
             object_unparent(obj);
             goto error;
qom/object_interfaces.c +3 -11
index 97b79b48bb..db85d1eb75 100644
@@ -8,18 +8,10 @@
 #include "qapi/opts-visitor.h"
 #include "qemu/config-file.h"
 
-void user_creatable_complete(Object *obj, Error **errp)
+void user_creatable_complete(UserCreatable *uc, Error **errp)
 {
+    UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc);
 
-    UserCreatableClass *ucc;
-    UserCreatable *uc =
-        (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
-
-    if (!uc) {
-        return;
-    }
-
-    ucc = USER_CREATABLE_GET_CLASS(uc);
     if (ucc->complete) {
         ucc->complete(uc, errp);
     }
@@ -89,7 +81,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
         goto out;
     }
 
-    user_creatable_complete(obj, &local_err);
+    user_creatable_complete(USER_CREATABLE(obj), &local_err);
     if (local_err) {
         object_property_del(object_get_objects_root(),
                             id, &error_abort);
Signature · 1 line
2.20.0.rc1
#4 lore raw

PATCH v5 4/19 accel: register global_props like machine globals

In reply to Marc-André Lureau

global_props is only used for Xen xen_compat_props. It's a static array of GlobalProperty, like machine globals in SET_MACHINE_COMPAT(). Let's register the globals the same way, without extra copy allocation.

---
 include/hw/qdev-properties.h | 29 -----------------------------
 accel/accel.c                |  9 ++++++++-
 hw/core/qdev-properties.c    | 21 ---------------------
 3 files changed, 8 insertions(+), 51 deletions(-)
include/hw/qdev-properties.h +0 -29
index 4f60cc88f3..a95f4a73eb 100644
@@ -255,35 +255,6 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
-/**
- * register_compat_prop:
- *
- * Register internal (not user-provided) global property, changing the
- * default value of a given property in a device type.  This can be used
- * for enabling machine-type compatibility or for enabling
- * accelerator-specific defaults in devices.
- *
- * The property values set using this function must be always valid and
- * never report setter errors, as the property will have
- * GlobalProperty::errp set to &error_abort.
- *
- * User-provided global properties should override internal global
- * properties, so callers of this function should ensure that it is
- * called before user-provided global properties are registered.
- *
- * @driver: Device type to be affected
- * @property: Property whose default value is going to be changed
- * @value: New default value for the property
- */
-void register_compat_prop(const char *driver, const char *property,
-                          const char *value);
-/*
- * register_compat_props_array(): using register_compat_prop(), which
- * only registers internal global properties (which has lower priority
- * than user-provided global properties)
- */
-void register_compat_props_array(GlobalProperty *prop);
-
 /**
  * qdev_property_add_static:
  * @dev: Device to add the property to.
accel/accel.c +8 -1
index 966b2d8f53..3da26eb90f 100644
@@ -34,6 +34,7 @@
 #include "qom/object.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
+#include "qapi/error.h"
 
 static const TypeInfo accel_type = {
     .name = TYPE_ACCEL,
@@ -121,7 +122,13 @@ void configure_accelerator(MachineState *ms)
 void accel_register_compat_props(AccelState *accel)
 {
     AccelClass *class = ACCEL_GET_CLASS(accel);
-    register_compat_props_array(class->global_props);
+    GlobalProperty *prop = class->global_props;
+
+    for (; prop && prop->driver; prop++) {
+        /* Any compat_props must never cause error */
+        prop->errp = &error_abort;
+        qdev_prop_register_global(prop);
+    }
 }
 
 void accel_setup_post(MachineState *ms)
hw/core/qdev-properties.c +0 -21
index 35072dec1e..ab61d502fd 100644
@@ -1180,27 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void register_compat_prop(const char *driver,
-                          const char *property,
-                          const char *value)
-{
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
-
-    /* Any compat_props must never cause error */
-    p->errp = &error_abort;
-    p->driver = driver;
-    p->property = property;
-    p->value = value;
-    qdev_prop_register_global(p);
-}
-
-void register_compat_props_array(GlobalProperty *prop)
-{
-    for (; prop && prop->driver; prop++) {
-        register_compat_prop(prop->driver, prop->property, prop->value);
-    }
-}
-
 void qdev_prop_register_global_list(GlobalProperty *props)
 {
     int i;
Signature · 1 line
2.20.0.rc1
#5 lore raw

PATCH v5 5/19 qdev: move qdev_prop_register_global_list() to tests

In reply to Marc-André Lureau

The function is only used by a test, move it there.

---
 include/hw/qdev-properties.h   |  1 -
 hw/core/qdev-properties.c      |  9 ---------
 tests/test-qdev-global-props.c | 18 ++++++++++++++----
 3 files changed, 14 insertions(+), 14 deletions(-)
include/hw/qdev-properties.h +0 -1
index a95f4a73eb..3ab9cd2eb6 100644
@@ -249,7 +249,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global(GlobalProperty *prop);
-void qdev_prop_register_global_list(GlobalProperty *props);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
hw/core/qdev-properties.c +0 -9
index ab61d502fd..bd84c4ea4c 100644
@@ -1180,15 +1180,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     global_props = g_list_append(global_props, prop);
 }
 
-void qdev_prop_register_global_list(GlobalProperty *props)
-{
-    int i;
-
-    for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props+i);
-    }
-}
-
 int qdev_prop_check_globals(void)
 {
     GList *l;
tests/test-qdev-global-props.c +14 -4
index ccdf6c57c1..b1eb505442 100644
@@ -89,6 +89,16 @@ static void test_static_prop(void)
     g_test_trap_assert_stdout("");
 }
 
+static void register_global_properties(GlobalProperty *props)
+{
+    int i;
+
+    for (i = 0; props[i].driver != NULL; i++) {
+        qdev_prop_register_global(props + i);
+    }
+}
+
+
 /* Test setting of static property using global properties */
 static void test_static_globalprop_subprocess(void)
 {
@@ -98,7 +108,7 @@ static void test_static_globalprop_subprocess(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_properties(props);
 
     mt = STATIC_TYPE(object_new(TYPE_STATIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -216,7 +226,7 @@ static void test_dynamic_globalprop_subprocess(void)
     };
     int global_error;
 
-    qdev_prop_register_global_list(props);
+    register_global_properties(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -261,7 +271,7 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
     };
     int global_error;
 
-    qdev_prop_register_global_list(props);
+    register_global_properties(props);
 
     mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
     qdev_init_nofail(DEVICE(mt));
@@ -299,7 +309,7 @@ static void test_subclass_global_props(void)
         {}
     };
 
-    qdev_prop_register_global_list(props);
+    register_global_properties(props);
 
     mt = STATIC_TYPE(object_new(TYPE_SUBCLASS));
     qdev_init_nofail(DEVICE(mt));
Signature · 1 line
2.20.0.rc1
#6 lore raw

PATCH v5 6/19 qom: remove unimplemented class_finalize

In reply to Marc-André Lureau

Instead of trying to implement something that isn't well specified, remove it. (it would be tricky to implement, since a class struct is memcpy on children types...)

---
 include/qom/object.h |  7 ++-----
 hw/core/machine.c    | 11 -----------
 qom/object.c         |  2 --
 3 files changed, 2 insertions(+), 18 deletions(-)
include/qom/object.h +2 -5
index f0b0bf39cc..0139838b69 100644
@@ -455,10 +455,8 @@ struct Object
  *   parent class initialization has occurred, but before the class itself
  *   is initialized.  This is the function to use to undo the effects of
  *   memcpy from the parent class to the descendants.
- * @class_finalize: This function is called during class destruction and is
- *   meant to release and dynamic parameters allocated by @class_init.
- * @class_data: Data to pass to the @class_init, @class_base_init and
- *   @class_finalize functions.  This can be useful when building dynamic
+ * @class_data: Data to pass to the @class_init,
+ *   @class_base_init. This can be useful when building dynamic
  *   classes.
  * @interfaces: The list of interfaces associated with this type.  This
  *   should point to a static array that's terminated with a zero filled
@@ -479,7 +477,6 @@ struct TypeInfo
 
     void (*class_init)(ObjectClass *klass, void *data);
     void (*class_base_init)(ObjectClass *klass, void *data);
-    void (*class_finalize)(ObjectClass *klass, void *data);
     void *class_data;
 
     InterfaceInfo *interfaces;
hw/core/machine.c +0 -11
index da50ad6de7..c51423b647 100644
@@ -834,16 +834,6 @@ void machine_run_board_init(MachineState *machine)
     machine_class->init(machine);
 }
 
-static void machine_class_finalize(ObjectClass *klass, void *data)
-{
-    MachineClass *mc = MACHINE_CLASS(klass);
-
-    if (mc->compat_props) {
-        g_array_free(mc->compat_props, true);
-    }
-    g_free(mc->name);
-}
-
 void machine_register_compat_props(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -869,7 +859,6 @@ static const TypeInfo machine_info = {
     .class_size = sizeof(MachineClass),
     .class_init    = machine_class_init,
     .class_base_init = machine_class_base_init,
-    .class_finalize = machine_class_finalize,
     .instance_size = sizeof(MachineState),
     .instance_init = machine_initfn,
     .instance_finalize = machine_finalize,
qom/object.c +0 -2
index eb770dbf7f..17921c0a71 100644
@@ -49,7 +49,6 @@ struct TypeImpl
 
     void (*class_init)(ObjectClass *klass, void *data);
     void (*class_base_init)(ObjectClass *klass, void *data);
-    void (*class_finalize)(ObjectClass *klass, void *data);
 
     void *class_data;
 
@@ -114,7 +113,6 @@ static TypeImpl *type_new(const TypeInfo *info)
 
     ti->class_init = info->class_init;
     ti->class_base_init = info->class_base_init;
-    ti->class_finalize = info->class_finalize;
     ti->class_data = info->class_data;
 
     ti->instance_init = info->instance_init;
Signature · 1 line
2.20.0.rc1
#7 lore raw

PATCH v5 7/19 hw: apply accel compat properties without touching globals

In reply to Marc-André Lureau

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)
include/hw/qdev-core.h +10 -0
index a24d0dd566..aeaa6dbbb8 100644
@@ -267,6 +267,16 @@ typedef struct GlobalProperty {
     Error **errp;
 } GlobalProperty;
 
+static inline void
+compat_props_add(GPtrArray *arr,
+                 GlobalProperty props[], size_t nelem)
+{
+    int i;
+    for (i = 0; i < nelem; i++) {
+        g_ptr_array_add(arr, (void *)&props[i]);
+    }
+}
+
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);
include/qom/object.h +3 -0
index 0139838b69..5183c587f3 100644
@@ -676,6 +676,9 @@ Object *object_new_with_propv(const char *typename,
                               Error **errp,
                               va_list vargs);
 
+void object_apply_global_props(Object *obj, const GPtrArray *props,
+                               Error **errp);
+
 /**
  * object_set_props:
  * @obj: the object instance to set properties on
include/sysemu/accel.h +1 -3
index 637358f430..f331d128e9 100644
@@ -49,7 +49,7 @@ typedef struct AccelClass {
      * global properties may be overridden by machine-type
      * compat_props or user-provided global properties.
      */
-    GlobalProperty *global_props;
+    GPtrArray *compat_props;
 } AccelClass;
 
 #define TYPE_ACCEL "accel"
@@ -67,8 +67,6 @@ typedef struct AccelClass {
 extern unsigned long tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
-/* Register accelerator specific global properties */
-void accel_register_compat_props(AccelState *accel);
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
 
accel/accel.c +0 -12
index 3da26eb90f..6db5d8f4df 100644
@@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
-void accel_register_compat_props(AccelState *accel)
-{
-    AccelClass *class = ACCEL_GET_CLASS(accel);
-    GlobalProperty *prop = class->global_props;
-
-    for (; prop && prop->driver; prop++) {
-        /* Any compat_props must never cause error */
-        prop->errp = &error_abort;
-        qdev_prop_register_global(prop);
-    }
-}
-
 void accel_setup_post(MachineState *ms)
 {
     AccelState *accel = ms->accelerator;
hw/core/qdev.c +9 -0
index 6b3cc55b27..53b507164f 100644
@@ -972,6 +972,15 @@ static void device_initfn(Object *obj)
 
 static void device_post_init(Object *obj)
 {
+    if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+        MachineState *m = MACHINE(qdev_get_machine());
+        AccelClass *ac = ACCEL_GET_CLASS(m->accelerator);
+
+        if (ac->compat_props) {
+            object_apply_global_props(obj, ac->compat_props, &error_abort);
+        }
+    }
+
     qdev_prop_set_globals(DEVICE(obj));
 }
 
hw/xen/xen-common.c +6 -3
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -1
index a5ae5f23d2..88ba658572 100644
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }
Signature · 1 line
2.20.0.rc1
#8 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 07/19] hw: apply accel compat properties without touching globals

Quoted 18 lines · On Tue, 4 Dec 2018 18:20:11 +0400 Marc-André Lureau…

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)

[...]

Quoted 13 lines
hw/xen/xen-common.c +1 -2
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 

hw/xen/xen-common.c static GlobalProperty xen_compat_props[] = { · line 188

Quoted 10 lines
hw/xen/xen-common.c +2 -1
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();

where is matching free for that?

Quoted 47 lines
hw/xen/xen-common.c +3 -0
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -0
index a5ae5f23d2..88ba658572 100644

vl.c static void user_register_global_props(void) · line 2973

Quoted 7 lines
vl.c +0 -1
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 07/19] hw: apply accel compat properties without touching globals

Quoted 35 lines · On Mon, 10 Dec 2018 17:45:22 +0100 Igor Mammedov <[email protected]> wrote:
Quoted 18 lines · On Tue, 4 Dec 2018 18:20:11 +0400 Marc-André Lureau…

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)

[...]

Quoted 13 lines
hw/xen/xen-common.c +1 -2
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 
Quoted 11 lines

hw/xen/xen-common.c static GlobalProperty xen_compat_props[] = { · line 188

Quoted 10 lines
hw/xen/xen-common.c +2 -1
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();

where is matching free for that?

can we at least annotate it somehow so that valgrind won't complain about this leak?

Quoted 47 lines
Quoted 47 lines
hw/xen/xen-common.c +3 -0
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -0
index a5ae5f23d2..88ba658572 100644
Quoted 10 lines

vl.c static void user_register_global_props(void) · line 2973

Quoted 8 lines
vl.c +0 -1
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 07/19] hw: apply accel compat properties without touching globals

Hi

Quoted 50 lines · Igor Mammedov
Quoted 35 lines · On Mon, 10 Dec 2018 17:45:22 +0100 Igor Mammedov <[email protected]> wrote:
Quoted 18 lines · On Tue, 4 Dec 2018 18:20:11 +0400 Marc-André Lureau…

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)

[...]

Quoted 13 lines
hw/xen/xen-common.c +1 -2
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 
Quoted 11 lines

hw/xen/xen-common.c static GlobalProperty xen_compat_props[] = { · line 188

Quoted 10 lines
hw/xen/xen-common.c +2 -1
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();

where is matching free for that?

Quoted 1 line

can we at least annotate it somehow so that valgrind won't complain about this leak?

If you check my commits on qemu, you should see that I do care (too much?) about leaks :)

In this case though, I don't see valgrind or asan complaining, I guess it's still a reachable reference.
Do you think a FIXME comment would be helpful?

(/me wish we had a proper object system, GObject, but that ship as long sailed..)

Quoted 60 lines
Quoted 58 lines
Quoted 56 lines
hw/xen/xen-common.c +3 -0
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -1
index a5ae5f23d2..88ba658572 100644
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }
Signature · 6 lines
Marc-André Lureau

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 07/19] hw: apply accel compat properties without touching globals

Quoted 52 lines · On Wed, 12 Dec 2018 16:00:06 +0400 Marc-André Lureau…

Hi

Quoted 50 lines · Igor Mammedov
Quoted 46 lines · On Mon, 10 Dec 2018 17:45:22 +0100 Igor Mammedov <[email protected]> wrote:
Quoted 18 lines · On Tue, 4 Dec 2018 18:20:11 +0400 Marc-André Lureau…

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)

[...]

Quoted 13 lines
hw/xen/xen-common.c +1 -2
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 

hw/xen/xen-common.c static GlobalProperty xen_compat_props[] = { · line 188

Quoted 10 lines
hw/xen/xen-common.c +2 -1
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();  

where is matching free for that?

Quoted 8 lines
Quoted 1 line

can we at least annotate it somehow so that valgrind won't complain about this leak?

If you check my commits on qemu, you should see that I do care (too much?) about leaks :)

In this case though, I don't see valgrind or asan complaining, I guess it's still a reachable reference.
Do you think a FIXME comment would be helpful?

I've looked at other cases were we leak, and well we leak a lot so it's probably futile exercise. But the comment won't hurt and will work as remainder.

Quoted 65 lines

(/me wish we had a proper object system, GObject, but that ship as long sailed..)

Quoted 60 lines
Quoted 58 lines
Quoted 56 lines
hw/xen/xen-common.c +3 -0
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -1
index a5ae5f23d2..88ba658572 100644
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }  

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v5 7/19
#12 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 07/19] hw: apply accel compat properties without touching globals

In reply to Marc-André Lureau
Quoted 7 lines · On Tue, 4 Dec 2018 18:20:11 +0400 Marc-André Lureau…

Instead of registering compat properties as globals, let's keep them in their own array, to avoid mixing with user globals.

Introduce object_apply_global_props() function, to apply compatibility properties from a GPtrArray.

other than static leak looks fine, considering that we already leak compat_props, it doesn't really matter, so:

Quoted 181 lines
---
 include/hw/qdev-core.h | 10 ++++++++++
 include/qom/object.h   |  3 +++
 include/sysemu/accel.h |  4 +---
 accel/accel.c          | 12 ------------
 hw/core/qdev.c         |  9 +++++++++
 hw/xen/xen-common.c    |  9 ++++++---
 qom/object.c           | 25 +++++++++++++++++++++++++
 vl.c                   |  1 -
 8 files changed, 54 insertions(+), 19 deletions(-)
include/hw/qdev-core.h +10 -0
index a24d0dd566..aeaa6dbbb8 100644
@@ -267,6 +267,16 @@ typedef struct GlobalProperty {
     Error **errp;
 } GlobalProperty;
 
+static inline void
+compat_props_add(GPtrArray *arr,
+                 GlobalProperty props[], size_t nelem)
+{
+    int i;
+    for (i = 0; i < nelem; i++) {
+        g_ptr_array_add(arr, (void *)&props[i]);
+    }
+}
+
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);
include/qom/object.h +3 -0
index 0139838b69..5183c587f3 100644
@@ -676,6 +676,9 @@ Object *object_new_with_propv(const char *typename,
                               Error **errp,
                               va_list vargs);
 
+void object_apply_global_props(Object *obj, const GPtrArray *props,
+                               Error **errp);
+
 /**
  * object_set_props:
  * @obj: the object instance to set properties on
include/sysemu/accel.h +1 -3
index 637358f430..f331d128e9 100644
@@ -49,7 +49,7 @@ typedef struct AccelClass {
      * global properties may be overridden by machine-type
      * compat_props or user-provided global properties.
      */
-    GlobalProperty *global_props;
+    GPtrArray *compat_props;
 } AccelClass;
 
 #define TYPE_ACCEL "accel"
@@ -67,8 +67,6 @@ typedef struct AccelClass {
 extern unsigned long tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
-/* Register accelerator specific global properties */
-void accel_register_compat_props(AccelState *accel);
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
 
accel/accel.c +0 -12
index 3da26eb90f..6db5d8f4df 100644
@@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms)
     }
 }
 
-void accel_register_compat_props(AccelState *accel)
-{
-    AccelClass *class = ACCEL_GET_CLASS(accel);
-    GlobalProperty *prop = class->global_props;
-
-    for (; prop && prop->driver; prop++) {
-        /* Any compat_props must never cause error */
-        prop->errp = &error_abort;
-        qdev_prop_register_global(prop);
-    }
-}
-
 void accel_setup_post(MachineState *ms)
 {
     AccelState *accel = ms->accelerator;
hw/core/qdev.c +9 -0
index 6b3cc55b27..53b507164f 100644
@@ -972,6 +972,15 @@ static void device_initfn(Object *obj)
 
 static void device_post_init(Object *obj)
 {
+    if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+        MachineState *m = MACHINE(qdev_get_machine());
+        AccelClass *ac = ACCEL_GET_CLASS(m->accelerator);
+
+        if (ac->compat_props) {
+            object_apply_global_props(obj, ac->compat_props, &error_abort);
+        }
+    }
+
     qdev_prop_set_globals(DEVICE(obj));
 }
 
hw/xen/xen-common.c +6 -3
index 6ec14c73ca..4532aa8632 100644
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
         .driver = "migration",
         .property = "send-section-footer",
         .value = "off",
-    },
-    { /* end of list */ },
+    }
 };
 
 static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
+
     ac->name = "Xen";
     ac->init_machine = xen_init;
     ac->setup_post = xen_setup_post;
     ac->allowed = &xen_allowed;
-    ac->global_props = xen_compat_props;
+    ac->compat_props = g_ptr_array_new();
+
+    compat_props_add(ac->compat_props,
+                     xen_compat_props, G_N_ELEMENTS(xen_compat_props));
 }
 
 #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
qom/object.c +25 -0
index 17921c0a71..dbdab0aead 100644
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
     }
 }
 
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+    Error *err = NULL;
+    int i;
+
+    if (!props) {
+        return;
+    }
+
+    for (i = 0; i < props->len; i++) {
+        GlobalProperty *p = g_ptr_array_index(props, i);
+
+        if (object_dynamic_cast(obj, p->driver) == NULL) {
+            continue;
+        }
+        p->used = true;
+        object_property_parse(obj, p->value, p->property, &err);
+        if (err != NULL) {
+            error_prepend(&err, "can't apply global %s.%s=%s: ",
+                          p->driver, p->property, p->value);
+            error_propagate(errp, err);
+        }
+    }
+}
+
 static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
 {
     Object *obj = data;
vl.c +0 -0
index a5ae5f23d2..88ba658572 100644

vl.c static void user_register_global_props(void) · line 2973

Quoted 7 lines
vl.c +0 -1
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    accel_register_compat_props(ms->accelerator);
     machine_register_compat_props(ms);
     user_register_global_props();
 }

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

PATCH v5 8/19 hw: apply machine compat properties without touching globals

In reply to Marc-André Lureau

Similarly to accel properties, move compat properties out of globals registration, and apply the machine compat properties during device_post_init().

As suggested during review, populating the arrays can be done directly without resorting to using macros.

---
 include/hw/boards.h        |   3 +-
 hw/arm/virt.c              |  48 ++-
 hw/core/machine.c          |  19 +-
 hw/core/qdev.c             |   2 +
 hw/i386/pc_piix.c          | 588 +++++++++++++++++++++----------------
 hw/i386/pc_q35.c           |  70 ++++-
 hw/ppc/spapr.c             | 209 +++++++------
 hw/s390x/s390-virtio-ccw.c | 220 +++++++-------
 vl.c                       |   1 -
 9 files changed, 673 insertions(+), 487 deletions(-)
include/hw/boards.h +1 -2
index f82f28468b..28c2b0af41 100644
@@ -69,7 +69,6 @@ int machine_kvm_shadow_mem(MachineState *machine);
 int machine_phandle_start(MachineState *machine);
 bool machine_dump_guest_core(MachineState *machine);
 bool machine_mem_merge(MachineState *machine);
-void machine_register_compat_props(MachineState *machine);
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
 void machine_set_cpu_numa_node(MachineState *machine,
                                const CpuInstanceProperties *props,
@@ -191,7 +190,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
-    GArray *compat_props;
+    GPtrArray *compat_props;
     const char *hw_version;
     ram_addr_t default_ram_size;
     const char *default_cpu_type;
hw/arm/virt.c +32 -16

142 lines not on this page · raw message

hw/core/machine.c +1 -18
index c51423b647..6e24924aba 100644
@@ -647,6 +647,7 @@ static void machine_class_base_init(ObjectClass *oc, void *data)
         assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
         mc->name = g_strndup(cname,
                             strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
+        mc->compat_props = g_ptr_array_new();
     }
 }
 
@@ -834,24 +835,6 @@ void machine_run_board_init(MachineState *machine)
     machine_class->init(machine);
 }
 
-void machine_register_compat_props(MachineState *machine)
-{
-    MachineClass *mc = MACHINE_GET_CLASS(machine);
-    int i;
-    GlobalProperty *p;
-
-    if (!mc->compat_props) {
-        return;
-    }
-
-    for (i = 0; i < mc->compat_props->len; i++) {
-        p = g_array_index(mc->compat_props, GlobalProperty *, i);
-        /* Machine compat_props must never cause errors: */
-        p->errp = &error_abort;
-        qdev_prop_register_global(p);
-    }
-}
-
 static const TypeInfo machine_info = {
     .name = TYPE_MACHINE,
     .parent = TYPE_OBJECT,
hw/core/qdev.c +2 -0
index 53b507164f..d510340bac 100644
@@ -974,11 +974,13 @@ static void device_post_init(Object *obj)
 {
     if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
         MachineState *m = MACHINE(qdev_get_machine());
+        MachineClass *mc = MACHINE_GET_CLASS(m);
         AccelClass *ac = ACCEL_GET_CLASS(m->accelerator);
 
         if (ac->compat_props) {
             object_apply_global_props(obj, ac->compat_props, &error_abort);
         }
+        object_apply_global_props(obj, mc->compat_props, &error_abort);
     }
 
     qdev_prop_set_globals(DEVICE(obj));
hw/i386/pc_piix.c +340 -248

882 lines not on this page · raw message

hw/i386/pc_q35.c +60 -10

166 lines not on this page · raw message

hw/ppc/spapr.c +117 -92

373 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +120 -100

286 lines not on this page · raw message

vl.c +0 -1
index 88ba658572..65f0dddb74 100644
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
  */
 static void register_global_properties(MachineState *ms)
 {
-    machine_register_compat_props(ms);
     user_register_global_props();
 }
 
Signature · 1 line
2.20.0.rc1
#14 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Quoted 46 lines · Marc-André Lureau

Similarly to accel properties, move compat properties out of globals registration, and apply the machine compat properties during device_post_init().

As suggested during review, populating the arrays can be done directly without resorting to using macros.

---
 include/hw/boards.h        |   3 +-
 hw/arm/virt.c              |  48 ++-
 hw/core/machine.c          |  19 +-
 hw/core/qdev.c             |   2 +
 hw/i386/pc_piix.c          | 588 +++++++++++++++++++++----------------
 hw/i386/pc_q35.c           |  70 ++++-
 hw/ppc/spapr.c             | 209 +++++++------
 hw/s390x/s390-virtio-ccw.c | 220 +++++++-------
 vl.c                       |   1 -
 9 files changed, 673 insertions(+), 487 deletions(-)
include/hw/boards.h +1 -2
index f82f28468b..28c2b0af41 100644
@@ -69,7 +69,6 @@ int machine_kvm_shadow_mem(MachineState *machine);
 int machine_phandle_start(MachineState *machine);
 bool machine_dump_guest_core(MachineState *machine);
 bool machine_mem_merge(MachineState *machine);
-void machine_register_compat_props(MachineState *machine);
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
 void machine_set_cpu_numa_node(MachineState *machine,
                                const CpuInstanceProperties *props,
@@ -191,7 +190,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
-    GArray *compat_props;
+    GPtrArray *compat_props;
     const char *hw_version;
     ram_addr_t default_ram_size;
     const char *default_cpu_type;
hw/arm/virt.c +0 -0
index f69e7eb399..530c8ca89d 100644

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 7 lines
hw/arm/virt.c +2 -1
@@ -1872,8 +1872,9 @@ static void virt_machine_3_1_options(MachineClass *mc)
 }
 DEFINE_VIRT_MACHINE_AS_LATEST(3, 1)
 
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};

[...]

All the changes to compat macros are independent from the change you describe in the patch subject, and makes review more difficult. What about doing that in a separate patch?

We can replace all the virt.c, pc_piix.c, pc_q35.c, and spapr.c hunks in this patch with the following:

include/hw/boards.h +1 -9
index f82f28468b..622bbaf939 100644
@@ -290,18 +289,10 @@ struct MachineState {
 
 #define SET_MACHINE_COMPAT(m, COMPAT) \
     do {                              \
-        int i;                        \
         static GlobalProperty props[] = {       \
             COMPAT                              \
-            { /* end of list */ }               \
         };                                      \
-        if (!m->compat_props) { \
-            m->compat_props = g_array_new(false, false, sizeof(void *)); \
-        } \
-        for (i = 0; props[i].driver != NULL; i++) {    \
-            GlobalProperty *prop = &props[i];          \
-            g_array_append_val(m->compat_props, prop); \
-        }                                              \
+        compat_props_add(m->compat_props, props, G_N_ELEMENTS(props)); \
     } while (0)
 
 #endif
Signature · 1 line
Eduardo
#15 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Hi

Quoted 79 lines · Eduardo Habkost
Quoted 46 lines · Marc-André Lureau

Similarly to accel properties, move compat properties out of globals registration, and apply the machine compat properties during device_post_init().

As suggested during review, populating the arrays can be done directly without resorting to using macros.

---
 include/hw/boards.h        |   3 +-
 hw/arm/virt.c              |  48 ++-
 hw/core/machine.c          |  19 +-
 hw/core/qdev.c             |   2 +
 hw/i386/pc_piix.c          | 588 +++++++++++++++++++++----------------
 hw/i386/pc_q35.c           |  70 ++++-
 hw/ppc/spapr.c             | 209 +++++++------
 hw/s390x/s390-virtio-ccw.c | 220 +++++++-------
 vl.c                       |   1 -
 9 files changed, 673 insertions(+), 487 deletions(-)
include/hw/boards.h +1 -2
index f82f28468b..28c2b0af41 100644
@@ -69,7 +69,6 @@ int machine_kvm_shadow_mem(MachineState *machine);
 int machine_phandle_start(MachineState *machine);
 bool machine_dump_guest_core(MachineState *machine);
 bool machine_mem_merge(MachineState *machine);
-void machine_register_compat_props(MachineState *machine);
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
 void machine_set_cpu_numa_node(MachineState *machine,
                                const CpuInstanceProperties *props,
@@ -191,7 +190,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
-    GArray *compat_props;
+    GPtrArray *compat_props;
     const char *hw_version;
     ram_addr_t default_ram_size;
     const char *default_cpu_type;
hw/arm/virt.c +0 -0
index f69e7eb399..530c8ca89d 100644

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 7 lines
hw/arm/virt.c +2 -1
@@ -1872,8 +1872,9 @@ static void virt_machine_3_1_options(MachineClass *mc)
 }
 DEFINE_VIRT_MACHINE_AS_LATEST(3, 1)
 
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};

[...]

All the changes to compat macros are independent from the change you describe in the patch subject, and makes review more difficult. What about doing that in a separate patch?

We can replace all the virt.c, pc_piix.c, pc_q35.c, and spapr.c hunks in this patch with the following:

include/hw/boards.h +0 -3
index f82f28468b..622bbaf939 100644
@@ -290,18 +289,10 @@ struct MachineState {
 
 #define SET_MACHINE_COMPAT(m, COMPAT) \
     do {                              \
-        int i;                        \
         static GlobalProperty props[] = {       \
             COMPAT                              \
-            { /* end of list */ }               \
         };                                      \
-        if (!m->compat_props) { \

include/hw/boards.h struct MachineState { · line 298

Quoted 10 lines
include/hw/boards.h +1 -6
-            m->compat_props = g_array_new(false, false, sizeof(void *)); \
-        } \
-        for (i = 0; props[i].driver != NULL; i++) {    \
-            GlobalProperty *prop = &props[i];          \
-            g_array_append_val(m->compat_props, prop); \
-        }                                              \
+        compat_props_add(m->compat_props, props, G_N_ELEMENTS(props)); \
     } while (0)
 
 #endif

Didn't you ask in a previous iteration to remove the macros? "I like us to be able to
register compat properties without macro magic. The existence of SET_MACHINE_COMPAT is a bug and not a feature.

Signature · 1 line
Marc-André Lureau
#16 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Quoted 90 lines · Marc-André Lureau

Hi

Quoted 87 lines · Eduardo Habkost
Quoted 46 lines · Marc-André Lureau

Similarly to accel properties, move compat properties out of globals registration, and apply the machine compat properties during device_post_init().

As suggested during review, populating the arrays can be done directly without resorting to using macros.

---
 include/hw/boards.h        |   3 +-
 hw/arm/virt.c              |  48 ++-
 hw/core/machine.c          |  19 +-
 hw/core/qdev.c             |   2 +
 hw/i386/pc_piix.c          | 588 +++++++++++++++++++++----------------
 hw/i386/pc_q35.c           |  70 ++++-
 hw/ppc/spapr.c             | 209 +++++++------
 hw/s390x/s390-virtio-ccw.c | 220 +++++++-------
 vl.c                       |   1 -
 9 files changed, 673 insertions(+), 487 deletions(-)
include/hw/boards.h +1 -2
index f82f28468b..28c2b0af41 100644
@@ -69,7 +69,6 @@ int machine_kvm_shadow_mem(MachineState *machine);
 int machine_phandle_start(MachineState *machine);
 bool machine_dump_guest_core(MachineState *machine);
 bool machine_mem_merge(MachineState *machine);
-void machine_register_compat_props(MachineState *machine);
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
 void machine_set_cpu_numa_node(MachineState *machine,
                                const CpuInstanceProperties *props,
@@ -191,7 +190,7 @@ struct MachineClass {
     const char *default_machine_opts;
     const char *default_boot_order;
     const char *default_display;
-    GArray *compat_props;
+    GPtrArray *compat_props;
     const char *hw_version;
     ram_addr_t default_ram_size;
     const char *default_cpu_type;
hw/arm/virt.c +0 -0
index f69e7eb399..530c8ca89d 100644

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 7 lines
hw/arm/virt.c +2 -1
@@ -1872,8 +1872,9 @@ static void virt_machine_3_1_options(MachineClass *mc)
 }
 DEFINE_VIRT_MACHINE_AS_LATEST(3, 1)
 
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};

[...]

All the changes to compat macros are independent from the change you describe in the patch subject, and makes review more difficult. What about doing that in a separate patch?

We can replace all the virt.c, pc_piix.c, pc_q35.c, and spapr.c hunks in this patch with the following:

include/hw/boards.h +1 -9
index f82f28468b..622bbaf939 100644
@@ -290,18 +289,10 @@ struct MachineState {
 
 #define SET_MACHINE_COMPAT(m, COMPAT) \
     do {                              \
-        int i;                        \
         static GlobalProperty props[] = {       \
             COMPAT                              \
-            { /* end of list */ }               \
         };                                      \
-        if (!m->compat_props) { \
-            m->compat_props = g_array_new(false, false, sizeof(void *)); \
-        } \
-        for (i = 0; props[i].driver != NULL; i++) {    \
-            GlobalProperty *prop = &props[i];          \
-            g_array_append_val(m->compat_props, prop); \
-        }                                              \
+        compat_props_add(m->compat_props, props, G_N_ELEMENTS(props)); \
     } while (0)
 
Quoted 7 lines

include/hw/boards.h struct MachineState { · line 298

Quoted 2 lines
include/hw/boards.h +0 -0
 #endif

Didn't you ask in a previous iteration to remove the macros? "I like us to be able to
register compat properties without macro magic. The existence of SET_MACHINE_COMPAT is a bug and not a feature.

I did ask you to not introduce a new macro in accel.c, and removing the existing macros is really welcome. I just don't think we should do everything in a single patch.

Signature · 1 line
Eduardo
#17 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

In reply to Marc-André Lureau

I have specific questions about the approach we are using to eliminate the macros.

My main goal when asking this to be moved to a separate patch is to not make this discussion block the register_global_properties() & device_post_init() changes (which look good to me).

On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
[...]

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 4 lines
hw/arm/virt.c +2 -1
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};

What about moving the array inside virt_machine_3_0_options()?

hw/arm/virt.c static void virt_3_0_instance_init(Object *obj) · line 1890

Quoted 12 lines

static void virt_3_0_instance_init(Object *obj)
{

hw/arm/virt.c +2 -1
@@ -1883,12 +1884,14 @@ static void virt_3_0_instance_init(Object *obj)
 static void virt_machine_3_0_options(MachineClass *mc)
 {
     virt_machine_3_1_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     virt_compat_3_0, G_N_ELEMENTS(virt_compat_3_0));
 }
 DEFINE_VIRT_MACHINE(3, 0)

This is nice, because it's basically the same amount of boilerplate code, but I would find a NULL-terminated array much easier to use than having to use G_N_ELEMENTS().

This would be nice in cases like virt, because we wouldn't even need to declare a separate array. We could do something like:

    compat_props_add(mc->compat_props, hw_compat_3_0);

and that's all. No need for HW_COMPAT_* macros, no need for extra arrays to be declared.

[...]

Quoted 15 lines
hw/i386/pc_piix.c +4 -0
index 7092d6d13f..575566e466 100644
@@ -438,74 +438,112 @@ static void pc_i440fx_3_1_machine_options(MachineClass *m)
 DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
                       pc_i440fx_3_1_machine_options);
 
+static GlobalProperty pc_compat_3_0[] = {
+    PC_COMPAT_3_0
+};
+
 static void pc_i440fx_3_0_machine_options(MachineClass *m)
 {
     pc_i440fx_3_1_machine_options(m);

hw/i386/pc_piix.c static void pc_i440fx_3_1_machine_options(MachineClass *m) · line 456

Quoted 10 lines
hw/i386/pc_piix.c +3 -1
     m->is_default = 0;
     m->alias = NULL;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_3_0);
+
+    compat_props_add(m->compat_props,
+                     pc_compat_3_0, G_N_ELEMENTS(pc_compat_3_0));
 }
 
 DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
                       pc_i440fx_3_0_machine_options);

Now, this is requiring _more_ boilerplate code than before. I'd like us to find a way to eliminate the macro without increasing the amount of boilerplate code.

[...]

Quoted 57 lines
hw/ppc/spapr.c +16 -13
index 7afd1a175b..d801ba71eb 100644
@@ -3973,8 +3973,9 @@ DEFINE_SPAPR_MACHINE(3_1, "3.1", true);
 /*
  * pseries-3.0
  */
-#define SPAPR_COMPAT_3_0                                              \
+static GlobalProperty spapr_compat_3_0[] = {
     HW_COMPAT_3_0
+};
 
 static void spapr_machine_3_0_instance_options(MachineState *machine)
 {
@@ -3986,7 +3987,8 @@ static void spapr_machine_3_0_class_options(MachineClass *mc)
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
 
     spapr_machine_3_1_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_3_0, G_N_ELEMENTS(spapr_compat_3_0));
 
     smc->legacy_irq_allocation = true;
     smc->irq = &spapr_irq_xics_legacy;
@@ -3997,18 +3999,19 @@ DEFINE_SPAPR_MACHINE(3_0, "3.0", false);
 /*
  * pseries-2.12
  */
-#define SPAPR_COMPAT_2_12                                              \
-    HW_COMPAT_2_12                                                     \
-    {                                                                  \
-        .driver = TYPE_POWERPC_CPU,                                    \
-        .property = "pre-3.0-migration",                               \
-        .value    = "on",                                              \
-    },                                                                 \
-    {                                                                  \
-        .driver = TYPE_SPAPR_CPU_CORE,                                 \
-        .property = "pre-3.0-migration",                               \
-        .value    = "on",                                              \
+static GlobalProperty spapr_compat_2_12[] = {
+    HW_COMPAT_2_12
+    {
+        .driver = TYPE_POWERPC_CPU,
+        .property = "pre-3.0-migration",
+        .value    = "on",
+    },
+    {
+        .driver = TYPE_SPAPR_CPU_CORE,
+        .property = "pre-3.0-migration",
+        .value    = "on",
     },
+};
 
 static void spapr_machine_2_12_instance_options(MachineState *machine)
 {

hw/ppc/spapr.c static void spapr_machine_2_12_class_options(MachineClass *mc) · line 4027

Quoted 6 lines
hw/ppc/spapr.c +2 -1
@@ -4020,7 +4023,8 @@ static void spapr_machine_2_12_class_options(MachineClass *mc)
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
 
     spapr_machine_3_0_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_12);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_12, G_N_ELEMENTS(spapr_compat_2_12));

It would be nice to be able to write this as:

    static GlobalProperty spapr_compat_2_12[] = {
        {
            .driver = TYPE_POWERPC_CPU,
            .property = "pre-3.0-migration",
            .value    = "on",
        },
        {
            .driver = TYPE_SPAPR_CPU_CORE,
            .property = "pre-3.0-migration",
            .value    = "on",
        },
        { /* end of list */ },
    };

    compat_props_add(mc->compat_props, hw_compat_3_0);
    compat_props_add(mc->compat_props, spapr_compat_2_12);

This way we won't need the HW_COMPAT_* macros anymore.

Other than that, it's also basically the same amount of boilerplate as before, so that's good.

Quoted 3 lines
hw/ppc/spapr.c +0 -0
     /* We depend on kvm_enabled() to choose a default value for the
      * hpt-max-page-size capability. Of course we can't do it here

[...]

Quoted 21 lines
hw/s390x/s390-virtio-ccw.c +0 -13
index a0615a8b35..275cbe5da4 100644
@@ -651,96 +651,106 @@ bool css_migration_enabled(void)
     }                                                                         \
     type_init(ccw_machine_register_##suffix)
 
-#define CCW_COMPAT_3_0 \
-        HW_COMPAT_3_0
-
-#define CCW_COMPAT_2_12 \
-        HW_COMPAT_2_12
-
-#define CCW_COMPAT_2_11 \
-        HW_COMPAT_2_11 \
-        {\
-            .driver   = TYPE_SCLP_EVENT_FACILITY,\
-            .property = "allow_all_mask_sizes",\
-            .value    = "off",\
-        },

[...]

Quoted 16 lines
hw/s390x/s390-virtio-ccw.c +16 -0
+static GlobalProperty ccw_compat_3_0[] = {
+    HW_COMPAT_3_0
+};
+
+static GlobalProperty ccw_compat_2_12[] = {
+    HW_COMPAT_2_12
+};
+
+static GlobalProperty ccw_compat_2_11[] = {
+    HW_COMPAT_2_11
+    {
+        .driver   = TYPE_SCLP_EVENT_FACILITY,
+        .property = "allow_all_mask_sizes",
+        .value    = "off",
+    },
+};

[...]

hw/s390x/s390-virtio-ccw.c static void ccw_machine_3_0_class_options(MachineClass *mc) · line 776

Quoted 10 lines

static void ccw_machine_3_1_instance_options(MachineState *machine) {

hw/s390x/s390-virtio-ccw.c +2 -1
@@ -762,7 +772,8 @@ static void ccw_machine_3_0_class_options(MachineClass *mc)
 
     s390mc->hpage_1m_allowed = false;
     ccw_machine_3_1_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_3_0, G_N_ELEMENTS(ccw_compat_3_0));

Same comments from spapr apply here: getting rid of the HW_COMPAT_* macros would be nice, but this version is good enough because it has the same amount of boilerplate code.

Quoted 2 lines
hw/s390x/s390-virtio-ccw.c +0 -0
 }
 DEFINE_CCW_MACHINE(3_0, "3.0", false);

[...]

Signature · 1 line
Eduardo
#18 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Hi

Quoted 9 lines · Eduardo Habkost

I have specific questions about the approach we are using to eliminate the macros.

My main goal when asking this to be moved to a separate patch is to not make this discussion block the register_global_properties() & device_post_init() changes (which look good to me).

Quoted 8 lines

On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
[...]

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 4 lines
hw/arm/virt.c +2 -1
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};

What about moving the array inside virt_machine_3_0_options()?

Sure

Quoted 17 lines

hw/arm/virt.c static void virt_3_0_instance_init(Object *obj) · line 1890

Quoted 13 lines

static void virt_3_0_instance_init(Object *obj)
{

hw/arm/virt.c +2 -1
@@ -1883,12 +1884,14 @@ static void virt_3_0_instance_init(Object *obj)
 static void virt_machine_3_0_options(MachineClass *mc)
 {
     virt_machine_3_1_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     virt_compat_3_0, G_N_ELEMENTS(virt_compat_3_0));
 }
 DEFINE_VIRT_MACHINE(3, 0)

This is nice, because it's basically the same amount of boilerplate code, but I would find a NULL-terminated array much easier to use than having to use G_N_ELEMENTS().

But easier to get wrong too. I prefer the explicit N arguments. (it also gives some flexibility, since you can point to inner pointer + size, although we don't care at this point)

Quoted 34 lines

This would be nice in cases like virt, because we wouldn't even need to declare a separate array. We could do something like:

    compat_props_add(mc->compat_props, hw_compat_3_0);

and that's all. No need for HW_COMPAT_* macros, no need for extra arrays to be declared.

[...]

Quoted 23 lines
hw/i386/pc_piix.c +7 -1
index 7092d6d13f..575566e466 100644
@@ -438,74 +438,112 @@ static void pc_i440fx_3_1_machine_options(MachineClass *m)
 DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
                       pc_i440fx_3_1_machine_options);
 
+static GlobalProperty pc_compat_3_0[] = {
+    PC_COMPAT_3_0
+};
+
 static void pc_i440fx_3_0_machine_options(MachineClass *m)
 {
     pc_i440fx_3_1_machine_options(m);
     m->is_default = 0;
     m->alias = NULL;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_3_0);
+
+    compat_props_add(m->compat_props,
+                     pc_compat_3_0, G_N_ELEMENTS(pc_compat_3_0));
 }
 
Quoted 6 lines

hw/i386/pc_piix.c static void pc_i440fx_3_1_machine_options(MachineClass *m) · line 456

Quoted 2 lines
hw/i386/pc_piix.c +0 -0
 DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
                       pc_i440fx_3_0_machine_options);

Now, this is requiring _more_ boilerplate code than before. I'd like us to find a way to eliminate the macro without increasing the amount of boilerplate code.

I am open to ideas

Quoted 86 lines

[...]

Quoted 57 lines
hw/ppc/spapr.c +16 -13
index 7afd1a175b..d801ba71eb 100644
@@ -3973,8 +3973,9 @@ DEFINE_SPAPR_MACHINE(3_1, "3.1", true);
 /*
  * pseries-3.0
  */
-#define SPAPR_COMPAT_3_0                                              \
+static GlobalProperty spapr_compat_3_0[] = {
     HW_COMPAT_3_0
+};
 
 static void spapr_machine_3_0_instance_options(MachineState *machine)
 {
@@ -3986,7 +3987,8 @@ static void spapr_machine_3_0_class_options(MachineClass *mc)
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
 
     spapr_machine_3_1_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_3_0, G_N_ELEMENTS(spapr_compat_3_0));
 
     smc->legacy_irq_allocation = true;
     smc->irq = &spapr_irq_xics_legacy;
@@ -3997,18 +3999,19 @@ DEFINE_SPAPR_MACHINE(3_0, "3.0", false);
 /*
  * pseries-2.12
  */
-#define SPAPR_COMPAT_2_12                                              \
-    HW_COMPAT_2_12                                                     \
-    {                                                                  \
-        .driver = TYPE_POWERPC_CPU,                                    \
-        .property = "pre-3.0-migration",                               \
-        .value    = "on",                                              \
-    },                                                                 \
-    {                                                                  \
-        .driver = TYPE_SPAPR_CPU_CORE,                                 \
-        .property = "pre-3.0-migration",                               \
-        .value    = "on",                                              \
+static GlobalProperty spapr_compat_2_12[] = {
+    HW_COMPAT_2_12
+    {
+        .driver = TYPE_POWERPC_CPU,
+        .property = "pre-3.0-migration",
+        .value    = "on",
+    },
+    {
+        .driver = TYPE_SPAPR_CPU_CORE,
+        .property = "pre-3.0-migration",
+        .value    = "on",
     },
+};
 
 static void spapr_machine_2_12_instance_options(MachineState *machine)
 {

hw/ppc/spapr.c static void spapr_machine_2_12_class_options(MachineClass *mc) · line 4027

Quoted 6 lines
hw/ppc/spapr.c +2 -1
@@ -4020,7 +4023,8 @@ static void spapr_machine_2_12_class_options(MachineClass *mc)
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
 
     spapr_machine_3_0_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_12);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_12, G_N_ELEMENTS(spapr_compat_2_12));

It would be nice to be able to write this as:

    static GlobalProperty spapr_compat_2_12[] = {
        {
            .driver = TYPE_POWERPC_CPU,
            .property = "pre-3.0-migration",
            .value    = "on",
        },
        {
            .driver = TYPE_SPAPR_CPU_CORE,
            .property = "pre-3.0-migration",
            .value    = "on",
        },
        { /* end of list */ },
    };

    compat_props_add(mc->compat_props, hw_compat_3_0);
    compat_props_add(mc->compat_props, spapr_compat_2_12);
Quoted 1 line

This way we won't need the HW_COMPAT_* macros anymore.

That could be done on top, I imagine. I can give it a try.

Quoted 53 lines

Other than that, it's also basically the same amount of boilerplate as before, so that's good.

Quoted 3 lines
hw/ppc/spapr.c +0 -0
     /* We depend on kvm_enabled() to choose a default value for the
      * hpt-max-page-size capability. Of course we can't do it here

[...]

Quoted 21 lines
hw/s390x/s390-virtio-ccw.c +0 -13
index a0615a8b35..275cbe5da4 100644
@@ -651,96 +651,106 @@ bool css_migration_enabled(void)
     }                                                                         \
     type_init(ccw_machine_register_##suffix)
 
-#define CCW_COMPAT_3_0 \
-        HW_COMPAT_3_0
-
-#define CCW_COMPAT_2_12 \
-        HW_COMPAT_2_12
-
-#define CCW_COMPAT_2_11 \
-        HW_COMPAT_2_11 \
-        {\
-            .driver   = TYPE_SCLP_EVENT_FACILITY,\
-            .property = "allow_all_mask_sizes",\
-            .value    = "off",\
-        },

[...]

Quoted 16 lines
hw/s390x/s390-virtio-ccw.c +16 -0
+static GlobalProperty ccw_compat_3_0[] = {
+    HW_COMPAT_3_0
+};
+
+static GlobalProperty ccw_compat_2_12[] = {
+    HW_COMPAT_2_12
+};
+
+static GlobalProperty ccw_compat_2_11[] = {
+    HW_COMPAT_2_11
+    {
+        .driver   = TYPE_SCLP_EVENT_FACILITY,
+        .property = "allow_all_mask_sizes",
+        .value    = "off",
+    },
+};

[...]

Quoted 5 lines

static void ccw_machine_3_1_instance_options(MachineState *machine) {

hw/s390x/s390-virtio-ccw.c +0 -0
@@ -762,7 +772,8 @@ static void ccw_machine_3_0_class_options(MachineClass *mc)
 
Quoted 11 lines

hw/s390x/s390-virtio-ccw.c static void ccw_machine_3_0_class_options(MachineClass *mc) · line 776

Quoted 5 lines
hw/s390x/s390-virtio-ccw.c +2 -1
     s390mc->hpage_1m_allowed = false;
     ccw_machine_3_1_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_3_0, G_N_ELEMENTS(ccw_compat_3_0));

Same comments from spapr apply here: getting rid of the HW_COMPAT_* macros would be nice, but this version is good enough because it has the same amount of boilerplate code.

thanks

Quoted 7 lines

hw/s390x/s390-virtio-ccw.c static void ccw_machine_3_0_class_options(MachineClass *mc) · line 778

Quoted 2 lines
hw/s390x/s390-virtio-ccw.c +0 -0
 }
 DEFINE_CCW_MACHINE(3_0, "3.0", false);

[...]

--
Eduardo

Signature · 1 line
Marc-André Lureau
#19 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Quoted 41 lines · On Tue, 11 Dec 2018 18:30:32 +0400 Marc-André Lureau…

Hi

Quoted 9 lines · Eduardo Habkost

I have specific questions about the approach we are using to eliminate the macros.

My main goal when asking this to be moved to a separate patch is to not make this discussion block the register_global_properties() & device_post_init() changes (which look good to me).

Quoted 8 lines

On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
[...]

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 4 lines
hw/arm/virt.c +2 -1
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};  

What about moving the array inside virt_machine_3_0_options()?

Sure

Quoted 17 lines

hw/arm/virt.c static void virt_3_0_instance_init(Object *obj) · line 1890

Quoted 13 lines

static void virt_3_0_instance_init(Object *obj)
{

hw/arm/virt.c +2 -1
@@ -1883,12 +1884,14 @@ static void virt_3_0_instance_init(Object *obj)
 static void virt_machine_3_0_options(MachineClass *mc)
 {
     virt_machine_3_1_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     virt_compat_3_0, G_N_ELEMENTS(virt_compat_3_0));
 }
 DEFINE_VIRT_MACHINE(3, 0)  

This is nice, because it's basically the same amount of boilerplate code, but I would find a NULL-terminated array much easier to use than having to use G_N_ELEMENTS().

Quoted 3 lines

But easier to get wrong too. I prefer the explicit N arguments. (it also gives some flexibility, since you can point to inner pointer + size, although we don't care at this point)

+1 to explicit array size,
it also allows to drop terminating NULL entry in compat declarations

[...]

#20 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals

Quoted 44 lines · Igor Mammedov
Quoted 41 lines · On Tue, 11 Dec 2018 18:30:32 +0400 Marc-André Lureau…

Hi

Quoted 9 lines · Eduardo Habkost

I have specific questions about the approach we are using to eliminate the macros.

My main goal when asking this to be moved to a separate patch is to not make this discussion block the register_global_properties() & device_post_init() changes (which look good to me).

Quoted 8 lines

On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
[...]

hw/arm/virt.c static void virt_machine_3_1_options(MachineClass *mc) · line 1877

Quoted 4 lines
hw/arm/virt.c +2 -1
-#define VIRT_COMPAT_3_0 \
+static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
+};  

What about moving the array inside virt_machine_3_0_options()?

Sure

Quoted 17 lines

hw/arm/virt.c static void virt_3_0_instance_init(Object *obj) · line 1890

Quoted 13 lines

static void virt_3_0_instance_init(Object *obj)
{

hw/arm/virt.c +2 -1
@@ -1883,12 +1884,14 @@ static void virt_3_0_instance_init(Object *obj)
 static void virt_machine_3_0_options(MachineClass *mc)
 {
     virt_machine_3_1_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_3_0);
+    compat_props_add(mc->compat_props,
+                     virt_compat_3_0, G_N_ELEMENTS(virt_compat_3_0));
 }
 DEFINE_VIRT_MACHINE(3, 0)  

This is nice, because it's basically the same amount of boilerplate code, but I would find a NULL-terminated array much easier to use than having to use G_N_ELEMENTS().

Quoted 5 lines
Quoted 3 lines

But easier to get wrong too. I prefer the explicit N arguments. (it also gives some flexibility, since you can point to inner pointer + size, although we don't care at this point)

+1 to explicit array size,
it also allows to drop terminating NULL entry in compat declarations

I don't mind using G_N_ELEMENTS if you really think it's better, but I wonder if it will be an obstacle for making
compat_props_add(compat_props, hw_compat_3_0, ...)
work, because the size of hw_compat_3_0 won't be known by compat.h or spapr.c.

Signature · 1 line
Eduardo
#21 lore raw

PATCH v5 9/19 hw: remove SET_MACHINE_COMPAT

In reply to Marc-André Lureau

No longer needed.

---
 include/hw/boards.h | 16 ----------------
 1 file changed, 16 deletions(-)
include/hw/boards.h +0 -16
index 28c2b0af41..f743d9d4a4 100644
@@ -287,20 +287,4 @@ struct MachineState {
     } \
     type_init(machine_initfn##_register_types)
 
-#define SET_MACHINE_COMPAT(m, COMPAT) \
-    do {                              \
-        int i;                        \
-        static GlobalProperty props[] = {       \
-            COMPAT                              \
-            { /* end of list */ }               \
-        };                                      \
-        if (!m->compat_props) { \
-            m->compat_props = g_array_new(false, false, sizeof(void *)); \
-        } \
-        for (i = 0; props[i].driver != NULL; i++) {    \
-            GlobalProperty *prop = &props[i];          \
-            g_array_append_val(m->compat_props, prop); \
-        }                                              \
-    } while (0)
-
 #endif
Signature · 1 line
2.20.0.rc1
#22 lore raw

PATCH v5 10/19 qdev: make a separate helper function to apply compat properties

In reply to Marc-André Lureau

This will allow to apply compat properties on other objects than QDev easily.

---
 include/hw/qdev-core.h | 2 ++
 hw/core/qdev.c         | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/hw/qdev-core.h +2 -0
index aeaa6dbbb8..4f9276f3e2 100644
@@ -422,6 +422,8 @@ const char *qdev_fw_name(DeviceState *dev);
 
 Object *qdev_get_machine(void);
 
+void object_apply_compat_props(Object *obj);
+
 /* FIXME: make this a link<> */
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
 
hw/core/qdev.c +5 -1
index d510340bac..3769a2bccb 100644
@@ -970,7 +970,7 @@ static void device_initfn(Object *obj)
     QLIST_INIT(&dev->gpios);
 }
 
-static void device_post_init(Object *obj)
+void object_apply_compat_props(Object *obj)
 {
     if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
         MachineState *m = MACHINE(qdev_get_machine());
@@ -982,7 +982,11 @@ static void device_post_init(Object *obj)
         }
         object_apply_global_props(obj, mc->compat_props, &error_abort);
     }
+}
 
+static void device_post_init(Object *obj)
+{
+    object_apply_compat_props(obj);
     qdev_prop_set_globals(DEVICE(obj));
 }
 
Signature · 1 line
2.20.0.rc1
#23 lore raw

PATCH v5 11/19 qdev: all globals are now user-provided

In reply to Marc-André Lureau

All globals are now either provided via -global or through -cpu features (CPU features are implemented by registering globals).

If the global isn't being used, it should warn in either case.

We can thus consider that all global_props are "user-provided" globals. No need to track this per-globals anymore.

---
 include/hw/qdev-core.h         |  3 --
 hw/core/qdev-properties.c      |  4 ---
 tests/test-qdev-global-props.c | 57 ++++------------------------------
 vl.c                           |  1 -
 4 files changed, 6 insertions(+), 59 deletions(-)
include/hw/qdev-core.h +0 -3
index 4f9276f3e2..7d25c99a77 100644
@@ -249,8 +249,6 @@ struct PropertyInfo {
 
 /**
  * GlobalProperty:
- * @user_provided: Set to true if property comes from user-provided config
- * (command-line or config file).
  * @used: Set to true if property was used when initializing a device.
  * @errp: Error destination, used like first argument of error_setg()
  *        in case property setting fails later. If @errp is NULL, we
@@ -262,7 +260,6 @@ typedef struct GlobalProperty {
     const char *driver;
     const char *property;
     const char *value;
-    bool user_provided;
     bool used;
     Error **errp;
 } GlobalProperty;
hw/core/qdev-properties.c +0 -4
index bd84c4ea4c..43c30a57f4 100644
@@ -1192,9 +1192,6 @@ int qdev_prop_check_globals(void)
         if (prop->used) {
             continue;
         }
-        if (!prop->user_provided) {
-            continue;
-        }
         oc = object_class_by_name(prop->driver);
         oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
         if (!oc) {
@@ -1233,7 +1230,6 @@ void qdev_prop_set_globals(DeviceState *dev)
             if (!dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
-                assert(prop->user_provided);
                 warn_report_err(err);
             }
         }
tests/test-qdev-global-props.c +6 -51

75 lines not on this page · raw message

vl.c +0 -1
index 65f0dddb74..dfc100f51a 100644
@@ -2936,7 +2936,6 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    g->user_provided = true;
     g->errp = &error_fatal;
     qdev_prop_register_global(g);
     return 0;
Signature · 1 line
2.20.0.rc1
Reviewed-by on v5 11/19
#24 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 11/19] qdev: all globals are now user-provided

Quoted 9 lines · On Tue, 4 Dec 2018 18:20:15 +0400 Marc-André Lureau…

All globals are now either provided via -global or through -cpu features (CPU features are implemented by registering globals).

If the global isn't being used, it should warn in either case.

We can thus consider that all global_props are "user-provided" globals. No need to track this per-globals anymore.

Quoted 144 lines
---
 include/hw/qdev-core.h         |  3 --
 hw/core/qdev-properties.c      |  4 ---
 tests/test-qdev-global-props.c | 57 ++++------------------------------
 vl.c                           |  1 -
 4 files changed, 6 insertions(+), 59 deletions(-)
include/hw/qdev-core.h +0 -3
index 4f9276f3e2..7d25c99a77 100644
@@ -249,8 +249,6 @@ struct PropertyInfo {
 
 /**
  * GlobalProperty:
- * @user_provided: Set to true if property comes from user-provided config
- * (command-line or config file).
  * @used: Set to true if property was used when initializing a device.
  * @errp: Error destination, used like first argument of error_setg()
  *        in case property setting fails later. If @errp is NULL, we
@@ -262,7 +260,6 @@ typedef struct GlobalProperty {
     const char *driver;
     const char *property;
     const char *value;
-    bool user_provided;
     bool used;
     Error **errp;
 } GlobalProperty;
hw/core/qdev-properties.c +0 -4
index bd84c4ea4c..43c30a57f4 100644
@@ -1192,9 +1192,6 @@ int qdev_prop_check_globals(void)
         if (prop->used) {
             continue;
         }
-        if (!prop->user_provided) {
-            continue;
-        }
         oc = object_class_by_name(prop->driver);
         oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
         if (!oc) {
@@ -1233,7 +1230,6 @@ void qdev_prop_set_globals(DeviceState *dev)
             if (!dev->hotplugged && prop->errp) {
                 error_propagate(prop->errp, err);
             } else {
-                assert(prop->user_provided);
                 warn_report_err(err);
             }
         }
tests/test-qdev-global-props.c +6 -51
index b1eb505442..60231b1372 100644
@@ -216,12 +216,12 @@ static void test_dynamic_globalprop_subprocess(void)
 {
     MyType *mt;
     static GlobalProperty props[] = {
-        { TYPE_DYNAMIC_PROPS, "prop1", "101", true },
-        { TYPE_DYNAMIC_PROPS, "prop2", "102", true },
-        { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103", true },
-        { TYPE_UNUSED_HOTPLUG, "prop4", "104", true },
-        { TYPE_UNUSED_NOHOTPLUG, "prop5", "105", true },
-        { TYPE_NONDEVICE, "prop6", "106", true },
+        { TYPE_DYNAMIC_PROPS, "prop1", "101", },
+        { TYPE_DYNAMIC_PROPS, "prop2", "102", },
+        { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103", },
+        { TYPE_UNUSED_HOTPLUG, "prop4", "104", },
+        { TYPE_UNUSED_NOHOTPLUG, "prop5", "105", },
+        { TYPE_NONDEVICE, "prop6", "106", },
         {}
     };
     int global_error;
@@ -256,46 +256,6 @@ static void test_dynamic_globalprop(void)
     g_test_trap_assert_stdout("");
 }
 
-/* Test setting of dynamic properties using user_provided=false properties */
-static void test_dynamic_globalprop_nouser_subprocess(void)
-{
-    MyType *mt;
-    static GlobalProperty props[] = {
-        { TYPE_DYNAMIC_PROPS, "prop1", "101" },
-        { TYPE_DYNAMIC_PROPS, "prop2", "102" },
-        { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103" },
-        { TYPE_UNUSED_HOTPLUG, "prop4", "104" },
-        { TYPE_UNUSED_NOHOTPLUG, "prop5", "105" },
-        { TYPE_NONDEVICE, "prop6", "106" },
-        {}
-    };
-    int global_error;
-
-    register_global_properties(props);
-
-    mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
-    qdev_init_nofail(DEVICE(mt));
-
-    g_assert_cmpuint(mt->prop1, ==, 101);
-    g_assert_cmpuint(mt->prop2, ==, 102);
-    global_error = qdev_prop_check_globals();
-    g_assert_cmpuint(global_error, ==, 0);
-    g_assert(props[0].used);
-    g_assert(props[1].used);
-    g_assert(!props[2].used);
-    g_assert(!props[3].used);
-    g_assert(!props[4].used);
-    g_assert(!props[5].used);
-}
-
-static void test_dynamic_globalprop_nouser(void)
-{
-    g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0);
-    g_test_trap_assert_passed();
-    g_test_trap_assert_stderr("");
-    g_test_trap_assert_stdout("");
-}
-
 /* Test if global props affecting subclasses are applied in the right order */
 static void test_subclass_global_props(void)
 {
@@ -345,11 +305,6 @@ int main(int argc, char **argv)
     g_test_add_func("/qdev/properties/dynamic/global",
                     test_dynamic_globalprop);
 
-    g_test_add_func("/qdev/properties/dynamic/global/nouser/subprocess",
-                    test_dynamic_globalprop_nouser_subprocess);
-    g_test_add_func("/qdev/properties/dynamic/global/nouser",
-                    test_dynamic_globalprop_nouser);
-
     g_test_add_func("/qdev/properties/global/subclass",
                     test_subclass_global_props);
 
vl.c +0 -1
index 65f0dddb74..dfc100f51a 100644
@@ -2936,7 +2936,6 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    g->user_provided = true;
     g->errp = &error_fatal;
     qdev_prop_register_global(g);
     return 0;
#25 lore raw

PATCH v5 12/19 qdev-props: convert global_props to GPtrArray

In reply to Marc-André Lureau

A step towards being able to call a common function, object_apply_global_props().

---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
hw/core/qdev-properties.c +20 -9
index 43c30a57f4..3467e0485c 100644
@@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static GList *global_props;
+static GPtrArray *global_props(void)
+{
+    static GPtrArray *gp;
+
+    if (!gp) {
+        gp = g_ptr_array_new();
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_ptr_array_add(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_ptr_array_index(global_props(), i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_ptr_array_index(global_props(), i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }
Signature · 1 line
2.20.0.rc1
#26 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 12/19] qdev-props: convert global_props to GPtrArray

Quoted 13 lines · On Tue, 4 Dec 2018 18:20:16 +0400 Marc-André Lureau…

A step towards being able to call a common function, object_apply_global_props().

---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
hw/core/qdev-properties.c +0 -0
index 43c30a57f4..3467e0485c 100644

hw/core/qdev-properties.c void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) · line 1181

Quoted 10 lines
hw/core/qdev-properties.c +6 -1
@@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static GList *global_props;
+static GPtrArray *global_props(void)
+{
+    static GPtrArray *gp;
+
+    if (!gp) {
+        gp = g_ptr_array_new();

one more leak?

Quoted 45 lines
hw/core/qdev-properties.c +14 -8
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_ptr_array_add(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_ptr_array_index(global_props(), i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_ptr_array_index(global_props(), i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }
#27 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 12/19] qdev-props: convert global_props to GPtrArray

Hi

Quoted 20 lines · Igor Mammedov
Quoted 16 lines · On Tue, 4 Dec 2018 18:20:16 +0400 Marc-André Lureau…

A step towards being able to call a common function, object_apply_global_props().

---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
hw/core/qdev-properties.c +0 -0
index 43c30a57f4..3467e0485c 100644
@@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
Quoted 8 lines

hw/core/qdev-properties.c void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) · line 1181

Quoted 7 lines
hw/core/qdev-properties.c +6 -1
-static GList *global_props;
+static GPtrArray *global_props(void)
+{
+    static GPtrArray *gp;
+
+    if (!gp) {
+        gp = g_ptr_array_new();

one more leak?

We leak the global_props list before and using a list is going to use more memory than using a GPtrArray.

If you worry about the global leaks, we can adress it with destructors. I don't think that matters here.

Quoted 48 lines
Quoted 46 lines
hw/core/qdev-properties.c +14 -8
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_ptr_array_add(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_ptr_array_index(global_props(), i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_ptr_array_index(global_props(), i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }
Signature · 1 line
Marc-André Lureau
#28 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 12/19] qdev-props: convert global_props to GPtrArray

Quoted 32 lines · On Tue, 11 Dec 2018 16:12:58 +0400 Marc-André Lureau…

Hi

Quoted 20 lines · Igor Mammedov
Quoted 16 lines · On Tue, 4 Dec 2018 18:20:16 +0400 Marc-André Lureau…

A step towards being able to call a common function, object_apply_global_props().

---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
hw/core/qdev-properties.c +0 -0
index 43c30a57f4..3467e0485c 100644
@@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
Quoted 8 lines

hw/core/qdev-properties.c void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) · line 1181

Quoted 7 lines
hw/core/qdev-properties.c +6 -1
-static GList *global_props;
+static GPtrArray *global_props(void)
+{
+    static GPtrArray *gp;
+
+    if (!gp) {
+        gp = g_ptr_array_new();  

one more leak?

Quoted 5 lines

We leak the global_props list before and using a list is going to use more memory than using a GPtrArray.

If you worry about the global leaks, we can adress it with destructors. I don't think that matters here.

We don't do it for a bunch of 'static' objects, so as Eduardo pointed out it's not worth it or more precisely it's broken currently and it's out of the scope of this series to fix it up.

Quoted 51 lines
Quoted 49 lines
Quoted 47 lines
hw/core/qdev-properties.c +14 -8
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_ptr_array_add(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_ptr_array_index(global_props(), i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_ptr_array_index(global_props(), i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }  
Reviewed-by on v5 12/19
#29 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 12/19] qdev-props: convert global_props to GPtrArray

In reply to Marc-André Lureau
Quoted 4 lines · On Tue, 4 Dec 2018 18:20:16 +0400 Marc-André Lureau…

A step towards being able to call a common function, object_apply_global_props().

Quoted 64 lines
---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
hw/core/qdev-properties.c +20 -9
index 43c30a57f4..3467e0485c 100644
@@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static GList *global_props;
+static GPtrArray *global_props(void)
+{
+    static GPtrArray *gp;
+
+    if (!gp) {
+        gp = g_ptr_array_new();
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_ptr_array_add(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_ptr_array_index(global_props(), i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_ptr_array_index(global_props(), i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }
#30 lore raw

PATCH v5 13/19 qdev-props: remove errp from GlobalProperty

In reply to Marc-André Lureau

All qdev_prop_register_global() set &error_fatal for errp, except '-rtc driftfix=slew', which arguably should also use &error_fatal, as otherwise failing to apply the property would only report a warning.

---
 include/hw/qdev-core.h    | 6 ------
 hw/core/qdev-properties.c | 4 ++--
 qom/cpu.c                 | 1 -
 target/i386/cpu.c         | 1 -
 target/sparc/cpu.c        | 1 -
 vl.c                      | 1 -
 6 files changed, 2 insertions(+), 12 deletions(-)
include/hw/qdev-core.h +0 -6
index 7d25c99a77..1d4f4aa1f5 100644
@@ -250,18 +250,12 @@ struct PropertyInfo {
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
- * @errp: Error destination, used like first argument of error_setg()
- *        in case property setting fails later. If @errp is NULL, we
- *        print warnings instead of ignoring errors silently. For
- *        hotplugged devices, errp is always ignored and warnings are
- *        printed instead.
  */
 typedef struct GlobalProperty {
     const char *driver;
     const char *property;
     const char *value;
     bool used;
-    Error **errp;
 } GlobalProperty;
 
 static inline void
hw/core/qdev-properties.c +2 -2
index 3467e0485c..a2d25d3d37 100644
@@ -1238,8 +1238,8 @@ void qdev_prop_set_globals(DeviceState *dev)
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
-                error_propagate(prop->errp, err);
+            if (!dev->hotplugged) {
+                error_propagate(&error_fatal, err);
             } else {
                 warn_report_err(err);
             }
qom/cpu.c +0 -1
index 9ad1372d57..5442a7323b 100644
@@ -312,7 +312,6 @@ static void cpu_common_parse_features(const char *typename, char *features,
             prop->driver = typename;
             prop->property = g_strdup(featurestr);
             prop->value = g_strdup(val);
-            prop->errp = &error_fatal;
             qdev_prop_register_global(prop);
         } else {
             error_setg(errp, "Expected key=value format, found %s.",
target/i386/cpu.c +0 -1
index f81d35e1f9..c687a9b694 100644
@@ -3568,7 +3568,6 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         prop->driver = typename;
         prop->property = g_strdup(name);
         prop->value = g_strdup(val);
-        prop->errp = &error_fatal;
         qdev_prop_register_global(prop);
     }
 
target/sparc/cpu.c +0 -1
index 0f090ece54..4a4445bdf5 100644
@@ -111,7 +111,6 @@ cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
     prop->driver = typename;
     prop->property = g_strdup(name);
     prop->value = g_strdup(val);
-    prop->errp = &error_fatal;
     qdev_prop_register_global(prop);
 }
 
vl.c +0 -1
index dfc100f51a..1b25cb3da2 100644
@@ -2936,7 +2936,6 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    g->errp = &error_fatal;
     qdev_prop_register_global(g);
     return 0;
 }
Signature · 1 line
2.20.0.rc1
Reviewed-by on v5 13/19
#31 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 13/19] qdev-props: remove errp from GlobalProperty

Quoted 2 lines · On Tue, 4 Dec 2018 18:20:17 +0400 Marc-André Lureau…

All qdev_prop_register_global() set &error_fatal for errp, except '-rtc driftfix=slew', which arguably should also use &error_fatal, as

this one shouldn't fail if machine has mc146818rtc instantiated, it should warn only in case when CLI is mis-configured (i.e. machine doesn't have mc146818rtc device). I'd say let it die in this case and make user fix CLI.

Quoted 3 lines

otherwise failing to apply the property would only report a warning.

Quoted 95 lines
---
 include/hw/qdev-core.h    | 6 ------
 hw/core/qdev-properties.c | 4 ++--
 qom/cpu.c                 | 1 -
 target/i386/cpu.c         | 1 -
 target/sparc/cpu.c        | 1 -
 vl.c                      | 1 -
 6 files changed, 2 insertions(+), 12 deletions(-)
include/hw/qdev-core.h +0 -6
index 7d25c99a77..1d4f4aa1f5 100644
@@ -250,18 +250,12 @@ struct PropertyInfo {
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
- * @errp: Error destination, used like first argument of error_setg()
- *        in case property setting fails later. If @errp is NULL, we
- *        print warnings instead of ignoring errors silently. For
- *        hotplugged devices, errp is always ignored and warnings are
- *        printed instead.
  */
 typedef struct GlobalProperty {
     const char *driver;
     const char *property;
     const char *value;
     bool used;
-    Error **errp;
 } GlobalProperty;
 
 static inline void
hw/core/qdev-properties.c +2 -2
index 3467e0485c..a2d25d3d37 100644
@@ -1238,8 +1238,8 @@ void qdev_prop_set_globals(DeviceState *dev)
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged && prop->errp) {
-                error_propagate(prop->errp, err);
+            if (!dev->hotplugged) {
+                error_propagate(&error_fatal, err);
             } else {
                 warn_report_err(err);
             }
qom/cpu.c +0 -1
index 9ad1372d57..5442a7323b 100644
@@ -312,7 +312,6 @@ static void cpu_common_parse_features(const char *typename, char *features,
             prop->driver = typename;
             prop->property = g_strdup(featurestr);
             prop->value = g_strdup(val);
-            prop->errp = &error_fatal;
             qdev_prop_register_global(prop);
         } else {
             error_setg(errp, "Expected key=value format, found %s.",
target/i386/cpu.c +0 -1
index f81d35e1f9..c687a9b694 100644
@@ -3568,7 +3568,6 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
         prop->driver = typename;
         prop->property = g_strdup(name);
         prop->value = g_strdup(val);
-        prop->errp = &error_fatal;
         qdev_prop_register_global(prop);
     }
 
target/sparc/cpu.c +0 -1
index 0f090ece54..4a4445bdf5 100644
@@ -111,7 +111,6 @@ cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
     prop->driver = typename;
     prop->property = g_strdup(name);
     prop->value = g_strdup(val);
-    prop->errp = &error_fatal;
     qdev_prop_register_global(prop);
 }
 
vl.c +0 -1
index dfc100f51a..1b25cb3da2 100644
@@ -2936,7 +2936,6 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    g->errp = &error_fatal;
     qdev_prop_register_global(g);
     return 0;
 }
#32 lore raw

PATCH v5 14/19 qdev-props: call object_apply_global_props()

In reply to Marc-André Lureau

It's now possible to use the common function.

Teach object_apply_global_props() to warn if Error argument is NULL.

---
 hw/core/qdev-properties.c | 24 ++----------------------
 qom/object.c              | 12 +++++++++++-
 2 files changed, 13 insertions(+), 23 deletions(-)
hw/core/qdev-properties.c +2 -22
index a2d25d3d37..6061090dc2 100644
@@ -1223,28 +1223,8 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    int i;
-
-    for (i = 0; i < global_props()->len; i++) {
-        GlobalProperty *prop;
-        Error *err = NULL;
-
-        prop = g_ptr_array_index(global_props(), i);
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
-            continue;
-        }
-        prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
-        if (err != NULL) {
-            error_prepend(&err, "can't apply global %s.%s=%s: ",
-                          prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged) {
-                error_propagate(&error_fatal, err);
-            } else {
-                warn_report_err(err);
-            }
-        }
-    }
+    object_apply_global_props(OBJECT(dev), global_props(),
+                              dev->hotplugged ? NULL : &error_fatal);
 }
 
 /* --- 64bit unsigned int 'size' type --- */
qom/object.c +11 -1
index dbdab0aead..aa6f3a2a71 100644
@@ -390,7 +390,17 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           p->driver, p->property, p->value);
-            error_propagate(errp, err);
+            /*
+             * If errp != NULL, propagate error and return.
+             * If errp == NULL, report a warning, but keep going
+             * with the remaining globals.
+             */
+            if (errp) {
+                error_propagate(errp, err);
+                return;
+            } else {
+                warn_report_err(err);
+            }
         }
     }
 }
Signature · 1 line
2.20.0.rc1
Reviewed-by on v5 14/19
#33 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 14/19] qdev-props: call object_apply_global_props()

Quoted 5 lines · On Tue, 4 Dec 2018 18:20:18 +0400 Marc-André Lureau…

It's now possible to use the common function.

Teach object_apply_global_props() to warn if Error argument is NULL.

Quoted 63 lines
---
 hw/core/qdev-properties.c | 24 ++----------------------
 qom/object.c              | 12 +++++++++++-
 2 files changed, 13 insertions(+), 23 deletions(-)
hw/core/qdev-properties.c +2 -22
index a2d25d3d37..6061090dc2 100644
@@ -1223,28 +1223,8 @@ int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    int i;
-
-    for (i = 0; i < global_props()->len; i++) {
-        GlobalProperty *prop;
-        Error *err = NULL;
-
-        prop = g_ptr_array_index(global_props(), i);
-        if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
-            continue;
-        }
-        prop->used = true;
-        object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
-        if (err != NULL) {
-            error_prepend(&err, "can't apply global %s.%s=%s: ",
-                          prop->driver, prop->property, prop->value);
-            if (!dev->hotplugged) {
-                error_propagate(&error_fatal, err);
-            } else {
-                warn_report_err(err);
-            }
-        }
-    }
+    object_apply_global_props(OBJECT(dev), global_props(),
+                              dev->hotplugged ? NULL : &error_fatal);
 }
 
 /* --- 64bit unsigned int 'size' type --- */
qom/object.c +11 -1
index dbdab0aead..aa6f3a2a71 100644
@@ -390,7 +390,17 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp
         if (err != NULL) {
             error_prepend(&err, "can't apply global %s.%s=%s: ",
                           p->driver, p->property, p->value);
-            error_propagate(errp, err);
+            /*
+             * If errp != NULL, propagate error and return.
+             * If errp == NULL, report a warning, but keep going
+             * with the remaining globals.
+             */
+            if (errp) {
+                error_propagate(errp, err);
+                return;
+            } else {
+                warn_report_err(err);
+            }
         }
     }
 }
#35 lore raw

PATCH v5 15/19 qom: add object_class_get_class_data()

In reply to Marc-André Lureau

Add a simple function to retrieve the associated class data.

---
 include/qom/object.h | 9 +++++++++
 qom/object.c         | 5 +++++
 2 files changed, 14 insertions(+)
include/qom/object.h +9 -0
index 5183c587f3..d5266405da 100644
@@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 ObjectClass *object_class_get_parent(ObjectClass *klass);
 
+
+/**
+ * object_class_get_class_data:
+ * @klass: The class to obtain associated data.
+ *
+ * Returns: the class_data given when registering the type.
+ */
+void *object_class_get_class_data(ObjectClass *klass);
+
 /**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
qom/object.c +5 -0
index aa6f3a2a71..bbc6fbbc01 100644
@@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
     return klass->type->name;
 }
 
+void *object_class_get_class_data(ObjectClass *klass)
+{
+    return klass->type->class_data;
+}
+
 ObjectClass *object_class_by_name(const char *typename)
 {
     TypeImpl *type = type_get_by_name(typename);
Signature · 1 line
2.20.0.rc1
#36 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()

Quoted 34 lines · On Tue, 4 Dec 2018 18:20:19 +0400 Marc-André Lureau…

Add a simple function to retrieve the associated class data.

---
 include/qom/object.h | 9 +++++++++
 qom/object.c         | 5 +++++
 2 files changed, 14 insertions(+)
include/qom/object.h +9 -0
index 5183c587f3..d5266405da 100644
@@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 ObjectClass *object_class_get_parent(ObjectClass *klass);
 
+
+/**
+ * object_class_get_class_data:
+ * @klass: The class to obtain associated data.
+ *
+ * Returns: the class_data given when registering the type.
+ */
+void *object_class_get_class_data(ObjectClass *klass);
+
 /**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
qom/object.c +0 -0
index aa6f3a2a71..bbc6fbbc01 100644
@@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
     return klass->type->name;

qom/object.c const char *object_class_get_name(ObjectClass *klass) · line 877

Quoted 10 lines
qom/object.c +5 -0
 }
 
+void *object_class_get_class_data(ObjectClass *klass)
+{
+    return klass->type->class_data;
+}
+
 ObjectClass *object_class_by_name(const char *typename)
 {
     TypeImpl *type = type_get_by_name(typename);

alternatively to what's done in 16/19 which requires this helper you can drop it and use x86 cpu approach, see:

static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)

{                                                                                
    X86CPUDefinition *cpudef = data;                                             
    X86CPUClass *xcc = X86_CPU_CLASS(oc);                                        
                                                                                 
    xcc->cpu_def = cpudef;
    ...
#37 lore raw

Re: [Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()

Hi

Quoted 52 lines · Igor Mammedov
Quoted 34 lines · On Tue, 4 Dec 2018 18:20:19 +0400 Marc-André Lureau…

Add a simple function to retrieve the associated class data.

---
 include/qom/object.h | 9 +++++++++
 qom/object.c         | 5 +++++
 2 files changed, 14 insertions(+)
include/qom/object.h +9 -0
index 5183c587f3..d5266405da 100644
@@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 ObjectClass *object_class_get_parent(ObjectClass *klass);
 
+
+/**
+ * object_class_get_class_data:
+ * @klass: The class to obtain associated data.
+ *
+ * Returns: the class_data given when registering the type.
+ */
+void *object_class_get_class_data(ObjectClass *klass);
+
 /**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
qom/object.c +0 -0
index aa6f3a2a71..bbc6fbbc01 100644
@@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
     return klass->type->name;

qom/object.c const char *object_class_get_name(ObjectClass *klass) · line 877

Quoted 10 lines
qom/object.c +5 -0
 }
 
+void *object_class_get_class_data(ObjectClass *klass)
+{
+    return klass->type->class_data;
+}
+
 ObjectClass *object_class_by_name(const char *typename)
 {
     TypeImpl *type = type_get_by_name(typename);

alternatively to what's done in 16/19 which requires this helper you can drop it and use x86 cpu approach, see:

Quoted 8 lines

static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)

{
    X86CPUDefinition *cpudef = data;
    X86CPUClass *xcc = X86_CPU_CLASS(oc);

    xcc->cpu_def = cpudef;
    ...

Indeed, that's perhaps a better alternative. I'll update the patch.

Signature · 1 line
Marc-André Lureau
#38 lore raw

PATCH v5 16/19 RFC: arm: replace instance_post_init()

In reply to Marc-André Lureau

Replace arm_cpu_post_init() instance callback by calling it from leaf classes, to avoid potential ordering issue with other post_init callbacks.

Note: this patch is no longer needed in this series, since the compat-props interface approach was abandoned.

---
 target/arm/cpu.h   |  2 ++
 target/arm/cpu.c   | 15 ++++++++++++---
 target/arm/cpu64.c | 11 ++++++++++-
 3 files changed, 24 insertions(+), 4 deletions(-)
target/arm/cpu.h +2 -0
index 2a73fed9a0..84fba2b24b 100644
@@ -884,6 +884,8 @@ static inline ARMCPU *arm_env_get_cpu(CPUARMState *env)
     return container_of(env, ARMCPU, env);
 }
 
+void arm_cpu_post_init(Object *obj);
+
 uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz);
 
 #define ENV_GET_CPU(e) CPU(arm_env_get_cpu(e))
target/arm/cpu.c +12 -3
index 60411f6bfe..8a4aae7438 100644
@@ -734,7 +734,7 @@ static Property arm_cpu_pmsav7_dregion_property =
 static Property arm_cpu_initsvtor_property =
             DEFINE_PROP_UINT32("init-svtor", ARMCPU, init_svtor, 0);
 
-static void arm_cpu_post_init(Object *obj)
+void arm_cpu_post_init(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
 
@@ -2094,6 +2094,7 @@ static void arm_host_initfn(Object *obj)
     ARMCPU *cpu = ARM_CPU(obj);
 
     kvm_arm_set_cpu_features_from_host(cpu);
+    arm_cpu_post_init(ARM_CPU(obj));
 }
 
 static const TypeInfo host_arm_cpu_type_info = {
@@ -2108,14 +2109,23 @@ static const TypeInfo host_arm_cpu_type_info = {
 
 #endif
 
+static void arm_cpu_instance_init(Object *obj)
+{
+    const ARMCPUInfo *info = object_class_get_class_data(object_get_class(obj));
+
+    info->initfn(obj);
+    arm_cpu_post_init(obj);
+}
+
 static void cpu_register(const ARMCPUInfo *info)
 {
     TypeInfo type_info = {
         .parent = TYPE_ARM_CPU,
         .instance_size = sizeof(ARMCPU),
-        .instance_init = info->initfn,
+        .instance_init = arm_cpu_instance_init,
         .class_size = sizeof(ARMCPUClass),
         .class_init = info->class_init,
+        .class_data = (void *)info,
     };
 
     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
@@ -2128,7 +2138,6 @@ static const TypeInfo arm_cpu_type_info = {
     .parent = TYPE_CPU,
     .instance_size = sizeof(ARMCPU),
     .instance_init = arm_cpu_initfn,
-    .instance_post_init = arm_cpu_post_init,
     .instance_finalize = arm_cpu_finalizefn,
     .abstract = true,
     .class_size = sizeof(ARMCPUClass),
target/arm/cpu64.c +10 -1
index 873f059bf2..dbfc3ee490 100644
@@ -447,14 +447,23 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_arch_name = aarch64_gdb_arch_name;
 }
 
+static void aarch64_cpu_instance_init(Object *obj)
+{
+    const ARMCPUInfo *info = object_class_get_class_data(object_get_class(obj));
+
+    info->initfn(obj);
+    arm_cpu_post_init(obj);
+}
+
 static void aarch64_cpu_register(const ARMCPUInfo *info)
 {
     TypeInfo type_info = {
         .parent = TYPE_AARCH64_CPU,
         .instance_size = sizeof(ARMCPU),
-        .instance_init = info->initfn,
+        .instance_init = aarch64_cpu_instance_init,
         .class_size = sizeof(ARMCPUClass),
         .class_init = info->class_init,
+        .class_data = (void *)info,
     };
 
     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
Signature · 1 line
2.20.0.rc1
Reviewed-by on v5 16/19
#39 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.2 v5 16/19] RFC: arm: replace instance_post_init()

Quoted 8 lines · On Tue, 4 Dec 2018 18:20:20 +0400 Marc-André Lureau…

Replace arm_cpu_post_init() instance callback by calling it from leaf classes, to avoid potential ordering issue with other post_init callbacks.

Note: this patch is no longer needed in this series, since the compat-props interface approach was abandoned.

Current call chain is
aarch64_a57_initfn()
arm_cpu_post_init()
device_post_init()

so no compats nor globals influence arm_cpu_post_init() flow, so it's save to squash it in initfn.

Quoted 102 lines
---
 target/arm/cpu.h   |  2 ++
 target/arm/cpu.c   | 15 ++++++++++++---
 target/arm/cpu64.c | 11 ++++++++++-
 3 files changed, 24 insertions(+), 4 deletions(-)
target/arm/cpu.h +2 -0
index 2a73fed9a0..84fba2b24b 100644
@@ -884,6 +884,8 @@ static inline ARMCPU *arm_env_get_cpu(CPUARMState *env)
     return container_of(env, ARMCPU, env);
 }
 
+void arm_cpu_post_init(Object *obj);
+
 uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz);
 
 #define ENV_GET_CPU(e) CPU(arm_env_get_cpu(e))
target/arm/cpu.c +12 -3
index 60411f6bfe..8a4aae7438 100644
@@ -734,7 +734,7 @@ static Property arm_cpu_pmsav7_dregion_property =
 static Property arm_cpu_initsvtor_property =
             DEFINE_PROP_UINT32("init-svtor", ARMCPU, init_svtor, 0);
 
-static void arm_cpu_post_init(Object *obj)
+void arm_cpu_post_init(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
 
@@ -2094,6 +2094,7 @@ static void arm_host_initfn(Object *obj)
     ARMCPU *cpu = ARM_CPU(obj);
 
     kvm_arm_set_cpu_features_from_host(cpu);
+    arm_cpu_post_init(ARM_CPU(obj));
 }
 
 static const TypeInfo host_arm_cpu_type_info = {
@@ -2108,14 +2109,23 @@ static const TypeInfo host_arm_cpu_type_info = {
 
 #endif
 
+static void arm_cpu_instance_init(Object *obj)
+{
+    const ARMCPUInfo *info = object_class_get_class_data(object_get_class(obj));
+
+    info->initfn(obj);
+    arm_cpu_post_init(obj);
+}
+
 static void cpu_register(const ARMCPUInfo *info)
 {
     TypeInfo type_info = {
         .parent = TYPE_ARM_CPU,
         .instance_size = sizeof(ARMCPU),
-        .instance_init = info->initfn,
+        .instance_init = arm_cpu_instance_init,
         .class_size = sizeof(ARMCPUClass),
         .class_init = info->class_init,
+        .class_data = (void *)info,
     };
 
     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
@@ -2128,7 +2138,6 @@ static const TypeInfo arm_cpu_type_info = {
     .parent = TYPE_CPU,
     .instance_size = sizeof(ARMCPU),
     .instance_init = arm_cpu_initfn,
-    .instance_post_init = arm_cpu_post_init,
     .instance_finalize = arm_cpu_finalizefn,
     .abstract = true,
     .class_size = sizeof(ARMCPUClass),
target/arm/cpu64.c +10 -1
index 873f059bf2..dbfc3ee490 100644
@@ -447,14 +447,23 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_arch_name = aarch64_gdb_arch_name;
 }
 
+static void aarch64_cpu_instance_init(Object *obj)
+{
+    const ARMCPUInfo *info = object_class_get_class_data(object_get_class(obj));
+
+    info->initfn(obj);
+    arm_cpu_post_init(obj);
+}
+
 static void aarch64_cpu_register(const ARMCPUInfo *info)
 {
     TypeInfo type_info = {
         .parent = TYPE_AARCH64_CPU,
         .instance_size = sizeof(ARMCPU),
-        .instance_init = info->initfn,
+        .instance_init = aarch64_cpu_instance_init,
         .class_size = sizeof(ARMCPUClass),
         .class_init = info->class_init,
+        .class_data = (void *)info,
     };
 
     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
#40 lore raw

PATCH v5 17/19 hw/i386: add pc-i440fx-4.0 & pc-q35-4.0

In reply to Marc-André Lureau

The following patch is going to add compatiblity parameters for qemu <= 3.1.

---
 include/hw/compat.h  |  3 +++
 include/hw/i386/pc.h |  3 +++
 hw/i386/pc_piix.c    | 21 +++++++++++++++++----
 hw/i386/pc_q35.c     | 18 ++++++++++++++++--
 4 files changed, 39 insertions(+), 6 deletions(-)
include/hw/compat.h +3 -0
index 6f4d5fc647..70958328fe 100644
@@ -1,6 +1,9 @@
 #ifndef HW_COMPAT_H
 #define HW_COMPAT_H
 
+#define HW_COMPAT_3_1 \
+    /* empty */
+
 #define HW_COMPAT_3_0 \
     /* empty */
 
include/hw/i386/pc.h +3 -0
index 136fe497b6..c37d4333a0 100644
@@ -294,6 +294,9 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
+#define PC_COMPAT_3_1 \
+    HW_COMPAT_3_1
+
 #define PC_COMPAT_3_0 \
     HW_COMPAT_3_0 \
     {\
hw/i386/pc_piix.c +17 -4
index 575566e466..34b3e924d6 100644
@@ -428,13 +428,29 @@ static void pc_i440fx_machine_options(MachineClass *m)
     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
 }
 
-static void pc_i440fx_3_1_machine_options(MachineClass *m)
+static void pc_i440fx_4_0_machine_options(MachineClass *m)
 {
     pc_i440fx_machine_options(m);
     m->alias = "pc";
     m->is_default = 1;
 }
 
+DEFINE_I440FX_MACHINE(v4_0, "pc-i440fx-4.0", NULL,
+                      pc_i440fx_4_0_machine_options);
+
+static GlobalProperty pc_compat_3_1[] = {
+    PC_COMPAT_3_1
+};
+
+static void pc_i440fx_3_1_machine_options(MachineClass *m)
+{
+    pc_i440fx_4_0_machine_options(m);
+    m->is_default = 0;
+    m->alias = NULL;
+    compat_props_add(m->compat_props,
+                     pc_compat_3_1, G_N_ELEMENTS(pc_compat_3_1));
+}
+
 DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
                       pc_i440fx_3_1_machine_options);
 
@@ -445,9 +461,6 @@ static GlobalProperty pc_compat_3_0[] = {
 static void pc_i440fx_3_0_machine_options(MachineClass *m)
 {
     pc_i440fx_3_1_machine_options(m);
-    m->is_default = 0;
-    m->alias = NULL;
-
     compat_props_add(m->compat_props,
                      pc_compat_3_0, G_N_ELEMENTS(pc_compat_3_0));
 }
hw/i386/pc_q35.c +16 -2
index 701c09b43e..f0874c42d8 100644
@@ -311,12 +311,27 @@ static void pc_q35_machine_options(MachineClass *m)
     m->max_cpus = 288;
 }
 
-static void pc_q35_3_1_machine_options(MachineClass *m)
+static void pc_q35_4_0_machine_options(MachineClass *m)
 {
     pc_q35_machine_options(m);
     m->alias = "q35";
 }
 
+DEFINE_Q35_MACHINE(v4_0, "pc-q35-4.0", NULL,
+                   pc_q35_4_0_machine_options);
+
+static GlobalProperty pc_compat_3_1[] = {
+    PC_COMPAT_3_1
+};
+
+static void pc_q35_3_1_machine_options(MachineClass *m)
+{
+    pc_q35_4_0_machine_options(m);
+    m->alias = NULL;
+    compat_props_add(m->compat_props,
+                     pc_compat_3_1, G_N_ELEMENTS(pc_compat_3_1));
+}
+
 DEFINE_Q35_MACHINE(v3_1, "pc-q35-3.1", NULL,
                    pc_q35_3_1_machine_options);
 
@@ -327,7 +342,6 @@ static GlobalProperty pc_compat_3_0[] = {
 static void pc_q35_3_0_machine_options(MachineClass *m)
 {
     pc_q35_3_1_machine_options(m);
-    m->alias = NULL;
     compat_props_add(m->compat_props,
                      pc_compat_3_0, G_N_ELEMENTS(pc_compat_3_0));
 }
Signature · 1 line
2.20.0.rc1
#41 lore raw

PATCH v5 18/19 hw/arm/virt: add virt-4.0 machine type

In reply to Marc-André Lureau
---
 hw/arm/virt.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
hw/arm/virt.c +20 -2
index 530c8ca89d..433374f0d0 100644
@@ -1797,7 +1797,7 @@ static void machvirt_machine_init(void)
 }
 type_init(machvirt_machine_init);
 
-static void virt_3_1_instance_init(Object *obj)
+static void virt_4_0_instance_init(Object *obj)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
     VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
@@ -1867,10 +1867,28 @@ static void virt_3_1_instance_init(Object *obj)
     vms->irqmap = a15irqmap;
 }
 
+static void virt_machine_4_0_options(MachineClass *mc)
+{
+}
+DEFINE_VIRT_MACHINE_AS_LATEST(4, 0)
+
+static GlobalProperty virt_compat_3_1[] = {
+    HW_COMPAT_3_1
+};
+
+static void virt_3_1_instance_init(Object *obj)
+{
+    virt_4_0_instance_init(obj);
+}
+
 static void virt_machine_3_1_options(MachineClass *mc)
 {
+    virt_machine_4_0_options(mc);
+    compat_props_add(mc->compat_props,
+                     virt_compat_3_1, G_N_ELEMENTS(virt_compat_3_1));
 }
-DEFINE_VIRT_MACHINE_AS_LATEST(3, 1)
+
+DEFINE_VIRT_MACHINE(3, 1)
 
 static GlobalProperty virt_compat_3_0[] = {
     HW_COMPAT_3_0
Signature · 1 line
2.20.0.rc1
#42 lore raw

PATCH v5 19/19 hostmem: use object id for memory region name with >= 4.0

In reply to Marc-André Lureau

hostmem-file and hostmem-memfd use the whole object path for the memory region name, and hostname-ram uses only the path component (the object id, or canonical path basename):

qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000

For consistency, change to use object id for -file and -memfd as well with >= 4.0.

Having a consistent naming allows to migrate to different hostmem backends.

---
 include/hw/compat.h      | 10 +++++++++-
 include/sysemu/hostmem.h |  3 ++-
 backends/hostmem-file.c  |  8 ++++----
 backends/hostmem-memfd.c |  2 +-
 backends/hostmem-ram.c   |  9 ++++-----
 backends/hostmem.c       | 36 ++++++++++++++++++++++++++++++++++++
 6 files changed, 56 insertions(+), 12 deletions(-)
include/hw/compat.h +9 -1
index 70958328fe..99cf6b1e03 100644
@@ -2,7 +2,15 @@
 #define HW_COMPAT_H
 
 #define HW_COMPAT_3_1 \
-    /* empty */
+    {\
+        .driver   = "memory-backend-file",\
+        .property = "x-use-canonical-path-for-ramblock-id",\
+        .value    = "true",\
+    },{\
+        .driver   = "memory-backend-memfd",\
+        .property = "x-use-canonical-path-for-ramblock-id",\
+        .value    = "true",\
+    },
 
 #define HW_COMPAT_3_0 \
     /* empty */
include/sysemu/hostmem.h +2 -1
index 6e6bd2c1cb..a023b372a4 100644
@@ -53,7 +53,7 @@ struct HostMemoryBackend {
 
     /* protected */
     uint64_t size;
-    bool merge, dump;
+    bool merge, dump, use_canonical_path;
     bool prealloc, force_prealloc, is_mapped, share;
     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
     HostMemPolicy policy;
@@ -67,5 +67,6 @@ MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
+char *host_memory_backend_get_name(HostMemoryBackend *backend);
 
 #endif
backends/hostmem-file.c +4 -4
index 6630021226..5b87e154f3 100644
@@ -43,7 +43,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
     HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
 #ifdef CONFIG_POSIX
-    gchar *path;
+    gchar *name;
 #endif
 
     if (!backend->size) {
@@ -58,14 +58,14 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
     error_setg(errp, "-mem-path not supported on this host");
 #else
     backend->force_prealloc = mem_prealloc;
-    path = object_get_canonical_path(OBJECT(backend));
+    name = host_memory_backend_get_name(backend);
     memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
-                                     path,
+                                     name,
                                      backend->size, fb->align,
                                      (backend->share ? RAM_SHARED : 0) |
                                      (fb->is_pmem ? RAM_PMEM : 0),
                                      fb->mem_path, errp);
-    g_free(path);
+    g_free(name);
 #endif
 }
 
backends/hostmem-memfd.c +1 -1
index 2eb9c827a5..98c9bf3240 100644
@@ -53,7 +53,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         return;
     }
 
-    name = object_get_canonical_path(OBJECT(backend));
+    name = host_memory_backend_get_name(backend);
     memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
                                    name, backend->size,
                                    backend->share, fd, errp);
backends/hostmem-ram.c +4 -5
index 7ddd08d370..24b65d9ae3 100644
@@ -16,21 +16,20 @@
 
 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
 
-
 static void
 ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
-    char *path;
+    char *name;
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
         return;
     }
 
-    path = object_get_canonical_path_component(OBJECT(backend));
-    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), path,
+    name = host_memory_backend_get_name(backend);
+    memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name,
                            backend->size, backend->share, errp);
-    g_free(path);
+    g_free(name);
 }
 
 static void
backends/hostmem.c +36 -0
index 1a89342039..c7a7020fed 100644
@@ -28,6 +28,16 @@ QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_BIND != MPOL_BIND);
 QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_INTERLEAVE != MPOL_INTERLEAVE);
 #endif
 
+char *
+host_memory_backend_get_name(HostMemoryBackend *self)
+{
+    if (!self->use_canonical_path) {
+        return object_get_canonical_path_component(OBJECT(self));
+    }
+
+    return object_get_canonical_path(OBJECT(self));
+}
+
 static void
 host_memory_backend_get_size(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
@@ -238,6 +248,11 @@ static void host_memory_backend_init(Object *obj)
     backend->prealloc = mem_prealloc;
 }
 
+static void host_memory_backend_post_init(Object *obj)
+{
+    object_apply_compat_props(obj);
+}
+
 bool host_memory_backend_mr_inited(HostMemoryBackend *backend)
 {
     /*
@@ -386,6 +401,23 @@ static void host_memory_backend_set_share(Object *o, bool value, Error **errp)
     backend->share = value;
 }
 
+static bool
+host_memory_backend_get_use_canonical_path(Object *obj, Error **errp)
+{
+    HostMemoryBackend *self = MEMORY_BACKEND(obj);
+
+    return self->use_canonical_path;
+}
+
+static void
+host_memory_backend_set_use_canonical_path(Object *obj, bool value,
+                                           Error **errp)
+{
+    HostMemoryBackend *self = MEMORY_BACKEND(obj);
+
+    self->use_canonical_path = value;
+}
+
 static void
 host_memory_backend_class_init(ObjectClass *oc, void *data)
 {
@@ -432,6 +464,9 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "share",
         "Mark the memory as private to QEMU or shared", &error_abort);
+    object_class_property_add_bool(oc, "x-use-canonical-path-for-ramblock-id",
+        host_memory_backend_get_use_canonical_path,
+        host_memory_backend_set_use_canonical_path, &error_abort);
 }
 
 static const TypeInfo host_memory_backend_info = {
@@ -442,6 +477,7 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
+    .instance_post_init = host_memory_backend_post_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
         { }
Signature · 1 line
2.20.0.rc1
#43 lore raw
In reply to Marc-André Lureau

On Tue, Dec 04, 2018 at 06:20:04PM +0400, Marc-André Lureau wrote:
[...]

Quoted 7 lines

Marc-André Lureau (19):
tests: qdev_prop_check_globals() doesn't return "all_used"
qom: make interface types abstract
qom: make user_creatable_complete() specific to UserCreatable
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests
qom: remove unimplemented class_finalize

Patches 1-6 (above) queued on machine-next. Thanks!

Quoted 14 lines

hw: apply accel compat properties without touching globals
hw: apply machine compat properties without touching globals
hw: remove SET_MACHINE_COMPAT
qdev: make a separate helper function to apply compat properties
qdev: all globals are now user-provided
qdev-props: convert global_props to GPtrArray
qdev-props: remove errp from GlobalProperty
qdev-props: call object_apply_global_props()
qom: add object_class_get_class_data()
RFC: arm: replace instance_post_init()
hw/i386: add pc-i440fx-4.0 & pc-q35-4.0
hw/arm/virt: add virt-4.0 machine type
hostmem: use object id for memory region name with >= 4.0

Signature · 1 line
Eduardo
#44 lore raw
Quoted 11 lines · On Mon, 10 Dec 2018 15:07:18 -0200 Eduardo Habkost <[email protected]> wrote:

On Tue, Dec 04, 2018 at 06:20:04PM +0400, Marc-André Lureau wrote:
[...]

Quoted 7 lines

Marc-André Lureau (19):
tests: qdev_prop_check_globals() doesn't return "all_used"
qom: make interface types abstract
qom: make user_creatable_complete() specific to UserCreatable
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests
qom: remove unimplemented class_finalize

Patches 1-6 (above) queued on machine-next. Thanks!

let's drop patch 6 for now until we decide what to do with GPtrArray leaks

Quoted 16 lines
Quoted 15 lines

hw: apply accel compat properties without touching globals
hw: apply machine compat properties without touching globals
hw: remove SET_MACHINE_COMPAT
qdev: make a separate helper function to apply compat properties
qdev: all globals are now user-provided
qdev-props: convert global_props to GPtrArray
qdev-props: remove errp from GlobalProperty
qdev-props: call object_apply_global_props()
qom: add object_class_get_class_data()
RFC: arm: replace instance_post_init()
hw/i386: add pc-i440fx-4.0 & pc-q35-4.0
hw/arm/virt: add virt-4.0 machine type
hostmem: use object id for memory region name with >= 4.0

#45 lore raw
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 10 Dec 2018 15:07:18 -0200 Eduardo Habkost <[email protected]> wrote:

On Tue, Dec 04, 2018 at 06:20:04PM +0400, Marc-André Lureau wrote:
[...]

Quoted 7 lines

Marc-André Lureau (19):
tests: qdev_prop_check_globals() doesn't return "all_used"
qom: make interface types abstract
qom: make user_creatable_complete() specific to UserCreatable
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests
qom: remove unimplemented class_finalize

Quoted 2 lines
Quoted 1 line

Patches 1-6 (above) queued on machine-next. Thanks!

let's drop patch 6 for now until we decide what to do with GPtrArray leaks

I appreciate your effort to make sure there are no memory allocations that could make Valgrind complain, but I don't see the point of keeping dead code that was never called in the tree.

Are the new GPtrArray allocations different from the g_malloc0() calls in type_new() and type_initialize()? Doesn't Valgrind complain about them today?

Signature · 1 line
Eduardo
#46 lore raw
Quoted 14 lines · On Mon, 10 Dec 2018 15:39:32 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 10 Dec 2018 15:07:18 -0200 Eduardo Habkost <[email protected]> wrote:

On Tue, Dec 04, 2018 at 06:20:04PM +0400, Marc-André Lureau wrote:
[...]

Quoted 7 lines

Marc-André Lureau (19):
tests: qdev_prop_check_globals() doesn't return "all_used"
qom: make interface types abstract
qom: make user_creatable_complete() specific to UserCreatable
accel: register global_props like machine globals
qdev: move qdev_prop_register_global_list() to tests
qom: remove unimplemented class_finalize

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Patches 1-6 (above) queued on machine-next. Thanks!

let's drop patch 6 for now until we decide what to do with GPtrArray leaks

I appreciate your effort to make sure there are no memory allocations that could make Valgrind complain, but I don't see the point of keeping dead code that was never called in the tree.

ps:
it looks like machine_finalize() isn't called either, but it at least documents what should be cleaned up. Maybe we should keep code removed by 6, for the same reasons.

Quoted 3 lines

Are the new GPtrArray allocations different from the g_malloc0() calls in type_new() and type_initialize()? Doesn't Valgrind complain about them today?

Currently we don't clean a bunch of onetime allocations, so I guess we can continue to ignore them in this case as well.