* [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once
@ 2025-05-02 21:45 Philippe Mathieu-Daudé
2025-05-02 21:45 ` [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out Philippe Mathieu-Daudé
` (5 more replies)
0 siblings, 6 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Since v2:
- Use TargetInfo API (Pierrick)
Since v1:
- Use max extent size of all archs (David)
Based-on: <20250501212113.2961531-1-richard.henderson@linaro.org>
Philippe Mathieu-Daudé (5):
qemu/target-info: Factor target_system_arch() out
qemu/target-info: Add %target_arch field to TargetInfo
hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime
hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime
hw/virtio: Compile virtio-mem.c once
include/qemu/target-info-impl.h | 4 +-
include/qemu/target-info.h | 9 +++
hw/core/machine-qmp-cmds.c | 6 +-
hw/virtio/virtio-mem.c | 101 +++++++++++++++++++-------------
target-info-stub.c | 1 +
target-info.c | 15 +++++
hw/virtio/meson.build | 2 +-
7 files changed, 90 insertions(+), 48 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
@ 2025-05-02 21:45 ` Philippe Mathieu-Daudé
2025-05-04 21:16 ` Pierrick Bouvier
2025-05-02 21:45 ` [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo Philippe Mathieu-Daudé
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/target-info.h | 9 +++++++++
hw/core/machine-qmp-cmds.c | 6 ++----
target-info.c | 12 ++++++++++++
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index 850a2958b9c..87b4b0e0cbb 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -9,6 +9,8 @@
#ifndef QEMU_TARGET_INFO_H
#define QEMU_TARGET_INFO_H
+#include "qapi/qapi-types-machine.h"
+
/**
* target_name:
*
@@ -16,6 +18,13 @@
*/
const char *target_name(void);
+/**
+ * target_system_arch:
+ *
+ * Returns: QAPI SysEmuTarget enum (i.e. SYS_EMU_TARGET_I386).
+ */
+SysEmuTarget target_system_arch(void);
+
/**
* target_long_bits:
*
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index d82043e1c68..8f491dba441 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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_system_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_system_arch();
return info;
}
diff --git a/target-info.c b/target-info.c
index 16fdca7aaaf..8232d488870 100644
--- a/target-info.c
+++ b/target-info.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "qemu/target-info.h"
#include "qemu/target-info-impl.h"
+#include "qapi/error.h"
const char *target_name(void)
{
@@ -20,6 +21,17 @@ unsigned target_long_bits(void)
return target_info()->long_bits;
}
+SysEmuTarget target_system_arch(void)
+{
+ static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
+
+ if (system_arch == SYS_EMU_TARGET__MAX) {
+ system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
+ &error_abort);
+ }
+ return system_arch;
+}
+
const char *target_cpu_type(void)
{
return target_info()->cpu_type;
--
2.47.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
2025-05-02 21:45 ` [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out Philippe Mathieu-Daudé
@ 2025-05-02 21:45 ` Philippe Mathieu-Daudé
2025-05-04 21:21 ` Pierrick Bouvier
2025-05-02 21:45 ` [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime Philippe Mathieu-Daudé
` (3 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/target-info-impl.h | 4 +++-
target-info-stub.c | 1 +
target-info.c | 3 +++
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/qemu/target-info-impl.h b/include/qemu/target-info-impl.h
index 1b51cbcfe1b..83d584d7dba 100644
--- a/include/qemu/target-info-impl.h
+++ b/include/qemu/target-info-impl.h
@@ -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-common.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 */
diff --git a/target-info-stub.c b/target-info-stub.c
index fecc0e71286..2e4407ff04b 100644
--- a/target-info-stub.c
+++ b/target-info-stub.c
@@ -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,
diff --git a/target-info.c b/target-info.c
index 8232d488870..5f6096606e4 100644
--- a/target-info.c
+++ b/target-info.c
@@ -25,6 +25,9 @@ SysEmuTarget target_system_arch(void)
{
static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
+ if (system_arch == SYS_EMU_TARGET__MAX) {
+ system_arch = target_info()->target_arch;
+ }
if (system_arch == SYS_EMU_TARGET__MAX) {
system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
&error_abort);
--
2.47.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
2025-05-02 21:45 ` [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out Philippe Mathieu-Daudé
2025-05-02 21:45 ` [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo Philippe Mathieu-Daudé
@ 2025-05-02 21:45 ` Philippe Mathieu-Daudé
2025-05-04 21:17 ` Pierrick Bouvier
2025-05-05 7:02 ` David Hildenbrand
2025-05-02 21:45 ` [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS " Philippe Mathieu-Daudé
` (2 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Use target_system_arch() to check at runtime which target
architecture is being run.
Note, since TARGET_ARM is defined for TARGET_AARCH64, we
check for both ARM & AARCH64 enum values.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/virtio/virtio-mem.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index a3d1a676e71..02c47730ae8 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -170,13 +170,20 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
* necessary (as the section size can change). But it's more likely that the
* section size will rather get smaller and not bigger over time.
*/
-#if defined(TARGET_X86_64) || defined(TARGET_I386) || defined(TARGET_S390X)
-#define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB))
-#elif defined(TARGET_ARM)
-#define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB))
-#else
-#error VIRTIO_MEM_USABLE_EXTENT not defined
-#endif
+static uint64_t virtio_mem_usable_extent_size(void)
+{
+ switch (target_system_arch()) {
+ case SYS_EMU_TARGET_I386:
+ case SYS_EMU_TARGET_X86_64:
+ case SYS_EMU_TARGET_S390X:
+ return 2 * 128 * MiB;
+ case SYS_EMU_TARGET_AARCH64:
+ case SYS_EMU_TARGET_ARM:
+ return 2 * 512 * MiB;
+ default:
+ g_assert_not_reached();
+ }
+}
static bool virtio_mem_is_busy(void)
{
@@ -721,7 +728,7 @@ static void virtio_mem_resize_usable_region(VirtIOMEM *vmem,
bool can_shrink)
{
uint64_t newsize = MIN(memory_region_size(&vmem->memdev->mr),
- requested_size + VIRTIO_MEM_USABLE_EXTENT);
+ requested_size + virtio_mem_usable_extent_size());
/* The usable region size always has to be multiples of the block size. */
newsize = QEMU_ALIGN_UP(newsize, vmem->block_size);
--
2.47.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2025-05-02 21:45 ` [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime Philippe Mathieu-Daudé
@ 2025-05-02 21:45 ` Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:03 ` David Hildenbrand
2025-05-02 21:45 ` [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once Philippe Mathieu-Daudé
2025-05-11 18:39 ` [PATCH v3 0/5] hw/virtio: Build " Michael S. Tsirkin
5 siblings, 2 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Check legacy guests support at runtime: instead of evaluating
the VIRTIO_MEM_HAS_LEGACY_GUESTS definition at compile time,
call target_system_arch() to detect which target is being run at
runtime. Register virtio_mem_legacy_guests_properties[] at runtime.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/virtio/virtio-mem.c | 77 ++++++++++++++++++++++++------------------
1 file changed, 44 insertions(+), 33 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 02c47730ae8..4234396f774 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -15,6 +15,7 @@
#include "qemu/cutils.h"
#include "qemu/error-report.h"
#include "qemu/units.h"
+#include "qemu/target-info.h"
#include "system/numa.h"
#include "system/system.h"
#include "system/reset.h"
@@ -33,13 +34,21 @@
static const VMStateDescription vmstate_virtio_mem_device_early;
-/*
- * We only had legacy x86 guests that did not support
- * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy guests.
- */
-#if defined(TARGET_X86_64) || defined(TARGET_I386)
-#define VIRTIO_MEM_HAS_LEGACY_GUESTS
-#endif
+static bool virtio_mem_has_legacy_guests(void)
+{
+ /*
+ * We only had legacy x86 guests that did not support
+ * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have
+ * legacy guests.
+ */
+ switch (target_system_arch()) {
+ case SYS_EMU_TARGET_I386:
+ case SYS_EMU_TARGET_X86_64:
+ return true;
+ default:
+ return false;
+ }
+}
/*
* Let's not allow blocks smaller than 1 MiB, for example, to keep the tracking
@@ -143,7 +152,6 @@ static uint64_t virtio_mem_default_block_size(RAMBlock *rb)
return MAX(page_size, VIRTIO_MEM_MIN_BLOCK_SIZE);
}
-#if defined(VIRTIO_MEM_HAS_LEGACY_GUESTS)
static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
{
/*
@@ -154,7 +162,6 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
return !qemu_ram_is_shared(rb) && qemu_ram_get_fd(rb) < 0 &&
qemu_ram_pagesize(rb) == qemu_real_host_page_size();
}
-#endif /* VIRTIO_MEM_HAS_LEGACY_GUESTS */
/*
* Size the usable region bigger than the requested size if possible. Esp.
@@ -1004,28 +1011,28 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
rb = vmem->memdev->mr.ram_block;
page_size = qemu_ram_pagesize(rb);
-#if defined(VIRTIO_MEM_HAS_LEGACY_GUESTS)
- switch (vmem->unplugged_inaccessible) {
- case ON_OFF_AUTO_AUTO:
- if (virtio_mem_has_shared_zeropage(rb)) {
- vmem->unplugged_inaccessible = ON_OFF_AUTO_OFF;
- } else {
- vmem->unplugged_inaccessible = ON_OFF_AUTO_ON;
+ if (virtio_mem_has_legacy_guests()) {
+ switch (vmem->unplugged_inaccessible) {
+ case ON_OFF_AUTO_AUTO:
+ if (virtio_mem_has_shared_zeropage(rb)) {
+ vmem->unplugged_inaccessible = ON_OFF_AUTO_OFF;
+ } else {
+ vmem->unplugged_inaccessible = ON_OFF_AUTO_ON;
+ }
+ break;
+ case ON_OFF_AUTO_OFF:
+ if (!virtio_mem_has_shared_zeropage(rb)) {
+ warn_report("'%s' property set to 'off' with a memdev that does"
+ " not support the shared zeropage.",
+ VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP);
+ }
+ break;
+ default:
+ break;
}
- break;
- case ON_OFF_AUTO_OFF:
- if (!virtio_mem_has_shared_zeropage(rb)) {
- warn_report("'%s' property set to 'off' with a memdev that does"
- " not support the shared zeropage.",
- VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP);
- }
- break;
- default:
- break;
+ } else {
+ vmem->unplugged_inaccessible = ON_OFF_AUTO_ON;
}
-#else /* VIRTIO_MEM_HAS_LEGACY_GUESTS */
- vmem->unplugged_inaccessible = ON_OFF_AUTO_ON;
-#endif /* VIRTIO_MEM_HAS_LEGACY_GUESTS */
if (vmem->dynamic_memslots &&
vmem->unplugged_inaccessible != ON_OFF_AUTO_ON) {
@@ -1718,16 +1725,17 @@ static const Property virtio_mem_properties[] = {
DEFINE_PROP_BOOL(VIRTIO_MEM_PREALLOC_PROP, VirtIOMEM, prealloc, false),
DEFINE_PROP_LINK(VIRTIO_MEM_MEMDEV_PROP, VirtIOMEM, memdev,
TYPE_MEMORY_BACKEND, HostMemoryBackend *),
-#if defined(VIRTIO_MEM_HAS_LEGACY_GUESTS)
- DEFINE_PROP_ON_OFF_AUTO(VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP, VirtIOMEM,
- unplugged_inaccessible, ON_OFF_AUTO_ON),
-#endif
DEFINE_PROP_BOOL(VIRTIO_MEM_EARLY_MIGRATION_PROP, VirtIOMEM,
early_migration, true),
DEFINE_PROP_BOOL(VIRTIO_MEM_DYNAMIC_MEMSLOTS_PROP, VirtIOMEM,
dynamic_memslots, false),
};
+static const Property virtio_mem_legacy_guests_properties[] = {
+ DEFINE_PROP_ON_OFF_AUTO(VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP, VirtIOMEM,
+ unplugged_inaccessible, ON_OFF_AUTO_ON),
+};
+
static uint64_t virtio_mem_rdm_get_min_granularity(const RamDiscardManager *rdm,
const MemoryRegion *mr)
{
@@ -1880,6 +1888,9 @@ static void virtio_mem_class_init(ObjectClass *klass, const void *data)
RamDiscardManagerClass *rdmc = RAM_DISCARD_MANAGER_CLASS(klass);
device_class_set_props(dc, virtio_mem_properties);
+ if (virtio_mem_has_legacy_guests()) {
+ device_class_set_props(dc, virtio_mem_legacy_guests_properties);
+ }
dc->vmsd = &vmstate_virtio_mem;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
--
2.47.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2025-05-02 21:45 ` [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS " Philippe Mathieu-Daudé
@ 2025-05-02 21:45 ` Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:04 ` David Hildenbrand
2025-05-11 18:39 ` [PATCH v3 0/5] hw/virtio: Build " Michael S. Tsirkin
5 siblings, 2 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-02 21:45 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand,
Philippe Mathieu-Daudé, Pierrick Bouvier
Remove unused "system/ram_addr.h" header. This file doesn't
use any target specific definitions anymore, compile it once
by moving it to system_virtio_ss[].
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/virtio-mem.c | 1 -
hw/virtio/meson.build | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 4234396f774..f4882c6901b 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -25,7 +25,6 @@
#include "hw/virtio/virtio-mem.h"
#include "qapi/error.h"
#include "qapi/visitor.h"
-#include "system/ram_addr.h"
#include "migration/misc.h"
#include "hw/boards.h"
#include "hw/qdev-properties.h"
diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index 164f6fd995a..525679954ee 100644
--- a/hw/virtio/meson.build
+++ b/hw/virtio/meson.build
@@ -56,7 +56,7 @@ 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'))
+system_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'))
--
2.47.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out
2025-05-02 21:45 ` [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out Philippe Mathieu-Daudé
@ 2025-05-04 21:16 ` Pierrick Bouvier
0 siblings, 0 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2025-05-04 21:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/qemu/target-info.h | 9 +++++++++
> hw/core/machine-qmp-cmds.c | 6 ++----
> target-info.c | 12 ++++++++++++
> 3 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
> index 850a2958b9c..87b4b0e0cbb 100644
> --- a/include/qemu/target-info.h
> +++ b/include/qemu/target-info.h
> @@ -9,6 +9,8 @@
> #ifndef QEMU_TARGET_INFO_H
> #define QEMU_TARGET_INFO_H
>
> +#include "qapi/qapi-types-machine.h"
> +
> /**
> * target_name:
> *
> @@ -16,6 +18,13 @@
> */
> const char *target_name(void);
>
> +/**
> + * target_system_arch:
> + *
> + * Returns: QAPI SysEmuTarget enum (i.e. SYS_EMU_TARGET_I386).
> + */
> +SysEmuTarget target_system_arch(void);
> +
> /**
> * target_long_bits:
> *
> diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
> index d82043e1c68..8f491dba441 100644
> --- a/hw/core/machine-qmp-cmds.c
> +++ b/hw/core/machine-qmp-cmds.c
> @@ -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_system_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_system_arch();
>
> return info;
> }
> diff --git a/target-info.c b/target-info.c
> index 16fdca7aaaf..8232d488870 100644
> --- a/target-info.c
> +++ b/target-info.c
> @@ -9,6 +9,7 @@
> #include "qemu/osdep.h"
> #include "qemu/target-info.h"
> #include "qemu/target-info-impl.h"
> +#include "qapi/error.h"
>
> const char *target_name(void)
> {
> @@ -20,6 +21,17 @@ unsigned target_long_bits(void)
> return target_info()->long_bits;
> }
>
> +SysEmuTarget target_system_arch(void)
> +{
> + static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
> +
It would be better to squash next commit, and modify
target_info()->target_arch directly, instead of introducing this static
variable.
> + if (system_arch == SYS_EMU_TARGET__MAX) {
> + system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
> + &error_abort);
> + }
> + return system_arch;
> +}
> +
> const char *target_cpu_type(void)
> {
> return target_info()->cpu_type;
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime
2025-05-02 21:45 ` [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime Philippe Mathieu-Daudé
@ 2025-05-04 21:17 ` Pierrick Bouvier
2025-05-05 7:02 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2025-05-04 21:17 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Use target_system_arch() to check at runtime which target
> architecture is being run.
> Note, since TARGET_ARM is defined for TARGET_AARCH64, we
> check for both ARM & AARCH64 enum values.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/virtio/virtio-mem.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime
2025-05-02 21:45 ` [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS " Philippe Mathieu-Daudé
@ 2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:03 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2025-05-04 21:18 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Check legacy guests support at runtime: instead of evaluating
> the VIRTIO_MEM_HAS_LEGACY_GUESTS definition at compile time,
> call target_system_arch() to detect which target is being run at
> runtime. Register virtio_mem_legacy_guests_properties[] at runtime.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/virtio/virtio-mem.c | 77 ++++++++++++++++++++++++------------------
> 1 file changed, 44 insertions(+), 33 deletions(-)
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once
2025-05-02 21:45 ` [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once Philippe Mathieu-Daudé
@ 2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:04 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2025-05-04 21:18 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Remove unused "system/ram_addr.h" header. This file doesn't
> use any target specific definitions anymore, compile it once
> by moving it to system_virtio_ss[].
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> ---
> hw/virtio/virtio-mem.c | 1 -
> hw/virtio/meson.build | 2 +-
> 2 files changed, 1 insertion(+), 2 deletions(-)
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo
2025-05-02 21:45 ` [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo Philippe Mathieu-Daudé
@ 2025-05-04 21:21 ` Pierrick Bouvier
0 siblings, 0 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2025-05-04 21:21 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, David Hildenbrand
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/qemu/target-info-impl.h | 4 +++-
> target-info-stub.c | 1 +
> target-info.c | 3 +++
> 3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/include/qemu/target-info-impl.h b/include/qemu/target-info-impl.h
> index 1b51cbcfe1b..83d584d7dba 100644
> --- a/include/qemu/target-info-impl.h
> +++ b/include/qemu/target-info-impl.h
> @@ -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-common.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 */
> diff --git a/target-info-stub.c b/target-info-stub.c
> index fecc0e71286..2e4407ff04b 100644
> --- a/target-info-stub.c
> +++ b/target-info-stub.c
> @@ -14,6 +14,7 @@
>
> static const TargetInfo target_info_stub = {
> .target_name = TARGET_NAME,
> + .target_arch = SYS_EMU_TARGET__MAX,
Time to suggest again to implement an ifdef with all TARGET_*, so we can
get rid of this "not set" value.
It would solve all the issues with target_system_arch() function,
without duplicating the enum SYS_EMU_TARGET itself.
The only compromise is this ifdef, that can be shrinked and eventually
removed when we'll have implemented target_info for all configs.
> .long_bits = TARGET_LONG_BITS,
> .cpu_type = CPU_RESOLVING_TYPE,
> .machine_typename = TYPE_MACHINE,
> diff --git a/target-info.c b/target-info.c
> index 8232d488870..5f6096606e4 100644
> --- a/target-info.c
> +++ b/target-info.c
> @@ -25,6 +25,9 @@ SysEmuTarget target_system_arch(void)
> {
> static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
>
> + if (system_arch == SYS_EMU_TARGET__MAX) {
> + system_arch = target_info()->target_arch;
> + }
> if (system_arch == SYS_EMU_TARGET__MAX) {
> system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
> &error_abort);
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime
2025-05-02 21:45 ` [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime Philippe Mathieu-Daudé
2025-05-04 21:17 ` Pierrick Bouvier
@ 2025-05-05 7:02 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2025-05-05 7:02 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, Pierrick Bouvier
On 02.05.25 23:45, Philippe Mathieu-Daudé wrote:
> Use target_system_arch() to check at runtime which target
> architecture is being run.
> Note, since TARGET_ARM is defined for TARGET_AARCH64, we
> check for both ARM & AARCH64 enum values.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime
2025-05-02 21:45 ` [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS " Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
@ 2025-05-05 7:03 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2025-05-05 7:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, Pierrick Bouvier
On 02.05.25 23:45, Philippe Mathieu-Daudé wrote:
> Check legacy guests support at runtime: instead of evaluating
> the VIRTIO_MEM_HAS_LEGACY_GUESTS definition at compile time,
> call target_system_arch() to detect which target is being run at
> runtime. Register virtio_mem_legacy_guests_properties[] at runtime.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once
2025-05-02 21:45 ` [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
@ 2025-05-05 7:04 ` David Hildenbrand
1 sibling, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2025-05-05 7:04 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Eduardo Habkost, Alex Bennée, Richard Henderson, Zhao Liu,
Yanan Wang, Daniel P. Berrangé, Michael S. Tsirkin,
Marcel Apfelbaum, Thomas Huth, Pierrick Bouvier
On 02.05.25 23:45, Philippe Mathieu-Daudé wrote:
> Remove unused "system/ram_addr.h" header. This file doesn't
> use any target specific definitions anymore, compile it once
> by moving it to system_virtio_ss[].
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2025-05-02 21:45 ` [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once Philippe Mathieu-Daudé
@ 2025-05-11 18:39 ` Michael S. Tsirkin
5 siblings, 0 replies; 15+ messages in thread
From: Michael S. Tsirkin @ 2025-05-11 18:39 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Eduardo Habkost, Alex Bennée, Richard Henderson,
Zhao Liu, Yanan Wang, Daniel P. Berrangé, Marcel Apfelbaum,
Thomas Huth, David Hildenbrand, Pierrick Bouvier
On Fri, May 02, 2025 at 11:45:46PM +0200, Philippe Mathieu-Daudé wrote:
> Since v2:
> - Use TargetInfo API (Pierrick)
>
> Since v1:
> - Use max extent size of all archs (David)
>
> Based-on: <20250501212113.2961531-1-richard.henderson@linaro.org>
virtio bits:
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
feel free to merge.
> Philippe Mathieu-Daudé (5):
> qemu/target-info: Factor target_system_arch() out
> qemu/target-info: Add %target_arch field to TargetInfo
> hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime
> hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime
> hw/virtio: Compile virtio-mem.c once
>
> include/qemu/target-info-impl.h | 4 +-
> include/qemu/target-info.h | 9 +++
> hw/core/machine-qmp-cmds.c | 6 +-
> hw/virtio/virtio-mem.c | 101 +++++++++++++++++++-------------
> target-info-stub.c | 1 +
> target-info.c | 15 +++++
> hw/virtio/meson.build | 2 +-
> 7 files changed, 90 insertions(+), 48 deletions(-)
>
> --
> 2.47.1
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-05-11 18:40 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02 21:45 [PATCH v3 0/5] hw/virtio: Build virtio-mem.c once Philippe Mathieu-Daudé
2025-05-02 21:45 ` [PATCH v3 1/5] qemu/target-info: Factor target_system_arch() out Philippe Mathieu-Daudé
2025-05-04 21:16 ` Pierrick Bouvier
2025-05-02 21:45 ` [PATCH v3 2/5] qemu/target-info: Add %target_arch field to TargetInfo Philippe Mathieu-Daudé
2025-05-04 21:21 ` Pierrick Bouvier
2025-05-02 21:45 ` [PATCH v3 3/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_USABLE_EXTENT to runtime Philippe Mathieu-Daudé
2025-05-04 21:17 ` Pierrick Bouvier
2025-05-05 7:02 ` David Hildenbrand
2025-05-02 21:45 ` [PATCH v3 4/5] hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS " Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:03 ` David Hildenbrand
2025-05-02 21:45 ` [PATCH v3 5/5] hw/virtio: Compile virtio-mem.c once Philippe Mathieu-Daudé
2025-05-04 21:18 ` Pierrick Bouvier
2025-05-05 7:04 ` David Hildenbrand
2025-05-11 18:39 ` [PATCH v3 0/5] hw/virtio: Build " Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).