hw/virtio/virtio-mem: Avoid call to target_info() in class_init
Subsystems (2)
PATCH 16/34 hw/virtio/virtio-mem: Avoid call to target_info() in class_init
Done by merge virtio_mem_legacy_guests_properties into virtio_mem_properties. As we already have vmem->unplugged_inaccessible handle in virtio_mem_device_realize So we can reject the wrong option in virtio_mem_device_realize, then the call target_info() in class_init no need anymore.
--- hw/virtio/virtio-mem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
hw/virtio/virtio-mem.c +5 -7
@@ -879,7 +879,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)break ; } }else { - vmem->unplugged_inaccessible =ON_OFF_AUTO_ON ; +if (vmem->unplugged_inaccessible !=ON_OFF_AUTO_ON ) { +error_setg (errp,"'%s' must be 'on' on non-x86 targets" , +VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ); +return ; + } } if (vmem->dynamic_memslots &&
@@ -1568,9 +1572,6 @@ static const Property virtio_mem_properties[] = { early_migration, true),DEFINE_PROP_BOOL (VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP ,VirtIOMEM ,dynamic_memslots ,false ), -}; - -static const Property virtio_mem_legacy_guests_properties[] = {DEFINE_PROP_ON_OFF_AUTO (VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ,VirtIOMEM , unplugged_inaccessible, ON_OFF_AUTO_ON), };
@@ -1635,9 +1636,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);
Signature · 1 line
2.55.0.windows.3
PATCH 17/34 target-info: add a combined-binary query stub
Declare target_combined_binary() in target-info.h and provide a stub implementation in stubs/target-info.c that returns false.
This lets target-independent tools and single-target binaries use the query without a combined qemu-system implementation. A combined binary can provide its own implementation returning true.
--- MAINTAINERS | 1 + include/qemu/target-info.h | 7 +++++++ stubs/meson.build | 1 + stubs/target-info.c | 10 ++++++++++ 4 files changed, 19 insertions(+) create mode 100644 stubs/target-info.c
MAINTAINERS +1 -0
@@ -2146,6 +2146,7 @@ TargetInfo API M: Pierrick Bouvier <[email protected]> M: Philippe Mathieu-Daudé <[email protected]> S: Supported +F: stubs/target-info.c F: include/qemu/target-info*.h F: target-info*.c F: tests/unit/test-multi-targets.c
include/qemu/target-info.h +7 -0
@@ -42,6 +42,13 @@ const char *target_cpu_type(void);*/ bool target_big_endian (void ); +/** +* target_combined_binary: +* +* Returns: %true if this is the combined qemu-system binary. +*/ +bool target_combined_binary (void ); +/** * target_base_arm: *
stubs/meson.build +1 -0
@@ -3,6 +3,7 @@ # below, so that it is clear who needs the stubbed functionality. stub_ss.add(files('cpu-get-clock.c')) +stub_ss.add(files('target-info.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('is-daemonized.c'))
stubs/target-info.c new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "qemu/target-info.h" + +bool target_combined_binary (void ) +{ +return false; +}
Signature · 1 line
2.55.0.windows.3
PATCH 18/34 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
@@ -1222,6 +1222,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);
@@ -274,7 +284,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.55.0.windows.3
PATCH 19/34 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 | 26 +++++++++++++------------- include/hw/riscv/virt.h | 5 ++++- 2 files changed, 17 insertions(+), 14 deletions(-)
hw/riscv/virt.c +13 -13
@@ -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 ;
@@ -1196,21 +1197,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 =TYPE_RISCV_VIRT_MACHINE , + .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); }
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_combined_binary() ? 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.55.0.windows.3
PATCH 20/34 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 | 54 +++++++++++++++++++++++-------------------- include/hw/arm/virt.h | 5 +++- 2 files changed, 33 insertions(+), 26 deletions(-)
hw/arm/virt.c +29 -25
@@ -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 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 virt_machine_info = \ + { \ + .name =target_combined_binary () ? \ +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__));
@@ -4417,24 +4421,24 @@ 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);
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_combined_binary() ? \ + 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.55.0.windows.3
PATCH 21/34 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
hw/or1k/virt.c +11 -9
@@ -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_combined_binary() ? MACHINE_TYPE_NAME("or1k-virt") : \ + MACHINE_TYPE_NAME("virt"))#define VIRT_MACHINE (obj) \ OBJECT_CHECK(OR1KVirtState, (obj), TYPE_VIRT_MACHINE)
@@ -548,22 +550,22 @@ 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; 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.55.0.windows.3
PATCH 22/34 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 | 23 +++++++++++++++-------- include/hw/hexagon/virt.h | 5 ++++- 2 files changed, 19 insertions(+), 9 deletions(-)
hw/hexagon/virt.c +15 -8
@@ -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;
@@ -373,12 +374,18 @@ static void virt_class_init(ObjectClass *oc, const void *data) mc->default_nic ="virtio-mmio-bus" ; } +static void virt_machine_register_types (void ) +{ +const TypeInfo virt_machine_types[] = { + { + .name =TYPE_HEXAGON_VIRT_MACHINE , + .parent =TYPE_HEXAGON_COMMON_MACHINE , + .instance_size =sizeof (HexagonVirtMachineState), + .class_init = virt_class_init, + } + }; +type_register_static_array (virt_machine_types, +ARRAY_SIZE (virt_machine_types)); +} -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, -} }; - -DEFINE_TYPES (virt_machine_types) +type_init (virt_machine_register_types)
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_combined_binary() ? 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.55.0.windows.3
PATCH 23/34 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 | 45 ++++++++++++++++++++----------------- include/hw/loongarch/virt.h | 5 ++++- 2 files changed, 28 insertions(+), 22 deletions(-)
hw/loongarch/virt.c +24 -21
@@ -1543,21 +1543,24 @@ 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; \ } \ } \ -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 virt_machine_info = \ + { \ + .name =target_combined_binary () ? \ +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__));
@@ -1579,22 +1582,22 @@ 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); }
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_combined_binary() ? 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.55.0.windows.3
PATCH 24/34 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 | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
hw/m68k/virt.c +22 -15
@@ -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,16 +323,19 @@ 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, -}; +#define TYPE_M68K_VIRT_MACHINE \ + (target_combined_binary() ? MACHINE_TYPE_NAME("m68k-virt") : \ + MACHINE_TYPE_NAME("virt"))static void virt_machine_register_types (void ) { +const TypeInfo virt_machine_info = { + .name =TYPE_M68K_VIRT_MACHINE , + .parent =TYPE_MACHINE , + .abstract = true, + .class_init = virt_machine_class_init, + .is_available = target_m68k, + };type_register_static (&virt_machine_info); }
@@ -346,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 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 virt_machine_info = \ + { \ + .name =target_combined_binary () ? \ +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.55.0.windows.3
PATCH 25/34 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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
hw/xtensa/virt.c +21 -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"
@@ -118,10 +119,29 @@ 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) +static void xtensa_virt_machine_class_init (ObjectClass *oc, +const void *data) +{ +xtensa_virt_machine_init (MACHINE_CLASS (oc)); +} + +static void xtensa_virt_machine_register_types (void ) +{ +const TypeInfo xtensa_virt_machine_typeinfo = { + .name =target_combined_binary () ?MACHINE_TYPE_NAME ("xtensa-virt" ) : +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.55.0.windows.3
PATCH 26/34 qapi: return MachineInfo typename from query-machines
In reply to Yonggang Luoquery-machines returned only the -M name, so management apps inferred the QOM type as that name plus "-machine". A prefixed type such as arm-virt-11.1-machine no longer matches -M virt-11.1. Return the QOM type in MachineInfo typename 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
@@ -116,6 +116,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
@@ -162,6 +162,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
@@ -202,7 +205,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',
@@ -231,6 +234,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.55.0.windows.3
PATCH 27/34 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(). Show the arm-virt QOM type, 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
@@ -480,28 +480,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_combined_binary() ? \ +* 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_combined_binary() ? \ +* 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__)); *
@@ -509,7 +518,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.55.0.windows.3
PATCH 28/34 hw: Add MachineClass.targets for all "virt" machines for all possible targets
In reply to Yonggang LuoThose targets are ARM, RISC-V, LoongArch, M68K, OpenRISC, Hexagon and Xtensa
--- hw/arm/virt.c | 2 ++ hw/hexagon/virt.c | 2 ++ hw/loongarch/virt.c | 2 ++ hw/m68k/virt.c | 2 ++ hw/or1k/virt.c | 2 ++ hw/riscv/virt.c | 2 ++ hw/xtensa/virt.c | 2 ++ 7 files changed, 14 insertions(+)
hw/arm/virt.c +2 -0
@@ -29,6 +29,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/datadir.h" #include "qemu/units.h" #include "qemu/option.h"
@@ -4162,6 +4163,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); + mc->targets =QEMU_ARCH_ARM ; mc->init = machvirt_init;/* Start with max_cpus set to 512, which is the maximum supported by KVM. * The value may be reduced later when we have more information about the
hw/hexagon/virt.c +2 -0
@@ -6,6 +6,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qapi/error.h" #include "hw/hexagon/virt.h" #include "elf.h"
@@ -358,6 +359,7 @@ static void virt_class_init(ObjectClass *oc, const void *data) {MachineClass *mc =MACHINE_CLASS (oc); + mc->targets =QEMU_ARCH_HEXAGON ; mc->desc ="Hexagon Virtual Machine" ;machine_class_set_name (mc,"virt" ); mc->init = virt_init;
hw/loongarch/virt.c +2 -0
@@ -5,6 +5,7 @@* Copyright (c) 2021 Loongson Technology Corporation Limited */ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/units.h" #include "qemu/datadir.h" #include "qemu/cutils.h"
@@ -1460,6 +1461,7 @@ static void virt_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); + mc->targets =QEMU_ARCH_LOONGARCH ; mc->init = virt_init; mc->default_cpu_type =LOONGARCH_CPU_TYPE_NAME ("la464" ); mc->default_ram_id ="loongarch.ram" ;
hw/m68k/virt.c +2 -0
@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/target-info.h" #include "qemu/units.h" #include "qemu/guest-random.h"
@@ -314,6 +315,7 @@ static void virt_init(MachineState *machine)static void virt_machine_class_init (ObjectClass *oc,const void *data) {MachineClass *mc =MACHINE_CLASS (oc); + mc->targets =QEMU_ARCH_M68K ; mc->desc ="QEMU M68K Virtual Machine" ; mc->init = virt_init; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m68040" );
hw/or1k/virt.c +2 -0
@@ -7,6 +7,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/error-report.h" #include "qemu/guest-random.h" #include "qapi/error.h"
@@ -549,6 +550,7 @@ static void openrisc_virt_machine_init(ObjectClass *oc, const void *data) {MachineClass *mc =MACHINE_CLASS (oc); + mc->targets =QEMU_ARCH_OR1K ; mc->desc ="or1k virtual machine" ;machine_class_set_name (mc,"virt" ); mc->init = openrisc_virt_init;
hw/riscv/virt.c +2 -0
@@ -19,6 +19,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/units.h" #include "qemu/error-report.h" #include "qemu/guest-random.h"
@@ -1133,6 +1134,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); + mc->targets =QEMU_ARCH_RISCV ; mc->desc ="RISC-V VirtIO board" ;machine_class_set_name (mc,"virt" ); mc->init = virt_machine_init;
hw/xtensa/virt.c +2 -0
@@ -26,6 +26,7 @@*/ #include "qemu/osdep.h" +#include "qemu/base-arch-defs.h" #include "qemu/target-info.h" #include "qapi/error.h" #include "system/reset.h"
@@ -118,6 +119,7 @@ static void xtensa_virt_init(MachineState *machine)static void xtensa_virt_machine_init (MachineClass *mc) { + mc->targets =QEMU_ARCH_XTENSA ; mc->desc ="virt machine (" XTENSA_DEFAULT_CPU_MODEL ")" ;machine_class_set_name (mc,"virt" ); mc->init = xtensa_virt_init;
Signature · 1 line
2.55.0.windows.3
PATCH 29/34 system/arch_init: update qemu_arch_available to handle non-target select condition
In reply to Yonggang LuoUnder multi-target qemu, target may not selected when call to qemu_arch_available, return true for that.
--- system/arch_init.c | 8 ++++++++ 1 file changed, 8 insertions(+)
system/arch_init.c +8 -0
@@ -24,9 +24,17 @@#include "qemu/osdep.h" #include "qemu/base-arch-defs.h" #include "qemu/bitops.h" +#include "qemu/target-info.h" +#include "qemu/target-info-def.h" #include "qemu/target-info-qapi.h" bool qemu_arch_available (uint64_t arch_bitmask) { +if (target_combined_binary ()) { +/* Allow all architectures until machine selection sets TargetInfo. */ +if (!target_info ()) { +return true; + } + }return extract64 (arch_bitmask,target_arch (),1 ); }
Signature · 1 line
2.55.0.windows.3
PATCH 30/34 meson: build combined qemu-system for multi-target configurations
In reply to Yonggang LuoBuild a top-level qemu-system executable when multiple supported targets are configured.
Now the test-multi-target.c are testing under no target selected condition. That's guard for future breakage
--- MAINTAINERS | 1 + meson.build | 58 ++++++++++++++++++++++++++++++++++ qom/object.c | 4 ++- system/target-info.c | 10 ++++++ tests/unit/meson.build | 4 +-- tests/unit/test-multi-target.c | 5 ++- 6 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 system/target-info.c
MAINTAINERS +1 -0
@@ -2147,6 +2147,7 @@ M: Pierrick Bouvier <[email protected]> M: Philippe Mathieu-Daudé <[email protected]> S: Supported F: stubs/target-info.c +F: system/target-info.c F: include/qemu/target-info*.h F: target-info*.c F: tests/unit/test-multi-targets.c
meson.build +58 -0
76 lines not on this page · raw message
qom/object.c +3 -1
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/target-info.h" #include "qom/compat-properties.h" #include "qom/object.h" #include "qom/object_interfaces.h"
@@ -167,7 +168,8 @@ static TypeImpl *type_register_internal(const TypeInfo *info)abort (); } -if (info->is_available && !info->is_available ()) { +if (!target_combined_binary () + && info->is_available && !info->is_available ()) {return NULL ; }
system/target-info.c new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "qemu/target-info.h" + +bool target_combined_binary (void ) +{ +return true; +}
tests/unit/meson.build +2 -2
@@ -217,12 +217,12 @@ foreach test_name, extra: tests endforeach # Multi targets test -if multi_target_objects != [] +if is_variable('qemu_system') test('test-multi-target', executable('test-multi-target', sources: [multi_target_crates, files('test-multi-target.c')], dependencies: multi_target_deps, - objects: multi_target_objects, + objects: multi_target_objects + multi_target_info_objects, link_depends: [block_syms, qemu_syms], link_args: multi_target_link_args), suite: ['unit'])
tests/unit/test-multi-target.c +2 -3
@@ -49,6 +49,8 @@ static bool target_arch_available(uint64_t arch_mask)static void test_qom_types_are_unique (void ) {g_assert (targets); +/* Verify this test runs like the combined qemu-system binary. */ +g_assert_true (target_combined_binary ());/* trigger type_initialize for all types */ object_class_get_list ("" , false);
@@ -89,9 +91,6 @@ int main(int argc, char **argv)target_info_qom_init (); targets =target_info_qom_get_targets (); -const TargetInfo *first_ti =TARGET_INFO_CLASS (targets->data)->target_info; -target_info_qom_set_target_info (first_ti); -/* register all types */ module_call_init (MODULE_INIT_QOM );
Signature · 1 line
2.55.0.windows.3
PATCH 31/34 qmp: Expose supported targets in query-machines
In reply to Yonggang Luo--- hw/core/machine-qmp-cmds.c | 16 ++++++++++++++++ qapi/machine.json | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-)
hw/core/machine-qmp-cmds.c +16 -0
@@ -21,8 +21,10 @@#include "qapi/qobject-input-visitor.h" #include "qapi/type-helpers.h" #include "qemu/uuid.h" +#include "qemu/base-arch-defs.h" #include "qemu/target-info.h" #include "qemu/target-info-qapi.h" +#include "qemu/target-info-qom.h" #include "qom/qom-qobject.h" #include "system/hostmem.h" #include "system/hw_accel.h"
@@ -104,6 +106,8 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props,MachineClass *mc = el->data;const char *default_cpu_type =machine_class_default_cpu_type (mc);MachineInfo *info; +QemuTargetInfoList **target_tail; +GSList *tel; info =g_malloc0 (sizeof (*info));if (mc->is_default) {
@@ -130,6 +134,18 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props, } info->secure =object_class_is_secure (OBJECT_CLASS (mc)); + target_tail = &info->targets; +for (tel =target_info_qom_get_targets (); tel; tel = tel->next) { +const TargetInfo *ti =TARGET_INFO_CLASS (tel->data)->target_info; + +if (mc->targets &QEMU_ARCH_BIT (ti->target_arch)) { +QemuTargetInfo *target =g_new0 (QemuTargetInfo,1 ); + + target->arch = ti->target_arch; +QAPI_LIST_APPEND (target_tail, target); + } + } +if (compat_props && mc->compat_props) {int i; info->compat_props =NULL ;
qapi/machine.json +4 -1
@@ -189,6 +189,9 @@ # # @acpi: machine type supports ACPI (since 8.0) # +# @targets: targets supported by this machine +# (since 11.2) +# # @compat-props: The machine type's compatibility properties. Only # present when `query-machines` argument @compat-props is true. # (since 9.1)
@@ -212,7 +215,7 @@ '*default-ram-id': 'str', 'acpi': 'bool', '*compat-props': { 'type': ['CompatProperty'], 'features': ['unstable'] }, - 'secure': 'bool' } } + 'secure': 'bool', 'targets': ['QemuTargetInfo'] } } ## # @query-machines:
Signature · 1 line
2.55.0.windows.3
PATCH 32/34 system/vl: select target from machine name in combined binaries
In reply to Yonggang LuoMatch -machine $target_arch-$machine_name against registered machine names and aliases. Also accept -machine $machine_name when it uniquely identifies a machine; report architecture-qualified choices when it is ambiguous.
This do not change single-target behavior.
--- system/vl.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 9 deletions(-)
system/vl.c +124 -9
@@ -1205,6 +1205,77 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } +static bool machine_target_matches (MachineClass *mc,const TargetInfo *ti, +const char *name) +{ +const char *names[] = { mc->name, mc->alias }; + +for (unsigned i =0 ; i <ARRAY_SIZE (names); i++) { +if (names[i]) { +if (!strcmp (name, names[i])) { +return true; + } + g_autofree char *qualified = +g_strdup_printf ("%s-%s" , ti->target_name, names[i]); + +if (!strcmp (name, qualified)) { +return true; + } + } + } +return false; +} + +static MachineClass *machine_target_select (GSList *machines,GSList **targets, +const char *name,Error **errp) +{ +ERRP_GUARD (); +MachineClass *machine =NULL ; +const TargetInfo *target =NULL ; +g_autoptr (GString) hints =g_string_new (NULL ); +unsigned count =0 ; +GSList *el; +GSList *tel; + + *targets =object_class_get_list (TYPE_TARGET_INFO , false); +if (!name) { +return NULL ; + } + +for (el = machines; el; el = el->next) { +MachineClass *mc = el->data; + +for (tel = *targets; tel; tel = tel->next) { +const TargetInfo *ti =TARGET_INFO_CLASS (tel->data)->target_info; + +if ((mc->targets &QEMU_ARCH_BIT (ti->target_arch)) && +machine_target_matches (mc, ti, name)) { + count++; + machine = mc; + target = ti; +g_string_append_printf (hints," -machine %s-%s\n" , + ti->target_name, mc->name); + } + } + } +if (!count) { +error_setg (errp,"unsupported machine type: \"%s\"" , name); +error_append_hint (errp,"Use -machine help to list supported names, " +"then select <arch>-<machine-name> or an " +"unambiguous <machine-name>\n" ); +return NULL ; + } +if (count !=1 ) { +error_setg (errp,"machine name '%s' is ambiguous" , name); +error_append_hint (errp,"Select an architecture-prefixed name:\n%s" , + hints->str); +return NULL ; + } + +target_info_qom_set_target_info (target); +return machine; +} +static int device_help_func (void *opaque,QemuOpts *opts,Error **errp) {return qdev_device_help (opts);
@@ -1565,16 +1636,23 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d)static void machine_help_func (const QDict *qdict) {g_autoptr (GSList) machines =NULL ; +g_autoptr (GSList) targets =NULL ;GSList *el; +GSList *tel;const char *type =qdict_get_try_str (qdict,"type" ); +MachineClass *machine_class =NULL ; machines =object_class_get_list (TYPE_MACHINE , false); -if (type) { -ObjectClass *machine_class =OBJECT_CLASS (find_machine (type, machines)); -if (machine_class) { -type_print_class_properties (object_class_get_name (machine_class)); -return ; - } +if (target_combined_binary ()) { + machine_class =machine_target_select (machines, &targets, type, + &error_fatal); + }else if (type) { + machine_class =find_machine (type, machines); + } +if (machine_class) { +type_print_class_properties ( +object_class_get_name (OBJECT_CLASS (machine_class))); +return ; }printf ("Supported machines are:\n" );
@@ -1585,9 +1663,20 @@ static void machine_help_func(const QDict *qdict)printf ("%-20s %s (alias of %s)\n" , mc->alias, mc->desc, mc->name); }printf ("%-20s %s%s%s%s\n" , mc->name, mc->desc, - mc->is_default ?" (default)" :"" , + mc->is_default && !target_combined_binary () ?" (default)" :"" , mc->deprecation_reason ?" (deprecated)" :"" ,object_class_is_secure (OBJECT_CLASS (mc)) ?" (secure)" :"" ); +for (tel = targets; tel; tel = tel->next) { +const TargetInfo *ti =TARGET_INFO_CLASS (tel->data)->target_info; + +if (mc->targets &QEMU_ARCH_BIT (ti->target_arch)) { +printf (" %s-%s\n" , ti->target_name, mc->name); +if (mc->alias &&strcmp (mc->name, mc->alias)) { +printf (" %s-%s (alias)\n" , + ti->target_name, mc->alias); + } + } + } } }
@@ -1684,6 +1773,26 @@ static MachineClass *select_machine(QDict *qdict, Error **errp)g_autoptr (GSList) machines =object_class_get_list (TYPE_MACHINE , false);MachineClass *machine_class =NULL ; +if (target_combined_binary ()) { +g_autoptr (GSList) targets =NULL ; + +if (!machine_type) { +error_setg (errp,"No machine specified; combined binaries " +"have no default machine" ); +error_append_hint (errp, +"Use -machine help to list supported names, " +"then select <arch>-<machine-name> or an " +"unambiguous <machine-name>\n" ); +return NULL ; + } + machine_class =machine_target_select (machines, &targets, machine_type, + errp); +if (machine_class) { +qdict_del (qdict,"type" ); + } +return machine_class; + } +if (machine_type) { machine_class =find_machine (machine_type, machines);if (!machine_class) {
@@ -2913,10 +3022,16 @@ void qemu_init(int argc, char **argv)os_setup_limits ();target_info_qom_init (); -target_info_qom_set_target (); +if (!target_combined_binary ()) { +target_info_qom_set_target (); + }module_init_info (qemu_modinfo); -module_allow_arch (target_name ()); +if (target_combined_binary ()) { +module_allow_all_arch (); + }else { +module_allow_arch (target_name ()); + }qemu_init_subsystems ();
Signature · 1 line
2.55.0.windows.3
PATCH 33/34 system/vl: handle cpu/device help properly for multi-target qemu
In reply to Yonggang LuoThis achieved by select the target by provided -machine $type option. Error when anything wrong.
--- system/vl.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
system/vl.c +28 -1
@@ -1278,6 +1278,18 @@ static MachineClass *machine_target_select(GSList *machines, GSList **targets,static int device_help_func (void *opaque,QemuOpts *opts,Error **errp) { +const char *driver =qemu_opt_get (opts,"driver" ); + +if (target_combined_binary () && driver && + (is_help_option (driver) ||qemu_opt_has_help_opt (opts))) { +const char *name =qdict_get_try_str (machine_opts_dict,"type" ); + +g_autoptr (GSList) machines =object_class_get_list (TYPE_MACHINE , + false); +g_autoptr (GSList) targets =NULL ; + +machine_target_select (machines, &targets, name, &error_fatal); + }return qdev_device_help (opts); }
@@ -2761,9 +2773,24 @@ static void qemu_process_help_options(void)* Check for -cpu help and -device help before we call select_machine(), * which will return an error if the architecture has no default machine * type and the user did not specify one, so that the user doesn't need -* to say '-cpu help -machine something'. +* to say '-cpu help -machine something' in single-target binaries. */ if (cpu_option &&is_help_option (cpu_option)) { +if (target_combined_binary ()) { +const char *name =qdict_get_try_str (machine_opts_dict,"type" ); + +if (!name) { +error_report ("-cpu help requires -machine " +"<arch>-<machine-name> or an unambiguous " +"<machine-name> in a combined binary" ); +exit (EXIT_FAILURE ); + } +g_autoptr (GSList) machines = +object_class_get_list (TYPE_MACHINE , false); +g_autoptr (GSList) targets =NULL ; + +machine_target_select (machines, &targets, name, &error_fatal); + }list_cpus ();exit (0 ); }
Signature · 1 line
2.55.0.windows.3
PATCH 34/34 qdev: Handle device alias ambiguous under multi-target qemu
In reply to Yonggang LuoFor example:
./qemu-system -device virtio-blk,help
will raise the following error:
qemu-system: -device virtio-blk,help: Device alias 'virtio-blk' is ambiguous without a selected machine Specify -machine <arch>-<machine-name> or an unambiguous <machine-name>, or use a concrete device name:
virtio-blk-device
virtio-blk-pci
--- include/monitor/qdev.h | 7 ++++++ system/qdev-monitor.c | 52 ++++++++++++++++++++++++++++++++++++++---- system/vl.c | 7 +++--- 3 files changed, 58 insertions(+), 8 deletions(-)
include/monitor/qdev.h +7 -0
@@ -10,6 +10,13 @@ void hmp_info_qtree(MonitorHMP *hmp, const QDict *qdict);void hmp_info_qdm (MonitorHMP *hmp,const QDict *qdict);void qmp_device_add (QDict *qdict,QObject **ret_data,Error **errp); +/** +* qdev_device_help: print device listing or property help when requested. +* @opts: device options +* +* Returns: 0 if no help was requested, 1 if handled, or -1 if an ambiguous +* alias prevented help. Other property-help errors retain the handled result. +*/ int qdev_device_help (QemuOpts *opts);DeviceState *qdev_device_add (QemuOpts *opts,Error **errp); DeviceState *qdev_device_add_from_qdict(const QDict *opts,
system/qdev-monitor.c +47 -5
88 lines not on this page · raw message
system/vl.c +4 -3
@@ -2795,9 +2795,10 @@ static void qemu_process_help_options(void)exit (0 ); } -if (qemu_opts_foreach (qemu_find_opts ("device" ), - device_help_func,NULL ,NULL )) { -exit (0 ); +int device_help =qemu_opts_foreach (qemu_find_opts ("device" ), + device_help_func,NULL ,NULL ); +if (device_help) { +exit (device_help <0 ?EXIT_FAILURE :EXIT_SUCCESS ); }/* -L help lists the data directories and exits. */
Signature · 1 line
2.55.0.windows.3
Quoted 38 lines · Yonggang Luo
Done by merge
virtio_mem_legacy_guests_propertiesintovirtio_mem_properties. As we already havevmem->unplugged_inaccessiblehandle invirtio_mem_device_realizeSo we can reject the wrong option invirtio_mem_device_realize, then the calltarget_info()inclass_initno need anymore.Signed-off-by Yonggang Luo <[email protected]>--- hw/virtio/virtio-mem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)hw/virtio/virtio-mem.c +5
-4@@ -879,7 +879,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)break ; } }else { - vmem->unplugged_inaccessible =ON_OFF_AUTO_ON ; +if (vmem->unplugged_inaccessible !=ON_OFF_AUTO_ON ) { +error_setg (errp,"'%s' must be 'on' on non-x86 targets" , +VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ); +return ; + } } if (vmem->dynamic_memslots &&@@ -1568,9 +1572,6 @@ static const Property virtio_mem_properties[] = { early_migration, true),DEFINE_PROP_BOOL (VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP ,VirtIOMEM ,dynamic_memslots ,false ), -}; - -static const Property virtio_mem_legacy_guests_properties[] = {DEFINE_PROP_ON_OFF_AUTO (VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ,VirtIOMEM , unplugged_inaccessible, ON_OFF_AUTO_ON), };
hw/virtio/virtio-mem.c static void virtio_mem_class_init(ObjectClass *klass, const void *data) · line 1641
Quoted 9 lines
hw/virtio/virtio-mem.c +0
-3@@ -1635,9 +1636,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);
Not sure what happened with the sending, but it seems like this series has been split in two threads.
Quoted 48 lines · Pierrick Bouvier
Quoted 46 lines · Yonggang Luo
Done by merge
virtio_mem_legacy_guests_propertiesintovirtio_mem_properties. As we already havevmem->unplugged_inaccessiblehandle invirtio_mem_device_realizeSo we can reject the wrong option invirtio_mem_device_realize, then the calltarget_info()inclass_initno need anymore.Signed-off-by Yonggang Luo <[email protected]>--- hw/virtio/virtio-mem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)hw/virtio/virtio-mem.c +5
-7@@ -879,7 +879,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)break ; } }else { - vmem->unplugged_inaccessible =ON_OFF_AUTO_ON ; +if (vmem->unplugged_inaccessible !=ON_OFF_AUTO_ON ) { +error_setg (errp,"'%s' must be 'on' on non-x86 targets" , +VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ); +return ; + } } if (vmem->dynamic_memslots &&@@ -1568,9 +1572,6 @@ static const Property virtio_mem_properties[] = { early_migration, true),DEFINE_PROP_BOOL (VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP ,VirtIOMEM ,dynamic_memslots ,false ), -}; - -static const Property virtio_mem_legacy_guests_properties[] = {DEFINE_PROP_ON_OFF_AUTO (VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ,VirtIOMEM , unplugged_inaccessible, ON_OFF_AUTO_ON), };@@ -1635,9 +1636,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;
Quoted 4 lines
hw/virtio/virtio-mem.c static void virtio_mem_class_init(ObjectClass *klass, const void *data) · line 1641
Quoted 1 line
hw/virtio/virtio-mem.c +0
-0set_bit (DEVICE_CATEGORY_MISC , dc->categories);Not sure what happened with the sending, but it seems like this series has been split in two threads.
I accidentally broke the sending procedure, till I found it's too late, what I am confused about is why when I recover to send the rest, it's not in the same threads. I am using git-publish.
Signature · 6 lines
此致
礼
罗勇刚
Yours
sincerely,
Yonggang LuoQuoted 38 lines · Yonggang Luo
Done by merge
virtio_mem_legacy_guests_propertiesintovirtio_mem_properties. As we already havevmem->unplugged_inaccessiblehandle invirtio_mem_device_realizeSo we can reject the wrong option invirtio_mem_device_realize, then the calltarget_info()inclass_initno need anymore.Signed-off-by Yonggang Luo <[email protected]>--- hw/virtio/virtio-mem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)hw/virtio/virtio-mem.c +5
-4@@ -879,7 +879,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)break ; } }else { - vmem->unplugged_inaccessible =ON_OFF_AUTO_ON ; +if (vmem->unplugged_inaccessible !=ON_OFF_AUTO_ON ) { +error_setg (errp,"'%s' must be 'on' on non-x86 targets" , +VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ); +return ; + } } if (vmem->dynamic_memslots &&@@ -1568,9 +1572,6 @@ static const Property virtio_mem_properties[] = { early_migration, true),DEFINE_PROP_BOOL (VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP ,VirtIOMEM ,dynamic_memslots ,false ), -}; - -static const Property virtio_mem_legacy_guests_properties[] = {DEFINE_PROP_ON_OFF_AUTO (VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ,VirtIOMEM , unplugged_inaccessible, ON_OFF_AUTO_ON), };
hw/virtio/virtio-mem.c static void virtio_mem_class_init(ObjectClass *klass, const void *data) · line 1641
Quoted 9 lines
hw/virtio/virtio-mem.c +0
-3@@ -1635,9 +1636,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);
Now a property introspection shows properties that don't make any sense for other targets.
I don't see the value, really.
Signature · 3 lines
Cheers, David
Quoted 48 lines · David Hildenbrand
Quoted 46 lines · Yonggang Luo
Done by merge
virtio_mem_legacy_guests_propertiesintovirtio_mem_properties. As we already havevmem->unplugged_inaccessiblehandle invirtio_mem_device_realizeSo we can reject the wrong option invirtio_mem_device_realize, then the calltarget_info()inclass_initno need anymore.Signed-off-by Yonggang Luo <[email protected]>--- hw/virtio/virtio-mem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)hw/virtio/virtio-mem.c +5
-7@@ -879,7 +879,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)break ; } }else { - vmem->unplugged_inaccessible =ON_OFF_AUTO_ON ; +if (vmem->unplugged_inaccessible !=ON_OFF_AUTO_ON ) { +error_setg (errp,"'%s' must be 'on' on non-x86 targets" , +VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ); +return ; + } } if (vmem->dynamic_memslots &&@@ -1568,9 +1572,6 @@ static const Property virtio_mem_properties[] = { early_migration, true),DEFINE_PROP_BOOL (VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP ,VirtIOMEM ,dynamic_memslots ,false ), -}; - -static const Property virtio_mem_legacy_guests_properties[] = {DEFINE_PROP_ON_OFF_AUTO (VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP ,VirtIOMEM , unplugged_inaccessible, ON_OFF_AUTO_ON), };@@ -1635,9 +1636,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;
Quoted 6 lines
hw/virtio/virtio-mem.c static void virtio_mem_class_init(ObjectClass *klass, const void *data) · line 1641
Quoted 1 line
hw/virtio/virtio-mem.c +0
-0set_bit (DEVICE_CATEGORY_MISC , dc->categories);Now a property introspection shows properties that don't make any sense for other targets.
I don't see the value, really.
This is the only way I can get a usable qemu-system(single-binary), looks ugly but I have already tried other means.
Using "is_avaiable" basically has the same effect like the one before this change.
And renaming the QOM name would cause much more issues. I'll wait for others to do these.
I've tried my best, sorry.
Quoted 6 lines
--
Cheers,David
Signature · 6 lines
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo