Skip to contentSkip to conversation

single-binary: Select the softmmu target through -machine <type>

PATCH In review Yonggang Luo 5 participants 26 messages Oct 14 – Oct 15 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover single-binary: Select the softmmu target through -machine <type>

MachineClass::targets declares each machine's supported targets as a uint64_t QEMU_ARCH_* mask.

In the combined executable, a machine can be selected from <target>-<machine-name> when <machine-name> is ambitious. Otherwise we can use <machine-name> to directly select a target.

Renaming SysEmuTarget to EmuTarget prepares the enum for both system and user-mode targets before introducing more usage of it. Rationale:
https://lore.kernel.org/qemu-devel/[email protected]/

The "virt" machines need distinct QOM names to coexist in a combined binary or test. Their existing CLI names and aliases are preserved.

Other indirect call of target_info() in class_init/type_init is removed by serveral commits, this is a prepare for select <target> by -machine $type. As target_info() will be NULL till the target is selected under machine_select.

The commits through "hw: add MachineClass::targets with a usage and test" add a minimal demo/test for introduce MachineClass::targets

The next group, through
"meson: build combined qemu-system for multi-target configurations", enabled the test guard to prevent introduce future calling target_info() in type_init or class_init

These two boundaries provide possible merge points.

"targets" be exported along with MachineInfo in commit
"qmp: Expose supported targets in query-machines", so that the qmp know how to set proper $<target>-<machine-name>.

The rest commits is the introduce of support of <target> select from -machine $type.

Yonggang Luo (34):
qemu/base-arch-defs: extract QEMU_ARCH_BIT for QEMU_ARCH_* enums
qemu: Use SYS_EMU_TARGET__MAX to define QEMU_ARCH_ALL
qemu: increase width of QEMU_ARCH_* masks enums to be 64 bits
qapi: rename SysEmuTarget to EmuTarget
qapi: add missing Linux user-mode targets to EmuTarget
meson: define TARGET_ARCH_VARIANT to target_name only
target-info: prepare the QOM target list before
module_call_init(MODULE_INIT_QOM)
hw: add MachineClass::targets with a usage and test
accel: register CPU parent for each target
meson: collect Rust crates for combined system target
module: Add module_allow_all_arch for allow all modules be loaded target/arm: defer max-v8 initializer selection until CPU creation hw/microblaze: defer PetaLogix endianness default until init hw/pci: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/scsi: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/virtio/virtio-mem: Avoid call to target_info() in class_init
target-info: add a combined-binary query stub
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: Add MachineClass.targets for all "virt" machines for all possible
targets
system/arch_init: update qemu_arch_available to handle non-target
select condition
meson: build combined qemu-system for multi-target configurations
qmp: Expose supported targets in query-machines
system/vl: select target from machine name in combined binaries system/vl: handle cpu/device help properly for multi-target qemu
qdev: Handle device alias ambiguous under multi-target qemu

 MAINTAINERS                              |   2 +
 accel/accel-common.c                     |   6 +-
 accel/accel-internal.h                   |   1 +
 accel/accel-system.c                     |  24 +++
 accel/accel-user.c                       |   7 +
 backends/igvm.c                          |   4 +-
 hw/alpha/dp264.c                         |   2 +
 hw/arm/virt.c                            |  56 +++----
 hw/core/machine-qmp-cmds.c               |  19 ++-
 hw/core/machine.c                        |   9 ++
 hw/hexagon/virt.c                        |  25 +++-
 hw/loongarch/virt.c                      |  47 +++---
 hw/m68k/virt.c                           |  39 +++--
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  11 +-
 hw/misc/vmlaunchupdate.c                 |   6 +-
 hw/or1k/virt.c                           |  22 +--
 hw/pci/pci.c                             |  18 ++-
 hw/riscv/virt.c                          |  28 ++--
 hw/scsi/scsi-disk.c                      |  18 ++-
 hw/uefi/ovmf-log.c                       |   4 +-
 hw/virtio/virtio-mem.c                   |  26 ++--
 hw/xtensa/virt.c                         |  24 ++-
 include/hw/arm/virt.h                    |   5 +-
 include/hw/core/boards.h                 |  45 ++++--
 include/hw/hexagon/virt.h                |   5 +-
 include/hw/loongarch/virt.h              |   5 +-
 include/hw/riscv/virt.h                  |   5 +-
 include/monitor/qdev.h                   |   7 +
 include/qemu/base-arch-defs.h            |  80 ++++++----
 include/qemu/module.h                    |   2 +
 include/qemu/target-info-def.h           |   2 +-
 include/qemu/target-info-qapi.h          |   4 +-
 include/qemu/target-info-qom.h           |   4 +
 include/qemu/target-info.h               |   7 +
 meson.build                              |  82 +++++++++-
 monitor/monitor-hmp-internal.h           |   2 +-
 qapi/machine.json                        |  44 +++---
 qapi/pragma.json                         |   4 +-
 qom/object.c                             |   4 +-
 stubs/meson.build                        |   1 +
 stubs/target-info.c                      |  10 ++
 system/arch_init.c                       |  12 +-
 system/qdev-monitor.c                    |  54 ++++++-
 system/target-info.c                     |  10 ++
 system/vl.c                              | 181 ++++++++++++++++++++---
 target-info-def.c                        |   2 +-
 target-info-qom.c                        |  26 +++-
 target-info.c                            |  38 ++---
 target/arm/tcg/cpu-max-v8.c              |  17 ++-
 tests/qtest/fuzz/fuzz.c                  |   2 +-
 tests/qtest/qom-test.c                   |  65 +++++++-
 tests/unit/meson.build                   |   4 +-
 tests/unit/test-multi-target.c           |  67 ++++++++-
 util/module.c                            |  10 +-
 54 files changed, 915 insertions(+), 289 deletions(-)
 create mode 100644 stubs/target-info.c
 create mode 100644 system/target-info.c
Signature · 1 line
2.55.0.windows.3
#1 lore raw

PATCH 1/34 qemu/base-arch-defs: extract QEMU_ARCH_BIT for QEMU_ARCH_* enums

---
 include/qemu/base-arch-defs.h | 60 ++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 29 deletions(-)
include/qemu/base-arch-defs.h +31 -29
index f33465738c9..806ad8094a4 100644
@@ -9,36 +9,38 @@
 
 #include "qapi/qapi-types-machine.h"
 
+#define QEMU_ARCH_BIT(target) (1UL << (target))
+
 enum {
-    QEMU_ARCH_ALPHA =       (1UL << SYS_EMU_TARGET_ALPHA),
-    QEMU_ARCH_ARM =         (1UL << SYS_EMU_TARGET_ARM) |
-                            (1UL << SYS_EMU_TARGET_AARCH64),
-    QEMU_ARCH_I386 =        (1UL << SYS_EMU_TARGET_I386) |
-                            (1UL << SYS_EMU_TARGET_X86_64),
-    QEMU_ARCH_M68K =        (1UL << SYS_EMU_TARGET_M68K),
-    QEMU_ARCH_MICROBLAZE =  (1UL << SYS_EMU_TARGET_MICROBLAZE),
-    QEMU_ARCH_MIPS =        (1UL << SYS_EMU_TARGET_MIPS) |
-                            (1UL << SYS_EMU_TARGET_MIPSEL) |
-                            (1UL << SYS_EMU_TARGET_MIPS64) |
-                            (1UL << SYS_EMU_TARGET_MIPS64EL),
-    QEMU_ARCH_PPC =         (1UL << SYS_EMU_TARGET_PPC) |
-                            (1UL << SYS_EMU_TARGET_PPC64),
-    QEMU_ARCH_S390X =       (1UL << SYS_EMU_TARGET_S390X),
-    QEMU_ARCH_SH4 =         (1UL << SYS_EMU_TARGET_SH4) |
-                            (1UL << SYS_EMU_TARGET_SH4EB),
-    QEMU_ARCH_SPARC =       (1UL << SYS_EMU_TARGET_SPARC) |
-                            (1UL << SYS_EMU_TARGET_SPARC64),
-    QEMU_ARCH_XTENSA =      (1UL << SYS_EMU_TARGET_XTENSA) |
-                            (1UL << SYS_EMU_TARGET_XTENSAEB),
-    QEMU_ARCH_OR1K =        (1UL << SYS_EMU_TARGET_OR1K),
-    QEMU_ARCH_TRICORE =     (1UL << SYS_EMU_TARGET_TRICORE),
-    QEMU_ARCH_HPPA =        (1UL << SYS_EMU_TARGET_HPPA),
-    QEMU_ARCH_RISCV =       (1UL << SYS_EMU_TARGET_RISCV32) |
-                            (1UL << SYS_EMU_TARGET_RISCV64),
-    QEMU_ARCH_RX =          (1UL << SYS_EMU_TARGET_RX),
-    QEMU_ARCH_AVR =         (1UL << SYS_EMU_TARGET_AVR),
-    QEMU_ARCH_HEXAGON =     (1UL << SYS_EMU_TARGET_HEXAGON),
-    QEMU_ARCH_LOONGARCH =   (1UL << SYS_EMU_TARGET_LOONGARCH64),
+    QEMU_ARCH_ALPHA =       QEMU_ARCH_BIT(SYS_EMU_TARGET_ALPHA),
+    QEMU_ARCH_ARM =         QEMU_ARCH_BIT(SYS_EMU_TARGET_ARM) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_AARCH64),
+    QEMU_ARCH_I386 =        QEMU_ARCH_BIT(SYS_EMU_TARGET_I386) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_X86_64),
+    QEMU_ARCH_M68K =        QEMU_ARCH_BIT(SYS_EMU_TARGET_M68K),
+    QEMU_ARCH_MICROBLAZE =  QEMU_ARCH_BIT(SYS_EMU_TARGET_MICROBLAZE),
+    QEMU_ARCH_MIPS =        QEMU_ARCH_BIT(SYS_EMU_TARGET_MIPS) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_MIPSEL) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_MIPS64) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_MIPS64EL),
+    QEMU_ARCH_PPC =         QEMU_ARCH_BIT(SYS_EMU_TARGET_PPC) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_PPC64),
+    QEMU_ARCH_S390X =       QEMU_ARCH_BIT(SYS_EMU_TARGET_S390X),
+    QEMU_ARCH_SH4 =         QEMU_ARCH_BIT(SYS_EMU_TARGET_SH4) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_SH4EB),
+    QEMU_ARCH_SPARC =       QEMU_ARCH_BIT(SYS_EMU_TARGET_SPARC) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_SPARC64),
+    QEMU_ARCH_XTENSA =      QEMU_ARCH_BIT(SYS_EMU_TARGET_XTENSA) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_XTENSAEB),
+    QEMU_ARCH_OR1K =        QEMU_ARCH_BIT(SYS_EMU_TARGET_OR1K),
+    QEMU_ARCH_TRICORE =     QEMU_ARCH_BIT(SYS_EMU_TARGET_TRICORE),
+    QEMU_ARCH_HPPA =        QEMU_ARCH_BIT(SYS_EMU_TARGET_HPPA),
+    QEMU_ARCH_RISCV =       QEMU_ARCH_BIT(SYS_EMU_TARGET_RISCV32) |
+                            QEMU_ARCH_BIT(SYS_EMU_TARGET_RISCV64),
+    QEMU_ARCH_RX =          QEMU_ARCH_BIT(SYS_EMU_TARGET_RX),
+    QEMU_ARCH_AVR =         QEMU_ARCH_BIT(SYS_EMU_TARGET_AVR),
+    QEMU_ARCH_HEXAGON =     QEMU_ARCH_BIT(SYS_EMU_TARGET_HEXAGON),
+    QEMU_ARCH_LOONGARCH =   QEMU_ARCH_BIT(SYS_EMU_TARGET_LOONGARCH64),
     QEMU_ARCH_ALL =         UINT32_MAX,
 };
 
Signature · 1 line
2.55.0.windows.3
#2 lore raw

PATCH 2/34 qemu: Use SYS_EMU_TARGET__MAX to define QEMU_ARCH_ALL

In reply to Yonggang Luo

This is more precise, so we can iterate all target_arch with QEMU_ARCH_ALL

---
 include/qemu/base-arch-defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/base-arch-defs.h +1 -1
index 806ad8094a4..a6478c2d3ff 100644
@@ -41,7 +41,7 @@ enum {
     QEMU_ARCH_AVR =         QEMU_ARCH_BIT(SYS_EMU_TARGET_AVR),
     QEMU_ARCH_HEXAGON =     QEMU_ARCH_BIT(SYS_EMU_TARGET_HEXAGON),
     QEMU_ARCH_LOONGARCH =   QEMU_ARCH_BIT(SYS_EMU_TARGET_LOONGARCH64),
-    QEMU_ARCH_ALL =         UINT32_MAX,
+    QEMU_ARCH_ALL =         QEMU_ARCH_BIT(SYS_EMU_TARGET__MAX) - 1,
 };
 
 QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 32);
Signature · 1 line
2.55.0.windows.3
#3 lore raw

PATCH 3/34 qemu: increase width of QEMU_ARCH_* masks enums to be 64 bits

In reply to Yonggang Luo

SYS_EMU_TARGET__MAX is already 29, nearing the 32-target limit. So increase width of QEMU_ARCH_* masks enums and related types; So that we can add needed Linux user-mode targets to EmuTarget; And also enabled the possibility add more system-mode targets in future.

---
 include/qemu/base-arch-defs.h  | 7 ++++---
 monitor/monitor-hmp-internal.h | 2 +-
 system/arch_init.c             | 4 ++--
 system/qdev-monitor.c          | 2 +-
 system/vl.c                    | 2 +-
 5 files changed, 9 insertions(+), 8 deletions(-)
include/qemu/base-arch-defs.h +4 -3
index a6478c2d3ff..f2e3bc54203 100644
@@ -9,7 +9,7 @@
 
 #include "qapi/qapi-types-machine.h"
 
-#define QEMU_ARCH_BIT(target) (1UL << (target))
+#define QEMU_ARCH_BIT(target) (1ULL << (target))
 
 enum {
     QEMU_ARCH_ALPHA =       QEMU_ARCH_BIT(SYS_EMU_TARGET_ALPHA),
@@ -44,7 +44,8 @@ enum {
     QEMU_ARCH_ALL =         QEMU_ARCH_BIT(SYS_EMU_TARGET__MAX) - 1,
 };
 
-QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 32);
+/* Keep target-specific masks within qemu_opt_set_number()'s int64_t range. */
+QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 63);
 
 /**
  * qemu_arch_available:
@@ -52,6 +53,6 @@ QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 32);
  *
  * Return whether the current target architecture is contained in @arch_bitmask
  */
-bool qemu_arch_available(uint32_t arch_bitmask);
+bool qemu_arch_available(uint64_t arch_bitmask);
 
 #endif
monitor/monitor-hmp-internal.h +1 -1
index 4e2430551ab..b61d2717076 100644
@@ -69,7 +69,7 @@ typedef struct HMPCommand {
      *     Allow to restrict the command for a particular set of
      *     target architectures.
      */
-    uint32_t arch_bitmask;
+    uint64_t arch_bitmask;
     bool coroutine;
 } HMPCommand;
 
system/arch_init.c +2 -2
index 1ad2f3d6f78..b8362b12a6d 100644
@@ -26,7 +26,7 @@
 #include "qemu/bitops.h"
 #include "qemu/target-info-qapi.h"
 
-bool qemu_arch_available(uint32_t arch_bitmask)
+bool qemu_arch_available(uint64_t arch_bitmask)
 {
-    return extract32(arch_bitmask, target_arch(), 1);
+    return extract64(arch_bitmask, target_arch(), 1);
 }
system/qdev-monitor.c +1 -1
index 8185822daa7..b3ca619f3c9 100644
@@ -54,7 +54,7 @@ typedef struct QDevAlias
 {
     const char *typename;
     const char *alias;
-    uint32_t arch_mask;
+    uint64_t arch_mask;
 } QDevAlias;
 
 /* default virtio transport per architecture */
system/vl.c +1 -1
index 468a9fc247a..fbe580746d3 100644
@@ -928,7 +928,7 @@ typedef struct QEMUOption {
     const char *name;
     int flags;
     int index;
-    uint32_t arch_mask;
+    uint64_t arch_mask;
 } QEMUOption;
 
 static const QEMUOption qemu_options[] = {
Signature · 1 line
2.55.0.windows.3
#4 lore raw

PATCH 4/34 qapi: rename SysEmuTarget to EmuTarget

In reply to Yonggang Luo

As now it's also expressing user-mode targets.

This changes the type name exposed by query-qmp-schema; enum values and serialized target values remain unchanged.

---
 backends/igvm.c                 |  4 +--
 hw/core/machine-qmp-cmds.c      |  2 +-
 hw/misc/vmlaunchupdate.c        |  6 ++--
 hw/uefi/ovmf-log.c              |  4 +--
 hw/virtio/virtio-mem.c          | 14 ++++----
 include/qemu/base-arch-defs.h   | 62 ++++++++++++++++-----------------
 include/qemu/target-info-def.h  |  2 +-
 include/qemu/target-info-qapi.h |  4 +--
 qapi/machine.json               |  8 ++---
 qapi/pragma.json                |  4 +--
 target-info-def.c               |  2 +-
 target-info.c                   | 26 +++++++-------
 12 files changed, 69 insertions(+), 69 deletions(-)
backends/igvm.c +2 -2
index 58f3097e851..f4045bb8651 100644
@@ -535,7 +535,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
             vp_context->gpa, data,
             igvm_get_buffer_size(ctx->cfg->file, data_handle),
             CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp);
-    } else if (target_arch() == SYS_EMU_TARGET_X86_64) {
+    } else if (target_arch() == EMU_TARGET_X86_64) {
         result = qigvm_x86_set_vp_context(data, vp_context->vp_index, errp);
     } else {
         error_setg(
@@ -647,7 +647,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
     if (ctx->machine_state->cgs && ctx->cgsc->get_mem_map_entry) {
         get_mem_map_entry = ctx->cgsc->get_mem_map_entry;
 
-    } else if (target_arch() == SYS_EMU_TARGET_X86_64) {
+    } else if (target_arch() == EMU_TARGET_X86_64) {
         get_mem_map_entry = qigvm_x86_get_mem_map_entry;
 
     } else {
hw/core/machine-qmp-cmds.c +1 -1
index 9c08b17510a..bc614a75c7d 100644
@@ -64,7 +64,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
     MachineState *ms = MACHINE(qdev_get_machine());
     MachineClass *mc = MACHINE_GET_CLASS(ms);
     CpuInfoFastList *head = NULL, **tail = &head;
-    SysEmuTarget target = target_arch();
+    EmuTarget target = target_arch();
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
hw/misc/vmlaunchupdate.c +3 -3
index 847d2d963f1..95cb2263828 100644
@@ -35,7 +35,7 @@ static VMLaunchUpdateState *vm_launchupdate_find(void)
 
 static bool vmlaunchupdate_supported(void)
 {
-    return target_arch() == SYS_EMU_TARGET_X86_64;
+    return target_arch() == EMU_TARGET_X86_64;
 }
 
 static void init_vm_launch_update(VMLaunchUpdateState *s)
@@ -192,7 +192,7 @@ static void launch_update_write(void *dev, off_t offset, size_t len)
 
     /* process guest provided IGVM image */
     if (s->launch_update.control & VM_LAUNCHUPDATE_FORMAT_IGVM) {
-        if (target_arch() == SYS_EMU_TARGET_X86_64) {
+        if (target_arch() == EMU_TARGET_X86_64) {
             addr = le64_to_cpu(s->launch_update.fw_image_addr);
             size = le64_to_cpu(s->launch_update.fw_image_size);
             rc = process_x86_igvm(s, addr, size);
@@ -229,7 +229,7 @@ static void vmlaunch_reset_enter(Object *obj, ResetType type)
 {
     VMLaunchUpdateState *s = VMLAUNCHUPDATE(obj);
 
-    if (target_arch() != SYS_EMU_TARGET_X86_64) {
+    if (target_arch() != EMU_TARGET_X86_64) {
         return;
     }
 
hw/uefi/ovmf-log.c +2 -2
index c4e6a506410..2d8961b80ec 100644
@@ -114,7 +114,7 @@ static dma_addr_t find_ovmf_log(void)
     MachineState *ms = MACHINE(qdev_get_machine());
     dma_addr_t start, end, offset;
 
-    if (target_arch() == SYS_EMU_TARGET_X86_64 &&
+    if (target_arch() == EMU_TARGET_X86_64 &&
         object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE)) {
         X86MachineState *x86ms = X86_MACHINE(ms);
 
@@ -133,7 +133,7 @@ static dma_addr_t find_ovmf_log(void)
         return find_ovmf_log_range(start, end);
     }
 
-    if (target_arch() == SYS_EMU_TARGET_AARCH64 &&
+    if (target_arch() == EMU_TARGET_AARCH64 &&
         object_dynamic_cast(OBJECT(ms), TYPE_VIRT_MACHINE)) {
         VirtMachineState *vms = VIRT_MACHINE(ms);
 
hw/virtio/virtio-mem.c +7 -7
index 7130ed852d9..a4110d61312 100644
@@ -43,8 +43,8 @@ static bool virtio_mem_has_legacy_guests(void)
      * legacy guests.
      */
     switch (target_arch()) {
-    case SYS_EMU_TARGET_I386:
-    case SYS_EMU_TARGET_X86_64:
+    case EMU_TARGET_I386:
+    case EMU_TARGET_X86_64:
         return true;
     default:
         return false;
@@ -181,12 +181,12 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
 static uint64_t virtio_mem_usable_extent_size(void)
 {
     switch (target_arch()) {
-    case SYS_EMU_TARGET_I386:
-    case SYS_EMU_TARGET_X86_64:
-    case SYS_EMU_TARGET_S390X:
+    case EMU_TARGET_I386:
+    case EMU_TARGET_X86_64:
+    case EMU_TARGET_S390X:
         return 2 * 128 * MiB;
-    case SYS_EMU_TARGET_AARCH64:
-    case SYS_EMU_TARGET_ARM:
+    case EMU_TARGET_AARCH64:
+    case EMU_TARGET_ARM:
         return 2 * 512 * MiB;
     default:
         g_assert_not_reached();
include/qemu/base-arch-defs.h +31 -31

71 lines not on this page · raw message

include/qemu/target-info-def.h +1 -1
index 8019d2c7196..479f7ddd39c 100644
@@ -16,7 +16,7 @@ typedef struct TargetInfo {
     /* runtime equivalent of TARGET_NAME definition */
     const char *target_name;
     /* related to TARGET_ARCH definition */
-    SysEmuTarget target_arch;
+    EmuTarget target_arch;
     /* runtime equivalent of TARGET_LONG_BITS definition */
     unsigned long_bits;
     /* runtime equivalent of CPU_RESOLVING_TYPE definition */
include/qemu/target-info-qapi.h +2 -2
index d5ce0523238..42a78ee38bc 100644
@@ -15,9 +15,9 @@
 /**
  * target_arch:
  *
- * Returns: QAPI SysEmuTarget enum (e.g. SYS_EMU_TARGET_X86_64).
+ * Returns: QAPI EmuTarget enum (e.g. EMU_TARGET_X86_64).
  */
-SysEmuTarget target_arch(void);
+EmuTarget target_arch(void);
 
 /**
  * target_endian_mode:
qapi/machine.json +4 -4
index 9b145c635ba..07fac4f0764 100644
@@ -14,7 +14,7 @@
 { 'include': 'machine-common.json' }
 
 ##
-# @SysEmuTarget:
+# @EmuTarget:
 #     The comprehensive enumeration of QEMU system emulation
 #     ("softmmu") targets.  Run "./configure --help" in the project
 #     root directory, and look for the \*-softmmu targets near the
@@ -35,7 +35,7 @@
 #
 # Since: 3.0
 ##
-{ 'enum' : 'SysEmuTarget',
+{ 'enum' : 'EmuTarget',
   'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
              'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',
              'mips64el', 'mipsel', 'or1k', 'ppc',
@@ -95,7 +95,7 @@
                       'qom-path'     : 'str',
                       'thread-id'    : 'int',
                       '*props'       : 'CpuInstanceProperties',
-                      'target'       : 'SysEmuTarget' },
+                      'target'       : 'EmuTarget' },
   'discriminator' : 'target',
   'data'          : { 's390x'        : 'CpuInfoS390' } }
 
@@ -281,7 +281,7 @@
 # Since: 1.2
 ##
 { 'struct': 'QemuTargetInfo',
-  'data': { 'arch': 'SysEmuTarget' } }
+  'data': { 'arch': 'EmuTarget' } }
 
 ##
 # @query-target:
qapi/pragma.json +2 -2
index 342cedc42e7..93a710ee937 100644
@@ -72,7 +72,7 @@
         'SsidSizeMode',
         'String',
         'StringWrapper',
-        'SysEmuTarget',
+        'EmuTarget',
         'ThrottleGroupProperties',
         'VncPrimaryAuth',
         'VncVencryptSubAuth',
@@ -109,7 +109,7 @@
         'QKeyCode',                 # send-key, input-sent-event
         'QapiErrorClass',           # QMP error replies
         'SshHostKeyCheckMode',      # blockdev-add, -blockdev
-        'SysEmuTarget',             # query-cpu-fast, query-target
+        'EmuTarget',                # query-cpu-fast, query-target
         'UuidInfo',                 # query-uuid
         'VncClientInfo',            # query-vnc, query-vnc-servers, ...
         'X86CPURegister32'          # qom-get of x86 CPU properties
target-info-def.c +1 -1
index bcf9cfe1e43..028816f4cf1 100644
@@ -26,7 +26,7 @@ QEMU_BUILD_BUG_ON(TARGET_PAGE_BITS < TARGET_PAGE_BITS_MIN);
 
 static const TargetInfo target_info_stub = {
     .target_name = TARGET_NAME,
-    .target_arch = glue(SYS_EMU_TARGET_, TARGET_ARCH_VARIANT),
+    .target_arch = glue(EMU_TARGET_, TARGET_ARCH_VARIANT),
     .long_bits = TARGET_LONG_BITS,
     .cpu_type = CPU_RESOLVING_TYPE,
     .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
target-info.c +13 -13
index 6b365113955..241be2b5563 100644
@@ -22,7 +22,7 @@ unsigned target_long_bits(void)
     return target_info()->long_bits;
 }
 
-SysEmuTarget target_arch(void)
+EmuTarget target_arch(void)
 {
     return target_info()->target_arch;
 }
@@ -45,8 +45,8 @@ bool target_big_endian(void)
 bool target_base_arm(void)
 {
     switch (target_arch()) {
-    case SYS_EMU_TARGET_ARM:
-    case SYS_EMU_TARGET_AARCH64:
+    case EMU_TARGET_ARM:
+    case EMU_TARGET_AARCH64:
         return true;
     default:
         return false;
@@ -55,29 +55,29 @@ bool target_base_arm(void)
 
 bool target_arm(void)
 {
-    return target_arch() == SYS_EMU_TARGET_ARM;
+    return target_arch() == EMU_TARGET_ARM;
 }
 
 bool target_aarch64(void)
 {
-    return target_arch() == SYS_EMU_TARGET_AARCH64;
+    return target_arch() == EMU_TARGET_AARCH64;
 }
 
 bool target_m68k(void)
 {
-    return target_arch() == SYS_EMU_TARGET_M68K;
+    return target_arch() == EMU_TARGET_M68K;
 }
 
 bool target_or1k(void)
 {
-    return target_arch() == SYS_EMU_TARGET_OR1K;
+    return target_arch() == EMU_TARGET_OR1K;
 }
 
 bool target_base_ppc(void)
 {
     switch (target_arch()) {
-    case SYS_EMU_TARGET_PPC:
-    case SYS_EMU_TARGET_PPC64:
+    case EMU_TARGET_PPC:
+    case EMU_TARGET_PPC64:
         return true;
     default:
         return false;
@@ -86,20 +86,20 @@ bool target_base_ppc(void)
 
 bool target_ppc(void)
 {
-    return target_arch() == SYS_EMU_TARGET_PPC;
+    return target_arch() == EMU_TARGET_PPC;
 }
 
 bool target_ppc64(void)
 {
-    return target_arch() == SYS_EMU_TARGET_PPC64;
+    return target_arch() == EMU_TARGET_PPC64;
 }
 
 bool target_s390x(void)
 {
-    return target_arch() == SYS_EMU_TARGET_S390X;
+    return target_arch() == EMU_TARGET_S390X;
 }
 
 bool target_riscv64(void)
 {
-    return target_arch() == SYS_EMU_TARGET_RISCV64;
+    return target_arch() == EMU_TARGET_RISCV64;
 }
Signature · 1 line
2.55.0.windows.3
#5 lore raw

Re: [PATCH 04/34] qapi: rename SysEmuTarget to EmuTarget

Quoted 4 lines · Yonggang Luo

As now it's also expressing user-mode targets.

This changes the type name exposed by query-qmp-schema; enum values and serialized target values remain unchanged.

Are you sure? query-qmp-schema masks the type names.

Quoted 1 line

[...]

qapi/machine.json line 20

Quoted 13 lines
qapi/machine.json +1 -1
index 9b145c635ba..07fac4f0764 100644
@@ -14,7 +14,7 @@
 { 'include': 'machine-common.json' }
 
 ##
-# @SysEmuTarget:
+# @EmuTarget:
 #     The comprehensive enumeration of QEMU system emulation
 #     ("softmmu") targets.  Run "./configure --help" in the project
 #     root directory, and look for the \*-softmmu targets near the

# "--target-list" option. The individual target constants are not
# documented here, for the time being.

Is this still correct?

Quoted 49 lines
qapi/machine.json +3 -3
@@ -35,7 +35,7 @@
 #
 # Since: 3.0
 ##
-{ 'enum' : 'SysEmuTarget',
+{ 'enum' : 'EmuTarget',
   'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
              'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',
              'mips64el', 'mipsel', 'or1k', 'ppc',
@@ -95,7 +95,7 @@
                       'qom-path'     : 'str',
                       'thread-id'    : 'int',
                       '*props'       : 'CpuInstanceProperties',
-                      'target'       : 'SysEmuTarget' },
+                      'target'       : 'EmuTarget' },
   'discriminator' : 'target',
   'data'          : { 's390x'        : 'CpuInfoS390' } }
 
@@ -281,7 +281,7 @@
 # Since: 1.2
 ##
 { 'struct': 'QemuTargetInfo',
-  'data': { 'arch': 'SysEmuTarget' } }
+  'data': { 'arch': 'EmuTarget' } }
 
 ##
 # @query-target:
qapi/pragma.json +2 -2
index 342cedc42e7..93a710ee937 100644
@@ -72,7 +72,7 @@
         'SsidSizeMode',
         'String',
         'StringWrapper',
-        'SysEmuTarget',
+        'EmuTarget',
         'ThrottleGroupProperties',
         'VncPrimaryAuth',
         'VncVencryptSubAuth',
@@ -109,7 +109,7 @@
         'QKeyCode',                 # send-key, input-sent-event
         'QapiErrorClass',           # QMP error replies
         'SshHostKeyCheckMode',      # blockdev-add, -blockdev
-        'SysEmuTarget',             # query-cpu-fast, query-target
+        'EmuTarget',                # query-cpu-fast, query-target
         'UuidInfo',                 # query-uuid
         'VncClientInfo',            # query-vnc, query-vnc-servers, ...
         'X86CPURegister32'          # qom-get of x86 CPU properties

[...]

#6 lore raw

Re: [PATCH 04/34] qapi: rename SysEmuTarget to EmuTarget

Quoted 9 lines · Markus Armbruster
Quoted 4 lines · Yonggang Luo

As now it's also expressing user-mode targets.

This changes the type name exposed by query-qmp-schema; enum values and serialized target values remain unchanged.

Are you sure? query-qmp-schema masks the type names.

Thanks, I'll remove this.

Quoted 21 lines
Quoted 2 lines

[...]

qapi/machine.json line 20

Quoted 13 lines
qapi/machine.json +1 -1
index 9b145c635ba..07fac4f0764 100644
@@ -14,7 +14,7 @@
 { 'include': 'machine-common.json' }
 
 ##
-# @SysEmuTarget:
+# @EmuTarget:
 #     The comprehensive enumeration of QEMU system emulation
 #     ("softmmu") targets.  Run "./configure --help" in the project
 #     root directory, and look for the \*-softmmu targets near the

# "--target-list" option. The individual target constants are not
# documented here, for the time being.

Quoted 1 line

Is this still correct?

This is a grep rename. I'll update it later, thanks.

Quoted 44 lines
Quoted 44 lines
qapi/machine.json +3 -3
@@ -35,7 +35,7 @@
 #
 # Since: 3.0
 ##
-{ 'enum' : 'SysEmuTarget',
+{ 'enum' : 'EmuTarget',
   'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
              'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',
              'mips64el', 'mipsel', 'or1k', 'ppc',
@@ -95,7 +95,7 @@
                       'qom-path'     : 'str',
                       'thread-id'    : 'int',
                       '*props'       : 'CpuInstanceProperties',
-                      'target'       : 'SysEmuTarget' },
+                      'target'       : 'EmuTarget' },
   'discriminator' : 'target',
   'data'          : { 's390x'        : 'CpuInfoS390' } }
 
@@ -281,7 +281,7 @@
 # Since: 1.2
 ##
 { 'struct': 'QemuTargetInfo',
-  'data': { 'arch': 'SysEmuTarget' } }
+  'data': { 'arch': 'EmuTarget' } }
 
 ##
 # @query-target:
qapi/pragma.json +1 -1
index 342cedc42e7..93a710ee937 100644
@@ -72,7 +72,7 @@
         'SsidSizeMode',
         'String',
         'StringWrapper',
-        'SysEmuTarget',
+        'EmuTarget',
         'ThrottleGroupProperties',
         'VncPrimaryAuth',
         'VncVencryptSubAuth',
@@ -109,7 +109,7 @@
         'QKeyCode',                 # send-key, input-sent-event
         'QapiErrorClass',           # QMP error replies
Quoted 9 lines
Quoted 6 lines
qapi/pragma.json +1 -1
         'SshHostKeyCheckMode',      # blockdev-add, -blockdev
-        'SysEmuTarget',             # query-cpu-fast, query-target
+        'EmuTarget',                # query-cpu-fast, query-target
         'UuidInfo',                 # query-uuid
         'VncClientInfo',            # query-vnc, query-vnc-servers, ...
         'X86CPURegister32'          # qom-get of x86 CPU properties

[...]

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#7 lore raw

PATCH 5/34 qapi: add missing Linux user-mode targets to EmuTarget

In reply to Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
 include/qemu/base-arch-defs.h | 13 +++++++++++++
 qapi/machine.json             | 25 +++++++++++++------------
 target-info.c                 | 26 +++++++++-----------------
 3 files changed, 35 insertions(+), 29 deletions(-)
include/qemu/base-arch-defs.h +13 -0
index 7ddecc3d0be..6f3dadcc3a8 100644
@@ -11,25 +11,38 @@
 
 #define QEMU_ARCH_BIT(target) (1ULL << (target))
 
+/* Unsuffixed family masks cover system targets; _ALL includes user targets. */
 enum {
     QEMU_ARCH_ALPHA =       QEMU_ARCH_BIT(EMU_TARGET_ALPHA),
     QEMU_ARCH_ARM =         QEMU_ARCH_BIT(EMU_TARGET_ARM) |
                             QEMU_ARCH_BIT(EMU_TARGET_AARCH64),
+    QEMU_ARCH_ARM_ALL =     QEMU_ARCH_ARM |
+                            QEMU_ARCH_BIT(EMU_TARGET_AARCH64_BE) |
+                            QEMU_ARCH_BIT(EMU_TARGET_ARMEB),
     QEMU_ARCH_I386 =        QEMU_ARCH_BIT(EMU_TARGET_I386) |
                             QEMU_ARCH_BIT(EMU_TARGET_X86_64),
     QEMU_ARCH_M68K =        QEMU_ARCH_BIT(EMU_TARGET_M68K),
     QEMU_ARCH_MICROBLAZE =  QEMU_ARCH_BIT(EMU_TARGET_MICROBLAZE),
+    QEMU_ARCH_MICROBLAZE_ALL = QEMU_ARCH_MICROBLAZE |
+                               QEMU_ARCH_BIT(EMU_TARGET_MICROBLAZEEL),
     QEMU_ARCH_MIPS =        QEMU_ARCH_BIT(EMU_TARGET_MIPS) |
                             QEMU_ARCH_BIT(EMU_TARGET_MIPSEL) |
                             QEMU_ARCH_BIT(EMU_TARGET_MIPS64) |
                             QEMU_ARCH_BIT(EMU_TARGET_MIPS64EL),
+    QEMU_ARCH_MIPS_ALL =    QEMU_ARCH_MIPS |
+                            QEMU_ARCH_BIT(EMU_TARGET_MIPSN32) |
+                            QEMU_ARCH_BIT(EMU_TARGET_MIPSN32EL),
     QEMU_ARCH_PPC =         QEMU_ARCH_BIT(EMU_TARGET_PPC) |
                             QEMU_ARCH_BIT(EMU_TARGET_PPC64),
+    QEMU_ARCH_PPC_ALL =     QEMU_ARCH_PPC |
+                            QEMU_ARCH_BIT(EMU_TARGET_PPC64LE),
     QEMU_ARCH_S390X =       QEMU_ARCH_BIT(EMU_TARGET_S390X),
     QEMU_ARCH_SH4 =         QEMU_ARCH_BIT(EMU_TARGET_SH4) |
                             QEMU_ARCH_BIT(EMU_TARGET_SH4EB),
     QEMU_ARCH_SPARC =       QEMU_ARCH_BIT(EMU_TARGET_SPARC) |
                             QEMU_ARCH_BIT(EMU_TARGET_SPARC64),
+    QEMU_ARCH_SPARC_ALL =   QEMU_ARCH_SPARC |
+                            QEMU_ARCH_BIT(EMU_TARGET_SPARC32PLUS),
     QEMU_ARCH_XTENSA =      QEMU_ARCH_BIT(EMU_TARGET_XTENSA) |
                             QEMU_ARCH_BIT(EMU_TARGET_XTENSAEB),
     QEMU_ARCH_OR1K =        QEMU_ARCH_BIT(EMU_TARGET_OR1K),
qapi/machine.json +13 -12
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
 
 ##
 # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
 #
 # @rx: since 5.0
 #
@@ -30,17 +29,19 @@
 # @hexagon: since 11.0
 #
 # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
 #
 # Since: 3.0
 ##
 { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
              'x86_64', 'xtensa', 'xtensaeb' ] }
 
 ##
target-info.c +9 -17
index 241be2b5563..b2abcd55bd3 100644
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/target-info.h"
 #include "qemu/target-info-qapi.h"
 #include "qemu/target-info-def.h"
@@ -44,23 +45,19 @@ bool target_big_endian(void)
 
 bool target_base_arm(void)
 {
-    switch (target_arch()) {
-    case EMU_TARGET_ARM:
-    case EMU_TARGET_AARCH64:
-        return true;
-    default:
-        return false;
-    }
+    return (QEMU_ARCH_ARM_ALL & QEMU_ARCH_BIT(target_arch())) != 0;
 }
 
 bool target_arm(void)
 {
-    return target_arch() == EMU_TARGET_ARM;
+    return target_arch() == EMU_TARGET_ARM ||
+           target_arch() == EMU_TARGET_ARMEB;
 }
 
 bool target_aarch64(void)
 {
-    return target_arch() == EMU_TARGET_AARCH64;
+    return target_arch() == EMU_TARGET_AARCH64 ||
+           target_arch() == EMU_TARGET_AARCH64_BE;
 }
 
 bool target_m68k(void)
@@ -75,13 +72,7 @@ bool target_or1k(void)
 
 bool target_base_ppc(void)
 {
-    switch (target_arch()) {
-    case EMU_TARGET_PPC:
-    case EMU_TARGET_PPC64:
-        return true;
-    default:
-        return false;
-    }
+    return (QEMU_ARCH_PPC_ALL & QEMU_ARCH_BIT(target_arch())) != 0;
 }
 
 bool target_ppc(void)
@@ -91,7 +82,8 @@ bool target_ppc(void)
 
 bool target_ppc64(void)
 {
-    return target_arch() == EMU_TARGET_PPC64;
+    return target_arch() == EMU_TARGET_PPC64 ||
+           target_arch() == EMU_TARGET_PPC64LE;
 }
 
 bool target_s390x(void)
Signature · 1 line
2.55.0.windows.3
#8 lore raw

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

Quoted 58 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
  include/qemu/base-arch-defs.h | 13 +++++++++++++
  qapi/machine.json             | 25 +++++++++++++------------
  target-info.c                 | 26 +++++++++-----------------
  3 files changed, 35 insertions(+), 29 deletions(-)
qapi/machine.json +7 -9
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
 
  ##
  # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
  #
  # @rx: since 5.0
  #
@@ -30,17 +29,19 @@
  # @hexagon: since 11.0
  #
  # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
  #
  # Since: 3.0
  ##
  { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',

qapi/machine.json line 45

Quoted 10 lines
qapi/machine.json +6 -3
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
               'x86_64', 'xtensa', 'xtensaeb' ] }

'machine.json' is for system binaries.

If we want to expose these QAPI types to the user binaries (I'm not sure we want...) then this declaration block should be moved in another {qapi}.json file. QAPI types are versioned,
so we'd need some " @aarch64_be # Since v13.0" comments.

Anyway I doubt we want to alter EmuTarget, I'd rather let it die as a legacy field, and expose {arch, wordsize, endianness} to management layer if this is important to consume.

#9 lore raw

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

Quoted 71 lines · Philippe Mathieu-Daudé
Quoted 57 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
  include/qemu/base-arch-defs.h | 13 +++++++++++++
  qapi/machine.json             | 25 +++++++++++++------------
  target-info.c                 | 26 +++++++++-----------------
  3 files changed, 35 insertions(+), 29 deletions(-)
qapi/machine.json +7 -9
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
  ##
  # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
  #
  # @rx: since 5.0
  #
@@ -30,17 +29,19 @@
  # @hexagon: since 11.0
  #
  # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
  #
  # Since: 3.0
  ##
  { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',

qapi/machine.json line 45

Quoted 10 lines
qapi/machine.json +6 -3
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
               'x86_64', 'xtensa', 'xtensaeb' ] }

'machine.json' is for system binaries.

Quoted 8 lines

If we want to expose these QAPI types to the user binaries (I'm not sure we want...) then this declaration block should be moved in another {qapi}.json file. QAPI types are versioned,
so we'd need some " @aarch64_be # Since v13.0" comments.

Anyway I doubt we want to alter EmuTarget, I'd rather let it die as a legacy field, and expose {arch, wordsize, endianness} to management layer if this is important to consume.

Libvirt uses query-target so we don't want that data to go away. If we want to expose other data alongside the target name that's fine.

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 :|
#10 lore raw

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

Quoted 77 lines · Daniel P. Berrangé
Quoted 76 lines · Philippe Mathieu-Daudé
Quoted 57 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
   include/qemu/base-arch-defs.h | 13 +++++++++++++
   qapi/machine.json             | 25 +++++++++++++------------
   target-info.c                 | 26 +++++++++-----------------
   3 files changed, 35 insertions(+), 29 deletions(-)
qapi/machine.json +7 -9
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
   ##
   # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
   #
   # @rx: since 5.0
   #
@@ -30,17 +29,19 @@
   # @hexagon: since 11.0
   #
   # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
   #
   # Since: 3.0
   ##
   { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',

qapi/machine.json line 45

Quoted 10 lines
qapi/machine.json +6 -3
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
                'x86_64', 'xtensa', 'xtensaeb' ] }

'machine.json' is for system binaries.

If we want to expose these QAPI types to the user binaries (I'm not sure we want...) then this declaration block should be moved in another {qapi}.json file. QAPI types are versioned,
so we'd need some " @aarch64_be # Since v13.0" comments.

Quoted 7 lines
Quoted 3 lines

Anyway I doubt we want to alter EmuTarget, I'd rather let it die as a legacy field, and expose {arch, wordsize, endianness} to management layer if this is important to consume.

Libvirt uses query-target so we don't want that data to go away. If we want to expose other data alongside the target name that's fine.

I'm not suggesting to change 'query-target' format; the opposite... If we are going to add 'query-targets' (the plural form) then we should report something more useful like {arch, wordsize, endianness} but not that EmuTarget type which I consider legacy.

#11 lore raw

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

Quoted 83 lines · Philippe Mathieu-Daudé
Quoted 81 lines · Daniel P. Berrangé
Quoted 79 lines · Philippe Mathieu-Daudé
Quoted 57 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
   include/qemu/base-arch-defs.h | 13 +++++++++++++
   qapi/machine.json             | 25 +++++++++++++------------
   target-info.c                 | 26 +++++++++-----------------
   3 files changed, 35 insertions(+), 29 deletions(-)
qapi/machine.json +7 -9
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
   ##
   # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
   #
   # @rx: since 5.0
   #
@@ -30,17 +29,19 @@
   # @hexagon: since 11.0
   #
   # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
   #
   # Since: 3.0
   ##
   { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',

qapi/machine.json line 45

Quoted 10 lines
qapi/machine.json +6 -3
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
                'x86_64', 'xtensa', 'xtensaeb' ] }

'machine.json' is for system binaries.

If we want to expose these QAPI types to the user binaries (I'm not sure we want...) then this declaration block should be moved in another {qapi}.json file. QAPI types are versioned,
so we'd need some " @aarch64_be # Since v13.0" comments.

Anyway I doubt we want to alter EmuTarget, I'd rather let it die as a legacy field, and expose {arch, wordsize, endianness} to management layer if this is important to consume.

Quoted 8 lines
Quoted 3 lines

Libvirt uses query-target so we don't want that data to go away. If we want to expose other data alongside the target name that's fine.

I'm not suggesting to change 'query-target' format; the opposite... If we are going to add 'query-targets' (the plural form) then we should report something more useful like {arch, wordsize, endianness} but not that EmuTarget type which I consider legacy.

I think it should be moved to qapi.json. As I needed it, do you have a better way to have an enum for mapping target-name to that enum?

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

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

In reply to Philippe Mathieu-Daudé
Quoted 73 lines · Philippe Mathieu-Daudé
Quoted 58 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

---
  include/qemu/base-arch-defs.h | 13 +++++++++++++
  qapi/machine.json             | 25 +++++++++++++------------
  target-info.c                 | 26 +++++++++-----------------
  3 files changed, 35 insertions(+), 29 deletions(-)
qapi/machine.json +7 -9
index 07fac4f0764..a3d6e08a847 100644
@@ -15,11 +15,10 @@
 
  ##
  # @EmuTarget:
-#     The comprehensive enumeration of QEMU system emulation
-#     ("softmmu") targets.  Run "./configure --help" in the project
-#     root directory, and look for the \*-softmmu targets near the
-#     "--target-list" option.  The individual target constants are not
-#     documented here, for the time being.
+#     The comprehensive enumeration of QEMU system and user-mode
+#     emulation targets.  Run "./configure --help" in the project root
+#     directory, and look for the targets near the "--target-list"
+#     option.  Individual target constants are not documented here.
  #
  # @rx: since 5.0
  #
@@ -30,17 +29,19 @@
  # @hexagon: since 11.0
  #
  # .. note:: The resulting QMP strings can be appended to the
-#    "qemu-system-" prefix to produce the corresponding QEMU
-#    executable name.  This is true even for "qemu-system-x86_64".
+#    "qemu-system-" prefix for system emulation, or the "qemu-" prefix
+#    for user-mode emulation, to produce the corresponding executable
+#    name, where that target supports the respective emulation mode.
  #
  # Since: 3.0
  ##
  { 'enum' : 'EmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
-             'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',

qapi/machine.json line 45

Quoted 10 lines
qapi/machine.json +6 -3
-             'mips64el', 'mipsel', 'or1k', 'ppc',
-             'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
-             'sh4eb', 'sparc', 'sparc64', 'tricore',
+  'data' : [ 'aarch64', 'aarch64_be', 'alpha', 'arm', 'armeb', 'avr',
+             'hexagon', 'hppa', 'i386', 'loongarch64', 'm68k', 'microblaze',
+             'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel',
+             'mipsn32', 'mipsn32el', 'or1k', 'ppc', 'ppc64', 'ppc64le',
+             'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc',
+             'sparc32plus', 'sparc64', 'tricore',
               'x86_64', 'xtensa', 'xtensaeb' ] }

'machine.json' is for system binaries.

Quoted 3 lines

If we want to expose these QAPI types to the user binaries (I'm not sure we want...) then this declaration block should be moved in another {qapi}.json file. QAPI types are versioned,

OK,

Quoted 4 lines

so we'd need some " @aarch64_be # Since v13.0" comments.

Anyway I doubt we want to alter EmuTarget, I'd rather let it die as a legacy field, and expose {arch, wordsize, endianness}

Are you talking about base_arch? that won't work(we need mapping to the EmuTarget to select the $target directly)
What the advantage of EmuTarget is that we can have a one-to-one mapping from EmuTarget to TargetInfo
That each EmuTarget only mapping to a single TargetInfo, so we can reliably choose TargetInfo from EmuTarget
that is one item of data

Hi Philippe
rationale:
https://lore.kernel.org/qemu-devel/[email protected]/
This was tried before and rejected.

Quoted 1 line

to management layer if this is important to consume.

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

Re: [PATCH 05/34] qapi: add missing Linux user-mode targets to EmuTarget

In reply to Yonggang Luo
Quoted 15 lines · Yonggang Luo

This usermode targets:
aarch64_be
armeb
microblazeel
mipsn32
mipsn32el
ppc64le
sparc32plus
are not in machine.json

This is a prepare for directly using TARGET_ARCH_VARIANT latter.

Also get target-info.c to be compatible with future TARGET_ARCH_VARIANT only usage. So that we can define TARGET_ARCH_VARIANT to target_name directly

Quoted 7 lines
---
 include/qemu/base-arch-defs.h | 13 +++++++++++++
 qapi/machine.json             | 25 +++++++++++++------------
 target-info.c                 | 26 +++++++++-----------------
 3 files changed, 35 insertions(+), 29 deletions(-)

This patch indeed allows to have a unique definition of TARGET_ARCH_VARIANT in next patch. However, it's absolutely not needed for anything else in this series, out of cleaning up one if in meson.build.

Is there is any concrete reason we need to expose linux-user missing variants?

Regards,
Pierrick

#14 lore raw

PATCH 6/34 meson: define TARGET_ARCH_VARIANT to target_name only

In reply to Yonggang Luo

So target_arch() only related to target_name.to_upper(), simplify it's meaning

---
 meson.build | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
meson.build +1 -5
index 255c887e8e6..3460d031a95 100644
@@ -3290,11 +3290,7 @@ fdt_required = []
 foreach target : target_dirs
   target_name = target.split('-')[0]
   config_target = { 'TARGET_NAME': target_name }
-  if target.endswith('linux-user')
-    config_target += { 'TARGET_ARCH_VARIANT': 'TARGET_ARCH' }
-  else
-    config_target += { 'TARGET_ARCH_VARIANT': target_name.to_upper() }
-  endif
+  config_target += { 'TARGET_ARCH_VARIANT': target_name.to_upper() }
 
   if target.endswith('linux-user')
     if host_os != 'linux'
Signature · 1 line
2.55.0.windows.3
#15 lore raw

PATCH 7/34 target-info: prepare the QOM target list before module_call_init(MODULE_INIT_QOM)

In reply to Yonggang Luo

We can not retrieve target list when do call to module_call_init(MODULE_INIT_QOM) But in future, we need iterate target list inside type_init referenced functions for generate all QOM variants depends on target list(without select the target). So we have to prepare the QOM target list before module_call_init(MODULE_INIT_QOM)

---
 include/qemu/target-info-qom.h |  4 ++++
 system/vl.c                    |  2 +-
 target-info-qom.c              | 26 +++++++++++++++++++++++++-
 tests/qtest/fuzz/fuzz.c        |  2 +-
 tests/unit/test-multi-target.c | 20 +++++++++++++-------
 5 files changed, 44 insertions(+), 10 deletions(-)
include/qemu/target-info-qom.h +4 -0
index ba2e4370afb..031d9ce32a5 100644
@@ -25,6 +25,10 @@ typedef struct TargetInfoQomClass {
 
 OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
 
+/* Initialize before MODULE_INIT_QOM; cache is owned by this module. */
+void target_info_qom_init(void);
+GSList *target_info_qom_get_targets(void);
+
 void target_info_qom_set_target(void);
 void target_info_qom_set_target_info(const TargetInfo *ti);
 
system/vl.c +1 -1
index fbe580746d3..a7684abdd3a 100644
@@ -2914,7 +2914,7 @@ void qemu_init(int argc, char **argv)
 
     os_setup_limits();
 
-    module_call_init(MODULE_INIT_TARGET_INFO);
+    target_info_qom_init();
     target_info_qom_set_target();
 
     module_init_info(qemu_modinfo);
target-info-qom.c +25 -1
index aeeedb7e818..8d3f2b7280b 100644
@@ -8,6 +8,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "qom/object.h"
 #include "qemu/target-info-def.h"
 #include "qemu/target-info-init.h"
@@ -34,6 +35,29 @@ static const TypeInfo target_info_parent_type = {
 DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
 
 static const TargetInfo *target_info_ptr;
+static GSList *target_info_classes;
+static bool target_info_initialized;
+
+void target_info_qom_init(void)
+{
+    if (target_info_initialized) {
+        return;
+    }
+
+    module_call_init(MODULE_INIT_TARGET_INFO);
+    /*
+     * Avoid enumerating target-info classes during QOM registration,
+     * which can leave unrelated types incomplete.
+     */
+    target_info_classes = object_class_get_list(TYPE_TARGET_INFO, false);
+    target_info_initialized = true;
+}
+
+GSList *target_info_qom_get_targets(void)
+{
+    assert(target_info_initialized);
+    return target_info_classes;
+}
 
 const TargetInfo *target_info(void)
 {
@@ -42,7 +66,7 @@ const TargetInfo *target_info(void)
 
 void target_info_qom_set_target(void)
 {
-    g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
+    GSList *targets = target_info_qom_get_targets();
 
     size_t num_found = g_slist_length(targets);
     if (num_found != 1) {
tests/qtest/fuzz/fuzz.c +1 -1
index a3a131c80f8..570fc0b45b2 100644
@@ -173,7 +173,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
 
     /* Initialize qgraph and modules */
     qos_graph_init();
-    module_call_init(MODULE_INIT_TARGET_INFO);
+    target_info_qom_init();
     target_info_qom_set_target();
     module_call_init(MODULE_INIT_FUZZ_TARGET);
     module_call_init(MODULE_INIT_QOM);
tests/unit/test-multi-target.c +13 -7
index 89b55bb1632..a91fe8e6d07 100644
@@ -30,23 +30,29 @@
 /* stub for system/main.c */
 int (*qemu_main)(void);
 
+static GSList *targets;
+
 static void test_qom_types_are_unique(void)
 {
-    module_call_init(MODULE_INIT_TARGET_INFO);
-    g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
     g_assert(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);
     /* trigger type_initialize for all types */
     object_class_get_list("", false);
+
+    g_assert_true(targets == target_info_qom_get_targets());
 }
 
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
+    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);
+
     g_test_add_func("/multi-targets/qom-types-are-unique",
                    test_qom_types_are_unique);
     return g_test_run();
Signature · 1 line
2.55.0.windows.3
#16 lore raw

PATCH 8/34 hw: add MachineClass::targets with a usage and test

In reply to Yonggang Luo

Add a target bitmask to MachineClass, defaulting to QEMU_ARCH_ALL. Update "clipper" machine as a demo/test

---
 hw/alpha/dp264.c               |  2 ++
 hw/core/machine.c              |  3 +++
 include/hw/core/boards.h       |  6 ++++++
 tests/unit/test-multi-target.c | 33 ++++++++++++++++++++++++++++++++-
 4 files changed, 43 insertions(+), 1 deletion(-)
hw/alpha/dp264.c +2 -0
index f928e0cee82..6be573c88bc 100644
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "target/alpha/cpu.h"
 #include "exec/target_page.h"
 #include "elf.h"
@@ -203,6 +204,7 @@ static void clipper_init(MachineState *machine)
 
 static void clipper_machine_init(MachineClass *mc)
 {
+    mc->targets = QEMU_ARCH_ALPHA;
     mc->desc = "Alpha DP264/CLIPPER";
     mc->init = clipper_init;
     mc->block_default_type = IF_IDE;
hw/core/machine.c +3 -0
index d9ac4b419a3..5c6f3cb0f68 100644
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/units.h"
 #include "qemu/accel.h"
 #include "system/replay.h"
@@ -1068,6 +1069,8 @@ static void machine_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
+    mc->targets = QEMU_ARCH_ALL;
+
     /* Default 128 MB as guest ram size */
     mc->default_ram_size = 128 * MiB;
     mc->rom_file_has_mr = true;
include/hw/core/boards.h +6 -0
index d0e4ad98201..d7713c45836 100644
@@ -186,6 +186,11 @@ typedef struct {
  * MachineClass:
  * @deprecation_reason: If set, the machine is marked as deprecated. The
  *    string should provide some clear information about what to use instead.
+ * @targets: bitmask of EmuTarget values supported by this machine. Each
+ *    target is represented by QEMU_ARCH_BIT(EMU_TARGET_*).
+ *    QEMU_ARCH_* masks may be used when the machine supports every target
+ *    in that architecture family. Defaults to QEMU_ARCH_ALL; machines that
+ *    support a narrower set of targets should declare that set explicitly.
  * @max_cpus: maximum number of CPUs supported. Default: 1
  * @min_cpus: minimum number of CPUs supported. Default: 1
  * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
@@ -273,6 +278,7 @@ struct MachineClass {
     const char *alias;
     const char *desc;
     const char *deprecation_reason;
+    uint64_t targets;
 
     void (*init)(MachineState *state);
     void (*reset)(MachineState *state, ResetType type);
tests/unit/test-multi-target.c +32 -1
index a91fe8e6d07..c2922e0fed5 100644
@@ -13,6 +13,8 @@
  */
 
 #include "qemu/osdep.h"
+#include "hw/core/boards.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/module.h"
 #include "qemu/target-info.h"
 #include "qemu/target-info-qom.h"
@@ -32,6 +34,17 @@ int (*qemu_main)(void);
 
 static GSList *targets;
 
+static bool target_arch_available(uint64_t arch_mask)
+{
+    for (GSList *l = targets; l; l = l->next) {
+        const TargetInfo *ti = TARGET_INFO_CLASS(l->data)->target_info;
+        if (QEMU_ARCH_BIT(ti->target_arch) & arch_mask) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static void test_qom_types_are_unique(void)
 {
     g_assert(targets);
@@ -41,6 +54,22 @@ static void test_qom_types_are_unique(void)
     g_assert_true(targets == target_info_qom_get_targets());
 }
 
+static void test_machine_targets(void)
+{
+    ObjectClass *oc;
+
+    oc = object_class_by_name(TYPE_MACHINE);
+    g_assert_nonnull(oc);
+    g_assert_cmpuint(MACHINE_CLASS(oc)->targets, ==, QEMU_ARCH_ALL);
+
+    if (target_arch_available(QEMU_ARCH_ALPHA)) {
+        oc = object_class_by_name(MACHINE_TYPE_NAME("clipper"));
+        g_assert_nonnull(oc);
+        g_assert_cmpuint(MACHINE_CLASS(oc)->targets, ==,
+                         QEMU_ARCH_BIT(EMU_TARGET_ALPHA));
+    }
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -54,6 +83,8 @@ int main(int argc, char **argv)
     module_call_init(MODULE_INIT_QOM);
 
     g_test_add_func("/multi-targets/qom-types-are-unique",
-                   test_qom_types_are_unique);
+                    test_qom_types_are_unique);
+    g_test_add_func("/multi-targets/machine-targets",
+                    test_machine_targets);
     return g_test_run();
 }
Signature · 1 line
2.55.0.windows.3
#17 lore raw

PATCH 9/34 accel: register CPU parent for each target

In reply to Yonggang Luo

Now we need use the prepared target-list to register different accel-$cpu_type parent QOM type. So that multi-target won't error missing parent for different accel for different arch.

Also add a test for it in test-multi-target.c

---
 accel/accel-common.c           |  6 ++----
 accel/accel-internal.h         |  1 +
 accel/accel-system.c           | 24 ++++++++++++++++++++++++
 accel/accel-user.c             |  7 +++++++
 tests/unit/test-multi-target.c | 15 +++++++++++++++
 5 files changed, 49 insertions(+), 4 deletions(-)
accel/accel-common.c +2 -4
index 00a400243f0..0f4e202d8f8 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+void accel_register_cpu_type(const char *cpu_type)
 {
-    g_autofree char *name = g_strconcat("accel-", target_cpu_type(), NULL);
+    g_autofree char *name = g_strconcat("accel-", cpu_type, NULL);
     const TypeInfo accel_cpu_type = {
         .name = name,
         .parent = TYPE_OBJECT,
@@ -142,5 +142,3 @@ static void register_accel_target_type(void)
 
     type_register_static(&accel_cpu_type);
 }
-
-type_init(register_accel_target_type);
accel/accel-internal.h +1 -0
index d3a4422cbf7..2b6f58526d3 100644
@@ -13,5 +13,6 @@
 #include "qemu/accel.h"
 
 void accel_init_ops_interfaces(AccelClass *ac);
+void accel_register_cpu_type(const char *cpu_type);
 
 #endif /* ACCEL_SYSTEM_H */
accel/accel-system.c +24 -0
index 1325b23864c..fdfa85179ee 100644
@@ -25,6 +25,8 @@
 
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
+#include "qemu/target-info-def.h"
+#include "qemu/target-info-qom.h"
 #include "qom/compat-properties.h"
 #include "qapi/qapi-commands-accelerator.h"
 #include "monitor/monitor.h"
@@ -32,6 +34,7 @@
 #include "hw/core/boards.h"
 #include "hw/core/cpu.h"
 #include "accel/accel-ops.h"
+#include "accel/accel-cpu.h"
 #include "accel/accel-cpu-ops.h"
 #include "system/cpus.h"
 #include "qemu/error-report.h"
@@ -124,6 +127,27 @@ static const TypeInfo accel_ops_type_info = {
 
 static void accel_system_register_types(void)
 {
+    GSList *targets = target_info_qom_get_targets();
+    const TargetInfo *ti, *prev_ti;
+
     type_register_static(&accel_ops_type_info);
+
+    for (GSList *l = targets; l; l = l->next) {
+        bool duplicate = false;
+
+        ti = TARGET_INFO_CLASS(l->data)->target_info;
+        for (GSList *prev = targets; prev != l; prev = prev->next) {
+            prev_ti = TARGET_INFO_CLASS(prev->data)->target_info;
+            if (g_str_equal(prev_ti->cpu_type, ti->cpu_type)) {
+                duplicate = true;
+                break;
+            }
+        }
+        if (duplicate) {
+            continue;
+        }
+
+        accel_register_cpu_type(ti->cpu_type);
+    }
 }
 type_init(accel_system_register_types);
accel/accel-user.c +7 -0
index 7d192306a65..85ede70e5bd 100644
@@ -9,8 +9,15 @@
 
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
+#include "qemu/target-info.h"
 #include "accel-internal.h"
 
+static void register_accel_target_type(void)
+{
+    accel_register_cpu_type(target_cpu_type());
+}
+type_init(register_accel_target_type);
+
 void accel_init_ops_interfaces(AccelClass *ac)
 {
     /* nothing */
tests/unit/test-multi-target.c +15 -0
index c2922e0fed5..704e3297ef9 100644
@@ -17,6 +17,7 @@
 #include "qemu/base-arch-defs.h"
 #include "qemu/module.h"
 #include "qemu/target-info.h"
+#include "qemu/target-info-def.h"
 #include "qemu/target-info-qom.h"
 #include "qom/object.h"
 
@@ -70,6 +71,18 @@ static void test_machine_targets(void)
     }
 }
 
+static void test_accel_cpu_parent_per_target(void)
+{
+    g_assert(targets);
+
+    for (GSList *l = targets; l; l = l->next) {
+        const TargetInfo *ti = TARGET_INFO_CLASS(l->data)->target_info;
+        g_autofree char *name = g_strconcat("accel-", ti->cpu_type, NULL);
+
+        g_assert_nonnull(object_class_by_name(name));
+    }
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -86,5 +99,7 @@ int main(int argc, char **argv)
                     test_qom_types_are_unique);
     g_test_add_func("/multi-targets/machine-targets",
                     test_machine_targets);
+    g_test_add_func("/multi-targets/accel-cpu-parent-per-target",
+                    test_accel_cpu_parent_per_target);
     return g_test_run();
 }
Signature · 1 line
2.55.0.windows.3
#18 lore raw

PATCH 10/34 meson: collect Rust crates for combined system target

In reply to Yonggang Luo

multi_target_crates += main_rs is not fine, that may repeat crates. So we need collect crates from different $arch directly, and unique them to a new list. then reuse 'rust_multi_target.rs' to generate it properly

---
 meson.build | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
meson.build +17 -1
index 3460d031a95..f54687e19dc 100644
@@ -4431,7 +4431,11 @@ foreach target : target_dirs
       multi_target_libs += lib
       multi_target_deps += arch_deps
       multi_target_deps += target_stubs
-      multi_target_crates += main_rs
+      foreach crate : crates
+        if crate not in multi_target_crates
+          multi_target_crates += crate
+        endif
+      endforeach
     endif
     execs = [{
       'name': 'qemu-system-' + target_name,
@@ -4516,6 +4520,18 @@ endforeach
 
 # Other build targets
 
+# Use collected crate names, not per-target main_rs sources, for the combined root.
+if multi_target_crates.length() > 0
+  multi_target_crates = custom_target(
+    'rust_multi_target.rs',
+    output: 'rust_multi_target.rs',
+    command: [rust_root_crate, multi_target_crates],
+    capture: true,
+    build_always_stale: true,
+  )
+  multi_target_crates = structured_sources(multi_target_crates)
+endif
+
 multi_target_objects = []
 foreach lib: multi_target_libs
   multi_target_objects += lib.extract_all_objects(recursive: true)
Signature · 1 line
2.55.0.windows.3
#19 lore raw

PATCH 11/34 module: Add module_allow_all_arch for allow all modules be loaded

In reply to Yonggang Luo

In multi-target qemu, we want all modules to be loaded without condition. So add this function for latter usage.
Add this independent function for decouple only

---
 include/qemu/module.h |  2 ++
 util/module.c         | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
include/qemu/module.h +2 -0
index fccf017bf9e..6268c3a8d75 100644
@@ -100,6 +100,8 @@ int module_load(const char *prefix, const char *name, Error **errp);
 int module_load_qom(const char *type, Error **errp);
 void module_load_qom_all(void);
 void module_allow_arch(const char *arch);
+/* Allow every arch-tagged module without selecting an architecture. */
+void module_allow_all_arch(void);
 
 /**
  * DOC: module info annotation macros
util/module.c +9 -1
index 8f8e6994f11..b7253fbd065 100644
@@ -119,6 +119,7 @@ static const QemuModinfo module_info_stub[] = { {
 } };
 static const QemuModinfo *module_info = module_info_stub;
 static const char *module_arch;
+static bool module_all_archs;
 
 void module_init_info(const QemuModinfo *info)
 {
@@ -128,11 +129,17 @@ void module_init_info(const QemuModinfo *info)
 void module_allow_arch(const char *arch)
 {
     module_arch = arch;
+    module_all_archs = false;
+}
+
+void module_allow_all_arch(void)
+{
+    module_all_archs = true;
 }
 
 static bool module_check_arch(const QemuModinfo *modinfo)
 {
-    if (modinfo->arch) {
+    if (modinfo->arch && !module_all_archs) {
         if (!module_arch) {
             /* no arch set -> ignore all */
             return false;
@@ -400,6 +407,7 @@ const QemuModinfo qemu_modinfo[] = {};
 
 void module_init_info(const QemuModinfo *info) {}
 void module_allow_arch(const char *arch) {}
+void module_allow_all_arch(void) {}
 void qemu_load_module_for_opts(const char *group) {}
 int module_load(const char *prefix, const char *name, Error **errp) { return 2; }
 int module_load_qom(const char *type, Error **errp) { return 2; }
Signature · 1 line
2.55.0.windows.3
#20 lore raw

PATCH 12/34 target/arm: defer max-v8 initializer selection until CPU creation

In reply to Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +13 -4
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)
Signature · 1 line
2.55.0.windows.3
#21 lore raw

PATCH 13/34 hw/microblaze: defer PetaLogix endianness default until init

In reply to Yonggang Luo

This is for avoid call target_info() in class_init

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

PATCH 14/34 hw/pci: Avoid guard loadparm with target_s390x() for s390x in class_init

In reply to Yonggang Luo

This is for avoid call target_info() in class_init. Now we directly guard in pci_qdev_property_set_loadparm instead. Don't know if its an API break, but the smallest change.

---
 hw/pci/pci.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/pci/pci.c +10 -8
index 0efb4eb4bb0..9d3dcd52942 100644
@@ -2878,6 +2878,11 @@ static void pci_qdev_property_set_loadparm(Object *obj, const char *value,
 {
     void *lp_str;
 
+    if (!target_s390x()) {
+        error_setg(errp, "'loadparm' is only supported on s390x");
+        return;
+    }
+
     if (object_property_get_int(obj, "bootindex", NULL) < 0) {
         error_setg(errp, "'loadparm' is only valid for boot devices");
         return;
@@ -2895,14 +2900,11 @@ void pci_qdev_property_add_specifics(DeviceClass *dc)
 {
     ObjectClass *oc = OBJECT_CLASS(dc);
 
-    /* The loadparm property is only supported on s390x */
-    if (target_s390x()) {
-        object_class_property_add_str(oc, "loadparm",
-                                      pci_qdev_property_get_loadparm,
-                                      pci_qdev_property_set_loadparm);
-        object_class_property_set_description(oc, "loadparm",
-                                              "load parameter (s390x only)");
-    }
+    object_class_property_add_str(oc, "loadparm",
+                                  pci_qdev_property_get_loadparm,
+                                  pci_qdev_property_set_loadparm);
+    object_class_property_set_description(oc, "loadparm",
+                                          "load parameter (s390x only)");
 }
 
 MemoryRegion *pci_address_space(PCIDevice *dev)
Signature · 1 line
2.55.0.windows.3
#23 lore raw

PATCH 15/34 hw/scsi: Avoid guard loadparm with target_s390x() for s390x in class_init

In reply to Yonggang Luo

This is for avoid call target_info() in class_init. Now we directly guard in scsi_property_set_loadparm instead. Don't know if its an API break, but the smallest change.

---
 hw/scsi/scsi-disk.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/scsi/scsi-disk.c +10 -8
index deb33ac1dda..276941ae537 100644
@@ -3179,6 +3179,11 @@ static void scsi_property_set_loadparm(Object *obj, const char *value,
 {
     void *lp_str;
 
+    if (!target_s390x()) {
+        error_setg(errp, "'loadparm' is only supported on s390x");
+        return;
+    }
+
     if (object_property_get_int(obj, "bootindex", NULL) < 0) {
         error_setg(errp, "'loadparm' is only valid for boot devices");
         return;
@@ -3196,14 +3201,11 @@ static void scsi_property_add_specifics(DeviceClass *dc)
 {
     ObjectClass *oc = OBJECT_CLASS(dc);
 
-    /* The loadparm property is only supported on s390x */
-    if (target_s390x()) {
-        object_class_property_add_str(oc, "loadparm",
-                                      scsi_property_get_loadparm,
-                                      scsi_property_set_loadparm);
-        object_class_property_set_description(oc, "loadparm",
-                                              "load parameter (s390x only)");
-    }
+    object_class_property_add_str(oc, "loadparm",
+                                  scsi_property_get_loadparm,
+                                  scsi_property_set_loadparm);
+    object_class_property_set_description(oc, "loadparm",
+                                          "load parameter (s390x only)");
 }
 
 static void scsi_disk_base_class_initfn(ObjectClass *klass, const void *data)
Signature · 1 line
2.55.0.windows.3
#24 lore raw
In reply to Yonggang Luo
Quoted 126 lines · Yonggang Luo

MachineClass::targets declares each machine's supported targets as a uint64_t QEMU_ARCH_* mask.

In the combined executable, a machine can be selected from <target>-<machine-name> when <machine-name> is ambitious. Otherwise we can use <machine-name> to directly select a target.

Renaming SysEmuTarget to EmuTarget prepares the enum for both system and user-mode targets before introducing more usage of it. Rationale:
https://lore.kernel.org/qemu-devel/[email protected]/

The "virt" machines need distinct QOM names to coexist in a combined binary or test. Their existing CLI names and aliases are preserved.

Other indirect call of target_info() in class_init/type_init is removed by serveral commits, this is a prepare for select <target> by -machine $type. As target_info() will be NULL till the target is selected under machine_select.

The commits through "hw: add MachineClass::targets with a usage and test" add a minimal demo/test for introduce MachineClass::targets

The next group, through
"meson: build combined qemu-system for multi-target configurations", enabled the test guard to prevent introduce future calling target_info() in type_init or class_init

These two boundaries provide possible merge points.

"targets" be exported along with MachineInfo in commit
"qmp: Expose supported targets in query-machines", so that the qmp know how to set proper $<target>-<machine-name>.

The rest commits is the introduce of support of <target> select from -machine $type.

Yonggang Luo (34):
qemu/base-arch-defs: extract QEMU_ARCH_BIT for QEMU_ARCH_* enums
qemu: Use SYS_EMU_TARGET__MAX to define QEMU_ARCH_ALL
qemu: increase width of QEMU_ARCH_* masks enums to be 64 bits
qapi: rename SysEmuTarget to EmuTarget
qapi: add missing Linux user-mode targets to EmuTarget
meson: define TARGET_ARCH_VARIANT to target_name only
target-info: prepare the QOM target list before
module_call_init(MODULE_INIT_QOM)
hw: add MachineClass::targets with a usage and test
accel: register CPU parent for each target
meson: collect Rust crates for combined system target
module: Add module_allow_all_arch for allow all modules be loaded target/arm: defer max-v8 initializer selection until CPU creation hw/microblaze: defer PetaLogix endianness default until init hw/pci: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/scsi: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/virtio/virtio-mem: Avoid call to target_info() in class_init
target-info: add a combined-binary query stub
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: Add MachineClass.targets for all "virt" machines for all possible
targets
system/arch_init: update qemu_arch_available to handle non-target
select condition
meson: build combined qemu-system for multi-target configurations
qmp: Expose supported targets in query-machines
system/vl: select target from machine name in combined binaries system/vl: handle cpu/device help properly for multi-target qemu
qdev: Handle device alias ambiguous under multi-target qemu

 MAINTAINERS                              |   2 +
 accel/accel-common.c                     |   6 +-
 accel/accel-internal.h                   |   1 +
 accel/accel-system.c                     |  24 +++
 accel/accel-user.c                       |   7 +
 backends/igvm.c                          |   4 +-
 hw/alpha/dp264.c                         |   2 +
 hw/arm/virt.c                            |  56 +++----
 hw/core/machine-qmp-cmds.c               |  19 ++-
 hw/core/machine.c                        |   9 ++
 hw/hexagon/virt.c                        |  25 +++-
 hw/loongarch/virt.c                      |  47 +++---
 hw/m68k/virt.c                           |  39 +++--
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  11 +-
 hw/misc/vmlaunchupdate.c                 |   6 +-
 hw/or1k/virt.c                           |  22 +--
 hw/pci/pci.c                             |  18 ++-
 hw/riscv/virt.c                          |  28 ++--
 hw/scsi/scsi-disk.c                      |  18 ++-
 hw/uefi/ovmf-log.c                       |   4 +-
 hw/virtio/virtio-mem.c                   |  26 ++--
 hw/xtensa/virt.c                         |  24 ++-
 include/hw/arm/virt.h                    |   5 +-
 include/hw/core/boards.h                 |  45 ++++--
 include/hw/hexagon/virt.h                |   5 +-
 include/hw/loongarch/virt.h              |   5 +-
 include/hw/riscv/virt.h                  |   5 +-
 include/monitor/qdev.h                   |   7 +
 include/qemu/base-arch-defs.h            |  80 ++++++----
 include/qemu/module.h                    |   2 +
 include/qemu/target-info-def.h           |   2 +-
 include/qemu/target-info-qapi.h          |   4 +-
 include/qemu/target-info-qom.h           |   4 +
 include/qemu/target-info.h               |   7 +
 meson.build                              |  82 +++++++++-
 monitor/monitor-hmp-internal.h           |   2 +-
 qapi/machine.json                        |  44 +++---
 qapi/pragma.json                         |   4 +-
 qom/object.c                             |   4 +-
 stubs/meson.build                        |   1 +
 stubs/target-info.c                      |  10 ++
 system/arch_init.c                       |  12 +-
 system/qdev-monitor.c                    |  54 ++++++-
 system/target-info.c                     |  10 ++
 system/vl.c                              | 181 ++++++++++++++++++++---
 target-info-def.c                        |   2 +-
 target-info-qom.c                        |  26 +++-
 target-info.c                            |  38 ++---
 target/arm/tcg/cpu-max-v8.c              |  17 ++-
Quoted 9 lines
 tests/qtest/fuzz/fuzz.c                  |   2 +-
 tests/qtest/qom-test.c                   |  65 +++++++-
 tests/unit/meson.build                   |   4 +-
 tests/unit/test-multi-target.c           |  67 ++++++++-
 util/module.c                            |  10 +-
 54 files changed, 915 insertions(+), 289 deletions(-)
 create mode 100644 stubs/target-info.c
 create mode 100644 system/target-info.c

Hi Yonggang,

in a previous thread, we had a long discussion about which direction we want to go, and what needs to be implemented. I politely suggested to focus first on simply removing dependency in class_init to target_info, and rely on is_available only. The idea was to convince you that small iteration steps are better than throw-all-in series. I thought we were on the same page.

Now, yet another mega series mixing cleanup, code and even going as far as introducing the qemu-system binary.

I feel like spending time to give advice didn't lead to a concrete change in behavior. As a result, I'm stopping to review all those series, and will let others drive this.

Regards,
Pierrick

#25 lore raw
Quoted 138 lines · Pierrick Bouvier
Quoted 126 lines · Yonggang Luo

MachineClass::targets declares each machine's supported targets as a uint64_t QEMU_ARCH_* mask.

In the combined executable, a machine can be selected from <target>-<machine-name> when <machine-name> is ambitious. Otherwise we can use <machine-name> to directly select a target.

Renaming SysEmuTarget to EmuTarget prepares the enum for both system and user-mode targets before introducing more usage of it. Rationale:
https://lore.kernel.org/qemu-devel/[email protected]/

The "virt" machines need distinct QOM names to coexist in a combined binary or test. Their existing CLI names and aliases are preserved.

Other indirect call of target_info() in class_init/type_init is removed by serveral commits, this is a prepare for select <target> by -machine $type. As target_info() will be NULL till the target is selected under machine_select.

The commits through "hw: add MachineClass::targets with a usage and test" add a minimal demo/test for introduce MachineClass::targets

The next group, through
"meson: build combined qemu-system for multi-target configurations", enabled the test guard to prevent introduce future calling target_info() in type_init or class_init

These two boundaries provide possible merge points.

"targets" be exported along with MachineInfo in commit
"qmp: Expose supported targets in query-machines", so that the qmp know how to set proper $<target>-<machine-name>.

The rest commits is the introduce of support of <target> select from -machine $type.

Yonggang Luo (34):
qemu/base-arch-defs: extract QEMU_ARCH_BIT for QEMU_ARCH_* enums
qemu: Use SYS_EMU_TARGET__MAX to define QEMU_ARCH_ALL
qemu: increase width of QEMU_ARCH_* masks enums to be 64 bits
qapi: rename SysEmuTarget to EmuTarget
qapi: add missing Linux user-mode targets to EmuTarget
meson: define TARGET_ARCH_VARIANT to target_name only
target-info: prepare the QOM target list before
module_call_init(MODULE_INIT_QOM)
hw: add MachineClass::targets with a usage and test
accel: register CPU parent for each target
meson: collect Rust crates for combined system target
module: Add module_allow_all_arch for allow all modules be loaded target/arm: defer max-v8 initializer selection until CPU creation hw/microblaze: defer PetaLogix endianness default until init hw/pci: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/scsi: Avoid guard loadparm with target_s390x() for s390x in
class_init
hw/virtio/virtio-mem: Avoid call to target_info() in class_init
target-info: add a combined-binary query stub
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: Add MachineClass.targets for all "virt" machines for all possible
targets
system/arch_init: update qemu_arch_available to handle non-target
select condition
meson: build combined qemu-system for multi-target configurations
qmp: Expose supported targets in query-machines
system/vl: select target from machine name in combined binaries system/vl: handle cpu/device help properly for multi-target qemu
qdev: Handle device alias ambiguous under multi-target qemu

 MAINTAINERS                              |   2 +
 accel/accel-common.c                     |   6 +-
 accel/accel-internal.h                   |   1 +
 accel/accel-system.c                     |  24 +++
 accel/accel-user.c                       |   7 +
 backends/igvm.c                          |   4 +-
 hw/alpha/dp264.c                         |   2 +
 hw/arm/virt.c                            |  56 +++----
 hw/core/machine-qmp-cmds.c               |  19 ++-
 hw/core/machine.c                        |   9 ++
 hw/hexagon/virt.c                        |  25 +++-
 hw/loongarch/virt.c                      |  47 +++---
 hw/m68k/virt.c                           |  39 +++--
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  11 +-
 hw/misc/vmlaunchupdate.c                 |   6 +-
 hw/or1k/virt.c                           |  22 +--
 hw/pci/pci.c                             |  18 ++-
 hw/riscv/virt.c                          |  28 ++--
 hw/scsi/scsi-disk.c                      |  18 ++-
 hw/uefi/ovmf-log.c                       |   4 +-
 hw/virtio/virtio-mem.c                   |  26 ++--
 hw/xtensa/virt.c                         |  24 ++-
 include/hw/arm/virt.h                    |   5 +-
 include/hw/core/boards.h                 |  45 ++++--
 include/hw/hexagon/virt.h                |   5 +-
 include/hw/loongarch/virt.h              |   5 +-
 include/hw/riscv/virt.h                  |   5 +-
 include/monitor/qdev.h                   |   7 +
 include/qemu/base-arch-defs.h            |  80 ++++++----
 include/qemu/module.h                    |   2 +
 include/qemu/target-info-def.h           |   2 +-
 include/qemu/target-info-qapi.h          |   4 +-
 include/qemu/target-info-qom.h           |   4 +
 include/qemu/target-info.h               |   7 +
 meson.build                              |  82 +++++++++-
 monitor/monitor-hmp-internal.h           |   2 +-
 qapi/machine.json                        |  44 +++---
 qapi/pragma.json                         |   4 +-
 qom/object.c                             |   4 +-
 stubs/meson.build                        |   1 +
 stubs/target-info.c                      |  10 ++
 system/arch_init.c                       |  12 +-
 system/qdev-monitor.c                    |  54 ++++++-
 system/target-info.c                     |  10 ++
 system/vl.c                              | 181 ++++++++++++++++++++---
 target-info-def.c                        |   2 +-
 target-info-qom.c                        |  26 +++-
 target-info.c                            |  38 ++---
 target/arm/tcg/cpu-max-v8.c              |  17 ++-
Quoted 9 lines
 tests/qtest/fuzz/fuzz.c                  |   2 +-
 tests/qtest/qom-test.c                   |  65 +++++++-
 tests/unit/meson.build                   |   4 +-
 tests/unit/test-multi-target.c           |  67 ++++++++-
 util/module.c                            |  10 +-
 54 files changed, 915 insertions(+), 289 deletions(-)
 create mode 100644 stubs/target-info.c
 create mode 100644 system/target-info.c
Quoted 5 lines

Hi Yonggang,

in a previous thread, we had a long discussion about which direction we want to go, and what needs to be implemented. I politely suggested to focus first on simply removing dependency in class_init to target_info,

The removing dependency in class_init to target_info is at:

https://lore.kernel.org/qemu-devel/[email protected]/

I think it's easy to avoid target_info in class_init , there is no need to rely
on is_available for this.

Quoted 3 lines

and rely on is_available only. The idea was to convince you that small iteration steps are better than throw-all-in series. I thought we were on the same page.

Sorry, I should add the DRAFT in the title, it is just a post for experiment(means
testing locally) and tells us our direction is correct. And also I can use it locally. Sorry for the burden.

Quoted 5 lines

Now, yet another mega series mixing cleanup, code and even going as far as introducing the qemu-system binary.

I feel like spending time to give advice didn't lead to a concrete

Your advice I am hearing and done at
https://lore.kernel.org/qemu-devel/[email protected]/

And I explained no need to introduce is_available to avoid target_info() in class_init.
Because I can not get a usable qemu-system that includes all QOM names.

Quoted 2 lines

change in behavior. As a result, I'm stopping to review all those series, and will let others drive this.

I am fine with that, thanks. Others drive(coding) will give more agreement. Things/Design
sometimes needed in conjunction with code.

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo