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

Marc-André Lureau posted 19 patches 6 years, 10 months ago
There is a newer version of this series
[Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Marc-André Lureau 6 years, 10 months ago
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.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 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(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index f82f28468b..28c2b0af41 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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;
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index f69e7eb399..530c8ca89d 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -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
+};
 
 static void virt_3_0_instance_init(Object *obj)
 {
@@ -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)
 
-#define VIRT_COMPAT_2_12 \
+static GlobalProperty virt_compat_2_12[] = {
     HW_COMPAT_2_12
+};
 
 static void virt_2_12_instance_init(Object *obj)
 {
@@ -1900,14 +1903,16 @@ static void virt_machine_2_12_options(MachineClass *mc)
     VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
 
     virt_machine_3_0_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_12);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_12, G_N_ELEMENTS(virt_compat_2_12));
     vmc->no_highmem_ecam = true;
     mc->max_cpus = 255;
 }
 DEFINE_VIRT_MACHINE(2, 12)
 
-#define VIRT_COMPAT_2_11 \
+static GlobalProperty virt_compat_2_11[] = {
     HW_COMPAT_2_11
+};
 
 static void virt_2_11_instance_init(Object *obj)
 {
@@ -1919,13 +1924,15 @@ static void virt_machine_2_11_options(MachineClass *mc)
     VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
 
     virt_machine_2_12_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_11);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_11, G_N_ELEMENTS(virt_compat_2_11));
     vmc->smbios_old_sys_ver = true;
 }
 DEFINE_VIRT_MACHINE(2, 11)
 
-#define VIRT_COMPAT_2_10 \
+static GlobalProperty virt_compat_2_10[] = {
     HW_COMPAT_2_10
+};
 
 static void virt_2_10_instance_init(Object *obj)
 {
@@ -1935,14 +1942,16 @@ static void virt_2_10_instance_init(Object *obj)
 static void virt_machine_2_10_options(MachineClass *mc)
 {
     virt_machine_2_11_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_10);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_10, G_N_ELEMENTS(virt_compat_2_10));
     /* before 2.11 we never faulted accesses to bad addresses */
     mc->ignore_memory_transaction_failures = true;
 }
 DEFINE_VIRT_MACHINE(2, 10)
 
-#define VIRT_COMPAT_2_9 \
+static GlobalProperty virt_compat_2_9[] = {
     HW_COMPAT_2_9
+};
 
 static void virt_2_9_instance_init(Object *obj)
 {
@@ -1952,12 +1961,14 @@ static void virt_2_9_instance_init(Object *obj)
 static void virt_machine_2_9_options(MachineClass *mc)
 {
     virt_machine_2_10_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_9);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_9, G_N_ELEMENTS(virt_compat_2_9));
 }
 DEFINE_VIRT_MACHINE(2, 9)
 
-#define VIRT_COMPAT_2_8 \
+static GlobalProperty virt_compat_2_8[] = {
     HW_COMPAT_2_8
+};
 
 static void virt_2_8_instance_init(Object *obj)
 {
@@ -1969,7 +1980,8 @@ static void virt_machine_2_8_options(MachineClass *mc)
     VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
 
     virt_machine_2_9_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_8);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_8, G_N_ELEMENTS(virt_compat_2_8));
     /* For 2.8 and earlier we falsely claimed in the DT that
      * our timers were edge-triggered, not level-triggered.
      */
@@ -1977,8 +1989,9 @@ static void virt_machine_2_8_options(MachineClass *mc)
 }
 DEFINE_VIRT_MACHINE(2, 8)
 
-#define VIRT_COMPAT_2_7 \
+static GlobalProperty virt_compat_2_7[] = {
     HW_COMPAT_2_7
+};
 
 static void virt_2_7_instance_init(Object *obj)
 {
@@ -1990,7 +2003,8 @@ static void virt_machine_2_7_options(MachineClass *mc)
     VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
 
     virt_machine_2_8_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_7);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_7, G_N_ELEMENTS(virt_compat_2_7));
     /* ITS was introduced with 2.8 */
     vmc->no_its = true;
     /* Stick with 1K pages for migration compatibility */
@@ -1998,8 +2012,9 @@ static void virt_machine_2_7_options(MachineClass *mc)
 }
 DEFINE_VIRT_MACHINE(2, 7)
 
-#define VIRT_COMPAT_2_6 \
+static GlobalProperty virt_compat_2_6[] = {
     HW_COMPAT_2_6
+};
 
 static void virt_2_6_instance_init(Object *obj)
 {
@@ -2011,7 +2026,8 @@ static void virt_machine_2_6_options(MachineClass *mc)
     VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
 
     virt_machine_2_7_options(mc);
-    SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_6);
+    compat_props_add(mc->compat_props,
+                     virt_compat_2_6, G_N_ELEMENTS(virt_compat_2_6));
     vmc->disallow_affinity_adjustment = true;
     /* Disable PMU for 2.6 as PMU support was first introduced in 2.7 */
     vmc->no_pmu = true;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index c51423b647..6e24924aba 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -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,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 53b507164f..d510340bac 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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));
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 7092d6d13f..575566e466 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -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));
 }
 
 DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
                       pc_i440fx_3_0_machine_options);
 
+static GlobalProperty pc_compat_2_12[] = {
+    PC_COMPAT_2_12
+};
+
 static void pc_i440fx_2_12_machine_options(MachineClass *m)
 {
     pc_i440fx_3_0_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_12, G_N_ELEMENTS(pc_compat_2_12));
 }
 
 DEFINE_I440FX_MACHINE(v2_12, "pc-i440fx-2.12", NULL,
                       pc_i440fx_2_12_machine_options);
 
+static GlobalProperty pc_compat_2_11[] = {
+    PC_COMPAT_2_11
+};
+
 static void pc_i440fx_2_11_machine_options(MachineClass *m)
 {
     pc_i440fx_2_12_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_11);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_11, G_N_ELEMENTS(pc_compat_2_11));
 }
 
 DEFINE_I440FX_MACHINE(v2_11, "pc-i440fx-2.11", NULL,
                       pc_i440fx_2_11_machine_options);
 
+static GlobalProperty pc_compat_2_10[] = {
+    PC_COMPAT_2_10
+};
+
 static void pc_i440fx_2_10_machine_options(MachineClass *m)
 {
     pc_i440fx_2_11_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_10);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_10, G_N_ELEMENTS(pc_compat_2_10));
     m->auto_enable_numa_with_memhp = false;
 }
 
 DEFINE_I440FX_MACHINE(v2_10, "pc-i440fx-2.10", NULL,
                       pc_i440fx_2_10_machine_options);
 
+static GlobalProperty pc_compat_2_9[] = {
+    PC_COMPAT_2_9
+};
+
 static void pc_i440fx_2_9_machine_options(MachineClass *m)
 {
     pc_i440fx_2_10_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_9);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_9, G_N_ELEMENTS(pc_compat_2_9));
     m->numa_auto_assign_ram = numa_legacy_auto_assign_ram;
 }
 
 DEFINE_I440FX_MACHINE(v2_9, "pc-i440fx-2.9", NULL,
                       pc_i440fx_2_9_machine_options);
 
+static GlobalProperty pc_compat_2_8[] = {
+    PC_COMPAT_2_8
+};
+
 static void pc_i440fx_2_8_machine_options(MachineClass *m)
 {
     pc_i440fx_2_9_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_8);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_8, G_N_ELEMENTS(pc_compat_2_8));
 }
 
 DEFINE_I440FX_MACHINE(v2_8, "pc-i440fx-2.8", NULL,
                       pc_i440fx_2_8_machine_options);
 
+static GlobalProperty pc_compat_2_7[] = {
+    PC_COMPAT_2_7
+};
 
 static void pc_i440fx_2_7_machine_options(MachineClass *m)
 {
     pc_i440fx_2_8_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_7, G_N_ELEMENTS(pc_compat_2_7));
 }
 
 DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
                       pc_i440fx_2_7_machine_options);
 
+static GlobalProperty pc_compat_2_6[] = {
+    PC_COMPAT_2_6
+};
 
 static void pc_i440fx_2_6_machine_options(MachineClass *m)
 {
@@ -513,12 +551,16 @@ static void pc_i440fx_2_6_machine_options(MachineClass *m)
     pc_i440fx_2_7_machine_options(m);
     pcmc->legacy_cpu_hotplug = true;
     pcmc->linuxboot_dma_enabled = false;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_6, G_N_ELEMENTS(pc_compat_2_6));
 }
 
 DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,
                       pc_i440fx_2_6_machine_options);
 
+static GlobalProperty pc_compat_2_5[] = {
+    PC_COMPAT_2_5
+};
 
 static void pc_i440fx_2_5_machine_options(MachineClass *m)
 {
@@ -526,12 +568,16 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m)
     pc_i440fx_2_6_machine_options(m);
     pcmc->save_tsc_khz = false;
     m->legacy_fw_cfg_order = 1;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_5);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_5, G_N_ELEMENTS(pc_compat_2_5));
 }
 
 DEFINE_I440FX_MACHINE(v2_5, "pc-i440fx-2.5", NULL,
                       pc_i440fx_2_5_machine_options);
 
+static GlobalProperty pc_compat_2_4[] = {
+    PC_COMPAT_2_4
+};
 
 static void pc_i440fx_2_4_machine_options(MachineClass *m)
 {
@@ -539,36 +585,48 @@ static void pc_i440fx_2_4_machine_options(MachineClass *m)
     pc_i440fx_2_5_machine_options(m);
     m->hw_version = "2.4.0";
     pcmc->broken_reserved_end = true;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_4);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_4, G_N_ELEMENTS(pc_compat_2_4));
 }
 
 DEFINE_I440FX_MACHINE(v2_4, "pc-i440fx-2.4", NULL,
-                      pc_i440fx_2_4_machine_options)
+                      pc_i440fx_2_4_machine_options);
 
+static GlobalProperty pc_compatp_2_3[] = {
+    PC_COMPAT_2_3
+};
 
 static void pc_i440fx_2_3_machine_options(MachineClass *m)
 {
     pc_i440fx_2_4_machine_options(m);
     m->hw_version = "2.3.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_3);
+    compat_props_add(m->compat_props,
+                     pc_compatp_2_3, G_N_ELEMENTS(pc_compatp_2_3));
 }
 
 DEFINE_I440FX_MACHINE(v2_3, "pc-i440fx-2.3", pc_compat_2_3,
                       pc_i440fx_2_3_machine_options);
 
+static GlobalProperty pc_compatp_2_2[] = {
+    PC_COMPAT_2_2
+};
 
 static void pc_i440fx_2_2_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_2_3_machine_options(m);
     m->hw_version = "2.2.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_2);
+    compat_props_add(m->compat_props,
+                     pc_compatp_2_2, G_N_ELEMENTS(pc_compatp_2_2));
     pcmc->rsdp_in_ram = false;
 }
 
 DEFINE_I440FX_MACHINE(v2_2, "pc-i440fx-2.2", pc_compat_2_2,
                       pc_i440fx_2_2_machine_options);
 
+static GlobalProperty pc_compatp_2_1[] = {
+    PC_COMPAT_2_1
+};
 
 static void pc_i440fx_2_1_machine_options(MachineClass *m)
 {
@@ -576,7 +634,8 @@ static void pc_i440fx_2_1_machine_options(MachineClass *m)
     pc_i440fx_2_2_machine_options(m);
     m->hw_version = "2.1.0";
     m->default_display = NULL;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_1);
+    compat_props_add(m->compat_props,
+                     pc_compatp_2_1, G_N_ELEMENTS(pc_compatp_2_1));
     pcmc->smbios_uuid_encoded = false;
     pcmc->enforce_aligned_dimm = false;
 }
@@ -584,14 +643,17 @@ static void pc_i440fx_2_1_machine_options(MachineClass *m)
 DEFINE_I440FX_MACHINE(v2_1, "pc-i440fx-2.1", pc_compat_2_1,
                       pc_i440fx_2_1_machine_options);
 
-
+static GlobalProperty pc_compatp_2_0[] = {
+    PC_COMPAT_2_0
+};
 
 static void pc_i440fx_2_0_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_2_1_machine_options(m);
     m->hw_version = "2.0.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_0);
+    compat_props_add(m->compat_props,
+                     pc_compatp_2_0, G_N_ELEMENTS(pc_compatp_2_0));
     pcmc->smbios_legacy_mode = true;
     pcmc->has_reserved_memory = false;
     /* This value depends on the actual DSDT and SSDT compiled into
@@ -617,6 +679,9 @@ static void pc_i440fx_2_0_machine_options(MachineClass *m)
 DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0,
                       pc_i440fx_2_0_machine_options);
 
+static GlobalProperty pc_compatp_1_7[] = {
+    PC_COMPAT_1_7
+};
 
 static void pc_i440fx_1_7_machine_options(MachineClass *m)
 {
@@ -625,7 +690,8 @@ static void pc_i440fx_1_7_machine_options(MachineClass *m)
     m->hw_version = "1.7.0";
     m->default_machine_opts = NULL;
     m->option_rom_has_mr = true;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_7);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_7, G_N_ELEMENTS(pc_compatp_1_7));
     pcmc->smbios_defaults = false;
     pcmc->gigabyte_align = false;
     pcmc->legacy_acpi_table_size = 6414;
@@ -634,6 +700,9 @@ static void pc_i440fx_1_7_machine_options(MachineClass *m)
 DEFINE_I440FX_MACHINE(v1_7, "pc-i440fx-1.7", pc_compat_1_7,
                       pc_i440fx_1_7_machine_options);
 
+static GlobalProperty pc_compatp_1_6[] = {
+    PC_COMPAT_1_6
+};
 
 static void pc_i440fx_1_6_machine_options(MachineClass *m)
 {
@@ -641,368 +710,391 @@ static void pc_i440fx_1_6_machine_options(MachineClass *m)
     pc_i440fx_1_7_machine_options(m);
     m->hw_version = "1.6.0";
     m->rom_file_has_mr = false;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_6);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_6, G_N_ELEMENTS(pc_compatp_1_6));
     pcmc->has_acpi_build = false;
 }
 
 DEFINE_I440FX_MACHINE(v1_6, "pc-i440fx-1.6", pc_compat_1_6,
                       pc_i440fx_1_6_machine_options);
 
+static GlobalProperty pc_compatp_1_5[] = {
+    PC_COMPAT_1_5
+};
 
 static void pc_i440fx_1_5_machine_options(MachineClass *m)
 {
     pc_i440fx_1_6_machine_options(m);
     m->hw_version = "1.5.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_5);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_5, G_N_ELEMENTS(pc_compatp_1_5));
 }
 
 DEFINE_I440FX_MACHINE(v1_5, "pc-i440fx-1.5", pc_compat_1_5,
                       pc_i440fx_1_5_machine_options);
 
+static GlobalProperty pc_compatp_1_4[] = {
+    PC_COMPAT_1_4
+};
 
 static void pc_i440fx_1_4_machine_options(MachineClass *m)
 {
     pc_i440fx_1_5_machine_options(m);
     m->hw_version = "1.4.0";
     m->hot_add_cpu = NULL;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_4);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_4, G_N_ELEMENTS(pc_compatp_1_4));
 }
 
 DEFINE_I440FX_MACHINE(v1_4, "pc-i440fx-1.4", pc_compat_1_4,
                       pc_i440fx_1_4_machine_options);
 
-
-#define PC_COMPAT_1_3 \
-        PC_CPU_MODEL_IDS("1.3.0") \
-        {\
-            .driver   = "usb-tablet",\
-            .property = "usb_version",\
-            .value    = stringify(1),\
-        },{\
-            .driver   = "virtio-net-pci",\
-            .property = "ctrl_mac_addr",\
-            .value    = "off",      \
-        },{ \
-            .driver   = "virtio-net-pci", \
-            .property = "mq", \
-            .value    = "off", \
-        }, {\
-            .driver   = "e1000",\
-            .property = "autonegotiation",\
-            .value    = "off",\
-        },
-
+static GlobalProperty pc_compatp_1_3[] = {
+    PC_CPU_MODEL_IDS("1.3.0")
+    {
+        .driver   = "usb-tablet",
+        .property = "usb_version",
+        .value    = stringify(1),
+    },{
+        .driver   = "virtio-net-pci",
+        .property = "ctrl_mac_addr",
+        .value    = "off",
+    },{
+        .driver   = "virtio-net-pci",
+        .property = "mq",
+        .value    = "off",
+    }, {
+        .driver   = "e1000",
+        .property = "autonegotiation",
+        .value    = "off",
+    },
+};
 
 static void pc_i440fx_1_3_machine_options(MachineClass *m)
 {
     pc_i440fx_1_4_machine_options(m);
     m->hw_version = "1.3.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_3);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_3, G_N_ELEMENTS(pc_compatp_1_3));
 }
 
 DEFINE_I440FX_MACHINE(v1_3, "pc-1.3", pc_compat_1_3,
                       pc_i440fx_1_3_machine_options);
 
 
-#define PC_COMPAT_1_2 \
-        PC_CPU_MODEL_IDS("1.2.0") \
-        {\
-            .driver   = "nec-usb-xhci",\
-            .property = "msi",\
-            .value    = "off",\
-        },{\
-            .driver   = "nec-usb-xhci",\
-            .property = "msix",\
-            .value    = "off",\
-        },{\
-            .driver   = "ivshmem",\
-            .property = "use64",\
-            .value    = "0",\
-        },{\
-            .driver   = "qxl",\
-            .property = "revision",\
-            .value    = stringify(3),\
-        },{\
-            .driver   = "qxl-vga",\
-            .property = "revision",\
-            .value    = stringify(3),\
-        },{\
-            .driver   = "VGA",\
-            .property = "mmio",\
-            .value    = "off",\
-        },
+static GlobalProperty pc_compatp_1_2[] = {
+    PC_CPU_MODEL_IDS("1.2.0")
+    {
+        .driver   = "nec-usb-xhci",
+        .property = "msi",
+        .value    = "off",
+    },{
+        .driver   = "nec-usb-xhci",
+        .property = "msix",
+        .value    = "off",
+    },{
+        .driver   = "ivshmem",
+        .property = "use64",
+        .value    = "0",
+    },{
+        .driver   = "qxl",
+        .property = "revision",
+        .value    = stringify(3),
+    },{
+        .driver   = "qxl-vga",
+        .property = "revision",
+        .value    = stringify(3),
+    },{
+        .driver   = "VGA",
+        .property = "mmio",
+        .value    = "off",
+    },
+};
 
 static void pc_i440fx_1_2_machine_options(MachineClass *m)
 {
     pc_i440fx_1_3_machine_options(m);
     m->hw_version = "1.2.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_2);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_2, G_N_ELEMENTS(pc_compatp_1_2));
 }
 
 DEFINE_I440FX_MACHINE(v1_2, "pc-1.2", pc_compat_1_2,
                       pc_i440fx_1_2_machine_options);
 
 
-#define PC_COMPAT_1_1 \
-        PC_CPU_MODEL_IDS("1.1.0") \
-        {\
-            .driver   = "virtio-scsi-pci",\
-            .property = "hotplug",\
-            .value    = "off",\
-        },{\
-            .driver   = "virtio-scsi-pci",\
-            .property = "param_change",\
-            .value    = "off",\
-        },{\
-            .driver   = "VGA",\
-            .property = "vgamem_mb",\
-            .value    = stringify(8),\
-        },{\
-            .driver   = "vmware-svga",\
-            .property = "vgamem_mb",\
-            .value    = stringify(8),\
-        },{\
-            .driver   = "qxl-vga",\
-            .property = "vgamem_mb",\
-            .value    = stringify(8),\
-        },{\
-            .driver   = "qxl",\
-            .property = "vgamem_mb",\
-            .value    = stringify(8),\
-        },{\
-            .driver   = "virtio-blk-pci",\
-            .property = "config-wce",\
-            .value    = "off",\
-        },
+static GlobalProperty pc_compatp_1_1[] = {
+    PC_CPU_MODEL_IDS("1.1.0")
+    {
+        .driver   = "virtio-scsi-pci",
+        .property = "hotplug",
+        .value    = "off",
+    },{
+        .driver   = "virtio-scsi-pci",
+        .property = "param_change",
+        .value    = "off",
+    },{
+        .driver   = "VGA",
+        .property = "vgamem_mb",
+        .value    = stringify(8),
+    },{
+        .driver   = "vmware-svga",
+        .property = "vgamem_mb",
+        .value    = stringify(8),
+    },{
+        .driver   = "qxl-vga",
+        .property = "vgamem_mb",
+        .value    = stringify(8),
+    },{
+        .driver   = "qxl",
+        .property = "vgamem_mb",
+        .value    = stringify(8),
+    },{
+        .driver   = "virtio-blk-pci",
+        .property = "config-wce",
+        .value    = "off",
+    },
+};
 
 static void pc_i440fx_1_1_machine_options(MachineClass *m)
 {
     pc_i440fx_1_2_machine_options(m);
     m->hw_version = "1.1.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_1);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_1, G_N_ELEMENTS(pc_compatp_1_1));
 }
 
 DEFINE_I440FX_MACHINE(v1_1, "pc-1.1", pc_compat_1_2,
                       pc_i440fx_1_1_machine_options);
 
-
-#define PC_COMPAT_1_0 \
-        PC_CPU_MODEL_IDS("1.0") \
-        {\
-            .driver   = TYPE_ISA_FDC,\
-            .property = "check_media_rate",\
-            .value    = "off",\
-        }, {\
-            .driver   = "virtio-balloon-pci",\
-            .property = "class",\
-            .value    = stringify(PCI_CLASS_MEMORY_RAM),\
-        },{\
-            .driver   = "apic-common",\
-            .property = "vapic",\
-            .value    = "off",\
-        },{\
-            .driver   = TYPE_USB_DEVICE,\
-            .property = "full-path",\
-            .value    = "no",\
-        },
+static GlobalProperty pc_compatp_1_0[] = {
+    PC_CPU_MODEL_IDS("1.0")
+    {
+        .driver   = TYPE_ISA_FDC,
+        .property = "check_media_rate",
+        .value    = "off",
+    },{
+        .driver   = "virtio-balloon-pci",
+        .property = "class",
+        .value    = stringify(PCI_CLASS_MEMORY_RAM),
+    },{
+        .driver   = "apic-common",
+        .property = "vapic",
+        .value    = "off",
+    },{
+        .driver   = TYPE_USB_DEVICE,
+        .property = "full-path",
+        .value    = "no",
+    },
+};
 
 static void pc_i440fx_1_0_machine_options(MachineClass *m)
 {
     pc_i440fx_1_1_machine_options(m);
     m->hw_version = "1.0";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_1_0);
+    compat_props_add(m->compat_props,
+                     pc_compatp_1_0, G_N_ELEMENTS(pc_compatp_1_0));
 }
 
 DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2,
                       pc_i440fx_1_0_machine_options);
 
 
-#define PC_COMPAT_0_15 \
-        PC_CPU_MODEL_IDS("0.15")
+static GlobalProperty pc_compatp_0_15[] = {
+    PC_CPU_MODEL_IDS("0.15")
+};
 
 static void pc_i440fx_0_15_machine_options(MachineClass *m)
 {
     pc_i440fx_1_0_machine_options(m);
     m->hw_version = "0.15";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_15);
+    compat_props_add(m->compat_props,
+                     pc_compatp_0_15, G_N_ELEMENTS(pc_compatp_0_15));
 }
 
 DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2,
                       pc_i440fx_0_15_machine_options);
 
 
-#define PC_COMPAT_0_14 \
-        PC_CPU_MODEL_IDS("0.14") \
-        {\
-            .driver   = "virtio-blk-pci",\
-            .property = "event_idx",\
-            .value    = "off",\
-        },{\
-            .driver   = "virtio-serial-pci",\
-            .property = "event_idx",\
-            .value    = "off",\
-        },{\
-            .driver   = "virtio-net-pci",\
-            .property = "event_idx",\
-            .value    = "off",\
-        },{\
-            .driver   = "virtio-balloon-pci",\
-            .property = "event_idx",\
-            .value    = "off",\
-        },{\
-            .driver   = "qxl",\
-            .property = "revision",\
-            .value    = stringify(2),\
-        },{\
-            .driver   = "qxl-vga",\
-            .property = "revision",\
-            .value    = stringify(2),\
-        },
+static GlobalProperty pc_compatp_0_14[] = {
+    PC_CPU_MODEL_IDS("0.14")
+    {
+        .driver   = "virtio-blk-pci",
+        .property = "event_idx",
+        .value    = "off",
+    },{
+        .driver   = "virtio-serial-pci",
+        .property = "event_idx",
+        .value    = "off",
+    },{
+        .driver   = "virtio-net-pci",
+        .property = "event_idx",
+        .value    = "off",
+    },{
+        .driver   = "virtio-balloon-pci",
+        .property = "event_idx",
+        .value    = "off",
+    },{
+        .driver   = "qxl",
+        .property = "revision",
+        .value    = stringify(2),
+    },{
+        .driver   = "qxl-vga",
+        .property = "revision",
+        .value    = stringify(2),
+    },
+};
 
 static void pc_i440fx_0_14_machine_options(MachineClass *m)
 {
     pc_i440fx_0_15_machine_options(m);
     m->hw_version = "0.14";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_14);
+    compat_props_add(m->compat_props,
+                     pc_compatp_0_14, G_N_ELEMENTS(pc_compatp_0_14));
 }
 
 DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2,
                       pc_i440fx_0_14_machine_options);
 
-
-#define PC_COMPAT_0_13 \
-        PC_CPU_MODEL_IDS("0.13") \
-        {\
-            .driver   = TYPE_PCI_DEVICE,\
-            .property = "command_serr_enable",\
-            .value    = "off",\
-        },{\
-            .driver   = "AC97",\
-            .property = "use_broken_id",\
-            .value    = stringify(1),\
-        },{\
-            .driver   = "virtio-9p-pci",\
-            .property = "vectors",\
-            .value    = stringify(0),\
-        },{\
-            .driver   = "VGA",\
-            .property = "rombar",\
-            .value    = stringify(0),\
-        },{\
-            .driver   = "vmware-svga",\
-            .property = "rombar",\
-            .value    = stringify(0),\
-        },
+static GlobalProperty pc_compatp_0_13[] = {
+    PC_CPU_MODEL_IDS("0.13")
+    {
+        .driver   = TYPE_PCI_DEVICE,
+        .property = "command_serr_enable",
+        .value    = "off",
+    },{
+        .driver   = "AC97",
+        .property = "use_broken_id",
+        .value    = stringify(1),
+    },{
+        .driver   = "virtio-9p-pci",
+        .property = "vectors",
+        .value    = stringify(0),
+    },{
+        .driver   = "VGA",
+        .property = "rombar",
+        .value    = stringify(0),
+    },{
+        .driver   = "vmware-svga",
+        .property = "rombar",
+        .value    = stringify(0),
+    },
+};
 
 static void pc_i440fx_0_13_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_0_14_machine_options(m);
     m->hw_version = "0.13";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_13);
+    compat_props_add(m->compat_props,
+                     pc_compatp_0_13, G_N_ELEMENTS(pc_compatp_0_13));
     pcmc->kvmclock_enabled = false;
 }
 
 DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13,
                       pc_i440fx_0_13_machine_options);
 
-
-#define PC_COMPAT_0_12 \
-        PC_CPU_MODEL_IDS("0.12") \
-        {\
-            .driver   = "virtio-serial-pci",\
-            .property = "max_ports",\
-            .value    = stringify(1),\
-        },{\
-            .driver   = "virtio-serial-pci",\
-            .property = "vectors",\
-            .value    = stringify(0),\
-        },{\
-            .driver   = "usb-mouse",\
-            .property = "serial",\
-            .value    = "1",\
-        },{\
-            .driver   = "usb-tablet",\
-            .property = "serial",\
-            .value    = "1",\
-        },{\
-            .driver   = "usb-kbd",\
-            .property = "serial",\
-            .value    = "1",\
-        },
+static GlobalProperty pc_compat_0_12[] = {
+    PC_CPU_MODEL_IDS("0.12")
+    {
+        .driver   = "virtio-serial-pci",
+        .property = "max_ports",
+        .value    = stringify(1),
+    },{
+        .driver   = "virtio-serial-pci",
+        .property = "vectors",
+        .value    = stringify(0),
+    },{
+        .driver   = "usb-mouse",
+        .property = "serial",
+        .value    = "1",
+    },{
+        .driver   = "usb-tablet",
+        .property = "serial",
+        .value    = "1",
+    },{
+        .driver   = "usb-kbd",
+        .property = "serial",
+        .value    = "1",
+    },
+};
 
 static void pc_i440fx_0_12_machine_options(MachineClass *m)
 {
     pc_i440fx_0_13_machine_options(m);
     m->hw_version = "0.12";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_12);
+    compat_props_add(m->compat_props,
+                     pc_compat_0_12, G_N_ELEMENTS(pc_compat_0_12));
 }
 
 DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13,
                       pc_i440fx_0_12_machine_options);
 
 
-#define PC_COMPAT_0_11 \
-        PC_CPU_MODEL_IDS("0.11") \
-        {\
-            .driver   = "virtio-blk-pci",\
-            .property = "vectors",\
-            .value    = stringify(0),\
-        },{\
-            .driver   = TYPE_PCI_DEVICE,\
-            .property = "rombar",\
-            .value    = stringify(0),\
-        },{\
-            .driver   = "ide-drive",\
-            .property = "ver",\
-            .value    = "0.11",\
-        },{\
-            .driver   = "scsi-disk",\
-            .property = "ver",\
-            .value    = "0.11",\
-        },
+static GlobalProperty pc_compat_0_11[] = {
+    PC_CPU_MODEL_IDS("0.11")
+    {
+        .driver   = "virtio-blk-pci",
+        .property = "vectors",
+        .value    = stringify(0),
+    },{
+        .driver   = TYPE_PCI_DEVICE,
+        .property = "rombar",
+        .value    = stringify(0),
+    },{
+        .driver   = "ide-drive",
+        .property = "ver",
+        .value    = "0.11",
+    },{
+        .driver   = "scsi-disk",
+        .property = "ver",
+        .value    = "0.11",
+    },
+};
 
 static void pc_i440fx_0_11_machine_options(MachineClass *m)
 {
     pc_i440fx_0_12_machine_options(m);
     m->hw_version = "0.11";
     m->deprecation_reason = "use a newer machine type instead";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_11);
+    compat_props_add(m->compat_props,
+                     pc_compat_0_11, G_N_ELEMENTS(pc_compat_0_11));
 }
 
 DEFINE_I440FX_MACHINE(v0_11, "pc-0.11", pc_compat_0_13,
                       pc_i440fx_0_11_machine_options);
 
-
-#define PC_COMPAT_0_10 \
-    PC_CPU_MODEL_IDS("0.10") \
-    {\
-        .driver   = "virtio-blk-pci",\
-        .property = "class",\
-        .value    = stringify(PCI_CLASS_STORAGE_OTHER),\
-    },{\
-        .driver   = "virtio-serial-pci",\
-        .property = "class",\
-        .value    = stringify(PCI_CLASS_DISPLAY_OTHER),\
-    },{\
-        .driver   = "virtio-net-pci",\
-        .property = "vectors",\
-        .value    = stringify(0),\
-    },{\
-        .driver   = "ide-drive",\
-        .property = "ver",\
-        .value    = "0.10",\
-    },{\
-        .driver   = "scsi-disk",\
-        .property = "ver",\
-        .value    = "0.10",\
+static GlobalProperty pc_compat_0_10[] = {
+    PC_CPU_MODEL_IDS("0.10")
+    {
+        .driver   = "virtio-blk-pci",
+        .property = "class",
+        .value    = stringify(PCI_CLASS_STORAGE_OTHER),
+    },{
+        .driver   = "virtio-serial-pci",
+        .property = "class",
+        .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
+    },{
+        .driver   = "virtio-net-pci",
+        .property = "vectors",
+        .value    = stringify(0),
+    },{
+        .driver   = "ide-drive",
+        .property = "ver",
+        .value    = "0.10",
+    },{
+        .driver   = "scsi-disk",
+        .property = "ver",
+        .value    = "0.10",
     },
+};
 
 static void pc_i440fx_0_10_machine_options(MachineClass *m)
 {
     pc_i440fx_0_11_machine_options(m);
     m->hw_version = "0.10";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_0_10);
+    compat_props_add(m->compat_props,
+                     pc_compat_0_10, G_N_ELEMENTS(pc_compat_0_10));
 }
 
 DEFINE_I440FX_MACHINE(v0_10, "pc-0.10", pc_compat_0_13,
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 4702bb13c4..701c09b43e 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -320,41 +320,61 @@ static void pc_q35_3_1_machine_options(MachineClass *m)
 DEFINE_Q35_MACHINE(v3_1, "pc-q35-3.1", NULL,
                    pc_q35_3_1_machine_options);
 
+static GlobalProperty pc_compat_3_0[] = {
+    PC_COMPAT_3_0
+};
+
 static void pc_q35_3_0_machine_options(MachineClass *m)
 {
     pc_q35_3_1_machine_options(m);
     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_Q35_MACHINE(v3_0, "pc-q35-3.0", NULL,
                     pc_q35_3_0_machine_options);
 
+static GlobalProperty pc_compat_2_12[] = {
+    PC_COMPAT_2_12
+};
+
 static void pc_q35_2_12_machine_options(MachineClass *m)
 {
     pc_q35_3_0_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_12, G_N_ELEMENTS(pc_compat_2_12));
 }
 
 DEFINE_Q35_MACHINE(v2_12, "pc-q35-2.12", NULL,
                    pc_q35_2_12_machine_options);
 
+static GlobalProperty pc_compat_2_11[] = {
+    PC_COMPAT_2_11
+};
+
 static void pc_q35_2_11_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
 
     pc_q35_2_12_machine_options(m);
     pcmc->default_nic_model = "e1000";
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_11);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_11, G_N_ELEMENTS(pc_compat_2_11));
 }
 
 DEFINE_Q35_MACHINE(v2_11, "pc-q35-2.11", NULL,
                    pc_q35_2_11_machine_options);
 
+static GlobalProperty pc_compat_2_10[] = {
+    PC_COMPAT_2_10
+};
+
 static void pc_q35_2_10_machine_options(MachineClass *m)
 {
     pc_q35_2_11_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_10);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_10, G_N_ELEMENTS(pc_compat_2_10));
     m->numa_auto_assign_ram = numa_legacy_auto_assign_ram;
     m->auto_enable_numa_with_memhp = false;
 }
@@ -362,65 +382,95 @@ static void pc_q35_2_10_machine_options(MachineClass *m)
 DEFINE_Q35_MACHINE(v2_10, "pc-q35-2.10", NULL,
                    pc_q35_2_10_machine_options);
 
+static GlobalProperty pc_compat_2_9[] = {
+    PC_COMPAT_2_9
+};
+
 static void pc_q35_2_9_machine_options(MachineClass *m)
 {
     pc_q35_2_10_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_9);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_9, G_N_ELEMENTS(pc_compat_2_9));
 }
 
 DEFINE_Q35_MACHINE(v2_9, "pc-q35-2.9", NULL,
                    pc_q35_2_9_machine_options);
 
+static GlobalProperty pc_compat_2_8[] = {
+    PC_COMPAT_2_8
+};
+
 static void pc_q35_2_8_machine_options(MachineClass *m)
 {
     pc_q35_2_9_machine_options(m);
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_8);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_8, G_N_ELEMENTS(pc_compat_2_8));
 }
 
 DEFINE_Q35_MACHINE(v2_8, "pc-q35-2.8", NULL,
                    pc_q35_2_8_machine_options);
 
+static GlobalProperty pc_compat_2_7[] = {
+    PC_COMPAT_2_7
+};
+
 static void pc_q35_2_7_machine_options(MachineClass *m)
 {
     pc_q35_2_8_machine_options(m);
     m->max_cpus = 255;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_7, G_N_ELEMENTS(pc_compat_2_7));
 }
 
 DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,
                    pc_q35_2_7_machine_options);
 
+static GlobalProperty pc_compat_2_6[] = {
+    PC_COMPAT_2_6
+};
+
 static void pc_q35_2_6_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_2_7_machine_options(m);
     pcmc->legacy_cpu_hotplug = true;
     pcmc->linuxboot_dma_enabled = false;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_6, G_N_ELEMENTS(pc_compat_2_6));
 }
 
 DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,
                    pc_q35_2_6_machine_options);
 
+static GlobalProperty pc_compat_2_5[] = {
+    PC_COMPAT_2_5
+};
+
 static void pc_q35_2_5_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_2_6_machine_options(m);
     pcmc->save_tsc_khz = false;
     m->legacy_fw_cfg_order = 1;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_5);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_5, G_N_ELEMENTS(pc_compat_2_5));
 }
 
 DEFINE_Q35_MACHINE(v2_5, "pc-q35-2.5", NULL,
                    pc_q35_2_5_machine_options);
 
+static GlobalProperty pc_compat_2_4[] = {
+    PC_COMPAT_2_4
+};
+
 static void pc_q35_2_4_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_2_5_machine_options(m);
     m->hw_version = "2.4.0";
     pcmc->broken_reserved_end = true;
-    SET_MACHINE_COMPAT(m, PC_COMPAT_2_4);
+    compat_props_add(m->compat_props,
+                     pc_compat_2_4, G_N_ELEMENTS(pc_compat_2_4));
 }
 
 DEFINE_Q35_MACHINE(v2_4, "pc-q35-2.4", NULL,
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 7afd1a175b..d801ba71eb 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -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)
 {
@@ -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));
 
     /* 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
@@ -4052,8 +4056,9 @@ DEFINE_SPAPR_MACHINE(2_12_sxxm, "2.12-sxxm", false);
 /*
  * pseries-2.11
  */
-#define SPAPR_COMPAT_2_11                                              \
+static GlobalProperty spapr_compat_2_11[] = {
     HW_COMPAT_2_11
+};
 
 static void spapr_machine_2_11_instance_options(MachineState *machine)
 {
@@ -4066,7 +4071,8 @@ static void spapr_machine_2_11_class_options(MachineClass *mc)
 
     spapr_machine_2_12_class_options(mc);
     smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_ON;
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_11);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_11, G_N_ELEMENTS(spapr_compat_2_11));
 }
 
 DEFINE_SPAPR_MACHINE(2_11, "2.11", false);
@@ -4074,8 +4080,9 @@ DEFINE_SPAPR_MACHINE(2_11, "2.11", false);
 /*
  * pseries-2.10
  */
-#define SPAPR_COMPAT_2_10                                              \
+static GlobalProperty spapr_compat_2_10[] = {
     HW_COMPAT_2_10
+};
 
 static void spapr_machine_2_10_instance_options(MachineState *machine)
 {
@@ -4085,7 +4092,8 @@ static void spapr_machine_2_10_instance_options(MachineState *machine)
 static void spapr_machine_2_10_class_options(MachineClass *mc)
 {
     spapr_machine_2_11_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_10);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_10, G_N_ELEMENTS(spapr_compat_2_10));
 }
 
 DEFINE_SPAPR_MACHINE(2_10, "2.10", false);
@@ -4093,13 +4101,14 @@ DEFINE_SPAPR_MACHINE(2_10, "2.10", false);
 /*
  * pseries-2.9
  */
-#define SPAPR_COMPAT_2_9                                               \
-    HW_COMPAT_2_9                                                      \
-    {                                                                  \
-        .driver = TYPE_POWERPC_CPU,                                    \
-        .property = "pre-2.10-migration",                              \
-        .value    = "on",                                              \
-    },                                                                 \
+static GlobalProperty spapr_compat_2_9[] = {
+    HW_COMPAT_2_9
+    {
+        .driver = TYPE_POWERPC_CPU,
+        .property = "pre-2.10-migration",
+        .value    = "on",
+    },
+};
 
 static void spapr_machine_2_9_instance_options(MachineState *machine)
 {
@@ -4111,7 +4120,8 @@ static void spapr_machine_2_9_class_options(MachineClass *mc)
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
 
     spapr_machine_2_10_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_9);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_9, G_N_ELEMENTS(spapr_compat_2_9));
     mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram;
     smc->pre_2_10_has_unused_icps = true;
     smc->resize_hpt_default = SPAPR_RESIZE_HPT_DISABLED;
@@ -4122,13 +4132,14 @@ DEFINE_SPAPR_MACHINE(2_9, "2.9", false);
 /*
  * pseries-2.8
  */
-#define SPAPR_COMPAT_2_8                                        \
-    HW_COMPAT_2_8                                               \
-    {                                                           \
-        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,                 \
-        .property = "pcie-extended-configuration-space",        \
-        .value    = "off",                                      \
+static GlobalProperty spapr_compat_2_8[] = {
+    HW_COMPAT_2_8
+    {
+        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "pcie-extended-configuration-space",
+        .value    = "off",
     },
+};
 
 static void spapr_machine_2_8_instance_options(MachineState *machine)
 {
@@ -4138,7 +4149,8 @@ static void spapr_machine_2_8_instance_options(MachineState *machine)
 static void spapr_machine_2_8_class_options(MachineClass *mc)
 {
     spapr_machine_2_9_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_8);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_8, G_N_ELEMENTS(spapr_compat_2_8));
     mc->numa_mem_align_shift = 23;
 }
 
@@ -4147,28 +4159,29 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", false);
 /*
  * pseries-2.7
  */
-#define SPAPR_COMPAT_2_7                            \
-    HW_COMPAT_2_7                                   \
-    {                                               \
-        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,     \
-        .property = "mem_win_size",                 \
-        .value    = stringify(SPAPR_PCI_2_7_MMIO_WIN_SIZE),\
-    },                                              \
-    {                                               \
-        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,     \
-        .property = "mem64_win_size",               \
-        .value    = "0",                            \
-    },                                              \
-    {                                               \
-        .driver = TYPE_POWERPC_CPU,                 \
-        .property = "pre-2.8-migration",            \
-        .value    = "on",                           \
-    },                                              \
-    {                                               \
-        .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,       \
-        .property = "pre-2.8-migration",            \
-        .value    = "on",                           \
+static GlobalProperty spapr_compat_2_7[] = {
+    HW_COMPAT_2_7
+    {
+        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "mem_win_size",
+        .value    = stringify(SPAPR_PCI_2_7_MMIO_WIN_SIZE),
+    },
+    {
+        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "mem64_win_size",
+        .value    = "0",
+    },
+    {
+        .driver = TYPE_POWERPC_CPU,
+        .property = "pre-2.8-migration",
+        .value    = "on",
+    },
+    {
+        .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "pre-2.8-migration",
+        .value    = "on",
     },
+};
 
 static void phb_placement_2_7(sPAPRMachineState *spapr, uint32_t index,
                               uint64_t *buid, hwaddr *pio,
@@ -4233,7 +4246,8 @@ static void spapr_machine_2_7_class_options(MachineClass *mc)
 
     spapr_machine_2_8_class_options(mc);
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power7_v2.3");
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_7);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_7, G_N_ELEMENTS(spapr_compat_2_7));
     smc->phb_placement = phb_placement_2_7;
 }
 
@@ -4242,13 +4256,14 @@ DEFINE_SPAPR_MACHINE(2_7, "2.7", false);
 /*
  * pseries-2.6
  */
-#define SPAPR_COMPAT_2_6 \
-    HW_COMPAT_2_6 \
-    { \
-        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,\
-        .property = "ddw",\
-        .value    = stringify(off),\
+static GlobalProperty spapr_compat_2_6[] = {
+    HW_COMPAT_2_6
+    {
+        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "ddw",
+        .value    = stringify(off),
     },
+};
 
 static void spapr_machine_2_6_instance_options(MachineState *machine)
 {
@@ -4259,7 +4274,8 @@ static void spapr_machine_2_6_class_options(MachineClass *mc)
 {
     spapr_machine_2_7_class_options(mc);
     mc->has_hotpluggable_cpus = false;
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_6);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_6, G_N_ELEMENTS(spapr_compat_2_6));
 }
 
 DEFINE_SPAPR_MACHINE(2_6, "2.6", false);
@@ -4267,13 +4283,14 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", false);
 /*
  * pseries-2.5
  */
-#define SPAPR_COMPAT_2_5 \
-    HW_COMPAT_2_5 \
-    { \
-        .driver   = "spapr-vlan", \
-        .property = "use-rx-buffer-pools", \
-        .value    = "off", \
+static GlobalProperty spapr_compat_2_5[] = {
+    HW_COMPAT_2_5
+    {
+        .driver   = "spapr-vlan",
+        .property = "use-rx-buffer-pools",
+        .value    = "off",
     },
+};
 
 static void spapr_machine_2_5_instance_options(MachineState *machine)
 {
@@ -4286,7 +4303,8 @@ static void spapr_machine_2_5_class_options(MachineClass *mc)
 
     spapr_machine_2_6_class_options(mc);
     smc->use_ohci_by_default = true;
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_5);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_5, G_N_ELEMENTS(spapr_compat_2_5));
 }
 
 DEFINE_SPAPR_MACHINE(2_5, "2.5", false);
@@ -4294,8 +4312,9 @@ DEFINE_SPAPR_MACHINE(2_5, "2.5", false);
 /*
  * pseries-2.4
  */
-#define SPAPR_COMPAT_2_4 \
-        HW_COMPAT_2_4
+static GlobalProperty spapr_compat_2_4[] = {
+    HW_COMPAT_2_4
+};
 
 static void spapr_machine_2_4_instance_options(MachineState *machine)
 {
@@ -4308,7 +4327,8 @@ static void spapr_machine_2_4_class_options(MachineClass *mc)
 
     spapr_machine_2_5_class_options(mc);
     smc->dr_lmb_enabled = false;
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_4);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_4, G_N_ELEMENTS(spapr_compat_2_4));
 }
 
 DEFINE_SPAPR_MACHINE(2_4, "2.4", false);
@@ -4316,13 +4336,14 @@ DEFINE_SPAPR_MACHINE(2_4, "2.4", false);
 /*
  * pseries-2.3
  */
-#define SPAPR_COMPAT_2_3 \
-        HW_COMPAT_2_3 \
-        {\
-            .driver   = "spapr-pci-host-bridge",\
-            .property = "dynamic-reconfiguration",\
-            .value    = "off",\
-        },
+static GlobalProperty spapr_compat_2_3[] = {
+    HW_COMPAT_2_3
+    {
+        .driver   = "spapr-pci-host-bridge",
+        .property = "dynamic-reconfiguration",
+        .value    = "off",
+    },
+};
 
 static void spapr_machine_2_3_instance_options(MachineState *machine)
 {
@@ -4332,21 +4353,22 @@ static void spapr_machine_2_3_instance_options(MachineState *machine)
 static void spapr_machine_2_3_class_options(MachineClass *mc)
 {
     spapr_machine_2_4_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_3);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_3, G_N_ELEMENTS(spapr_compat_2_3));
 }
 DEFINE_SPAPR_MACHINE(2_3, "2.3", false);
 
 /*
  * pseries-2.2
  */
-
-#define SPAPR_COMPAT_2_2 \
-        HW_COMPAT_2_2 \
-        {\
-            .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,\
-            .property = "mem_win_size",\
-            .value    = "0x20000000",\
-        },
+static GlobalProperty spapr_compat_2_2[] = {
+    HW_COMPAT_2_2
+    {
+        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,
+        .property = "mem_win_size",
+        .value    = "0x20000000",
+    },
+};
 
 static void spapr_machine_2_2_instance_options(MachineState *machine)
 {
@@ -4357,15 +4379,17 @@ static void spapr_machine_2_2_instance_options(MachineState *machine)
 static void spapr_machine_2_2_class_options(MachineClass *mc)
 {
     spapr_machine_2_3_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_2);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_2, G_N_ELEMENTS(spapr_compat_2_2));
 }
 DEFINE_SPAPR_MACHINE(2_2, "2.2", false);
 
 /*
  * pseries-2.1
  */
-#define SPAPR_COMPAT_2_1 \
-        HW_COMPAT_2_1
+static GlobalProperty spapr_compat_2_1[] = {
+    HW_COMPAT_2_1
+};
 
 static void spapr_machine_2_1_instance_options(MachineState *machine)
 {
@@ -4375,7 +4399,8 @@ static void spapr_machine_2_1_instance_options(MachineState *machine)
 static void spapr_machine_2_1_class_options(MachineClass *mc)
 {
     spapr_machine_2_2_class_options(mc);
-    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_1);
+    compat_props_add(mc->compat_props,
+                     spapr_compat_2_1, G_N_ELEMENTS(spapr_compat_2_1));
 }
 DEFINE_SPAPR_MACHINE(2_1, "2.1", false);
 
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index a0615a8b35..275cbe5da4 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -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",\
-        },
-
-#define CCW_COMPAT_2_10 \
-        HW_COMPAT_2_10
-
-#define CCW_COMPAT_2_9 \
-        HW_COMPAT_2_9 \
-        {\
-            .driver   = TYPE_S390_STATTRIB,\
-            .property = "migration-enabled",\
-            .value    = "off",\
-        },
-
-#define CCW_COMPAT_2_8 \
-        HW_COMPAT_2_8 \
-        {\
-            .driver   = TYPE_S390_FLIC_COMMON,\
-            .property = "adapter_routes_max_batch",\
-            .value    = "64",\
-        },
-
-#define CCW_COMPAT_2_7 \
-        HW_COMPAT_2_7
-
-#define CCW_COMPAT_2_6 \
-        HW_COMPAT_2_6 \
-        {\
-            .driver   = TYPE_S390_IPL,\
-            .property = "iplbext_migration",\
-            .value    = "off",\
-        }, {\
-            .driver   = TYPE_VIRTUAL_CSS_BRIDGE,\
-            .property = "css_dev_path",\
-            .value    = "off",\
-        },
-
-#define CCW_COMPAT_2_5 \
-        HW_COMPAT_2_5
-
-#define CCW_COMPAT_2_4 \
-        HW_COMPAT_2_4 \
-        {\
-            .driver   = TYPE_S390_SKEYS,\
-            .property = "migration-enabled",\
-            .value    = "off",\
-        },{\
-            .driver   = "virtio-blk-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-balloon-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-serial-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-9p-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-rng-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-net-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "virtio-scsi-ccw",\
-            .property = "max_revision",\
-            .value    = "0",\
-        },{\
-            .driver   = "vhost-scsi-ccw",\
-            .property = "max_revision",\
-            .value    = "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",
+    },
+};
+
+static GlobalProperty ccw_compat_2_10[] = {
+    HW_COMPAT_2_10
+};
+
+static GlobalProperty ccw_compat_2_9[] = {
+    HW_COMPAT_2_9
+    {
+        .driver   = TYPE_S390_STATTRIB,
+        .property = "migration-enabled",
+        .value    = "off",
+    },
+};
+
+static GlobalProperty ccw_compat_2_8[] = {
+    HW_COMPAT_2_8
+    {
+        .driver   = TYPE_S390_FLIC_COMMON,
+        .property = "adapter_routes_max_batch",
+        .value    = "64",
+    },
+};
+
+static GlobalProperty ccw_compat_2_7[] = {
+    HW_COMPAT_2_7
+};
+
+static GlobalProperty ccw_compat_2_6[] = {
+    HW_COMPAT_2_6
+    {
+        .driver   = TYPE_S390_IPL,
+        .property = "iplbext_migration",
+        .value    = "off",
+    }, {
+        .driver   = TYPE_VIRTUAL_CSS_BRIDGE,
+        .property = "css_dev_path",
+        .value    = "off",
+    },
+};
+
+static GlobalProperty ccw_compat_2_5[] = {
+    HW_COMPAT_2_5
+};
+
+static GlobalProperty ccw_compat_2_4[] = {
+    HW_COMPAT_2_4
+    {
+        .driver   = TYPE_S390_SKEYS,
+        .property = "migration-enabled",
+        .value    = "off",
+    },{
+        .driver   = "virtio-blk-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-balloon-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-serial-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-9p-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-rng-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-net-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "virtio-scsi-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },{
+        .driver   = "vhost-scsi-ccw",
+        .property = "max_revision",
+        .value    = "0",
+    },
+};
 
 static void ccw_machine_3_1_instance_options(MachineState *machine)
 {
@@ -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));
 }
 DEFINE_CCW_MACHINE(3_0, "3.0", false);
 
@@ -776,7 +787,8 @@ static void ccw_machine_2_12_instance_options(MachineState *machine)
 static void ccw_machine_2_12_class_options(MachineClass *mc)
 {
     ccw_machine_3_0_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_12);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_12, G_N_ELEMENTS(ccw_compat_2_12));
 }
 DEFINE_CCW_MACHINE(2_12, "2.12", false);
 
@@ -792,7 +804,8 @@ static void ccw_machine_2_11_instance_options(MachineState *machine)
 static void ccw_machine_2_11_class_options(MachineClass *mc)
 {
     ccw_machine_2_12_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_11);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_11, G_N_ELEMENTS(ccw_compat_2_11));
 }
 DEFINE_CCW_MACHINE(2_11, "2.11", false);
 
@@ -804,7 +817,8 @@ static void ccw_machine_2_10_instance_options(MachineState *machine)
 static void ccw_machine_2_10_class_options(MachineClass *mc)
 {
     ccw_machine_2_11_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_10);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_10, G_N_ELEMENTS(ccw_compat_2_10));
 }
 DEFINE_CCW_MACHINE(2_10, "2.10", false);
 
@@ -823,7 +837,8 @@ static void ccw_machine_2_9_class_options(MachineClass *mc)
     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
 
     ccw_machine_2_10_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_9);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_9, G_N_ELEMENTS(ccw_compat_2_9));
     s390mc->css_migration_enabled = false;
 }
 DEFINE_CCW_MACHINE(2_9, "2.9", false);
@@ -836,7 +851,8 @@ static void ccw_machine_2_8_instance_options(MachineState *machine)
 static void ccw_machine_2_8_class_options(MachineClass *mc)
 {
     ccw_machine_2_9_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_8);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_8, G_N_ELEMENTS(ccw_compat_2_8));
 }
 DEFINE_CCW_MACHINE(2_8, "2.8", false);
 
@@ -851,7 +867,8 @@ static void ccw_machine_2_7_class_options(MachineClass *mc)
 
     s390mc->cpu_model_allowed = false;
     ccw_machine_2_8_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_7);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_7, G_N_ELEMENTS(ccw_compat_2_7));
 }
 DEFINE_CCW_MACHINE(2_7, "2.7", false);
 
@@ -866,7 +883,8 @@ static void ccw_machine_2_6_class_options(MachineClass *mc)
 
     s390mc->ri_allowed = false;
     ccw_machine_2_7_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_6);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_6, G_N_ELEMENTS(ccw_compat_2_6));
 }
 DEFINE_CCW_MACHINE(2_6, "2.6", false);
 
@@ -878,7 +896,8 @@ static void ccw_machine_2_5_instance_options(MachineState *machine)
 static void ccw_machine_2_5_class_options(MachineClass *mc)
 {
     ccw_machine_2_6_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_5);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_5, G_N_ELEMENTS(ccw_compat_2_5));
 }
 DEFINE_CCW_MACHINE(2_5, "2.5", false);
 
@@ -890,7 +909,8 @@ static void ccw_machine_2_4_instance_options(MachineState *machine)
 static void ccw_machine_2_4_class_options(MachineClass *mc)
 {
     ccw_machine_2_5_class_options(mc);
-    SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_4);
+    compat_props_add(mc->compat_props,
+                     ccw_compat_2_4, G_N_ELEMENTS(ccw_compat_2_4));
 }
 DEFINE_CCW_MACHINE(2_4, "2.4", false);
 
diff --git a/vl.c b/vl.c
index 88ba658572..65f0dddb74 100644
--- a/vl.c
+++ b/vl.c
@@ -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();
 }
 
-- 
2.20.0.rc1


Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Eduardo Habkost 6 years, 10 months ago
On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
> 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.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  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(-)
> 
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index f82f28468b..28c2b0af41 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -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;
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index f69e7eb399..530c8ca89d 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -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:

diff --git a/include/hw/boards.h b/include/hw/boards.h
index f82f28468b..622bbaf939 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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


-- 
Eduardo

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Marc-André Lureau 6 years, 9 months ago
Hi

On Mon, Dec 10, 2018 at 9:31 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
> > 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.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  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(-)
> >
> > diff --git a/include/hw/boards.h b/include/hw/boards.h
> > index f82f28468b..28c2b0af41 100644
> > --- a/include/hw/boards.h
> > +++ b/include/hw/boards.h
> > @@ -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;
> > diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> > index f69e7eb399..530c8ca89d 100644
> > --- a/hw/arm/virt.c
> > +++ b/hw/arm/virt.c
> > @@ -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:
>
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index f82f28468b..622bbaf939 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -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
>

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.


-- 
Marc-André Lureau

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Eduardo Habkost 6 years, 9 months ago
On Tue, Dec 11, 2018 at 04:07:19PM +0400, Marc-André Lureau wrote:
> Hi
> 
> On Mon, Dec 10, 2018 at 9:31 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > On Tue, Dec 04, 2018 at 06:20:12PM +0400, Marc-André Lureau wrote:
> > > 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.
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > >  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(-)
> > >
> > > diff --git a/include/hw/boards.h b/include/hw/boards.h
> > > index f82f28468b..28c2b0af41 100644
> > > --- a/include/hw/boards.h
> > > +++ b/include/hw/boards.h
> > > @@ -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;
> > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> > > index f69e7eb399..530c8ca89d 100644
> > > --- a/hw/arm/virt.c
> > > +++ b/hw/arm/virt.c
> > > @@ -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:
> >
> > diff --git a/include/hw/boards.h b/include/hw/boards.h
> > index f82f28468b..622bbaf939 100644
> > --- a/include/hw/boards.h
> > +++ b/include/hw/boards.h
> > @@ -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
> >
> 
> 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.

-- 
Eduardo

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Eduardo Habkost 6 years, 9 months ago
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:
[...]
> -#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()?

>  
>  static void virt_3_0_instance_init(Object *obj)
>  {
> @@ -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.


[...]
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 7092d6d13f..575566e466 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -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));
>  }
>  
>  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.


[...]
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 7afd1a175b..d801ba71eb 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -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)
>  {
> @@ -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.


>  
>      /* 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
[...]
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index a0615a8b35..275cbe5da4 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -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",\
> -        },
[...]
> +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",
> +    },
> +};
[...]
>  
>  static void ccw_machine_3_1_instance_options(MachineState *machine)
>  {
> @@ -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.


>  }
>  DEFINE_CCW_MACHINE(3_0, "3.0", false);
[...]

-- 
Eduardo

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Marc-André Lureau 6 years, 9 months ago
Hi

On Tue, Dec 11, 2018 at 6:24 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> 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:
> [...]
> > -#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

>
> >
> >  static void virt_3_0_instance_init(Object *obj)
> >  {
> > @@ -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)

>
> 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.
>
>
> [...]
> > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> > index 7092d6d13f..575566e466 100644
> > --- a/hw/i386/pc_piix.c
> > +++ b/hw/i386/pc_piix.c
> > @@ -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));
> >  }
> >
> >  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

>
>
> [...]
> > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > index 7afd1a175b..d801ba71eb 100644
> > --- a/hw/ppc/spapr.c
> > +++ b/hw/ppc/spapr.c
> > @@ -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)
> >  {
> > @@ -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.

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

>
> Other than that, it's also basically the same amount of
> boilerplate as before, so that's good.
>
>
> >
> >      /* 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
> [...]
> > diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> > index a0615a8b35..275cbe5da4 100644
> > --- a/hw/s390x/s390-virtio-ccw.c
> > +++ b/hw/s390x/s390-virtio-ccw.c
> > @@ -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",\
> > -        },
> [...]
> > +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",
> > +    },
> > +};
> [...]
> >
> >  static void ccw_machine_3_1_instance_options(MachineState *machine)
> >  {
> > @@ -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.
>
>

thanks

> >  }
> >  DEFINE_CCW_MACHINE(3_0, "3.0", false);
> [...]
>
> --
> Eduardo
>


-- 
Marc-André Lureau

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Igor Mammedov 6 years, 9 months ago
On Tue, 11 Dec 2018 18:30:32 +0400
Marc-André Lureau <marcandre.lureau@gmail.com> wrote:

> Hi
> 
> On Tue, Dec 11, 2018 at 6:24 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > 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:
> > [...]  
> > > -#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
> 
> >  
> > >
> > >  static void virt_3_0_instance_init(Object *obj)
> > >  {
> > > @@ -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)
+1 to explicit array size,
it also allows to drop terminating NULL entry in compat declarations

[...]

Re: [Qemu-devel] [PATCH for-3.2 v5 08/19] hw: apply machine compat properties without touching globals
Posted by Eduardo Habkost 6 years, 9 months ago
On Tue, Dec 11, 2018 at 04:52:29PM +0100, Igor Mammedov wrote:
> On Tue, 11 Dec 2018 18:30:32 +0400
> Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> 
> > Hi
> > 
> > On Tue, Dec 11, 2018 at 6:24 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> > >
> > > 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:
> > > [...]  
> > > > -#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
> > 
> > >  
> > > >
> > > >  static void virt_3_0_instance_init(Object *obj)
> > > >  {
> > > > @@ -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)
> +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.

-- 
Eduardo