Skip to contentSkip to conversation

target-info: Add more API for VirtIO cleanups

PATCH Superseded Philippe Mathieu-Daudé 3 participants 23 messages Jul 8, 2025

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover target-info: Add more API for VirtIO cleanups

Since v6:
- Added R-b tags
- Fixed typos
- Dropped "Introduce target_base_arch()" because unused so far
- Dropped unrelated patches

Philippe Mathieu-Daudé (8):
target/qmp: Use target_cpu_type()
qemu/target-info: Factor target_arch() out qemu/target-info: Add %target_arch field to TargetInfo qemu/target-info: Add target_endian_mode()
qemu: Convert target_words_bigendian() to TargetInfo API gdbstub/helpers: Replace TARGET_BIG_ENDIAN -> target_big_endian()
qemu: Declare all load/store helper in 'qemu/bswap.h' hw/virtio: Build various files once

 include/exec/tswap.h                  | 83 +--------------------------
 include/gdbstub/helpers.h             | 15 ++---
 include/qemu/bswap.h                  | 73 +++++++++++++++++++++++
 include/qemu/target-info-impl.h       |  6 +-
 include/qemu/target-info-qapi.h       | 29 ++++++++++
 include/qemu/target-info.h            | 10 +++-
 include/system/memory.h               |  1 -
 include/user/abitypes.h               |  1 -
 target/ppc/mmu-hash64.h               |  2 -
 cpu-target.c                          |  7 ---
 hw/acpi/bios-linker-loader.c          |  2 -
 hw/arm/allwinner-r40.c                |  1 -
 hw/arm/boot.c                         |  2 +
 hw/arm/npcm7xx.c                      |  2 +-
 hw/block/hd-geometry.c                |  1 -
 hw/char/riscv_htif.c                  |  1 -
 hw/core/cpu-system.c                  |  2 +-
 hw/core/machine-qmp-cmds.c            |  8 +--
 hw/cxl/cxl-events.c                   |  2 -
 hw/display/artist.c                   |  1 +
 hw/display/ati.c                      |  1 +
 hw/display/vga.c                      |  2 +-
 hw/net/can/ctucan_core.c              |  1 -
 hw/net/lan9118.c                      |  1 +
 hw/net/rtl8139.c                      |  1 +
 hw/net/vmxnet3.c                      |  1 -
 hw/pci-host/gt64120.c                 |  1 +
 hw/pci-host/pnv_phb3.c                |  1 +
 hw/pci-host/pnv_phb4.c                |  1 +
 hw/pci-host/ppce500.c                 |  1 -
 hw/pci-host/sh_pci.c                  |  1 -
 hw/s390x/s390-pci-inst.c              |  1 +
 hw/sensor/lsm303dlhc_mag.c            |  1 -
 hw/smbios/smbios.c                    |  1 +
 hw/vfio/migration-multifd.c           |  1 -
 hw/virtio/virtio-config-io.c          |  1 -
 hw/virtio/virtio-pci.c                |  1 +
 hw/virtio/virtio.c                    |  2 +-
 hw/vmapple/virtio-blk.c               |  1 -
 system/memory.c                       |  1 +
 system/qtest.c                        |  1 +
 target-info-stub.c                    |  2 +
 target-info.c                         | 23 ++++++++
 target/arm/arm-qmp-cmds.c             |  3 +-
 target/arm/cpu.c                      |  1 -
 target/i386/tcg/system/excp_helper.c  |  1 -
 target/i386/xsave_helper.c            |  1 -
 target/loongarch/loongarch-qmp-cmds.c |  3 +-
 target/mips/system/mips-qmp-cmds.c    |  3 +-
 target/riscv/vector_helper.c          |  1 -
 tests/tcg/plugins/mem.c               |  1 +
 hw/block/meson.build                  |  6 +-
 hw/virtio/meson.build                 | 20 ++++---
 53 files changed, 191 insertions(+), 146 deletions(-)
 create mode 100644 include/qemu/target-info-qapi.h
Signature · 1 line
2.49.0
#1 lore raw

PATCH v7 1/8 target/qmp: Use target_cpu_type()

---
 target/arm/arm-qmp-cmds.c             | 3 ++-
 target/loongarch/loongarch-qmp-cmds.c | 3 ++-
 target/mips/system/mips-qmp-cmds.c    | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
target/arm/arm-qmp-cmds.c +2 -1
index cefd2352638..d292c974c44 100644
@@ -21,6 +21,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "hw/boards.h"
 #include "kvm_arm.h"
 #include "qapi/error.h"
@@ -241,7 +242,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list;
 
-    list = object_class_get_list(TYPE_ARM_CPU, false);
+    list = object_class_get_list(target_cpu_type(), false);
     g_slist_foreach(list, arm_cpu_add_definition, &cpu_list);
     g_slist_free(list);
 
target/loongarch/loongarch-qmp-cmds.c +2 -1
index f5f1cd0009d..1d8cd32f5fc 100644
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine.h"
 #include "cpu.h"
@@ -32,7 +33,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list;
 
-    list = object_class_get_list(TYPE_LOONGARCH_CPU, false);
+    list = object_class_get_list(target_cpu_type(), false);
     g_slist_foreach(list, loongarch_cpu_add_definition, &cpu_list);
     g_slist_free(list);
 
target/mips/system/mips-qmp-cmds.c +2 -1
index d98d6623f2f..b6a2874f2dd 100644
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine.h"
 #include "cpu.h"
@@ -40,7 +41,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     CpuDefinitionInfoList *cpu_list = NULL;
     GSList *list;
 
-    list = object_class_get_list(TYPE_MIPS_CPU, false);
+    list = object_class_get_list(target_cpu_type(), false);
     g_slist_foreach(list, mips_cpu_add_definition, &cpu_list);
     g_slist_free(list);
 
Signature · 1 line
2.49.0
Reviewed-by on v7 1/8
#2 lore raw

Re: [PATCH-for-10.1 v7 1/8] target/qmp: Use target_cpu_type()

Quoted 7 lines · Philippe Mathieu-Daudé
---
  target/arm/arm-qmp-cmds.c             | 3 ++-
  target/loongarch/loongarch-qmp-cmds.c | 3 ++-
  target/mips/system/mips-qmp-cmds.c    | 3 ++-
  3 files changed, 6 insertions(+), 3 deletions(-) 
#3 lore raw

PATCH v7 2/8 qemu/target-info: Factor target_arch() out

In reply to Philippe Mathieu-Daudé

To keep "qemu/target-info.h" self-contained to native types, declare target_arch() -- which returns a QAPI type -- in "qemu/target-info-qapi.h".

No logical change.

Keeping native types in "qemu/target-info.h" is necessary to keep building tests such tests/tcg/plugins/mem.c, as per the comment added in commit ecbcc9ead2f ("tests/tcg:
add a system test to check memory instrumentation"):

/*
* plugins should not include anything from QEMU aside from the
* API header. However as this is a test plugin to exercise the
* internals of QEMU and we want to avoid needless code duplication we
* do so here. bswap.h is pretty self-contained although it needs a
* few things provided by compiler.h.
*/

---
 include/qemu/target-info-qapi.h | 21 +++++++++++++++++++++
 include/qemu/target-info.h      |  2 +-
 hw/core/machine-qmp-cmds.c      |  8 +++-----
 target-info.c                   |  8 ++++++++
 4 files changed, 33 insertions(+), 6 deletions(-)
 create mode 100644 include/qemu/target-info-qapi.h
include/qemu/target-info-qapi.h new file +21 -0
new file mode 100644
index 00000000000..dae92c47eb1
@@ -0,0 +1,21 @@
+/*
+ * QEMU target info API (returning QAPI types)
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_EXTRA_H
+#define QEMU_TARGET_INFO_EXTRA_H
+
+#include "qapi/qapi-types-machine.h"
+
+/**
+ * target_arch:
+ *
+ * Returns: QAPI SysEmuTarget enum (i.e. SYS_EMU_TARGET_X86_64).
+ */
+SysEmuTarget target_arch(void);
+
+#endif
include/qemu/target-info.h +1 -1
index 850a2958b9c..dde0e7d968a 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU target info API
+ * QEMU target info API (returning native types)
  *
  *  Copyright (c) Linaro
  *
hw/core/machine-qmp-cmds.c +3 -5
index d82043e1c68..cd98daedd18 100644
@@ -19,7 +19,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/type-helpers.h"
 #include "qemu/uuid.h"
-#include "qemu/target-info.h"
+#include "qemu/target-info-qapi.h"
 #include "qom/qom-qobject.h"
 #include "system/hostmem.h"
 #include "system/hw_accel.h"
@@ -37,8 +37,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 = qapi_enum_parse(&SysEmuTarget_lookup, target_name(),
-                                          -1, &error_abort);
+    SysEmuTarget target = target_arch();
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
@@ -139,8 +138,7 @@ QemuTargetInfo *qmp_query_target(Error **errp)
 {
     QemuTargetInfo *info = g_malloc0(sizeof(*info));
 
-    info->arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
-                                 &error_abort);
+    info->arch = target_arch();
 
     return info;
 }
target-info.c +8 -0
index 16fdca7aaaf..9ebabec988f 100644
@@ -8,7 +8,9 @@
 
 #include "qemu/osdep.h"
 #include "qemu/target-info.h"
+#include "qemu/target-info-qapi.h"
 #include "qemu/target-info-impl.h"
+#include "qapi/error.h"
 
 const char *target_name(void)
 {
@@ -20,6 +22,12 @@ unsigned target_long_bits(void)
     return target_info()->long_bits;
 }
 
+SysEmuTarget target_arch(void)
+{
+    return qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
+                           &error_abort);
+}
+
 const char *target_cpu_type(void)
 {
     return target_info()->cpu_type;
Signature · 1 line
2.49.0
Reviewed-by on v7 2/8
#4 lore raw

Re: [PATCH-for-10.1 v7 2/8] qemu/target-info: Factor target_arch() out

Quoted 21 lines · Philippe Mathieu-Daudé

To keep "qemu/target-info.h" self-contained to native types, declare target_arch() -- which returns a QAPI type -- in "qemu/target-info-qapi.h".

No logical change.

Keeping native types in "qemu/target-info.h" is necessary to keep building tests such tests/tcg/plugins/mem.c, as per the comment added in commit ecbcc9ead2f ("tests/tcg:
add a system test to check memory instrumentation"):

/*
* plugins should not include anything from QEMU aside from the
* API header. However as this is a test plugin to exercise the
* internals of QEMU and we want to avoid needless code duplication we
* do so here. bswap.h is pretty self-contained although it needs a
* few things provided by compiler.h.
*/

Quoted 7 lines
---
  include/qemu/target-info-qapi.h | 21 +++++++++++++++++++++
  include/qemu/target-info.h      |  2 +-
  hw/core/machine-qmp-cmds.c      |  8 +++-----
  target-info.c                   |  8 ++++++++
  4 files changed, 33 insertions(+), 6 deletions(-)

create mode 100644 include/qemu/target-info-qapi.h

#5 lore raw

PATCH v7 3/8 qemu/target-info: Add %target_arch field to TargetInfo

In reply to Philippe Mathieu-Daudé
---
 include/qemu/target-info-impl.h | 4 +++-
 target-info-stub.c              | 1 +
 target-info.c                   | 9 +++++++--
 3 files changed, 11 insertions(+), 3 deletions(-)
include/qemu/target-info-impl.h +3 -1
index 1b51cbcfe1b..a8b34d150ab 100644
@@ -9,11 +9,13 @@
 #ifndef QEMU_TARGET_INFO_IMPL_H
 #define QEMU_TARGET_INFO_IMPL_H
 
-#include "qemu/target-info.h"
+#include "qapi/qapi-types-machine.h"
 
 typedef struct TargetInfo {
     /* runtime equivalent of TARGET_NAME definition */
     const char *target_name;
+    /* related to TARGET_ARCH definition */
+    SysEmuTarget target_arch;
     /* runtime equivalent of TARGET_LONG_BITS definition */
     unsigned long_bits;
     /* runtime equivalent of CPU_RESOLVING_TYPE definition */
target-info-stub.c +1 -0
index fecc0e71286..2e4407ff04b 100644
@@ -14,6 +14,7 @@
 
 static const TargetInfo target_info_stub = {
     .target_name = TARGET_NAME,
+    .target_arch = SYS_EMU_TARGET__MAX,
     .long_bits = TARGET_LONG_BITS,
     .cpu_type = CPU_RESOLVING_TYPE,
     .machine_typename = TYPE_MACHINE,
target-info.c +7 -2
index 9ebabec988f..8e29553b4ef 100644
@@ -24,8 +24,13 @@ unsigned target_long_bits(void)
 
 SysEmuTarget target_arch(void)
 {
-    return qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
-                           &error_abort);
+    SysEmuTarget arch = target_info()->target_arch;
+
+    if (arch == SYS_EMU_TARGET__MAX) {
+        arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
+                               &error_abort);
+    }
+    return arch;
 }
 
 const char *target_cpu_type(void)
Signature · 1 line
2.49.0
Reviewed-by on v7 3/8
#6 lore raw

Re: [PATCH-for-10.1 v7 3/8] qemu/target-info: Add %target_arch field to TargetInfo

Quoted 7 lines · Philippe Mathieu-Daudé
---
  include/qemu/target-info-impl.h | 4 +++-
  target-info-stub.c              | 1 +
  target-info.c                   | 9 +++++++--
  3 files changed, 11 insertions(+), 3 deletions(-)
#7 lore raw

PATCH v7 4/8 qemu/target-info: Add target_endian_mode()

In reply to Philippe Mathieu-Daudé

target_endian_mode() returns the default endianness (QAPI type) of a target.

---
 include/qemu/target-info-impl.h | 2 ++
 include/qemu/target-info-qapi.h | 8 ++++++++
 target-info-stub.c              | 1 +
 target-info.c                   | 5 +++++
 4 files changed, 16 insertions(+)
include/qemu/target-info-impl.h +2 -0
index a8b34d150ab..17887f64e26 100644
@@ -22,6 +22,8 @@ typedef struct TargetInfo {
     const char *cpu_type;
     /* QOM typename machines for this binary must implement */
     const char *machine_typename;
+    /* related to TARGET_BIG_ENDIAN definition */
+    EndianMode endianness;
 } TargetInfo;
 
 /**
include/qemu/target-info-qapi.h +8 -0
index dae92c47eb1..bdf207e6a3e 100644
@@ -9,6 +9,7 @@
 #ifndef QEMU_TARGET_INFO_EXTRA_H
 #define QEMU_TARGET_INFO_EXTRA_H
 
+#include "qapi/qapi-types-common.h"
 #include "qapi/qapi-types-machine.h"
 
 /**
@@ -18,4 +19,11 @@
  */
 SysEmuTarget target_arch(void);
 
+/**
+ * target_endian_mode:
+ *
+ * Returns: QAPI EndianMode enum (i.e. ENDIAN_MODE_LITTLE).
+ */
+EndianMode target_endian_mode(void);
+
 #endif
target-info-stub.c +1 -0
index 2e4407ff04b..ca0caa3686c 100644
@@ -18,6 +18,7 @@ static const TargetInfo target_info_stub = {
     .long_bits = TARGET_LONG_BITS,
     .cpu_type = CPU_RESOLVING_TYPE,
     .machine_typename = TYPE_MACHINE,
+    .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
 };
 
 const TargetInfo *target_info(void)
target-info.c +5 -0
index 8e29553b4ef..a756c0714c4 100644
@@ -42,3 +42,8 @@ const char *target_machine_typename(void)
 {
     return target_info()->machine_typename;
 }
+
+EndianMode target_endian_mode(void)
+{
+    return target_info()->endianness;
+}
Signature · 1 line
2.49.0
Reviewed-by on v7 4/8
#8 lore raw

Re: [PATCH-for-10.1 v7 4/8] qemu/target-info: Add target_endian_mode()

Quoted 10 lines · Philippe Mathieu-Daudé

target_endian_mode() returns the default endianness (QAPI type) of a target.

---
  include/qemu/target-info-impl.h | 2 ++
  include/qemu/target-info-qapi.h | 8 ++++++++
  target-info-stub.c              | 1 +
  target-info.c                   | 5 +++++
  4 files changed, 16 insertions(+)
#10 lore raw

Re: [PATCH-for-10.1 v7 4/8] qemu/target-info: Add target_endian_mode()

Quoted 7 lines · Richard Henderson
Quoted 4 lines · Philippe Mathieu-Daudé

+/**
+ * target_endian_mode:
+ *
+ * Returns: QAPI EndianMode enum (i.e. ENDIAN_MODE_LITTLE).

s/i.e./e.g./

TIL i.e. vs e.g. :)

Quoted 6 lines

Otherwise,

r~

#11 lore raw

PATCH v7 5/8 qemu: Convert target_words_bigendian() to TargetInfo API

In reply to Philippe Mathieu-Daudé
---
 include/exec/tswap.h       | 13 +------------
 include/qemu/target-info.h |  8 ++++++++
 cpu-target.c               |  7 -------
 hw/core/cpu-system.c       |  2 +-
 hw/display/vga.c           |  2 +-
 hw/virtio/virtio.c         |  2 +-
 system/memory.c            |  1 +
 system/qtest.c             |  1 +
 target-info.c              |  5 +++++
 9 files changed, 19 insertions(+), 22 deletions(-)
include/exec/tswap.h +1 -12
index 49511f26117..55ffa633598 100644
@@ -9,18 +9,7 @@
 #define TSWAP_H
 
 #include "qemu/bswap.h"
-
-/**
- * target_big_endian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */
-bool target_big_endian(void);
-#ifdef COMPILING_PER_TARGET
-#define target_big_endian()   TARGET_BIG_ENDIAN
-#endif
+#include "qemu/target-info.h"
 
 /*
  * If we're in target-specific code, we can hard-code the swapping
include/qemu/target-info.h +8 -0
index dde0e7d968a..18a8c4ff6e8 100644
@@ -38,4 +38,12 @@ const char *target_machine_typename(void);
  */
 const char *target_cpu_type(void);
 
+/**
+ * target_big_endian:
+ *
+ * Returns: %true if the (default) endianness of the target is big endian,
+ *          %false otherwise.
+ */
+bool target_big_endian(void);
+
 #endif
cpu-target.c +0 -7
index 1c90a307593..20db5ff3108 100644
@@ -22,7 +22,6 @@
 #include "system/accel-ops.h"
 #include "system/cpus.h"
 #include "exec/cpu-common.h"
-#include "exec/tswap.h"
 #include "exec/replay-core.h"
 #include "exec/log.h"
 #include "hw/core/cpu.h"
@@ -85,9 +84,3 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
 #endif
     abort();
 }
-
-#undef target_big_endian
-bool target_big_endian(void)
-{
-    return TARGET_BIG_ENDIAN;
-}
hw/core/cpu-system.c +1 -1
index 3c84176a0c5..a975405d3a0 100644
@@ -24,7 +24,7 @@
 #include "exec/cputlb.h"
 #include "system/memory.h"
 #include "exec/tb-flush.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "hw/core/sysemu-cpu-ops.h"
hw/display/vga.c +1 -1
index 20475ebbd31..90b89cf4044 100644
@@ -26,7 +26,7 @@
 #include "qemu/units.h"
 #include "system/reset.h"
 #include "qapi/error.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "hw/display/vga.h"
 #include "hw/i386/x86.h"
 #include "hw/pci/pci.h"
hw/virtio/virtio.c +1 -1
index 82a285a31d1..0f4d28033d7 100644
@@ -20,7 +20,7 @@
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "qom/object_interfaces.h"
 #include "hw/core/cpu.h"
 #include "hw/virtio/virtio.h"
system/memory.c +1 -0
index e8d9b15b28f..38da62f5052 100644
@@ -22,6 +22,7 @@
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target-info.h"
 #include "qom/object.h"
 #include "trace.h"
 #include "system/ram_addr.h"
system/qtest.c +1 -0
index 301b03be2d3..fa42c9f9215 100644
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "qemu/cutils.h"
+#include "qemu/target-info.h"
 #include "qom/object_interfaces.h"
 
 #define MAX_IRQ 256
target-info.c +5 -0
index a756c0714c4..3110ab32f75 100644
@@ -47,3 +47,8 @@ EndianMode target_endian_mode(void)
 {
     return target_info()->endianness;
 }
+
+bool target_big_endian(void)
+{
+    return target_endian_mode() == ENDIAN_MODE_BIG;
+}
Signature · 1 line
2.49.0
Reviewed-by on v7 5/8
#12 lore raw

Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API

Quoted 7 lines · Philippe Mathieu-Daudé

-/**
- * target_big_endian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */

...

include/qemu/target-info.h const char *target_machine_typename(void); · line 47

Quoted 7 lines
include/qemu/target-info.h +7 -0
+/**
+ * target_big_endian:
+ *
+ * Returns: %true if the (default) endianness of the target is big endian,
+ *          %false otherwise.
+ */
+bool target_big_endian(void);

Perhaps retain the warning about not using this unless necessary.

r~

#13 lore raw

Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API

Quoted 11 lines · Richard Henderson
Quoted 9 lines · Philippe Mathieu-Daudé

-/**
- * target_big_endian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */

...

Quoted 10 lines
Quoted 8 lines

+/**
+ * target_big_endian:
+ *
+ * Returns: %true if the (default) endianness of the target is big endian,
+ *          %false otherwise.
+ */
+bool target_big_endian(void);

Perhaps retain the warning about not using this unless necessary.

This is what I did in a previous version, but Thomas (or Pierrick?) said something about this method now being safe, so the comment obsolete.

I told Pierrick this method doesn't make sense to me in a heterogeneous context, he said to not make change with the current behavior, when run on a vCPU we'll eventually infer via TargetInfo on the vCPU TLS area, and otherwise (I/O thread) this method shouldn't be called so we should abort. Such change LGTM. I can start updating the documentation mentioning "the (default) endianness of the current vCPU." Currently on I/O thread this is the endianness of the binary.

Quoted 4 lines

r~

#14 lore raw

Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Philippe Mathieu-Daudé

-/**
- * target_big_endian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */

...

Quoted 10 lines
Quoted 8 lines

+/**
+ * target_big_endian:
+ *
+ * Returns: %true if the (default) endianness of the target is big endian,
+ *          %false otherwise.
+ */
+bool target_big_endian(void);

Perhaps retain the warning about not using this unless necessary.

Quoted 3 lines

This is what I did in a previous version, but Thomas (or Pierrick?) said something about this method now being safe, so the comment obsolete.

Bah I'm mixing various conversations, what Pierrick said is different:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 14 lines

I told Pierrick this method doesn't make sense to me in a heterogeneous context, he said to not make change with the current behavior, when run on a vCPU we'll eventually infer via TargetInfo on the vCPU TLS area, and otherwise (I/O thread) this method shouldn't be called so we should abort. Such change LGTM. I can start updating the documentation mentioning "the (default) endianness of the current vCPU." Currently on I/O thread this is the endianness of the binary.

Quoted 4 lines

r~

Reviewed-by on v7 5/8
#15 lore raw

Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé
---
  include/exec/tswap.h       | 13 +------------
  include/qemu/target-info.h |  8 ++++++++
  cpu-target.c               |  7 -------
  hw/core/cpu-system.c       |  2 +-
  hw/display/vga.c           |  2 +-
  hw/virtio/virtio.c         |  2 +-
  system/memory.c            |  1 +
  system/qtest.c             |  1 +
  target-info.c              |  5 +++++
  9 files changed, 19 insertions(+), 22 deletions(-)
#16 lore raw

PATCH v7 6/8 gdbstub/helpers: Replace TARGET_BIG_ENDIAN -> target_big_endian()

In reply to Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
 include/gdbstub/helpers.h | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
include/gdbstub/helpers.h +6 -9
index 6f7cc48adcb..1411b136d5c 100644
@@ -16,6 +16,7 @@
 #error "gdbstub helpers should only be included by target specific code"
 #endif
 
+#include "qemu/target-info.h"
 #include "exec/tswap.h"
 #include "cpu-param.h"
 
@@ -55,18 +56,14 @@ static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
 static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
                                  uint64_t val_lo)
 {
+    bool be = target_big_endian();
     uint64_t to_quad;
-#if TARGET_BIG_ENDIAN
-    to_quad = tswap64(val_hi);
+
+    to_quad = tswap64(be ? val_hi : val_lo);
     g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-    to_quad = tswap64(val_lo);
+    to_quad = tswap64(be ? val_lo : val_hi);
     g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-#else
-    to_quad = tswap64(val_lo);
-    g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-    to_quad = tswap64(val_hi);
-    g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-#endif
+
     return 16;
 }
 
Signature · 1 line
2.49.0
#17 lore raw

Re: [PATCH-for-10.1 v7 6/8] gdbstub/helpers: Replace TARGET_BIG_ENDIAN -> target_big_endian()

Quoted 30 lines · Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
  include/gdbstub/helpers.h | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
include/gdbstub/helpers.h +4 -2
index 6f7cc48adcb..1411b136d5c 100644
@@ -16,6 +16,7 @@
  #error "gdbstub helpers should only be included by target specific code"
  #endif
 
+#include "qemu/target-info.h"
  #include "exec/tswap.h"
  #include "cpu-param.h"
 
@@ -55,18 +56,14 @@ static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
  static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
                                   uint64_t val_lo)
  {
+    bool be = target_big_endian();
      uint64_t to_quad;
-#if TARGET_BIG_ENDIAN
-    to_quad = tswap64(val_hi);
+
+    to_quad = tswap64(be ? val_hi : val_lo);

include/gdbstub/helpers.h static inline int gdb_get_reg64(GByteArray *buf, uint64_t val) · line 69

Quoted 10 lines
include/gdbstub/helpers.h +1 -7
      g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-    to_quad = tswap64(val_lo);
+    to_quad = tswap64(be ? val_lo : val_hi);
      g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-#else
-    to_quad = tswap64(val_lo);
-    g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-    to_quad = tswap64(val_hi);
-    g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
-#endif

Don't split the endianness check between here and also within tswap64.

This would be much better as

    uint64_t tmp[2];
    if (target_big_endian()) {
        tmp[0] = cpu_to_be64(val_hi);
        tmp[1] = cpu_to_be64(val_lo);
    } else {
        tmp[0] = cpu_to_le64(val_lo);
        tmp[1] = cpu_to_le64(val_hi);
    }
    g_byte_array_append(buf, (uint8_t *)&tmp, 16);

r~

Reviewed-by on v7 6/8
#18 lore raw

Re: [PATCH-for-10.1 v7 6/8] gdbstub/helpers: Replace TARGET_BIG_ENDIAN -> target_big_endian()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
  include/gdbstub/helpers.h | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
#19 lore raw

PATCH v7 7/8 qemu: Declare all load/store helper in 'qemu/bswap.h'

In reply to Philippe Mathieu-Daudé

Restrict "exec/tswap.h" to the tswap*() methods,
move the load/store helpers with the other ones
declared in "qemu/bswap.h".

---
 include/exec/tswap.h                 | 70 --------------------------
 include/qemu/bswap.h                 | 73 ++++++++++++++++++++++++++++
 include/system/memory.h              |  1 -
 include/user/abitypes.h              |  1 -
 target/ppc/mmu-hash64.h              |  2 -
 hw/acpi/bios-linker-loader.c         |  2 -
 hw/arm/allwinner-r40.c               |  1 -
 hw/arm/boot.c                        |  2 +
 hw/arm/npcm7xx.c                     |  2 +-
 hw/block/hd-geometry.c               |  1 -
 hw/char/riscv_htif.c                 |  1 -
 hw/cxl/cxl-events.c                  |  2 -
 hw/display/artist.c                  |  1 +
 hw/display/ati.c                     |  1 +
 hw/net/can/ctucan_core.c             |  1 -
 hw/net/lan9118.c                     |  1 +
 hw/net/rtl8139.c                     |  1 +
 hw/net/vmxnet3.c                     |  1 -
 hw/pci-host/gt64120.c                |  1 +
 hw/pci-host/pnv_phb3.c               |  1 +
 hw/pci-host/pnv_phb4.c               |  1 +
 hw/pci-host/ppce500.c                |  1 -
 hw/pci-host/sh_pci.c                 |  1 -
 hw/s390x/s390-pci-inst.c             |  1 +
 hw/sensor/lsm303dlhc_mag.c           |  1 -
 hw/smbios/smbios.c                   |  1 +
 hw/vfio/migration-multifd.c          |  1 -
 hw/virtio/virtio-pci.c               |  1 +
 hw/vmapple/virtio-blk.c              |  1 -
 target/arm/cpu.c                     |  1 -
 target/i386/tcg/system/excp_helper.c |  1 -
 target/i386/xsave_helper.c           |  1 -
 target/riscv/vector_helper.c         |  1 -
 tests/tcg/plugins/mem.c              |  1 +
 34 files changed, 87 insertions(+), 93 deletions(-)
include/exec/tswap.h +0 -70
index 55ffa633598..72219e2c431 100644
@@ -69,74 +69,4 @@ static inline void tswap64s(uint64_t *s)
     }
 }
 
-/* Return ld{word}_{le,be}_p following target endianness. */
-#define LOAD_IMPL(word, args...)                    \
-do {                                                \
-    if (target_big_endian()) {                      \
-        return glue(glue(ld, word), _be_p)(args);   \
-    } else {                                        \
-        return glue(glue(ld, word), _le_p)(args);   \
-    }                                               \
-} while (0)
-
-static inline int lduw_p(const void *ptr)
-{
-    LOAD_IMPL(uw, ptr);
-}
-
-static inline int ldsw_p(const void *ptr)
-{
-    LOAD_IMPL(sw, ptr);
-}
-
-static inline int ldl_p(const void *ptr)
-{
-    LOAD_IMPL(l, ptr);
-}
-
-static inline uint64_t ldq_p(const void *ptr)
-{
-    LOAD_IMPL(q, ptr);
-}
-
-static inline uint64_t ldn_p(const void *ptr, int sz)
-{
-    LOAD_IMPL(n, ptr, sz);
-}
-
-#undef LOAD_IMPL
-
-/* Call st{word}_{le,be}_p following target endianness. */
-#define STORE_IMPL(word, args...)           \
-do {                                        \
-    if (target_big_endian()) {              \
-        glue(glue(st, word), _be_p)(args);  \
-    } else {                                \
-        glue(glue(st, word), _le_p)(args);  \
-    }                                       \
-} while (0)
-
-
-static inline void stw_p(void *ptr, uint16_t v)
-{
-    STORE_IMPL(w, ptr, v);
-}
-
-static inline void stl_p(void *ptr, uint32_t v)
-{
-    STORE_IMPL(l, ptr, v);
-}
-
-static inline void stq_p(void *ptr, uint64_t v)
-{
-    STORE_IMPL(q, ptr, v);
-}
-
-static inline void stn_p(void *ptr, int sz, uint64_t v)
-{
-    STORE_IMPL(n, ptr, sz, v);
-}
-
-#undef STORE_IMPL
-
 #endif  /* TSWAP_H */
include/qemu/bswap.h +73 -0

83 lines not on this page · raw message

include/system/memory.h +0 -1
index 46248d4a52c..3ba34d49ba3 100644
@@ -19,7 +19,6 @@
 #include "exec/memattrs.h"
 #include "exec/memop.h"
 #include "exec/ramlist.h"
-#include "exec/tswap.h"
 #include "qemu/bswap.h"
 #include "qemu/queue.h"
 #include "qemu/int128.h"
include/user/abitypes.h +0 -1
index 7528124b62f..be7a8765238 100644
@@ -6,7 +6,6 @@
 #endif
 
 #include "exec/cpu-defs.h"
-#include "exec/tswap.h"
 #include "user/tswap-target.h"
 
 #ifdef TARGET_ABI32
target/ppc/mmu-hash64.h +0 -2
index b8fb12a9705..ae8d4b37aed 100644
@@ -1,8 +1,6 @@
 #ifndef MMU_HASH64_H
 #define MMU_HASH64_H
 
-#include "exec/tswap.h"
-
 #ifndef CONFIG_USER_ONLY
 
 #ifdef TARGET_PPC64
hw/acpi/bios-linker-loader.c +0 -2
index 108061828b1..c9ffe449aac 100644
@@ -22,8 +22,6 @@
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/nvram/fw_cfg.h"
 
-#include "qemu/bswap.h"
-
 /*
  * Linker/loader is a paravirtualized interface that passes commands to guest.
  * The commands can be used to request guest to
hw/arm/allwinner-r40.c +0 -1
index 0bf700865c2..c8eda39957c 100644
@@ -20,7 +20,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "qemu/bswap.h"
 #include "qemu/module.h"
 #include "qemu/units.h"
 #include "hw/boards.h"
hw/arm/boot.c +2 -0
index becd827af13..d391cd01bb1 100644
@@ -15,6 +15,7 @@
 #include "hw/arm/boot.h"
 #include "hw/arm/linux-boot-if.h"
 #include "cpu.h"
+#include "exec/tswap.h"
 #include "exec/target_page.h"
 #include "system/kvm.h"
 #include "system/tcg.h"
@@ -29,6 +30,7 @@
 #include "qemu/config-file.h"
 #include "qemu/option.h"
 #include "qemu/units.h"
+#include "qemu/bswap.h"
 
 /* Kernel boot protocol is specified in the kernel docs
  * Documentation/arm/Booting and Documentation/arm64/booting.txt
hw/arm/npcm7xx.c +1 -1
index 2f30c49df55..ecfae328a96 100644
@@ -24,7 +24,7 @@
 #include "hw/qdev-clock.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
-#include "qemu/bswap.h"
+#include "exec/tswap.h"
 #include "qemu/units.h"
 #include "system/system.h"
 #include "target/arm/cpu-qom.h"
hw/block/hd-geometry.c +0 -1
index f3939e73f42..db221901cf4 100644
@@ -33,7 +33,6 @@
 #include "qemu/osdep.h"
 #include "system/block-backend.h"
 #include "qapi/qapi-types-block.h"
-#include "qemu/bswap.h"
 #include "hw/block/block.h"
 #include "trace.h"
 
hw/char/riscv_htif.c +0 -1
index c884be5d757..a78ea9b01c0 100644
@@ -29,7 +29,6 @@
 #include "qemu/timer.h"
 #include "qemu/error-report.h"
 #include "system/address-spaces.h"
-#include "exec/tswap.h"
 #include "system/dma.h"
 #include "system/runstate.h"
 #include "trace.h"
hw/cxl/cxl-events.c +0 -2
index 12dee2e4675..f90470930d6 100644
@@ -8,8 +8,6 @@
  */
 
 #include "qemu/osdep.h"
-
-#include "qemu/bswap.h"
 #include "qemu/error-report.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
hw/display/artist.c +1 -0
index 3fafc8a222b..3c884c92437 100644
@@ -12,6 +12,7 @@
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qemu/units.h"
+#include "qemu/bswap.h"
 #include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "hw/loader.h"
hw/display/ati.c +1 -0
index 7de27732cdc..f7c0006a879 100644
@@ -22,6 +22,7 @@
 #include "vga-access.h"
 #include "hw/qdev-properties.h"
 #include "vga_regs.h"
+#include "qemu/bswap.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qemu/error-report.h"
hw/net/can/ctucan_core.c +0 -1
index 17131a4e18f..6bd99c477b2 100644
@@ -28,7 +28,6 @@
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
-#include "qemu/bswap.h"
 #include "qemu/bitops.h"
 #include "hw/irq.h"
 #include "migration/vmstate.h"
hw/net/lan9118.c +1 -0
index 6dda1e5c940..3017e129710 100644
@@ -21,6 +21,7 @@
 #include "hw/ptimer.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
+#include "qemu/bswap.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include <zlib.h> /* for crc32 */
hw/net/rtl8139.c +1 -0
index 654a087d80a..324fb932aac 100644
@@ -57,6 +57,7 @@
 #include "system/dma.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "qemu/bswap.h"
 #include "net/net.h"
 #include "net/eth.h"
 #include "system/system.h"
hw/net/vmxnet3.c +0 -1
index 7c0ca56b7c0..af73aa8ef28 100644
@@ -22,7 +22,6 @@
 #include "net/tap.h"
 #include "net/checksum.h"
 #include "system/system.h"
-#include "qemu/bswap.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "hw/pci/msix.h"
hw/pci-host/gt64120.c +1 -0
index b12a25696c4..b1d96f62fe9 100644
@@ -28,6 +28,7 @@
 #include "qapi/error.h"
 #include "qemu/units.h"
 #include "qemu/log.h"
+#include "qemu/bswap.h"
 #include "hw/qdev-properties.h"
 #include "hw/registerfields.h"
 #include "hw/pci/pci_device.h"
hw/pci-host/pnv_phb3.c +1 -0
index a4335f44f22..5d8383fac30 100644
@@ -8,6 +8,7 @@
  */
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "qemu/bswap.h"
 #include "qapi/visitor.h"
 #include "qapi/error.h"
 #include "hw/pci-host/pnv_phb3_regs.h"
hw/pci-host/pnv_phb4.c +1 -0
index 77ea35299d3..18992054e83 100644
@@ -8,6 +8,7 @@
  */
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "qemu/bswap.h"
 #include "qapi/visitor.h"
 #include "qapi/error.h"
 #include "target/ppc/cpu.h"
hw/pci-host/ppce500.c +0 -1
index 52269b05bb1..975d191ccb8 100644
@@ -20,7 +20,6 @@
 #include "migration/vmstate.h"
 #include "hw/pci/pci_device.h"
 #include "hw/pci/pci_host.h"
-#include "qemu/bswap.h"
 #include "hw/pci-host/ppce500.h"
 #include "qom/object.h"
 
hw/pci-host/sh_pci.c +0 -1
index de8f6a84aab..62fb945075f 100644
@@ -28,7 +28,6 @@
 #include "hw/irq.h"
 #include "hw/pci/pci_device.h"
 #include "hw/pci/pci_host.h"
-#include "qemu/bswap.h"
 #include "qemu/module.h"
 #include "qom/object.h"
 
hw/s390x/s390-pci-inst.c +1 -0
index b5dddb22b84..a3bb5aa2216 100644
@@ -16,6 +16,7 @@
 #include "exec/target_page.h"
 #include "system/memory.h"
 #include "qemu/error-report.h"
+#include "qemu/bswap.h"
 #include "system/hw_accel.h"
 #include "hw/boards.h"
 #include "hw/pci/pci_device.h"
hw/sensor/lsm303dlhc_mag.c +0 -1
index f9e501da840..cd5773ae64e 100644
@@ -28,7 +28,6 @@
 #include "qapi/visitor.h"
 #include "qemu/module.h"
 #include "qemu/log.h"
-#include "qemu/bswap.h"
 
 enum LSM303DLHCMagReg {
     LSM303DLHC_MAG_REG_CRA          = 0x00,
hw/smbios/smbios.c +1 -0
index ad4cd6721e6..1ac063cfb4b 100644
@@ -17,6 +17,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/bswap.h"
 #include "qapi/error.h"
 #include "qemu/config-file.h"
 #include "qemu/module.h"
hw/vfio/migration-multifd.c +0 -1
index 850a3194887..69e57833dbd 100644
@@ -13,7 +13,6 @@
 #include "hw/vfio/vfio-device.h"
 #include "migration/misc.h"
 #include "qapi/error.h"
-#include "qemu/bswap.h"
 #include "qemu/error-report.h"
 #include "qemu/lockable.h"
 #include "qemu/main-loop.h"
hw/virtio/virtio-pci.c +1 -0
index fba2372c93b..767216d7959 100644
@@ -30,6 +30,7 @@
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "qemu/bswap.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/loader.h"
hw/vmapple/virtio-blk.c +0 -1
index 532b5649ab7..9de9aaae0bf 100644
@@ -19,7 +19,6 @@
 #include "hw/vmapple/vmapple.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-pci.h"
-#include "qemu/bswap.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
target/arm/cpu.c +0 -1
index ebac86f70d3..baaa13aed6d 100644
@@ -23,7 +23,6 @@
 #include "qemu/timer.h"
 #include "qemu/log.h"
 #include "exec/page-vary.h"
-#include "exec/tswap.h"
 #include "target/arm/idau.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
target/i386/tcg/system/excp_helper.c +0 -1
index c1626215877..50040f6fcaf 100644
@@ -25,7 +25,6 @@
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "exec/tlb-flags.h"
-#include "exec/tswap.h"
 #include "tcg/helper-tcg.h"
 
 typedef struct TranslateParams {
target/i386/xsave_helper.c +0 -1
index 24ab7be8e9a..996e9f3bfef 100644
@@ -5,7 +5,6 @@
 #include "qemu/osdep.h"
 
 #include "cpu.h"
-#include "exec/tswap.h"
 
 void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen)
 {
target/riscv/vector_helper.c +0 -1
index b41c29da0be..7c67d67a13f 100644
@@ -27,7 +27,6 @@
 #include "exec/helper-proto.h"
 #include "exec/tlb-flags.h"
 #include "exec/target_page.h"
-#include "exec/tswap.h"
 #include "fpu/softfloat.h"
 #include "tcg/tcg-gvec-desc.h"
 #include "internals.h"
tests/tcg/plugins/mem.c +1 -0
index ca4e8883dd2..9649bce99ca 100644
@@ -20,6 +20,7 @@
  * few things provided by compiler.h.
  */
 #include <compiler.h>
+#include <stdbool.h>
 #include <bswap.h>
 #include <qemu-plugin.h>
 
Signature · 1 line
2.49.0
Reviewed-by on v7 7/8
#20 lore raw

Re: [PATCH-for-10.1 v7 7/8] qemu: Declare all load/store helper in 'qemu/bswap.h'

Quoted 33 lines · Philippe Mathieu-Daudé

Restrict "exec/tswap.h" to the tswap*() methods,
move the load/store helpers with the other ones
declared in "qemu/bswap.h".

---
  include/exec/tswap.h                 | 70 --------------------------
  include/qemu/bswap.h                 | 73 ++++++++++++++++++++++++++++
  include/system/memory.h              |  1 -
  include/user/abitypes.h              |  1 -
  target/ppc/mmu-hash64.h              |  2 -
  hw/acpi/bios-linker-loader.c         |  2 -
  hw/arm/allwinner-r40.c               |  1 -
  hw/arm/boot.c                        |  2 +
  hw/arm/npcm7xx.c                     |  2 +-
  hw/block/hd-geometry.c               |  1 -
  hw/char/riscv_htif.c                 |  1 -
  hw/cxl/cxl-events.c                  |  2 -
  hw/display/artist.c                  |  1 +
  hw/display/ati.c                     |  1 +
  hw/net/can/ctucan_core.c             |  1 -
  hw/net/lan9118.c                     |  1 +
  hw/net/rtl8139.c                     |  1 +
  hw/net/vmxnet3.c                     |  1 -
  hw/pci-host/gt64120.c                |  1 +
  hw/pci-host/pnv_phb3.c               |  1 +
  hw/pci-host/pnv_phb4.c               |  1 +
  hw/pci-host/ppce500.c                |  1 -
  hw/pci-host/sh_pci.c                 |  1 -
  hw/s390x/s390-pci-inst.c             |  1 +
  hw/sensor/lsm303dlhc_mag.c           |  1 -
  hw/smbios/smbios.c                   |  1 +
  hw/vfio/migration-multifd.c          |  1 -
Quoted 8 lines
  hw/virtio/virtio-pci.c               |  1 +
  hw/vmapple/virtio-blk.c              |  1 -
  target/arm/cpu.c                     |  1 -
  target/i386/tcg/system/excp_helper.c |  1 -
  target/i386/xsave_helper.c           |  1 -
  target/riscv/vector_helper.c         |  1 -
  tests/tcg/plugins/mem.c              |  1 +
  34 files changed, 87 insertions(+), 93 deletions(-)
#21 lore raw

PATCH v7 8/8 hw/virtio: Build various files once

In reply to Philippe Mathieu-Daudé

Now that various VirtIO files don't use target specific API anymore, we can move them to the system_ss[] source set to build them once.

---
MST prefers to defer this one to 10.2.

 hw/virtio/virtio-config-io.c |  1 -
 hw/block/meson.build         |  6 ++++--
 hw/virtio/meson.build        | 20 +++++++++++---------
 3 files changed, 15 insertions(+), 12 deletions(-)
hw/virtio/virtio-config-io.c +0 -1
index ad78e0b9bc5..f58d90b6e31 100644
@@ -11,7 +11,6 @@
 
 #include "qemu/osdep.h"
 #include "hw/virtio/virtio.h"
-#include "cpu.h"
 
 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
 {
hw/block/meson.build +4 -2
index 655704471a5..43ed296cf47 100644
@@ -13,7 +13,9 @@ system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
 system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
 system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c'))
 
-specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c', 'virtio-blk-common.c'))
-specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c', 'virtio-blk-common.c'))
+specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
+system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk-common.c'))
+specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c'))
+system_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('virtio-blk-common.c'))
 
 subdir('dataplane')
hw/virtio/meson.build +11 -9
index 164f6fd995a..3ea7b3cec83 100644
@@ -1,6 +1,7 @@
 system_virtio_ss = ss.source_set()
 system_virtio_ss.add(files('virtio-bus.c'))
 system_virtio_ss.add(files('iothread-vq-mapping.c'))
+system_virtio_ss.add(files('virtio-config-io.c'))
 system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('virtio-pci.c'))
 system_virtio_ss.add(when: 'CONFIG_VIRTIO_MMIO', if_true: files('virtio-mmio.c'))
 system_virtio_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-crypto.c'))
@@ -10,11 +11,11 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')
 
 specific_virtio_ss = ss.source_set()
 specific_virtio_ss.add(files('virtio.c'))
-specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c'))
+specific_virtio_ss.add(files('virtio-qmp.c'))
 
 if have_vhost
   system_virtio_ss.add(files('vhost.c'))
-  specific_virtio_ss.add(files('vhost-backend.c', 'vhost-iova-tree.c'))
+  system_virtio_ss.add(files('vhost-backend.c', 'vhost-iova-tree.c'))
   if have_vhost_user
     # fixme - this really should be generic
     specific_virtio_ss.add(files('vhost-user.c'))
@@ -43,22 +44,22 @@ if have_vhost
   endif
   if have_vhost_vdpa
     system_virtio_ss.add(files('vhost-vdpa.c'))
-    specific_virtio_ss.add(files('vhost-shadow-virtqueue.c'))
+    system_virtio_ss.add(files('vhost-shadow-virtqueue.c'))
   endif
 else
   system_virtio_ss.add(files('vhost-stub.c'))
 endif
+system_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c'))
+system_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c'))
 
 specific_virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs.c'))
 specific_virtio_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem.c'))
 specific_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c'))
-specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c'))
-specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c'))
-specific_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('virtio-nsm.c', 'cbor-helpers.c'), libcbor])
 specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c'))
-specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c'))
-specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI'], if_true: files('vhost-user-scmi-pci.c'))
+system_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: files('virtio-nsm.c'))
+system_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('cbor-helpers.c'), libcbor])
+system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c'))
 
 virtio_pci_ss = ss.source_set()
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
@@ -67,6 +68,7 @@ virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi-pci.c'))
 
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-crypto-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_INPUT_HOST', if_true: files('virtio-input-host-pci.c'))
@@ -85,7 +87,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-md-pci.c'))
 
-specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
+system_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 
 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss)
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
Signature · 1 line
2.49.0
Reviewed-by on v7 8/8
#22 lore raw

Re: [PATCH-for-10.1? v7 8/8] hw/virtio: Build various files once

Quoted 6 lines · Philippe Mathieu-Daudé

Now that various VirtIO files don't use target specific API anymore, we can move them to the system_ss[] source set to build them once.

Quoted 7 lines

---
MST prefers to defer this one to 10.2.

  hw/virtio/virtio-config-io.c |  1 -
  hw/block/meson.build         |  6 ++++--
  hw/virtio/meson.build        | 20 +++++++++++---------
  3 files changed, 15 insertions(+), 12 deletions(-)

Good job!