Skip to contentSkip to conversation

qom: resolve type name conflicts, avoid target_info() in class_init or type_init

PATCH Superseded Yonggang Luo 2 participants 28 messages Oct 28 – Oct 30

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover qom: resolve type name conflicts, avoid target_info() in class_init or type_init

The goal is a single binary that links several targets, where every QOM type is registered once for all of them. Types that share a name go into one bucket per name, each variant tagged with the targets it serves, and the selected target picks the variant at lookup time. For that to work, registering a type and building its class must not depend on which target is selected.

Today some class_init and type_init functions call target_info(), directly or through helpers such as target_s390x(). The result is fixed for the one target selected when the class is built, so the other targets never get their own form of that type.

max-v8 called target_aarch64() from its type_init to pick an instance initializer. scsi-hd, scsi-cd, virtio-blk-pci, virtio-net-pci and virtio-mem called target_s390x() or target_arch() from class_init to add properties. The PetaLogix machine called target_big_endian() from class_init to set the default endianness.

Instead, each target-specific form becomes its own TypeInfo under the same name. Its is_available callback says which target it belongs to. Today QOM registers only the one that matches; a bucket can later keep all of them. LoongArch and Xtensa virt machines are handled the same way, since both share the virt-machine name. PetaLogix keeps one type: its endianness default is "unspecified" until the machine starts. A few target_*() helpers are added for the new callbacks.

Yonggang Luo (12):
target-info: add target_loongarch()
hw/loongarch/virt: select virt machine types with is_available
target-info: add target_xtensa()
hw/xtensa/virt: select virt machine types with is_available target/arm: register separate max-v8 CPU types for arm and aarch64
target-info: add target_not_s390x()
hw/scsi/scsi-disk: register s390x scsi-hd and scsi-cd variants hw/virtio/virtio-pci: pass is_available through
VirtioPCIDeviceTypeInfo
hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants
target-info: add target_base_i386() and target_not_base_i386() hw/virtio/virtio-mem: register legacy-guest variant with is_available hw/microblaze: defer PetaLogix endianness default until init

 hw/loongarch/virt.c                      |  3 ++
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 11 ++++--
 hw/pci/pci.c                             | 13 +++----
 hw/scsi/scsi-disk.c                      | 43 +++++++++++++++++-----
 hw/virtio/virtio-blk-pci.c               | 22 ++++++++++-
 hw/virtio/virtio-mem.c                   | 47 ++++++++++++++----------
 hw/virtio/virtio-net-pci.c               | 22 ++++++++++-
 hw/virtio/virtio-pci.c                   |  4 ++
 hw/xtensa/virt.c                         | 21 ++++++++++-
 include/hw/virtio/virtio-mem.h           |  2 +
 include/hw/virtio/virtio-pci.h           |  1 +
 include/qemu/target-info.h               | 35 ++++++++++++++++++
 target-info.c                            | 37 +++++++++++++++++++
 target/arm/cpu.c                         |  1 +
 target/arm/cpu.h                         |  1 +
 target/arm/tcg/cpu-max-v8.c              | 16 ++++++--
 16 files changed, 231 insertions(+), 48 deletions(-)
Signature · 1 line
2.55.0.windows.3
#1 lore raw

PATCH 1/12 target-info: add target_loongarch()

Report whether the selected target architecture is LoongArch.

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++
 2 files changed, 12 insertions(+)
include/qemu/target-info.h +7 -0
index 2cd4cc5671b..6c4e2809ad3 100644
@@ -92,6 +92,13 @@ bool target_hexagon(void);
  */
 bool target_or1k(void);
 
+/**
+ * target_loongarch:
+ *
+ * Returns whether the target architecture is LoongArch.
+ */
+bool target_loongarch(void);
+
 /**
  * target_base_ppc:
  *
target-info.c +5 -0
index e67d7bed520..b6d9cd8d97c 100644
@@ -84,6 +84,11 @@ bool target_or1k(void)
     return target_arch() == SYS_EMU_TARGET_OR1K;
 }
 
+bool target_loongarch(void)
+{
+    return target_arch() == SYS_EMU_TARGET_LOONGARCH64;
+}
+
 bool target_base_ppc(void)
 {
     switch (target_arch()) {
Signature · 1 line
2.55.0.windows.3
#3 lore raw

PATCH 2/12 hw/loongarch/virt: select virt machine types with is_available

In reply to Yonggang Luo

LoongArch virt machines use the same QOM names as virt machines on other targets. Register them only when the selected target is LoongArch, via target_loongarch().

---
 hw/loongarch/virt.c | 3 +++
 1 file changed, 3 insertions(+)
hw/loongarch/virt.c +3 -0
index 9c5371af9de..3f1b82f25ef 100644
@@ -11,6 +11,7 @@
 #include "qapi/error.h"
 #include "exec/target_page.h"
 #include "hw/core/boards.h"
+#include "qemu/target-info.h"
 #include "hw/char/serial-mm.h"
 #include "system/kvm.h"
 #include "system/tcg.h"
@@ -1553,6 +1554,7 @@ static void virt_class_init(ObjectClass *oc, const void *data)
         .name = MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \
         .parent = TYPE_LOONGARCH_VIRT_MACHINE, \
         .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \
+        .is_available = target_loongarch, \
     }; \
     static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \
     { \
@@ -1587,6 +1589,7 @@ static const TypeInfo virt_machine_info = {
     .class_init     = virt_class_init,
     .instance_init  = virt_initfn,
     .instance_finalize = virt_instance_finalize,
+    .is_available   = target_loongarch,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
         { }
Signature · 1 line
2.55.0.windows.3
Reviewed-by on v1 2/12
#4 lore raw

Re: [PATCH 02/12] hw/loongarch/virt: select virt machine types with is_available

Quoted 9 lines · Yonggang Luo

LoongArch virt machines use the same QOM names as virt machines on other targets. Register them only when the selected target is LoongArch, via target_loongarch().

---
 hw/loongarch/virt.c | 3 +++
 1 file changed, 3 insertions(+)
#5 lore raw

PATCH 3/12 target-info: add target_xtensa()

In reply to Yonggang Luo

Report whether the selected target architecture is Xtensa.

---
 include/qemu/target-info.h |  7 +++++++
 target-info.c              | 11 +++++++++++
 2 files changed, 18 insertions(+)
include/qemu/target-info.h +7 -0
index 6c4e2809ad3..1d6c6f4472c 100644
@@ -99,6 +99,13 @@ bool target_or1k(void);
  */
 bool target_loongarch(void);
 
+/**
+ * target_xtensa:
+ *
+ * Returns whether the target architecture is Xtensa.
+ */
+bool target_xtensa(void);
+
 /**
  * target_base_ppc:
  *
target-info.c +11 -0
index b6d9cd8d97c..07dc88fd366 100644
@@ -89,6 +89,17 @@ bool target_loongarch(void)
     return target_arch() == SYS_EMU_TARGET_LOONGARCH64;
 }
 
+bool target_xtensa(void)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return true;
+    default:
+        return false;
+    }
+}
+
 bool target_base_ppc(void)
 {
     switch (target_arch()) {
Signature · 1 line
2.55.0.windows.3
#7 lore raw

PATCH 4/12 hw/xtensa/virt: select virt machine types with is_available

In reply to Yonggang Luo

The Xtensa virt machine uses the QOM name virt-machine, which other targets register as well. Register it only when the selected target is Xtensa, via target_xtensa().

---
 hw/xtensa/virt.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
hw/xtensa/virt.c +20 -1
index 271f06e0953..2b30cb863d4 100644
@@ -29,6 +29,7 @@
 #include "qapi/error.h"
 #include "system/reset.h"
 #include "hw/core/boards.h"
+#include "qemu/target-info.h"
 #include "hw/core/loader.h"
 #include "hw/pci-host/gpex.h"
 #include "net/net.h"
@@ -124,4 +125,22 @@ static void xtensa_virt_machine_init(MachineClass *mc)
     mc->default_nic = "virtio-net-pci";
 }
 
-DEFINE_MACHINE("virt", xtensa_virt_machine_init)
+static void xtensa_virt_machine_class_init(ObjectClass *oc, const void *data)
+{
+    xtensa_virt_machine_init(MACHINE_CLASS(oc));
+}
+
+static const TypeInfo xtensa_virt_machine_info = {
+    .name = MACHINE_TYPE_NAME("virt"),
+    .parent = TYPE_MACHINE,
+    .class_init = xtensa_virt_machine_class_init,
+    .instance_size = sizeof(MachineState),
+    .is_available = target_xtensa,
+};
+
+static void xtensa_virt_machine_register_types(void)
+{
+    type_register_static(&xtensa_virt_machine_info);
+}
+
+type_init(xtensa_virt_machine_register_types)
Signature · 1 line
2.55.0.windows.3
Reviewed-by on v1 4/12
#8 lore raw

Re: [PATCH 04/12] hw/xtensa/virt: select virt machine types with is_available

Quoted 9 lines · Yonggang Luo

The Xtensa virt machine uses the QOM name virt-machine, which other targets register as well. Register it only when the selected target is Xtensa, via target_xtensa().

---
 hw/xtensa/virt.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
#9 lore raw

PATCH 5/12 target/arm: register separate max-v8 CPU types for arm and aarch64

In reply to Yonggang Luo

max-v8 was one TypeInfo whose instance initializer was chosen from the selected target at registration. Register both initializers, and let target_arm() and target_aarch64() select which type is available.

---
 target/arm/cpu.c            |  1 +
 target/arm/cpu.h            |  1 +
 target/arm/tcg/cpu-max-v8.c | 16 ++++++++++++----
 3 files changed, 14 insertions(+), 4 deletions(-)
target/arm/cpu.c +1 -0
index 510fc9eeb3b..6eb55242980 100644
@@ -2695,6 +2695,7 @@ void arm_cpu_register(const ARMCPUInfo *info)
         .instance_init = arm_cpu_instance_init,
         .class_init = info->class_init ?: cpu_register_class_init,
         .class_data = info,
+        .is_available = info->is_available,
     };
 
     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
target/arm/cpu.h +1 -0
index add993ef101..3240a8633ee 100644
@@ -1203,6 +1203,7 @@ typedef struct ARMCPUInfo {
     const char *deprecation_note;
     void (*initfn)(Object *obj);
     void (*class_init)(ObjectClass *oc, const void *data);
+    bool (*is_available)(void);
 } ARMCPUInfo;
 
 /**
target/arm/tcg/cpu-max-v8.c +12 -4
index 65f851f2006..e819d07e6ce 100644
@@ -121,10 +121,18 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8_aarch32 = {
+        .name = "max-v8",
+        .initfn = aarch32_max_v8_tcg_initfn,
+        .is_available = target_arm,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    static const ARMCPUInfo max_v8_aarch64 = {
+        .name = "max-v8",
+        .initfn = aarch64_max_v8_tcg_initfn,
+        .is_available = target_aarch64,
+    };
+
+    arm_cpu_register(&max_v8_aarch32);
+    arm_cpu_register(&max_v8_aarch64);
 }
 type_init(cpu_max_v8_register_type)
Signature · 1 line
2.55.0.windows.3
Reviewed-by on v1 5/12
#10 lore raw

Re: [PATCH 05/12] target/arm: register separate max-v8 CPU types for arm and aarch64

Quoted 11 lines · Yonggang Luo

max-v8 was one TypeInfo whose instance initializer was chosen from the selected target at registration. Register both initializers, and let target_arm() and target_aarch64() select which type is available.

---
 target/arm/cpu.c            |  1 +
 target/arm/cpu.h            |  1 +
 target/arm/tcg/cpu-max-v8.c | 16 ++++++++++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

Looks good to me, thanks for the update.

#11 lore raw

PATCH 6/12 target-info: add target_not_s390x()

In reply to Yonggang Luo

Add the negation of target_s390x() so an is_available callback can select every target except s390x.

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++
 2 files changed, 12 insertions(+)
include/qemu/target-info.h +7 -0
index 1d6c6f4472c..4bc25789d8d 100644
@@ -134,6 +134,13 @@ bool target_ppc64(void);
  */
 bool target_s390x(void);
 
+/**
+ * target_not_s390x:
+ *
+ * Returns whether the target architecture is not S390x.
+ */
+bool target_not_s390x(void);
+
 /**
  * target_base_riscv:
  *
target-info.c +5 -0
index 07dc88fd366..d9e15c939d6 100644
@@ -126,6 +126,11 @@ bool target_s390x(void)
     return target_arch() == SYS_EMU_TARGET_S390X;
 }
 
+bool target_not_s390x(void)
+{
+    return !target_s390x();
+}
+
 bool target_base_riscv(void)
 {
     switch (target_arch()) {
Signature · 1 line
2.55.0.windows.3
#12 lore raw

Re: [PATCH 06/12] target-info: add target_not_s390x()

Quoted 33 lines · Yonggang Luo

Add the negation of target_s390x() so an is_available callback can select every target except s390x.

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++
 2 files changed, 12 insertions(+)
include/qemu/target-info.h +7 -0
index 1d6c6f4472c..4bc25789d8d 100644
@@ -134,6 +134,13 @@ bool target_ppc64(void);
  */
 bool target_s390x(void);
 
+/**
+ * target_not_s390x:
+ *
+ * Returns whether the target architecture is not S390x.
+ */
+bool target_not_s390x(void);
+
 /**
  * target_base_riscv:
  *
target-info.c +0 -0
index 07dc88fd366..d9e15c939d6 100644
@@ -126,6 +126,11 @@ bool target_s390x(void)
     return target_arch() == SYS_EMU_TARGET_S390X;

target-info.c bool target_s390x(void) · line 136

Quoted 10 lines
target-info.c +5 -0
 }
 
+bool target_not_s390x(void)
+{
+    return !target_s390x();
+}
+
 bool target_base_riscv(void)
 {
     switch (target_arch()) {

Let's not introduce this globally.
Instead, we can define local functions where required.

Regards,
Pierrick

#13 lore raw

PATCH 7/12 hw/scsi/scsi-disk: register s390x scsi-hd and scsi-cd variants

In reply to Yonggang Luo

scsi-hd and scsi-cd added the s390x loadparm property from class_init when target_s390x() was true. Register a second type for each name that always adds loadparm, and select the two with target_s390x() and target_not_s390x().

---
 hw/scsi/scsi-disk.c | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)
hw/scsi/scsi-disk.c +33 -10
index 6341089ddf2..f981dc2c903 100644
@@ -3221,14 +3221,11 @@ static void scsi_property_add_specifics(DeviceClass *dc)
 {
     ObjectClass *oc = OBJECT_CLASS(dc);
 
-    /* The loadparm property is only supported on s390x */
-    if (target_s390x()) {
-        object_class_property_add_str(oc, "loadparm",
-                                      scsi_property_get_loadparm,
-                                      scsi_property_set_loadparm);
-        object_class_property_set_description(oc, "loadparm",
-                                              "load parameter (s390x only)");
-    }
+    object_class_property_add_str(oc, "loadparm",
+                                  scsi_property_get_loadparm,
+                                  scsi_property_set_loadparm);
+    object_class_property_set_description(oc, "loadparm",
+                                          "load parameter (s390x only)");
 }
 
 static void scsi_disk_base_class_initfn(ObjectClass *klass, const void *data)
@@ -3362,14 +3359,26 @@ static void scsi_hd_class_initfn(ObjectClass *klass, const void *data)
     dc->desc = "virtual SCSI disk";
     device_class_set_props(dc, scsi_hd_properties);
     dc->vmsd  = &vmstate_scsi_disk_state;
+}
 
-    scsi_property_add_specifics(dc);
+static void scsi_hd_s390x_class_initfn(ObjectClass *klass, const void *data)
+{
+    scsi_hd_class_initfn(klass, data);
+    scsi_property_add_specifics(DEVICE_CLASS(klass));
 }
 
 static const TypeInfo scsi_hd_info = {
     .name          = "scsi-hd",
     .parent        = TYPE_SCSI_DISK_BASE,
     .class_init    = scsi_hd_class_initfn,
+    .is_available  = target_not_s390x,
+};
+
+static const TypeInfo scsi_hd_s390x_info = {
+    .name          = "scsi-hd",
+    .parent        = TYPE_SCSI_DISK_BASE,
+    .class_init    = scsi_hd_s390x_class_initfn,
+    .is_available  = target_s390x,
 };
 
 static const Property scsi_cd_properties[] = {
@@ -3405,14 +3414,26 @@ static void scsi_cd_class_initfn(ObjectClass *klass, const void *data)
     dc->desc = "virtual SCSI CD-ROM";
     device_class_set_props(dc, scsi_cd_properties);
     dc->vmsd  = &vmstate_scsi_disk_state;
+}
 
-    scsi_property_add_specifics(dc);
+static void scsi_cd_s390x_class_initfn(ObjectClass *klass, const void *data)
+{
+    scsi_cd_class_initfn(klass, data);
+    scsi_property_add_specifics(DEVICE_CLASS(klass));
 }
 
 static const TypeInfo scsi_cd_info = {
     .name          = "scsi-cd",
     .parent        = TYPE_SCSI_DISK_BASE,
     .class_init    = scsi_cd_class_initfn,
+    .is_available  = target_not_s390x,
+};
+
+static const TypeInfo scsi_cd_s390x_info = {
+    .name          = "scsi-cd",
+    .parent        = TYPE_SCSI_DISK_BASE,
+    .class_init    = scsi_cd_s390x_class_initfn,
+    .is_available  = target_s390x,
 };
 
 #ifdef __linux__
@@ -3462,7 +3483,9 @@ static void scsi_disk_register_types(void)
 {
     type_register_static(&scsi_disk_base_info);
     type_register_static(&scsi_hd_info);
+    type_register_static(&scsi_hd_s390x_info);
     type_register_static(&scsi_cd_info);
+    type_register_static(&scsi_cd_s390x_info);
 #ifdef __linux__
     type_register_static(&scsi_block_info);
 #endif
Signature · 1 line
2.55.0.windows.3
#14 lore raw

Re: [PATCH 07/12] hw/scsi/scsi-disk: register s390x scsi-hd and scsi-cd variants

Quoted 10 lines · Yonggang Luo

scsi-hd and scsi-cd added the s390x loadparm property from class_init when target_s390x() was true. Register a second type for each name that always adds loadparm, and select the two with target_s390x() and target_not_s390x().

---
 hw/scsi/scsi-disk.c | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

Looks good to me overall, let's just keep the !s390 as a local callback here.

Regards,
Pierrick

#15 lore raw

PATCH 8/12 hw/virtio/virtio-pci: pass is_available through VirtioPCIDeviceTypeInfo

In reply to Yonggang Luo

virtio_pci_types_register() builds the base, generic, transitional and non-transitional TypeInfos for one virtio-pci device. Copy an is_available callback onto each of them so a device can register target-specific variants of the same names.

---
 hw/virtio/virtio-pci.c         | 4 ++++
 include/hw/virtio/virtio-pci.h | 1 +
 2 files changed, 5 insertions(+)
hw/virtio/virtio-pci.c +4 -0
index c73f1f546cb..1ce39e92e9d 100644
@@ -2522,11 +2522,13 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)
         .class_size    = t->class_size,
         .abstract      = true,
         .interfaces    = t->interfaces,
+        .is_available  = t->is_available,
     };
     TypeInfo generic_type_info = {
         .name = t->generic_name,
         .parent = base_type_info.name,
         .class_init = virtio_pci_generic_class_init,
+        .is_available = t->is_available,
         .interfaces = (const InterfaceInfo[]) {
             { INTERFACE_PCIE_DEVICE },
             { INTERFACE_CONVENTIONAL_PCI_DEVICE },
@@ -2562,6 +2564,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)
             .name          = t->non_transitional_name,
             .parent        = base_type_info.name,
             .instance_init = virtio_pci_non_transitional_instance_init,
+            .is_available  = t->is_available,
             .interfaces = (const InterfaceInfo[]) {
                 { INTERFACE_PCIE_DEVICE },
                 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
@@ -2576,6 +2579,7 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)
             .name          = t->transitional_name,
             .parent        = base_type_info.name,
             .instance_init = virtio_pci_transitional_instance_init,
+            .is_available  = t->is_available,
             .interfaces = (const InterfaceInfo[]) {
                 /*
                  * Transitional virtio devices work only as Conventional PCI
include/hw/virtio/virtio-pci.h +1 -0
index ee50fb0d551..6c3561d319a 100644
@@ -236,6 +236,7 @@ typedef struct VirtioPCIDeviceTypeInfo {
     void (*instance_init)(Object *obj);
     void (*instance_finalize)(Object *obj);
     void (*class_init)(ObjectClass *klass, const void *data);
+    bool (*is_available)(void);
     const InterfaceInfo *interfaces;
 } VirtioPCIDeviceTypeInfo;
 
Signature · 1 line
2.55.0.windows.3
#16 lore raw

Re: [PATCH 08/12] hw/virtio/virtio-pci: pass is_available through VirtioPCIDeviceTypeInfo

Quoted 11 lines · Yonggang Luo

virtio_pci_types_register() builds the base, generic, transitional and non-transitional TypeInfos for one virtio-pci device. Copy an is_available callback onto each of them so a device can register target-specific variants of the same names.

---
 hw/virtio/virtio-pci.c         | 4 ++++
 include/hw/virtio/virtio-pci.h | 1 +
 2 files changed, 5 insertions(+)

Fine for me, let's see what virtio maintainers think about it.

Regards,
Pierrick

#17 lore raw

PATCH 9/12 hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants

In reply to Yonggang Luo

virtio-blk-pci and virtio-net-pci added the s390x loadparm property from class_init when target_s390x() was true. Register each VirtioPCIDeviceTypeInfo twice. The s390x variant calls pci_qdev_property_add_specifics(), which now always adds loadparm, and the other variant does not. target_s390x() and target_not_s390x() select the two.

---
 hw/pci/pci.c               | 13 +++++--------
 hw/virtio/virtio-blk-pci.c | 22 +++++++++++++++++++++-
 hw/virtio/virtio-net-pci.c | 22 +++++++++++++++++++++-
 3 files changed, 47 insertions(+), 10 deletions(-)
hw/pci/pci.c +5 -8
index 0efb4eb4bb0..e1bd3bb0e29 100644
@@ -2895,14 +2895,11 @@ void pci_qdev_property_add_specifics(DeviceClass *dc)
 {
     ObjectClass *oc = OBJECT_CLASS(dc);
 
-    /* The loadparm property is only supported on s390x */
-    if (target_s390x()) {
-        object_class_property_add_str(oc, "loadparm",
-                                      pci_qdev_property_get_loadparm,
-                                      pci_qdev_property_set_loadparm);
-        object_class_property_set_description(oc, "loadparm",
-                                              "load parameter (s390x only)");
-    }
+    object_class_property_add_str(oc, "loadparm",
+                                  pci_qdev_property_get_loadparm,
+                                  pci_qdev_property_set_loadparm);
+    object_class_property_set_description(oc, "loadparm",
+                                          "load parameter (s390x only)");
 }
 
 MemoryRegion *pci_address_space(PCIDevice *dev)
hw/virtio/virtio-blk-pci.c +21 -1
index 3eecc23a657..f4f86f7b428 100644
@@ -22,6 +22,7 @@
 #include "hw/virtio/virtio-pci.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/target-info.h"
 #include "qom/object.h"
 
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
@@ -71,7 +72,6 @@ static void virtio_blk_pci_class_init(ObjectClass *klass, const void *data)
 
     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
     device_class_set_props(dc, virtio_blk_pci_properties);
-    pci_qdev_property_add_specifics(dc);
     k->realize = virtio_blk_pci_realize;
     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
@@ -89,6 +89,13 @@ static void virtio_blk_pci_instance_init(Object *obj)
                               "bootindex");
 }
 
+static void virtio_blk_pci_s390x_class_init(ObjectClass *klass,
+                                            const void *data)
+{
+    virtio_blk_pci_class_init(klass, data);
+    pci_qdev_property_add_specifics(DEVICE_CLASS(klass));
+}
+
 static const VirtioPCIDeviceTypeInfo virtio_blk_pci_info = {
     .base_name              = TYPE_VIRTIO_BLK_PCI,
     .generic_name           = "virtio-blk-pci",
@@ -97,11 +104,24 @@ static const VirtioPCIDeviceTypeInfo virtio_blk_pci_info = {
     .instance_size = sizeof(VirtIOBlkPCI),
     .instance_init = virtio_blk_pci_instance_init,
     .class_init    = virtio_blk_pci_class_init,
+    .is_available  = target_not_s390x,
+};
+
+static const VirtioPCIDeviceTypeInfo virtio_blk_pci_s390x_info = {
+    .base_name              = TYPE_VIRTIO_BLK_PCI,
+    .generic_name           = "virtio-blk-pci",
+    .transitional_name      = "virtio-blk-pci-transitional",
+    .non_transitional_name  = "virtio-blk-pci-non-transitional",
+    .instance_size = sizeof(VirtIOBlkPCI),
+    .instance_init = virtio_blk_pci_instance_init,
+    .class_init    = virtio_blk_pci_s390x_class_init,
+    .is_available  = target_s390x,
 };
 
 static void virtio_blk_pci_register(void)
 {
     virtio_pci_types_register(&virtio_blk_pci_info);
+    virtio_pci_types_register(&virtio_blk_pci_s390x_info);
 }
 
 type_init(virtio_blk_pci_register)
hw/virtio/virtio-net-pci.c +21 -1
index 893d1905a97..d7aaf255507 100644
@@ -22,6 +22,7 @@
 #include "hw/virtio/virtio-pci.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/target-info.h"
 #include "qom/object.h"
 
 typedef struct VirtIONetPCI VirtIONetPCI;
@@ -77,7 +78,6 @@ static void virtio_net_pci_class_init(ObjectClass *klass, const void *data)
     k->sriov_vf_user_creatable = true;
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
     device_class_set_props(dc, virtio_net_properties);
-    pci_qdev_property_add_specifics(dc);
     vpciklass->realize = virtio_net_pci_realize;
 }
 
@@ -91,6 +91,13 @@ static void virtio_net_pci_instance_init(Object *obj)
                               "bootindex");
 }
 
+static void virtio_net_pci_s390x_class_init(ObjectClass *klass,
+                                            const void *data)
+{
+    virtio_net_pci_class_init(klass, data);
+    pci_qdev_property_add_specifics(DEVICE_CLASS(klass));
+}
+
 static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = {
     .base_name             = TYPE_VIRTIO_NET_PCI,
     .generic_name          = "virtio-net-pci",
@@ -99,11 +106,24 @@ static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = {
     .instance_size = sizeof(VirtIONetPCI),
     .instance_init = virtio_net_pci_instance_init,
     .class_init    = virtio_net_pci_class_init,
+    .is_available  = target_not_s390x,
+};
+
+static const VirtioPCIDeviceTypeInfo virtio_net_pci_s390x_info = {
+    .base_name             = TYPE_VIRTIO_NET_PCI,
+    .generic_name          = "virtio-net-pci",
+    .transitional_name     = "virtio-net-pci-transitional",
+    .non_transitional_name = "virtio-net-pci-non-transitional",
+    .instance_size = sizeof(VirtIONetPCI),
+    .instance_init = virtio_net_pci_instance_init,
+    .class_init    = virtio_net_pci_s390x_class_init,
+    .is_available  = target_s390x,
 };
 
 static void virtio_net_pci_register(void)
 {
     virtio_pci_types_register(&virtio_net_pci_info);
+    virtio_pci_types_register(&virtio_net_pci_s390x_info);
 }
 
 type_init(virtio_net_pci_register)
Signature · 1 line
2.55.0.windows.3
#18 lore raw

Re: [PATCH 09/12] hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants

Quoted 7 lines · Yonggang Luo

virtio-blk-pci and virtio-net-pci added the s390x loadparm property from class_init when target_s390x() was true. Register each VirtioPCIDeviceTypeInfo twice. The s390x variant calls pci_qdev_property_add_specifics(), which now always adds loadparm, and the other variant does not. target_s390x() and target_not_s390x() select the two.

Quoted 7 lines
---
 hw/pci/pci.c               | 13 +++++--------
 hw/virtio/virtio-blk-pci.c | 22 +++++++++++++++++++++-
 hw/virtio/virtio-net-pci.c | 22 +++++++++++++++++++++-
 3 files changed, 47 insertions(+), 10 deletions(-)

Fine for me, let's see what virtio maintainers think about it.

Regards,
Pierrick

#19 lore raw

Re: [PATCH 09/12] hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants

Quoted 17 lines · Pierrick Bouvier
Quoted 5 lines · Yonggang Luo

virtio-blk-pci and virtio-net-pci added the s390x loadparm property from class_init when target_s390x() was true. Register each VirtioPCIDeviceTypeInfo twice. The s390x variant calls pci_qdev_property_add_specifics(), which now always adds loadparm, and the other variant does not. target_s390x() and target_not_s390x()

select

Quoted 9 lines

the two.

---
 hw/pci/pci.c               | 13 +++++--------
 hw/virtio/virtio-blk-pci.c | 22 +++++++++++++++++++++-
 hw/virtio/virtio-net-pci.c | 22 +++++++++++++++++++++-
 3 files changed, 47 insertions(+), 10 deletions(-)
Quoted 1 line

target_not_s390x will be duplicated at many place, is that fine?

Fine for me, let's see what virtio maintainers think about it.

Quoted 4 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#20 lore raw

Re: [PATCH 09/12] hw/virtio: register s390x virtio-blk-pci and virtio-net-pci variants

Quoted 24 lines · Yonggang Luo

On Thursday, October 29, 2026, Pierrick Bouvier <[email protected] <mailto:[email protected]>> wrote:

    On 10/28/2026 12:15 PM, Yonggang Luo wrote:
    > virtio-blk-pci and virtio-net-pci added the s390x loadparm property
    > from class_init when target_s390x() was true. Register each
    > VirtioPCIDeviceTypeInfo twice. The s390x variant calls
    > pci_qdev_property_add_specifics(), which now always adds loadparm,
    > and the other variant does not. target_s390x() and
    target_not_s390x() select
    > the two.
    >
    > Signed-off-by: Yonggang Luo <[email protected]
    <mailto:[email protected]>>
    > ---
    >  hw/pci/pci.c               | 13 +++++--------
    >  hw/virtio/virtio-blk-pci.c | 22 +++++++++++++++++++++-
    >  hw/virtio/virtio-net-pci.c | 22 +++++++++++++++++++++-
    >  3 files changed, 47 insertions(+), 10 deletions(-)
    >
Quoted 2 lines

target_not_s390x will be duplicated at many place, is that fine?

Good for me.

Quoted 16 lines

Fine for me, let's see what virtio maintainers think about it.

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#21 lore raw

PATCH 10/12 target-info: add target_base_i386() and target_not_base_i386()

In reply to Yonggang Luo

target_base_arm(), target_base_ppc() and target_base_riscv() report whether the selected target belongs to a CPU family. Add the same predicate for i386 and x86_64, and target_not_base_i386() as its negation.

---
 include/qemu/target-info.h | 14 ++++++++++++++
 target-info.c              | 16 ++++++++++++++++
 2 files changed, 30 insertions(+)
include/qemu/target-info.h +14 -0
index 4bc25789d8d..48206d01ba9 100644
@@ -57,6 +57,20 @@ bool target_heterogeneous(void);
  */
 bool target_base_arm(void);
 
+/**
+ * target_base_i386:
+ *
+ * Returns whether the target architecture is i386 or x86_64.
+ */
+bool target_base_i386(void);
+
+/**
+ * target_not_base_i386:
+ *
+ * Returns whether the target architecture is not i386 or x86_64.
+ */
+bool target_not_base_i386(void);
+
 /**
  * target_arm:
  *
target-info.c +16 -0
index d9e15c939d6..32ba85691b7 100644
@@ -59,6 +59,22 @@ bool target_base_arm(void)
     }
 }
 
+bool target_base_i386(void)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return true;
+    default:
+        return false;
+    }
+}
+
+bool target_not_base_i386(void)
+{
+    return !target_base_i386();
+}
+
 bool target_arm(void)
 {
     return target_arch() == SYS_EMU_TARGET_ARM;
Signature · 1 line
2.55.0.windows.3
#22 lore raw

Re: [PATCH 10/12] target-info: add target_base_i386() and target_not_base_i386()

Quoted 52 lines · Yonggang Luo

target_base_arm(), target_base_ppc() and target_base_riscv() report whether the selected target belongs to a CPU family. Add the same predicate for i386 and x86_64, and target_not_base_i386() as its negation.

---
 include/qemu/target-info.h | 14 ++++++++++++++
 target-info.c              | 16 ++++++++++++++++
 2 files changed, 30 insertions(+)
include/qemu/target-info.h +14 -0
index 4bc25789d8d..48206d01ba9 100644
@@ -57,6 +57,20 @@ bool target_heterogeneous(void);
  */
 bool target_base_arm(void);
 
+/**
+ * target_base_i386:
+ *
+ * Returns whether the target architecture is i386 or x86_64.
+ */
+bool target_base_i386(void);
+
+/**
+ * target_not_base_i386:
+ *
+ * Returns whether the target architecture is not i386 or x86_64.
+ */
+bool target_not_base_i386(void);
+
 /**
  * target_arm:
  *
target-info.c +9 -0
index d9e15c939d6..32ba85691b7 100644
@@ -59,6 +59,22 @@ bool target_base_arm(void)
     }
 }
 
+bool target_base_i386(void)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return true;
+    default:
+        return false;
+    }

target-info.c bool target_base_arm(void) · line 80

Quoted 10 lines
target-info.c +7 -0
+}
+
+bool target_not_base_i386(void)
+{
+    return !target_base_i386();
+}
+
 bool target_arm(void)
 {
     return target_arch() == SYS_EMU_TARGET_ARM;

Same comment than for target_not_s390x, keep it local where needed.

#23 lore raw

PATCH 11/12 hw/virtio/virtio-mem: register legacy-guest variant with is_available

In reply to Yonggang Luo

virtio-mem decided in class_init and realize whether x86 guests can leave unplugged memory accessible. Register a second virtio-mem type that adds virtio_mem_legacy_guests_properties and sets VirtIOMEMClass.has_legacy_guests. Select the two with target_base_i386() and target_not_base_i386().

---
 hw/virtio/virtio-mem.c         | 47 +++++++++++++++++++---------------
 include/hw/virtio/virtio-mem.h |  2 ++
 2 files changed, 29 insertions(+), 20 deletions(-)
hw/virtio/virtio-mem.c +27 -20
index 7130ed852d9..bf241a3112b 100644
@@ -15,6 +15,7 @@
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "qemu/target-info.h"
 #include "qemu/target-info-qapi.h"
 #include "system/memory.h"
 #include "system/numa.h"
@@ -35,22 +36,6 @@
 
 static const VMStateDescription vmstate_virtio_mem_device_early;
 
-static bool virtio_mem_has_legacy_guests(void)
-{
-    /*
-     * We only had legacy x86 guests that did not support
-     * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have
-     * legacy guests.
-     */
-    switch (target_arch()) {
-    case SYS_EMU_TARGET_I386:
-    case SYS_EMU_TARGET_X86_64:
-        return true;
-    default:
-        return false;
-    }
-}
-
 /*
  * Let's not allow blocks smaller than 1 MiB, for example, to keep the tracking
  * bitmap small.
@@ -859,7 +844,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
     rb = vmem->memdev->mr.ram_block;
     page_size = qemu_ram_pagesize(rb);
 
-    if (virtio_mem_has_legacy_guests()) {
+    if (VIRTIO_MEM_GET_CLASS(vmem)->has_legacy_guests) {
         switch (vmem->unplugged_inaccessible) {
         case ON_OFF_AUTO_AUTO:
             if (virtio_mem_has_shared_zeropage(rb)) {
@@ -1635,9 +1620,6 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     RamDiscardSourceClass *rdsc = RAM_DISCARD_SOURCE_CLASS(klass);
 
     device_class_set_props(dc, virtio_mem_properties);
-    if (virtio_mem_has_legacy_guests()) {
-        device_class_set_props(dc, virtio_mem_legacy_guests_properties);
-    }
     dc->vmsd = &vmstate_virtio_mem;
 
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1660,6 +1642,14 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     rdsc->is_populated = virtio_mem_rds_is_populated;
 }
 
+static void virtio_mem_legacy_class_init(ObjectClass *klass, const void *data)
+{
+    virtio_mem_class_init(klass, data);
+    device_class_set_props(DEVICE_CLASS(klass),
+                           virtio_mem_legacy_guests_properties);
+    VIRTIO_MEM_CLASS(klass)->has_legacy_guests = true;
+}
+
 static const TypeInfo virtio_mem_info = {
     .name = TYPE_VIRTIO_MEM,
     .parent = TYPE_VIRTIO_DEVICE,
@@ -1668,6 +1658,22 @@ static const TypeInfo virtio_mem_info = {
     .instance_finalize = virtio_mem_instance_finalize,
     .class_init = virtio_mem_class_init,
     .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_not_base_i386,
+    .interfaces = (const InterfaceInfo[]) {
+        { TYPE_RAM_DISCARD_SOURCE },
+        { }
+    },
+};
+
+static const TypeInfo virtio_mem_legacy_info = {
+    .name = TYPE_VIRTIO_MEM,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOMEM),
+    .instance_init = virtio_mem_instance_init,
+    .instance_finalize = virtio_mem_instance_finalize,
+    .class_init = virtio_mem_legacy_class_init,
+    .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_base_i386,
     .interfaces = (const InterfaceInfo[]) {
         { TYPE_RAM_DISCARD_SOURCE },
         { }
@@ -1677,6 +1683,7 @@ static const TypeInfo virtio_mem_info = {
 static void virtio_register_types(void)
 {
     type_register_static(&virtio_mem_info);
+    type_register_static(&virtio_mem_legacy_info);
 }
 
 type_init(virtio_register_types)
include/hw/virtio/virtio-mem.h +2 -0
index 5d1d19c6bec..f367959ecb0 100644
@@ -134,6 +134,8 @@ struct VirtIOMEMClass {
     VirtioDeviceClass parent_class;
 
     /* public */
+    bool has_legacy_guests;
+
     void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
     MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
     void (*decide_memslots)(VirtIOMEM *vmem, unsigned int limit);
Signature · 1 line
2.55.0.windows.3
#24 lore raw

Re: [PATCH 11/12] hw/virtio/virtio-mem: register legacy-guest variant with is_available

Quoted 117 lines · Yonggang Luo

virtio-mem decided in class_init and realize whether x86 guests can leave unplugged memory accessible. Register a second virtio-mem type that adds virtio_mem_legacy_guests_properties and sets VirtIOMEMClass.has_legacy_guests. Select the two with target_base_i386() and target_not_base_i386().

---
 hw/virtio/virtio-mem.c         | 47 +++++++++++++++++++---------------
 include/hw/virtio/virtio-mem.h |  2 ++
 2 files changed, 29 insertions(+), 20 deletions(-)
hw/virtio/virtio-mem.c +27 -20
index 7130ed852d9..bf241a3112b 100644
@@ -15,6 +15,7 @@
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "qemu/target-info.h"
 #include "qemu/target-info-qapi.h"
 #include "system/memory.h"
 #include "system/numa.h"
@@ -35,22 +36,6 @@
 
 static const VMStateDescription vmstate_virtio_mem_device_early;
 
-static bool virtio_mem_has_legacy_guests(void)
-{
-    /*
-     * We only had legacy x86 guests that did not support
-     * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have
-     * legacy guests.
-     */
-    switch (target_arch()) {
-    case SYS_EMU_TARGET_I386:
-    case SYS_EMU_TARGET_X86_64:
-        return true;
-    default:
-        return false;
-    }
-}
-
 /*
  * Let's not allow blocks smaller than 1 MiB, for example, to keep the tracking
  * bitmap small.
@@ -859,7 +844,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
     rb = vmem->memdev->mr.ram_block;
     page_size = qemu_ram_pagesize(rb);
 
-    if (virtio_mem_has_legacy_guests()) {
+    if (VIRTIO_MEM_GET_CLASS(vmem)->has_legacy_guests) {
         switch (vmem->unplugged_inaccessible) {
         case ON_OFF_AUTO_AUTO:
             if (virtio_mem_has_shared_zeropage(rb)) {
@@ -1635,9 +1620,6 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     RamDiscardSourceClass *rdsc = RAM_DISCARD_SOURCE_CLASS(klass);
 
     device_class_set_props(dc, virtio_mem_properties);
-    if (virtio_mem_has_legacy_guests()) {
-        device_class_set_props(dc, virtio_mem_legacy_guests_properties);
-    }
     dc->vmsd = &vmstate_virtio_mem;
 
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1660,6 +1642,14 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     rdsc->is_populated = virtio_mem_rds_is_populated;
 }
 
+static void virtio_mem_legacy_class_init(ObjectClass *klass, const void *data)
+{
+    virtio_mem_class_init(klass, data);
+    device_class_set_props(DEVICE_CLASS(klass),
+                           virtio_mem_legacy_guests_properties);
+    VIRTIO_MEM_CLASS(klass)->has_legacy_guests = true;
+}
+
 static const TypeInfo virtio_mem_info = {
     .name = TYPE_VIRTIO_MEM,
     .parent = TYPE_VIRTIO_DEVICE,
@@ -1668,6 +1658,22 @@ static const TypeInfo virtio_mem_info = {
     .instance_finalize = virtio_mem_instance_finalize,
     .class_init = virtio_mem_class_init,
     .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_not_base_i386,
+    .interfaces = (const InterfaceInfo[]) {
+        { TYPE_RAM_DISCARD_SOURCE },
+        { }
+    },
+};
+
+static const TypeInfo virtio_mem_legacy_info = {
+    .name = TYPE_VIRTIO_MEM,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOMEM),
+    .instance_init = virtio_mem_instance_init,
+    .instance_finalize = virtio_mem_instance_finalize,
+    .class_init = virtio_mem_legacy_class_init,
+    .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_base_i386,
     .interfaces = (const InterfaceInfo[]) {
         { TYPE_RAM_DISCARD_SOURCE },
         { }
@@ -1677,6 +1683,7 @@ static const TypeInfo virtio_mem_info = {
 static void virtio_register_types(void)
 {
     type_register_static(&virtio_mem_info);
+    type_register_static(&virtio_mem_legacy_info);
 }
 
 type_init(virtio_register_types)
include/hw/virtio/virtio-mem.h +0 -0
index 5d1d19c6bec..f367959ecb0 100644

include/hw/virtio/virtio-mem.h struct VirtIOMEMClass { · line 141

Quoted 8 lines
include/hw/virtio/virtio-mem.h +2 -0
@@ -134,6 +134,8 @@ struct VirtIOMEMClass {
     VirtioDeviceClass parent_class;
 
     /* public */
+    bool has_legacy_guests;
+
     void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
     MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
     void (*decide_memslots)(VirtIOMEM *vmem, unsigned int limit);

Fine for me, let's see what virtio maintainers think about it.

Regards,
Pierrick

#25 lore raw

Re: [PATCH 11/12] hw/virtio/virtio-mem: register legacy-guest variant with is_available

Quoted 121 lines · Pierrick Bouvier
Quoted 119 lines · Yonggang Luo

virtio-mem decided in class_init and realize whether x86 guests can leave unplugged memory accessible. Register a second virtio-mem type that adds virtio_mem_legacy_guests_properties and sets VirtIOMEMClass.has_legacy_guests. Select the two with target_base_i386() and target_not_base_i386().

---
 hw/virtio/virtio-mem.c         | 47 +++++++++++++++++++---------------
 include/hw/virtio/virtio-mem.h |  2 ++
 2 files changed, 29 insertions(+), 20 deletions(-)
hw/virtio/virtio-mem.c +27 -20
index 7130ed852d9..bf241a3112b 100644
@@ -15,6 +15,7 @@
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "qemu/target-info.h"
 #include "qemu/target-info-qapi.h"
 #include "system/memory.h"
 #include "system/numa.h"
@@ -35,22 +36,6 @@
 
 static const VMStateDescription vmstate_virtio_mem_device_early;
 
-static bool virtio_mem_has_legacy_guests(void)
-{
-    /*
-     * We only had legacy x86 guests that did not support
-     * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have
-     * legacy guests.
-     */
-    switch (target_arch()) {
-    case SYS_EMU_TARGET_I386:
-    case SYS_EMU_TARGET_X86_64:
-        return true;
-    default:
-        return false;
-    }
-}
-
 /*
  * Let's not allow blocks smaller than 1 MiB, for example, to keep the tracking
  * bitmap small.
@@ -859,7 +844,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
     rb = vmem->memdev->mr.ram_block;
     page_size = qemu_ram_pagesize(rb);
 
-    if (virtio_mem_has_legacy_guests()) {
+    if (VIRTIO_MEM_GET_CLASS(vmem)->has_legacy_guests) {
         switch (vmem->unplugged_inaccessible) {
         case ON_OFF_AUTO_AUTO:
             if (virtio_mem_has_shared_zeropage(rb)) {
@@ -1635,9 +1620,6 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     RamDiscardSourceClass *rdsc = RAM_DISCARD_SOURCE_CLASS(klass);
 
     device_class_set_props(dc, virtio_mem_properties);
-    if (virtio_mem_has_legacy_guests()) {
-        device_class_set_props(dc, virtio_mem_legacy_guests_properties);
-    }
     dc->vmsd = &vmstate_virtio_mem;
 
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1660,6 +1642,14 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
     rdsc->is_populated = virtio_mem_rds_is_populated;
 }
 
+static void virtio_mem_legacy_class_init(ObjectClass *klass, const void *data)
+{
+    virtio_mem_class_init(klass, data);
+    device_class_set_props(DEVICE_CLASS(klass),
+                           virtio_mem_legacy_guests_properties);
+    VIRTIO_MEM_CLASS(klass)->has_legacy_guests = true;
+}
+
 static const TypeInfo virtio_mem_info = {
     .name = TYPE_VIRTIO_MEM,
     .parent = TYPE_VIRTIO_DEVICE,
@@ -1668,6 +1658,22 @@ static const TypeInfo virtio_mem_info = {
     .instance_finalize = virtio_mem_instance_finalize,
     .class_init = virtio_mem_class_init,
     .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_not_base_i386,
+    .interfaces = (const InterfaceInfo[]) {
+        { TYPE_RAM_DISCARD_SOURCE },
+        { }
+    },
+};
+
+static const TypeInfo virtio_mem_legacy_info = {
+    .name = TYPE_VIRTIO_MEM,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOMEM),
+    .instance_init = virtio_mem_instance_init,
+    .instance_finalize = virtio_mem_instance_finalize,
+    .class_init = virtio_mem_legacy_class_init,
+    .class_size = sizeof(VirtIOMEMClass),
+    .is_available = target_base_i386,
     .interfaces = (const InterfaceInfo[]) {
         { TYPE_RAM_DISCARD_SOURCE },
         { }
@@ -1677,6 +1683,7 @@ static const TypeInfo virtio_mem_info = {
 static void virtio_register_types(void)
 {
     type_register_static(&virtio_mem_info);
+    type_register_static(&virtio_mem_legacy_info);
 }
 
 type_init(virtio_register_types)
include/hw/virtio/virtio-mem.h +0 -0
index 5d1d19c6bec..f367959ecb0 100644
@@ -134,6 +134,8 @@ struct VirtIOMEMClass {
     VirtioDeviceClass parent_class;
 
Quoted 8 lines

include/hw/virtio/virtio-mem.h struct VirtIOMEMClass { · line 141

Quoted 6 lines
include/hw/virtio/virtio-mem.h +2 -0
     /* public */
+    bool has_legacy_guests;
+
     void (*fill_device_info)(const VirtIOMEM *vmen, VirtioMEMDeviceInfo *vi);
     MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp);
     void (*decide_memslots)(VirtIOMEM *vmem, unsigned int limit);

Fine for me, let's see what virtio maintainers think about it.

Ping it, also the V2 version is ready, may I send it now?

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#26 lore raw

PATCH 12/12 hw/microblaze: defer PetaLogix endianness default until init

In reply to Yonggang Luo

The PetaLogix machine read its endianness default from target_big_endian() in class_init. In a multi-target binary the target is not selected yet at class_init, so the default cannot be computed there. Set the property default to "unspecified" instead, and resolve it to big or little in petalogix_s3adsp1800_init(), where the target is known.

Until the machine is initialized, endianness reads back as "unspecified" rather than big or little.

---
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
hw/microblaze/petalogix_s3adsp1800_mmu.c +8 -3
index c5f64319009..4abb6e0f0bf 100644
@@ -83,7 +83,13 @@ petalogix_s3adsp1800_init(MachineState *machine)
     MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
     qemu_irq irq[32];
     MemoryRegion *sysmem = get_system_memory();
-    EndianMode endianness = psms->endianness;
+    EndianMode endianness;
+
+    if (psms->endianness == ENDIAN_MODE_UNSPECIFIED) {
+        psms->endianness = target_big_endian() ? ENDIAN_MODE_BIG :
+                                                 ENDIAN_MODE_LITTLE;
+    }
+    endianness = psms->endianness;
 
     cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
     object_property_set_str(OBJECT(cpu), "version", "7.10.d", &error_abort);
@@ -178,8 +184,7 @@ static void petalogix_s3adsp1800_machine_class_init(ObjectClass *oc,
                                           &EndianMode_lookup,
                                           machine_get_endianness,
                                           machine_set_endianness);
-    object_property_set_default_str(prop, target_big_endian() ? "big"
-                                                              : "little");
+    object_property_set_default_str(prop, "unspecified");
     object_class_property_set_description(oc, "endianness",
             "Defines whether the machine runs in big or little endian mode");
 }
Signature · 1 line
2.55.0.windows.3
Reviewed-by on v1 12/12
#27 lore raw

Re: [PATCH 12/12] hw/microblaze: defer PetaLogix endianness default until init

Quoted 7 lines · Yonggang Luo

The PetaLogix machine read its endianness default from target_big_endian() in class_init. In a multi-target binary the target is not selected yet at class_init, so the default cannot be computed there. Set the property default to "unspecified" instead, and resolve it to big or little in petalogix_s3adsp1800_init(), where the target is known.

Quoted 8 lines

Until the machine is initialized, endianness reads back as "unspecified" rather than big or little.

---
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)