machine: uniquify virt QOM names
v4 cover machine: uniquify virt QOM names
Multiple targets register a virt board as MACHINE_TYPE_NAME("virt"). Those QOM types collide if more than one board is linked into one qemu-system process. This series splits the QOM type from the -M name so each virt board can keep a unique type while -M virt, help, and migration stay the same.
- Add machine_class_set_name() so boards can set MachineClass::name when it must differ from the QOM type. machine_class_base_init still defaults the name to the QOM type without -machine. Document that MachineClass::name is the -M name, not the QOM type. Sort -M help by that name so order matches the printed names after types are prefixed (arm-virt-11.1-machine vs virt-11.1).
- When target_heterogeneous() is true, give each colliding virt board a unique QOM type and keep the existing -M name via machine_class_set_name(): riscv-virt, arm-virt, or1k-virt, hexagon-virt, loongarch-virt, m68k-virt, and xtensa-virt. Otherwise keep virt. Versioned ARM, LoongArch, and M68K boards keep virt-<ver>. Latest ARM virt still sets mc->alias to virt.
This is for the review from Daniel:
- query-machines returns MachineInfo typename, the QOM type from object_class_get_name(), for qom-list-properties. The -M name alone is not that type once virt boards are prefixed.
- Use target_heterogeneous() from the base. It still returns false, so qemu-system-<target> keeps the QOM type virt.
Changes v3 -> v4:
Rebased onto d73149283205645625bfa9fe029cfb68e4c4a9ae, which already includes target-info: add target_heterogeneous. The boards.h example uses arm-virt only when that returns true.
Changes v2 -> v3:
The versioned-machine example in boards.h now follows hw/arm/virt.c. machine_class_set_name() keeps the -M name as virt-<version>, the QOM type in the example is arm-virt, and the latest helper is DEFINE_VIRT_MACHINE_AS_LATEST.
Changes v1 -> v2:
- query-machines returns MachineInfo typename. v1 returned only the -M name, so a client that appended "-machine" looked up the wrong type for a prefixed board such as arm-virt-11.1-machine versus -M virt-11.1.
Yonggang Luo (17):
hw/riscv/virt: move virt TypeInfo into its type_init hw/arm/virt: move virt TypeInfo into its type_init hw/or1k/virt: move virt TypeInfo into its type_init hw/hexagon/virt: move virt TypeInfo into its type_init hw/loongarch/virt: move virt TypeInfo into its type_init hw/m68k/virt: move virt TypeInfo into its type_init hw/xtensa/virt: move virt TypeInfo into its type_init
machine: allow -M name to differ from QOM type hw/riscv/virt: use unique QOM name
hw/arm/virt: use unique QOM name
hw/or1k/virt: use unique QOM name hw/hexagon/virt: use unique QOM name hw/loongarch/virt: use unique QOM name hw/m68k/virt: use unique QOM name hw/xtensa/virt: use unique QOM name
qapi: return MachineInfo typename from query-machines
machine: match the versioned virt example to arm virt
hw/arm/virt.c | 53 ++++++++++++++++-------------- hw/core/machine-qmp-cmds.c | 1 + hw/core/machine.c | 6 ++++ hw/hexagon/virt.c | 21 +++++++----- hw/loongarch/virt.c | 44 +++++++++++++------------ hw/m68k/virt.c | 37 ++++++++++++--------- hw/or1k/virt.c | 20 +++++++----- hw/riscv/virt.c | 26 +++++++-------- hw/xtensa/virt.c | 20 ++++++++++-- include/hw/arm/virt.h | 5 ++- include/hw/core/boards.h | 39 ++++++++++++++++------ include/hw/hexagon/virt.h | 5 ++- include/hw/loongarch/virt.h | 5 ++- include/hw/riscv/virt.h | 5 ++- qapi/machine.json | 6 +++- system/vl.c | 8 ++--- tests/qtest/qom-test.c | 65 +++++++++++++++++++++++++++++++++---- 17 files changed, 247 insertions(+), 119 deletions(-)
Signature · 1 line
2.52.0.windows.1
PATCH v4 1/17 hw/riscv/virt: move virt TypeInfo into its type_init
virt_machine_typeinfo is a file-scope constant, so .name has to be a constant expression. Move it into virt_machine_init_register_types() so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary. The other virt boards will follow the same pattern.
--- hw/riscv/virt.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
hw/riscv/virt.c +12 -13
@@ -1196,21 +1196,20 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) "Enable IOMMU platform device"); } -static const TypeInfo virt_machine_typeinfo = { - .name =MACHINE_TYPE_NAME ("virt" ), - .parent =TYPE_MACHINE , - .class_init = virt_machine_class_init, - .instance_init = virt_machine_instance_init, - .instance_finalize = virt_machine_instance_finalize, - .instance_size =sizeof (RISCVVirtState), - .interfaces = (const InterfaceInfo []) { - {TYPE_HOTPLUG_HANDLER }, - { } - }, -}; -static void virt_machine_init_register_types (void ) { +const TypeInfo virt_machine_typeinfo = { + .name =MACHINE_TYPE_NAME ("virt" ), + .parent =TYPE_MACHINE , + .class_init = virt_machine_class_init, + .instance_init = virt_machine_instance_init, + .instance_finalize = virt_machine_instance_finalize, + .instance_size =sizeof (RISCVVirtState), + .interfaces = (const InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, + };type_register_static (&virt_machine_typeinfo); }
Signature · 1 line
2.52.0.windows.1
PATCH v4 2/17 hw/arm/virt: move virt TypeInfo into its type_init
In reply to Yonggang LuoThe base virt type and each versioned type are file-scope constants, so .name has to be a constant expression. Move them into the type init functions so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/arm/virt.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
hw/arm/virt.c +22 -23
@@ -127,15 +127,15 @@ static void arm_virt_compat_default_set(MachineClass *mc) mc->alias ="virt" ; \ } \ } \ -static const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ - { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ - .parent =TYPE_VIRT_MACHINE , \ - .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ - .is_available = target_base_arm, \ - }; \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ +const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ + { \ + .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .parent =TYPE_VIRT_MACHINE , \ + .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ + .is_available = target_base_arm, \ + }; \MACHINE_VER_DELETION (__VA_ARGS__); \type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ } \
@@ -4419,24 +4419,23 @@ static void virt_instance_finalize(Object *obj)g_ptr_array_free (vms->smmuv3_devices, TRUE); } -static const TypeInfo virt_machine_info = { - .name =TYPE_VIRT_MACHINE , - .parent =TYPE_MACHINE , - .abstract = true, - .instance_size =sizeof (VirtMachineState), - .class_size =sizeof (VirtMachineClass), - .class_init = virt_machine_class_init, - .instance_init = virt_instance_init, - .instance_finalize = virt_instance_finalize, - .interfaces = (const InterfaceInfo []) { - {TYPE_HOTPLUG_HANDLER }, - { } - }, - .is_available = target_base_arm, -}; -static void machvirt_machine_init (void ) { +const TypeInfo virt_machine_info = { + .name =TYPE_VIRT_MACHINE , + .parent =TYPE_MACHINE , + .abstract = true, + .instance_size =sizeof (VirtMachineState), + .class_size =sizeof (VirtMachineClass), + .class_init = virt_machine_class_init, + .instance_init = virt_instance_init, + .instance_finalize = virt_instance_finalize, + .interfaces = (const InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, + .is_available = target_base_arm, + };type_register_static (&virt_machine_info); }type_init (machvirt_machine_init);
Signature · 1 line
2.52.0.windows.1
PATCH v4 3/17 hw/or1k/virt: move virt TypeInfo into its type_init
In reply to Yonggang Luoor1ksim_machine_typeinfo is a file-scope constant, so .name has to be a constant expression. Move it into or1ksim_machine_init_register_types() so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/or1k/virt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
hw/or1k/virt.c +7 -8
@@ -554,16 +554,15 @@ static void openrisc_virt_machine_init(ObjectClass *oc, const void *data) mc->default_cpu_type =OPENRISC_CPU_TYPE_NAME ("or1200" ); } -static const TypeInfo or1ksim_machine_typeinfo = { - .name =TYPE_VIRT_MACHINE , - .parent =TYPE_MACHINE , - .class_init = openrisc_virt_machine_init, - .instance_size =sizeof (OR1KVirtState), - .is_available = target_or1k, -}; -static void or1ksim_machine_init_register_types (void ) { +const TypeInfo or1ksim_machine_typeinfo = { + .name =TYPE_VIRT_MACHINE , + .parent =TYPE_MACHINE , + .class_init = openrisc_virt_machine_init, + .instance_size =sizeof (OR1KVirtState), + .is_available = target_or1k, + };type_register_static (&or1ksim_machine_typeinfo); }
Signature · 1 line
2.52.0.windows.1
PATCH v4 4/17 hw/hexagon/virt: move virt TypeInfo into its type_init
In reply to Yonggang Luovirt_machine_types is a file-scope constant, so .name has to be a constant expression. Register a local TypeInfo from virt_machine_register_types() so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/hexagon/virt.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
hw/hexagon/virt.c +13 -9
@@ -375,12 +375,16 @@ static void virt_class_init(ObjectClass *oc, const void *data) } -static const TypeInfo virt_machine_types[] = { { - .name =TYPE_HEXAGON_VIRT_MACHINE , - .parent =TYPE_HEXAGON_COMMON_MACHINE , - .instance_size =sizeof (HexagonVirtMachineState), - .class_init = virt_class_init, - .is_available = target_hexagon, -} }; - -DEFINE_TYPES (virt_machine_types) +static void virt_machine_register_types (void ) +{ +const TypeInfo virt_machine_typeinfo = { + .name =TYPE_HEXAGON_VIRT_MACHINE , + .parent =TYPE_HEXAGON_COMMON_MACHINE , + .instance_size =sizeof (HexagonVirtMachineState), + .class_init = virt_class_init, + .is_available = target_hexagon, + }; +type_register_static (&virt_machine_typeinfo); +} + +type_init (virt_machine_register_types)
Signature · 1 line
2.52.0.windows.1
PATCH v4 5/17 hw/loongarch/virt: move virt TypeInfo into its type_init
In reply to Yonggang LuoThe base virt type and each versioned type are file-scope constants, so .name has to be a constant expression. Move them into the type init functions so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/loongarch/virt.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
hw/loongarch/virt.c +19 -20
@@ -1548,14 +1548,14 @@ static void virt_class_init(ObjectClass *oc, const void *data) mc->is_default = true; \ } \ } \ -static const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ - { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ - .parent =TYPE_LOONGARCH_VIRT_MACHINE , \ - .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ - }; \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ +const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ + { \ + .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .parent =TYPE_LOONGARCH_VIRT_MACHINE , \ + .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ + }; \MACHINE_VER_DELETION (__VA_ARGS__); \type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ } \
@@ -1579,22 +1579,21 @@ static void virt_instance_finalize(Object *obj)g_free (lvms->oem_table_id); } -static const TypeInfo virt_machine_info = { - .name =TYPE_LOONGARCH_VIRT_MACHINE , - .parent =TYPE_MACHINE , - .abstract = true, - .instance_size =sizeof (LoongArchVirtMachineState), - .class_init = virt_class_init, - .instance_init = virt_initfn, - .instance_finalize = virt_instance_finalize, - .interfaces = (InterfaceInfo []) { - {TYPE_HOTPLUG_HANDLER }, - { } - }, -}; -static void machvirt_machine_init (void ) { +const TypeInfo virt_machine_info = { + .name =TYPE_LOONGARCH_VIRT_MACHINE , + .parent =TYPE_MACHINE , + .abstract = true, + .instance_size =sizeof (LoongArchVirtMachineState), + .class_init = virt_class_init, + .instance_init = virt_initfn, + .instance_finalize = virt_instance_finalize, + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, + };type_register_static (&virt_machine_info); }
Signature · 1 line
2.52.0.windows.1
PATCH v4 6/17 hw/m68k/virt: move virt TypeInfo into its type_init
In reply to Yonggang LuoThe base virt type and each versioned type are file-scope constants, so .name has to be a constant expression. Move them into the type init functions so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/m68k/virt.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
hw/m68k/virt.c +14 -15
@@ -322,16 +322,15 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) mc->default_ram_id ="m68k_virt.ram" ; } -static const TypeInfo virt_machine_info = { - .name =MACHINE_TYPE_NAME ("virt" ), - .parent =TYPE_MACHINE , - .abstract = true, - .class_init = virt_machine_class_init, - .is_available = target_m68k, -}; -static void virt_machine_register_types (void ) { +const TypeInfo virt_machine_info = { + .name =MACHINE_TYPE_NAME ("virt" ), + .parent =TYPE_MACHINE , + .abstract = true, + .class_init = virt_machine_class_init, + .is_available = target_m68k, + };type_register_static (&virt_machine_info); }
@@ -350,15 +349,15 @@ type_init(virt_machine_register_types) mc->alias ="virt" ; \ } \ } \ -static const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ - { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ - .parent =MACHINE_TYPE_NAME ("virt" ), \ - .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ - .is_available = target_m68k, \ - }; \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ +const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ + { \ + .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .parent =MACHINE_TYPE_NAME ("virt" ), \ + .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ + .is_available = target_m68k, \ + }; \MACHINE_VER_DELETION (__VA_ARGS__); \type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ } \
Signature · 1 line
2.52.0.windows.1
PATCH v4 7/17 hw/xtensa/virt: move virt TypeInfo into its type_init
In reply to Yonggang LuoDEFINE_MACHINE() keeps the virt TypeInfo at file scope, so .name has to be a constant expression. Register it from xtensa_virt_machine_register_types() so a later commit can compute the name: "virt" for a single-target binary, and "<target_base_name>-virt" for a multi-target binary.
--- hw/xtensa/virt.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
hw/xtensa/virt.c +14 -2
@@ -115,8 +115,9 @@ static void xtensa_virt_init(MachineState *machine)xtensa_sim_load_kernel (cpu, machine); } -static void xtensa_virt_machine_init (MachineClass *mc) +static void xtensa_virt_machine_class_init (ObjectClass *oc,const void *data) { +MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="virt machine (" XTENSA_DEFAULT_CPU_MODEL ")" ; mc->init = xtensa_virt_init; mc->max_cpus =32 ;
@@ -124,4 +125,15 @@ 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_register_types (void ) +{ +const TypeInfo xtensa_virt_machine_typeinfo = { + .name =MACHINE_TYPE_NAME ("virt" ), + .parent =TYPE_MACHINE , + .class_init = xtensa_virt_machine_class_init, + .instance_size =sizeof (MachineState), + }; +type_register_static (&xtensa_virt_machine_typeinfo); +} + +type_init (xtensa_virt_machine_register_types)
Signature · 1 line
2.52.0.windows.1
PATCH v4 8/17 machine: allow -M name to differ from QOM type
In reply to Yonggang Luo- Add machine_class_set_name() so boards can keep a stable -M name when the QOM type is uniquified. machine_class_base_init still defaults the name to the QOM type without -machine.
- Document that MachineClass::name is the -M name, not the QOM type.
- Sort -M help by MachineClass::name so order matches the printed names when QOM types are prefixed (arm-virt-11.1-machine vs virt-11.1).
--- hw/core/machine.c | 6 ++++++ include/hw/core/boards.h | 12 +++++++++++- system/vl.c | 8 +++----- 3 files changed, 20 insertions(+), 6 deletions(-)
hw/core/machine.c +6 -0
@@ -1219,6 +1219,12 @@ static void machine_class_init(ObjectClass *oc, const void *data) "Memory size configuration"); } +void machine_class_set_name (MachineClass *mc,const char *name) +{ +g_free (mc->name); + mc->name =g_strdup (name); +} +static void machine_class_base_init (ObjectClass *oc,const void *data) {MachineClass *mc =MACHINE_CLASS (oc);
include/hw/core/boards.h +11 -1
@@ -36,6 +36,16 @@ const char *machine_default_cpu_type(const MachineState *ms);* @mc: Machine class */ const char *machine_class_default_cpu_type (MachineClass *mc); +/** +* machine_class_set_name: Set the -M name when it differs from the QOM type +* @mc: Machine class +* @name: Name used by -M lookup, help, and migration +* +* machine_class_base_init sets MachineClass::name from the QOM type with +* the -machine suffix removed. Call this from board class_init when the +* CLI name must stay stable after the QOM type is uniquified. +*/ +void machine_class_set_name (MachineClass *mc,const char *name);void machine_add_audiodev_property (MachineClass *mc);void machine_run_board_init (MachineState *machine,const char *mem_path,Error **errp);
@@ -269,7 +279,7 @@ struct MachineClass {/*< public >*/ const char *family;/* NULL iff @name identifies a standalone machtype */ -char *name; +char *name;/* -M name; default is QOM type without -machine */ const char *alias;const char *desc;const char *deprecation_reason;
system/vl.c +3 -5
@@ -1538,10 +1538,9 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d)if (mc1->family ==NULL ) {if (mc2->family ==NULL ) {/* Compare standalone machine types against each other; they sort -* in increasing order. +* in increasing order by the name shown in -M help. */ -return strcmp (object_class_get_name (OBJECT_CLASS (mc1)), -object_class_get_name (OBJECT_CLASS (mc2))); +return strcmp (mc1->name, mc2->name); }/* Standalone machine types sort after families. */
@@ -1560,8 +1559,7 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d) }/* Within the same family, machine types sort in decreasing order. */ -return strcmp (object_class_get_name (OBJECT_CLASS (mc2)), -object_class_get_name (OBJECT_CLASS (mc1))); +return strcmp (mc2->name, mc1->name); }static void machine_help_func (const QDict *qdict)
Signature · 1 line
2.52.0.windows.1
PATCH v4 9/17 hw/riscv/virt: use unique QOM name
In reply to Yonggang LuoDefine TYPE_RISCV_VIRT_MACHINE as riscv-virt when target_heterogeneous() is true, and as virt otherwise. Register that type and keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/riscv/virt.c | 3 ++- include/hw/riscv/virt.h | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-)
hw/riscv/virt.c +2 -1
@@ -1134,6 +1134,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); mc->desc ="RISC-V VirtIO board" ; +machine_class_set_name (mc,"virt" ); mc->init = virt_machine_init; mc->max_cpus =VIRT_CPUS_MAX ; mc->default_cpu_type =TYPE_RISCV_CPU_BASE ;
@@ -1199,7 +1200,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)static void virt_machine_init_register_types (void ) {const TypeInfo virt_machine_typeinfo = { - .name =MACHINE_TYPE_NAME ("virt" ), + .name =TYPE_RISCV_VIRT_MACHINE , .parent =TYPE_MACHINE , .class_init = virt_machine_class_init, .instance_init = virt_machine_instance_init,
include/hw/riscv/virt.h +4 -1
@@ -24,13 +24,16 @@#include "hw/core/sysbus.h" #include "hw/block/flash.h" #include "hw/intc/riscv_imsic.h" +#include "qemu/target-info.h" #define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)#define VIRT_SOCKETS_MAX_BITS 2#define VIRT_SOCKETS_MAX (1 << VIRT_SOCKETS_MAX_BITS) -#define TYPE_RISCV_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_RISCV_VIRT_MACHINE \ + (target_heterogeneous() ? MACHINE_TYPE_NAME("riscv-virt") : \ + MACHINE_TYPE_NAME("virt"))typedef struct RISCVVirtState RISCVVirtState ;DECLARE_INSTANCE_CHECKER (RISCVVirtState,RISCV_VIRT_MACHINE ,TYPE_RISCV_VIRT_MACHINE )
Signature · 1 line
2.52.0.windows.1
PATCH v4 10/17 hw/arm/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_VIRT_MACHINE and the versioned types to arm-virt when target_heterogeneous() is true, and to virt otherwise. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/arm/virt.c | 12 ++++++++---- include/hw/arm/virt.h | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-)
hw/arm/virt.c +8 -4
@@ -121,23 +121,27 @@ static void arm_virt_compat_default_set(MachineClass *mc)MachineClass *mc =MACHINE_CLASS (oc); \arm_virt_compat_default_set (mc); \MACHINE_VER_SYM (options, virt, __VA_ARGS__)(mc); \ - mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " ARM Virtual Machine"; \ + mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) \ +" ARM Virtual Machine" ; \MACHINE_VER_DEPRECATION (__VA_ARGS__); \ +machine_class_set_name (mc,"virt-" MACHINE_VER_STR (__VA_ARGS__)); \if (latest) { \ mc->alias ="virt" ; \ } \ } \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ -const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ +const TypeInfo virt_machine_info = \ { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .name =target_heterogeneous () ? \ +MACHINE_VER_TYPE_NAME ("arm-virt" , __VA_ARGS__) : \ +MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ .parent =TYPE_VIRT_MACHINE , \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ .is_available = target_base_arm, \ }; \MACHINE_VER_DELETION (__VA_ARGS__); \ -type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ +type_register_static (&virt_machine_info); \ } \type_init (MACHINE_VER_SYM (register, virt, __VA_ARGS__));
include/hw/arm/virt.h +4 -1
@@ -32,6 +32,7 @@#include "exec/hwaddr.h" #include "qemu/notify.h" +#include "qemu/target-info.h" #include "hw/core/boards.h" #include "hw/acpi/ghes.h" #include "hw/arm/boot.h"
@@ -215,7 +216,9 @@ struct VirtMachineState {#define VIRT_ECAM_ID (high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM) -#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_VIRT_MACHINE (target_heterogeneous() ? \ + MACHINE_TYPE_NAME("arm-virt") : \ + MACHINE_TYPE_NAME("virt")) OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)void virt_acpi_setup (VirtMachineState *vms);
Signature · 1 line
2.52.0.windows.1
PATCH v4 11/17 hw/or1k/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_VIRT_MACHINE to or1k-virt when target_heterogeneous() is true, and to virt otherwise. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/or1k/virt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/or1k/virt.c +4 -1
@@ -34,7 +34,9 @@#define VIRT_CPUS_MAX 4#define VIRT_CLK_MHZ 20000000 -#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_VIRT_MACHINE \ + (target_heterogeneous() ? MACHINE_TYPE_NAME("or1k-virt") : \ + MACHINE_TYPE_NAME("virt"))#define VIRT_MACHINE (obj) \ OBJECT_CHECK(OR1KVirtState, (obj), TYPE_VIRT_MACHINE)
@@ -548,6 +550,7 @@ static void openrisc_virt_machine_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="or1k virtual machine" ; +machine_class_set_name (mc,"virt" ); mc->init = openrisc_virt_init; mc->max_cpus =VIRT_CPUS_MAX ; mc->is_default = false;
Signature · 1 line
2.52.0.windows.1
PATCH v4 12/17 hw/hexagon/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_HEXAGON_VIRT_MACHINE to hexagon-virt when target_heterogeneous() is true, and to virt otherwise. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/hexagon/virt.c | 1 + include/hw/hexagon/virt.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
hw/hexagon/virt.c +1 -0
@@ -360,6 +360,7 @@ static void virt_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="Hexagon Virtual Machine" ; +machine_class_set_name (mc,"virt" ); mc->init = virt_init; mc->default_cpu_type =HEXAGON_CPU_TYPE_NAME ("v68" ); mc->default_ram_size =4 * GiB;
include/hw/hexagon/virt.h +4 -1
@@ -9,6 +9,7 @@#define HW_HEXAGONVIRT_H #include "hw/hexagon/hexagon.h" +#include "qemu/target-info.h" #include "target/hexagon/cpu.h" #define VIRTIO_DEV_COUNT 8
@@ -26,7 +27,9 @@ struct HexagonVirtMachineState {void hexagon_load_fdt (const struct HexagonVirtMachineState *vms); -#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_HEXAGON_VIRT_MACHINE \ + (target_heterogeneous() ? MACHINE_TYPE_NAME("hexagon-virt") : \ + MACHINE_TYPE_NAME("virt")) OBJECT_DECLARE_SIMPLE_TYPE(HexagonVirtMachineState, HEXAGON_VIRT_MACHINE)#endif /* HW_HEXAGONVIRT_H */
Signature · 1 line
2.52.0.windows.1
PATCH v4 13/17 hw/loongarch/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_LOONGARCH_VIRT_MACHINE and the versioned types to loongarch-virt when target_heterogeneous() is true, and to virt otherwise. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/loongarch/virt.c | 9 ++++++--- include/hw/loongarch/virt.h | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-)
hw/loongarch/virt.c +6 -3
@@ -1543,6 +1543,7 @@ static void virt_class_init(ObjectClass *oc, const void *data)MACHINE_VER_SYM (options, virt, __VA_ARGS__)(mc); \ mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " LoongArch Virtual Machine"; \MACHINE_VER_DEPRECATION (__VA_ARGS__); \ +machine_class_set_name (mc,"virt-" MACHINE_VER_STR (__VA_ARGS__)); \if (latest) { \ mc->alias ="virt" ; \ mc->is_default = true; \
@@ -1550,14 +1551,16 @@ static void virt_class_init(ObjectClass *oc, const void *data) } \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ -const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ +const TypeInfo virt_machine_info = \ { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .name =target_heterogeneous () ? \ +MACHINE_VER_TYPE_NAME ("loongarch-virt" , __VA_ARGS__) : \ +MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ .parent =TYPE_LOONGARCH_VIRT_MACHINE , \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ }; \MACHINE_VER_DELETION (__VA_ARGS__); \ -type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ +type_register_static (&virt_machine_info); \ } \type_init (MACHINE_VER_SYM (register, virt, __VA_ARGS__));
include/hw/loongarch/virt.h +4 -1
@@ -9,6 +9,7 @@#define HW_LOONGARCH_H #include "hw/core/boards.h" +#include "qemu/target-info.h" #include "qemu/queue.h" #include "hw/block/flash.h" #include "hw/loongarch/boot.h"
@@ -130,7 +131,9 @@ struct LoongArchVirtMachineState {bool highmem_mmio; }; -#define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_LOONGARCH_VIRT_MACHINE \ + (target_heterogeneous() ? MACHINE_TYPE_NAME("loongarch-virt") : \ + MACHINE_TYPE_NAME("virt")) OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHINE)void virt_acpi_setup (LoongArchVirtMachineState *lvms);void virt_fdt_setup (LoongArchVirtMachineState *lvms);
Signature · 1 line
2.52.0.windows.1
PATCH v4 14/17 hw/m68k/virt: use unique QOM name
In reply to Yonggang LuoSet the parent and versioned QOM types to m68k-virt when target_heterogeneous() is true, and to virt otherwise. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/m68k/virt.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
hw/m68k/virt.c +13 -5
@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "qemu/target-info.h" #include "qemu/units.h" #include "qemu/guest-random.h" #include "exec/target_page.h"
@@ -322,10 +323,14 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) mc->default_ram_id ="m68k_virt.ram" ; } +#define TYPE_M68K_VIRT_MACHINE \ + (target_heterogeneous() ? MACHINE_TYPE_NAME("m68k-virt") : \ + MACHINE_TYPE_NAME("virt")) +static void virt_machine_register_types (void ) {const TypeInfo virt_machine_info = { - .name =MACHINE_TYPE_NAME ("virt" ), + .name =TYPE_M68K_VIRT_MACHINE , .parent =TYPE_MACHINE , .abstract = true, .class_init = virt_machine_class_init,
@@ -345,21 +350,24 @@ type_init(virt_machine_register_types)MACHINE_VER_SYM (options, virt, __VA_ARGS__)(mc); \ mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " M68K Virtual Machine"; \MACHINE_VER_DEPRECATION (__VA_ARGS__); \ +machine_class_set_name (mc,"virt-" MACHINE_VER_STR (__VA_ARGS__)); \if (latest) { \ mc->alias ="virt" ; \ } \ } \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ { \ -const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ +const TypeInfo virt_machine_info = \ { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ - .parent =MACHINE_TYPE_NAME ("virt" ), \ + .name =target_heterogeneous () ? \ +MACHINE_VER_TYPE_NAME ("m68k-virt" , __VA_ARGS__) : \ +MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .parent =TYPE_M68K_VIRT_MACHINE , \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ .is_available = target_m68k, \ }; \MACHINE_VER_DELETION (__VA_ARGS__); \ -type_register_static (&MACHINE_VER_SYM (info, virt, __VA_ARGS__)); \ +type_register_static (&virt_machine_info); \ } \type_init (MACHINE_VER_SYM (register, virt, __VA_ARGS__));
Signature · 1 line
2.52.0.windows.1
PATCH v4 15/17 hw/xtensa/virt: use unique QOM name
In reply to Yonggang LuoRegister the board as xtensa-virt when target_heterogeneous() is true, and as virt otherwise. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/xtensa/virt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/xtensa/virt.c +5 -1
@@ -26,6 +26,7 @@*/ #include "qemu/osdep.h" +#include "qemu/target-info.h" #include "qapi/error.h" #include "system/reset.h" #include "hw/core/boards.h"
@@ -119,6 +120,7 @@ static void xtensa_virt_machine_class_init(ObjectClass *oc, const void *data) {MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="virt machine (" XTENSA_DEFAULT_CPU_MODEL ")" ; +machine_class_set_name (mc,"virt" ); mc->init = xtensa_virt_init; mc->max_cpus =32 ; mc->default_cpu_type =XTENSA_DEFAULT_CPU_TYPE ;
@@ -128,7 +130,9 @@ static void xtensa_virt_machine_class_init(ObjectClass *oc, const void *data)static void xtensa_virt_machine_register_types (void ) {const TypeInfo xtensa_virt_machine_typeinfo = { - .name =MACHINE_TYPE_NAME ("virt" ), + .name =target_heterogeneous () ? +MACHINE_TYPE_NAME ("xtensa-virt" ) : +MACHINE_TYPE_NAME ("virt" ), .parent =TYPE_MACHINE , .class_init = xtensa_virt_machine_class_init, .instance_size =sizeof (MachineState),
Signature · 1 line
2.52.0.windows.1
PATCH v4 16/17 qapi: return MachineInfo typename from query-machines
In reply to Yonggang Luotarget_heterogeneous() needs MachineInfo typename: a prefixed type such as arm-virt-11.1-machine does not match -M virt-11.1. qemu-system-<target> keeps its behavior, so the QOM type is still the -M name plus "-machine". typename can still be used when target_heterogeneous() is false. Return the QOM type from object_class_get_name() in qmp_query_machines(). test_query_machines_typename checks that qom-list-properties accepts it.
--- hw/core/machine-qmp-cmds.c | 1 + qapi/machine.json | 6 +++- tests/qtest/qom-test.c | 65 ++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 7 deletions(-)
hw/core/machine-qmp-cmds.c +1 -0
@@ -174,6 +174,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props, } info->name =g_strdup (mc->name); + info->q_typename =g_strdup (object_class_get_name (OBJECT_CLASS (mc))); info->cpu_max = !mc->max_cpus ?1 : mc->max_cpus; info->hotpluggable_cpus = mc->has_hotpluggable_cpus; info->numa_mem_supported = mc->numa_mem_supported;
qapi/machine.json +5 -1
@@ -161,6 +161,9 @@ # # @name: the name of the machine # +# @typename: QOM type name of the machine, for qom-list-properties +# (since 11.2) +# # @alias: an alias for the machine name # # @is-default: whether the machine is default
@@ -201,7 +204,7 @@ # Since: 1.2 ## { 'struct': 'MachineInfo', - 'data': { 'name': 'str', '*alias': 'str', + 'data': { 'name': 'str', 'typename': 'str', '*alias': 'str', '*is-default': 'bool', 'cpu-max': 'int', 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool', 'deprecated': 'bool', '*default-cpu-type': 'str',
@@ -230,6 +233,7 @@ # { # "hotpluggable-cpus": true, # "name": "pc-q35-6.2", +# "typename": "pc-q35-6.2-machine", # "compat-props": [ # { # "qom-type": "virtio-mem",
tests/qtest/qom-test.c +59 -6
84 lines not on this page · raw message
Signature · 1 line
2.52.0.windows.1
PATCH v4 17/17 machine: match the versioned virt example to arm virt
In reply to Yonggang LuoThe comment still showed MACHINE_VER_TYPE_NAME("virt") and left out machine_class_set_name(). Use arm-virt only when target_heterogeneous() is true. qemu-system-<target> keeps virt. Keep the -M name as virt-<version>, and name the latest helper DEFINE_VIRT_MACHINE_AS_LATEST.
--- include/hw/core/boards.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
include/hw/core/boards.h +18 -9
@@ -474,28 +474,37 @@ struct MachineState {* For example, a macro that can be used to define versioned * 'virt' machine types would look like: * +* #define TYPE_VIRT_MACHINE (target_heterogeneous() ? \ +* MACHINE_TYPE_NAME("arm-virt") : \ +* MACHINE_TYPE_NAME("virt")) +* * #define DEFINE_VIRT_MACHINE_IMPL(latest, ...) \ * static void MACHINE_VER_SYM(class_init, virt, __VA_ARGS__)( \ * ObjectClass *oc, \ -* void *data) \ +* const void *data) \ * { \ * MachineClass *mc = MACHINE_CLASS(oc); \ * MACHINE_VER_SYM(options, virt, __VA_ARGS__)(mc); \ -* mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " Virtual Machine"; \ +* mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) \ +* " ARM Virtual Machine"; \ * MACHINE_VER_DEPRECATION(__VA_ARGS__); \ +* machine_class_set_name(mc, "virt-" MACHINE_VER_STR(__VA_ARGS__)); \ * if (latest) { \ * mc->alias = "virt"; \ * } \ * } \ -* static const TypeInfo MACHINE_VER_SYM(info, virt, __VA_ARGS__) = { \ -* .name = MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \ -* .parent = TYPE_VIRT_MACHINE, \ -* .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \ -* }; \ * static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \ * { \ +* const TypeInfo virt_machine_info = \ +* { \ +* .name = target_heterogeneous() ? \ +* MACHINE_VER_TYPE_NAME("arm-virt", __VA_ARGS__) : \ +* MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \ +* .parent = TYPE_VIRT_MACHINE, \ +* .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \ +* }; \ * MACHINE_VER_DELETION(__VA_ARGS__); \ -* type_register_static(&MACHINE_VER_SYM(info, virt, __VA_ARGS__)); \ +* type_register_static(&virt_machine_info); \ * } \ * type_init(MACHINE_VER_SYM(register, virt, __VA_ARGS__)); *
@@ -503,7 +512,7 @@ struct MachineState {* whichever scenarios need to be catered for with a machine: * * // Normal 2 digit, marked as latest e.g. 'virt-9.0' -* #define DEFINE_VIRT_MACHINE_LATEST(major, minor) \ +* #define DEFINE_VIRT_MACHINE_AS_LATEST(major, minor) \ * DEFINE_VIRT_MACHINE_IMPL(true, major, minor) * * // Normal 2 digit e.g. 'virt-9.0'
Signature · 1 line
2.52.0.windows.1
Quoted 71 lines · Yonggang Luo
Multiple targets register a virt board as
MACHINE_TYPE_NAME("virt"). Those QOM types collide if more than one board is linked into one qemu-system process. This series splits the QOM type from the -M name so each virt board can keep a unique type while -M virt, help, and migration stay the same.- Add
machine_class_set_name()so boards can setMachineClass::namewhen it must differ from the QOM type.machine_class_base_initstill defaults the name to the QOM type without -machine. Document thatMachineClass::nameis the -M name, not the QOM type. Sort -M help by that name so order matches the printed names after types are prefixed (arm-virt-11.1-machine vs virt-11.1).
- Whentarget_heterogeneous()is true, give each colliding virt board a unique QOM type and keep the existing -M name viamachine_class_set_name(): riscv-virt, arm-virt, or1k-virt, hexagon-virt, loongarch-virt, m68k-virt, and xtensa-virt. Otherwise keep virt. Versioned ARM, LoongArch, and M68K boards keep virt-<ver>. Latest ARM virt still setsmc->aliasto virt.
This is for the review from Daniel:- query-machines returns MachineInfo typename, the QOM type from
object_class_get_name(), for qom-list-properties. The -M name alone is not that type once virt boards are prefixed.
- Usetarget_heterogeneous()from the base. It still returns false, so qemu-system-<target> keeps the QOM type virt.Changes v3 -> v4:
Rebased ontod73149283205645625bfa9fe029cfb68e4c4a9ae, which already includes target-info: addtarget_heterogeneous. Theboards.hexample uses arm-virt only when that returns true.Changes v2 -> v3:
The versioned-machine example inboards.hnow followshw/arm/virt.c.machine_class_set_name()keeps the -M name as virt-<version>, the QOM type in the example is arm-virt, and the latest helper isDEFINE_VIRT_MACHINE_AS_LATEST.Changes v1 -> v2:
- query-machines returns MachineInfo typename. v1 returned only the -M name, so a client that appended "-machine" looked up the wrong type for a prefixed board such as arm-virt-11.1-machine versus -M virt-11.1.Yonggang Luo (17):
hw/riscv/virt: move virt TypeInfo into itstype_inithw/arm/virt: move virt TypeInfo into itstype_inithw/or1k/virt: move virt TypeInfo into itstype_inithw/hexagon/virt: move virt TypeInfo into itstype_inithw/loongarch/virt: move virt TypeInfo into itstype_inithw/m68k/virt: move virt TypeInfo into itstype_inithw/xtensa/virt: move virt TypeInfo into itstype_init
machine: allow -M name to differ from QOM type hw/riscv/virt: use unique QOM name
hw/arm/virt: use unique QOM name
hw/or1k/virt: use unique QOM name hw/hexagon/virt: use unique QOM name hw/loongarch/virt: use unique QOM name hw/m68k/virt: use unique QOM name hw/xtensa/virt: use unique QOM name
qapi: return MachineInfo typename from query-machines
machine: match the versioned virt example to arm virthw/arm/virt.c | 53 ++++++++++++++++-------------- hw/core/machine-qmp-cmds.c | 1 + hw/core/machine.c | 6 ++++ hw/hexagon/virt.c | 21 +++++++----- hw/loongarch/virt.c | 44 +++++++++++++------------ hw/m68k/virt.c | 37 ++++++++++++--------- hw/or1k/virt.c | 20 +++++++----- hw/riscv/virt.c | 26 +++++++-------- hw/xtensa/virt.c | 20 ++++++++++-- include/hw/arm/virt.h | 5 ++-
Quoted 9 lines
include/hw/core/boards.h | 39 ++++++++++++++++------ include/hw/hexagon/virt.h | 5 ++- include/hw/loongarch/virt.h | 5 ++- include/hw/riscv/virt.h | 5 ++- qapi/machine.json | 6 +++- system/vl.c | 8 ++--- tests/qtest/qom-test.c | 65 +++++++++++++++++++++++++++++++++---- 17 files changed, 247 insertions(+), 119 deletions(-)
If we follow approach to register types per target bucket, we don't need to introduce anything specific at registration time, and we would still be able to detect duplication and propose the list of available alternatives automatically.
``` virt is an ambiguous machine type, please choose among: - aarch64-virt - riscv64-virt ```
Regards,
Pierrick