machine: uniquify virt QOM names
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).
- 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. Versioned ARM, LoongArch, and M68K boards keep virt-<ver>. Latest ARM virt still sets mc->alias to virt.
Yonggang Luo (8):
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
hw/arm/virt.c | 3 ++- hw/core/machine.c | 6 ++++++ hw/hexagon/virt.c | 1 + hw/loongarch/virt.c | 3 ++- hw/m68k/virt.c | 7 ++++--- hw/or1k/virt.c | 3 ++- hw/riscv/virt.c | 3 ++- hw/xtensa/virt.c | 3 ++- include/hw/arm/virt.h | 2 +- include/hw/core/boards.h | 12 +++++++++++- include/hw/hexagon/virt.h | 2 +- include/hw/loongarch/virt.h | 2 +- include/hw/riscv/virt.h | 2 +- system/vl.c | 8 +++----- 14 files changed, 39 insertions(+), 18 deletions(-)
Signature · 1 line
2.52.0.windows.1
PATCH 1/8 machine: allow -M name to differ from QOM type
- 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
@@ -1215,6 +1215,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
Re: [PATCH 1/8] machine: allow -M name to differ from QOM type
Quoted 7 lines · Yonggang Luo
- Add
machine_class_set_name()so boards can keep a stable -M name when the QOM type is uniquified.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 byMachineClass::nameso order matches the printed names when QOM types are prefixed (arm-virt-11.1-machine vs virt-11.1).
Quoted 6 lines
Signed-off-by Yonggang Luo <[email protected]>--- hw/core/machine.c | 6 ++++++ include/hw/core/boards.h | 12 +++++++++++- system/vl.c | 8 +++----- 3 files changed, 20 insertions(+), 6 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH 1/8] machine: allow -M name to differ from QOM type
Quoted 8 lines · Daniel P. Berrangé
Quoted 7 lines · Yonggang Luo
- Add
machine_class_set_name()so boards can keep a stable -M name when the QOM type is uniquified.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 byMachineClass::nameso order matches the printed names when QOM types are prefixed (arm-virt-11.1-machine vs virt-11.1).
Quoted 8 lines
Quoted 6 lines
Signed-off-by Yonggang Luo <[email protected]>--- hw/core/machine.c | 6 ++++++ include/hw/core/boards.h | 12 +++++++++++- system/vl.c | 8 +++----- 3 files changed, 20 insertions(+), 6 deletions(-)Reviewed-by Daniel P. Berrangé <[email protected]>
When I apply this series and test libvirt, libvirt crashes because it sees a machine name "virt-11.1" and then to introspect it, it calls
qom-list-properties type=virt-11.1-machine
this doesn't work as the actual type name is
qom-list-properties type=arm-virt-11.1-machine
The problem we put ourselves in here is that 'query-machines' only returns the machine name, and not the typename, so mgmt apps have
to infer that typename==$machinename + "-machine".
Libvirt shouldn't crash of course and the fix for the crash it "easy", but when fixing it, then libvirt simply won't be able to introspect the machine, as it doesn't name the naming convention to get the typename out.
I think we probably need to extend 'query-machines' so that it includes a @typename field, so mgmt apps don't have to make the bad assumptions about naming conventions for types.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
PATCH 2/8 hw/riscv/virt: use unique QOM name
In reply to Yonggang LuoUse TYPE_RISCV_VIRT_MACHINE so the RISC-V virt QOM type does not collide with ARM virt in a combined qemu-system binary. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/riscv/virt.c | 3 ++- include/hw/riscv/virt.h | 2 +- 2 files changed, 3 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 ;
@@ -1197,7 +1198,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) }static 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 +1 -1
@@ -30,7 +30,7 @@#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 MACHINE_TYPE_NAME("riscv-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 3/8 hw/arm/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_VIRT_MACHINE to MACHINE_TYPE_NAME("arm-virt") so ARM virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/arm/virt.c | 3 ++- include/hw/arm/virt.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
hw/arm/virt.c +2 -1
@@ -123,13 +123,14 @@ static void arm_virt_compat_default_set(MachineClass *mc)MACHINE_VER_SYM (options, virt, __VA_ARGS__)(mc); \ 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__), \ + .name =MACHINE_VER_TYPE_NAME ("arm-virt" , __VA_ARGS__), \ .parent =TYPE_VIRT_MACHINE , \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ }; \
include/hw/arm/virt.h +1 -1
@@ -215,7 +215,7 @@ 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 MACHINE_TYPE_NAME("arm-virt") OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)void virt_acpi_setup (VirtMachineState *vms);
Signature · 1 line
2.52.0.windows.1
PATCH 4/8 hw/or1k/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_VIRT_MACHINE to MACHINE_TYPE_NAME("or1k-virt") so OpenRISC virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/or1k/virt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/or1k/virt.c +2 -1
@@ -34,7 +34,7 @@#define VIRT_CPUS_MAX 4#define VIRT_CLK_MHZ 20000000 -#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("or1k-virt")#define VIRT_MACHINE (obj) \ OBJECT_CHECK(OR1KVirtState, (obj), TYPE_VIRT_MACHINE)
@@ -548,6 +548,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 5/8 hw/hexagon/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_HEXAGON_VIRT_MACHINE to MACHINE_TYPE_NAME("hexagon-virt") so Hexagon virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/hexagon/virt.c | 1 + include/hw/hexagon/virt.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
hw/hexagon/virt.c +1 -0
@@ -359,6 +359,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 +1 -1
@@ -26,7 +26,7 @@ struct HexagonVirtMachineState {void hexagon_load_fdt (const struct HexagonVirtMachineState *vms); -#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("hexagon-virt") OBJECT_DECLARE_SIMPLE_TYPE(HexagonVirtMachineState, HEXAGON_VIRT_MACHINE)#endif /* HW_HEXAGONVIRT_H */
Signature · 1 line
2.52.0.windows.1
Re: [PATCH 5/8] hw/hexagon/virt: use unique QOM name
Quoted 7 lines · Yonggang Luo
Set
TYPE_HEXAGON_VIRT_MACHINEtoMACHINE_TYPE_NAME("hexagon-virt")so Hexagon virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt viamachine_class_set_name().Signed-off-by Yonggang Luo <[email protected]>---
Quoted 29 lines
hw/hexagon/virt.c | 1 + include/hw/hexagon/virt.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)hw/hexagon/virt.c +1
-0@@ -359,6 +359,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 +1
-1@@ -26,7 +26,7 @@ struct HexagonVirtMachineState {void hexagon_load_fdt (const struct HexagonVirtMachineState *vms); -#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("hexagon-virt") OBJECT_DECLARE_SIMPLE_TYPE(HexagonVirtMachineState, HEXAGON_VIRT_MACHINE)#endif /* HW_HEXAGONVIRT_H */
PATCH 6/8 hw/loongarch/virt: use unique QOM name
In reply to Yonggang LuoSet TYPE_LOONGARCH_VIRT_MACHINE to MACHINE_TYPE_NAME("loongarch-virt") so LoongArch virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/loongarch/virt.c | 3 ++- include/hw/loongarch/virt.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
hw/loongarch/virt.c +2 -1
@@ -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,7 +1551,7 @@ static void virt_class_init(ObjectClass *oc, const void *data) } \static const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ + .name =MACHINE_VER_TYPE_NAME ("loongarch-virt" , __VA_ARGS__), \ .parent =TYPE_LOONGARCH_VIRT_MACHINE , \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ }; \
include/hw/loongarch/virt.h +1 -1
@@ -130,7 +130,7 @@ struct LoongArchVirtMachineState {bool highmem_mmio; }; -#define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("virt") +#define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("loongarch-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 7/8 hw/m68k/virt: use unique QOM name
In reply to Yonggang LuoSet the parent and versioned QOM types to m68k-virt so M68K virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt-* via machine_class_set_name().
--- hw/m68k/virt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/m68k/virt.c +4 -3
@@ -323,7 +323,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) }static const TypeInfo virt_machine_info = { - .name =MACHINE_TYPE_NAME ("virt" ), + .name =MACHINE_TYPE_NAME ("m68k-virt" ), .parent =TYPE_MACHINE , .abstract = true, .class_init = virt_machine_class_init,
@@ -345,14 +345,15 @@ 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 const TypeInfo MACHINE_VER_SYM (info ,virt ,__VA_ARGS__ ) = \ { \ - .name =MACHINE_VER_TYPE_NAME ("virt" , __VA_ARGS__), \ - .parent =MACHINE_TYPE_NAME ("virt" ), \ + .name =MACHINE_VER_TYPE_NAME ("m68k-virt" , __VA_ARGS__), \ + .parent =MACHINE_TYPE_NAME ("m68k-virt" ), \ .class_init =MACHINE_VER_SYM (class_init, virt, __VA_ARGS__), \ }; \ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \
Signature · 1 line
2.52.0.windows.1
PATCH 8/8 hw/xtensa/virt: use unique QOM name
In reply to Yonggang LuoRegister the board as xtensa-virt so Xtensa virt no longer collides with other virt-machine types in one process. Keep the -M / help / migration name as virt via machine_class_set_name().
--- hw/xtensa/virt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/xtensa/virt.c +2 -1
@@ -118,10 +118,11 @@ static void xtensa_virt_init(MachineState *machine)static void xtensa_virt_machine_init (MachineClass *mc) { 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 ; mc->default_nic ="virtio-net-pci" ; } -DEFINE_MACHINE ("virt" , xtensa_virt_machine_init) +DEFINE_MACHINE ("xtensa-virt" , xtensa_virt_machine_init)
Signature · 1 line
2.52.0.windows.1