multi-target: add riscv64-softmmu
Subsystems (2)
v3 cover multi-target: add riscv64-softmmu
This series adds this target to set of multi-target.
Changes are straightforward: functions and helpers renaming, and one type restriction for this target only.
Based-on: [email protected] "multi-target: prefix helpers with target prefix"
v3
--
- rebase on master
- dropped the patch renaming helpers. Now based on:
[email protected] "multi-target: prefix helpers with target prefix"
- fixed issue on riscv host where kvm cpu type had no parent type in multi-target test.
v2
--
- make virt machine only available for riscv targets
- enhance multi-target test to detect duplicated types between all targets (we missed the virt machine since we were always picking the first target avail)
- add an additional commit with the rest of softmmu commented for future work
Pierrick Bouvier (9):
target-info: add target_base_riscv
hw/riscv/virt: make machine available for riscv targets only test/unit/multi-target: check QOM types can be initialized with any
target
hw/riscv/virt: restrict scope of virt_is_acpi_enabled to this file target/riscv: rename virt_acpi_setup to riscv_virt_acpi_setup target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets meson.build: add riscv64-softmmu to multi-target meson.build: list all remaining softmmu targets as comments
hw/riscv/virt-acpi-build.c | 2 +- hw/riscv/virt.c | 14 ++++++++------ include/hw/riscv/virt.h | 3 +-- include/qemu/target-info.h | 7 +++++++ meson.build | 18 ++++++++++++++++++ target-info.c | 11 +++++++++++ target/riscv/kvm/kvm-cpu.c | 2 ++ target/riscv/tcg/tcg-cpu.c | 1 + tests/unit/test-multi-target.c | 34 ++++++++++++++++++++++++++-------- 9 files changed, 75 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/9 target-info: add target_base_riscv
--- include/qemu/target-info.h | 7 +++++++ target-info.c | 11 +++++++++++ 2 files changed, 18 insertions(+)
include/qemu/target-info.h +7 -0
@@ -120,6 +120,13 @@ bool target_ppc64(void);*/ bool target_s390x (void ); +/** +* target_base_riscv: +* +* Returns whether the target architecture is RISC-V 32-bit or 64-bit. +*/ +bool target_base_riscv (void ); +/** * target_riscv64: *
target-info.c +11 -0
@@ -110,6 +110,17 @@ bool target_s390x(void)return target_arch () ==SYS_EMU_TARGET_S390X ; } +bool target_base_riscv (void ) +{ +switch (target_arch ()) { +case SYS_EMU_TARGET_RISCV32 : +case SYS_EMU_TARGET_RISCV64 : +return true; +default : +return false; + } +} +bool target_riscv64 (void ) {return target_arch () ==SYS_EMU_TARGET_RISCV64 ;
Signature · 1 line
2.43.0
PATCH v3 2/9 hw/riscv/virt: make machine available for riscv targets only
In reply to Pierrick Bouvier--- hw/riscv/virt.c | 2 ++ 1 file changed, 2 insertions(+)
hw/riscv/virt.c +2 -0
@@ -22,6 +22,7 @@#include "qemu/units.h" #include "qemu/error-report.h" #include "qemu/guest-random.h" +#include "qemu/target-info.h" #include "qapi/error.h" #include "hw/core/boards.h" #include "hw/core/loader.h"
@@ -1203,6 +1204,7 @@ static const TypeInfo virt_machine_typeinfo = { .instance_init = virt_machine_instance_init, .instance_finalize = virt_machine_instance_finalize, .instance_size = sizeof(RISCVVirtState), + .is_available = target_base_riscv, .interfaces = (const InterfaceInfo []) { {TYPE_HOTPLUG_HANDLER }, { }
Signature · 1 line
2.43.0
PATCH v3 3/9 test/unit/multi-target: check QOM types can be initialized with any target
In reply to Pierrick BouvierCurrently, we are initializing QOM type after having set target to the first one available. That's not enough to catch conflicts among types within targets. Indeed, we'll miss some conflicts since some types are registered conditionnally through .is_available.
To ensure full coverage, we detect all targets available, and generate a sub test for each of them. Then, using g_test_trap_subprocess(), we can recursively call only this test in a children process.
--- tests/unit/test-multi-target.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
tests/unit/test-multi-target.c +26 -8
@@ -30,13 +30,20 @@/* stub for system/main.c */ int (*qemu_main)(void ); -static void test_qom_types_are_unique (void ) +static void test_qom_types_are_unique (const void *data) { -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); +const TargetInfo *ti = data; + +/* QOM types can be initialized only once, so do it in a subprocess. */ +if (!g_test_subprocess ()) { +/* parent process path - respawn this exact test path */ +g_test_trap_subprocess (NULL ,0 ,G_TEST_SUBPROCESS_INHERIT_STDERR ); +g_test_trap_assert_passed (); +return ; + } +/* child process path */ + +target_info_qom_set_target_info (ti);/* register all types */ module_call_init (MODULE_INIT_QOM );
@@ -47,7 +54,18 @@ static void test_qom_types_are_unique(void)int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/multi-targets/qom-types-are-unique" , - test_qom_types_are_unique); + +module_call_init (MODULE_INIT_TARGET_INFO ); +g_autoptr (GSList) targets =object_class_get_list_sorted (TYPE_TARGET_INFO , + false); +g_assert (targets); +for (GSList *elem = targets; elem; elem = elem->next) { +const TargetInfo *ti =TARGET_INFO_CLASS (elem->data)->target_info; + g_autofree char *path = +g_strdup_printf ("/multi-targets/qom-types-are-unique/%s" , + ti->target_name); +g_test_add_data_func (path, ti, test_qom_types_are_unique); + } +return g_test_run (); }
Signature · 1 line
2.43.0
PATCH v3 4/9 hw/riscv/virt: restrict scope of virt_is_acpi_enabled to this file
In reply to Pierrick BouvierThis removes conflict with the same function from target/arm. To the opposite of arm target, there is no external caller for this function.
--- hw/riscv/virt.c | 10 +++++----- include/hw/riscv/virt.h | 1 - 2 files changed, 5 insertions(+), 6 deletions(-)
hw/riscv/virt.c +5 -5
@@ -72,6 +72,11 @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type)return riscv_is_kvm_aia_aplic_imsic (msimode); } +static bool virt_is_acpi_enabled (RISCVVirtState *s) +{ +return s->acpi !=ON_OFF_AUTO_OFF ; +} +static bool virt_use_emulated_aplic (RISCVVirtAIAType aia_type) {bool msimode = aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ;
@@ -1067,11 +1072,6 @@ static void virt_set_iommu_sys(Object *obj, Visitor *v, const char *name,visit_type_OnOffAuto (v, name, &s->iommu_sys, errp); } -bool virt_is_acpi_enabled (RISCVVirtState *s) -{ -return s->acpi !=ON_OFF_AUTO_OFF ; -} -static void virt_get_acpi (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
include/hw/riscv/virt.h +0 -1
@@ -121,7 +121,6 @@ enum {#define VIRT_PLIC_SIZE (__num_context) \ (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE) -bool virt_is_acpi_enabled (RISCVVirtState *s);bool virt_is_iommu_sys_enabled (RISCVVirtState *s);void virt_acpi_setup (RISCVVirtState *vms);
Signature · 1 line
2.43.0
PATCH v3 5/9 target/riscv: rename virt_acpi_setup to riscv_virt_acpi_setup
In reply to Pierrick BouvierThis removes conflict with same function from target/arm.
--- hw/riscv/virt-acpi-build.c | 2 +- hw/riscv/virt.c | 2 +- include/hw/riscv/virt.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
hw/riscv/virt-acpi-build.c +1 -1
@@ -1021,7 +1021,7 @@ static const VMStateDescription vmstate_virt_acpi_build = { }, }; -void virt_acpi_setup (RISCVVirtState *s) +void riscv_virt_acpi_setup (RISCVVirtState *s) {AcpiBuildTables tables;AcpiBuildState *build_state;
hw/riscv/virt.c +1 -1
@@ -712,7 +712,7 @@ static void virt_machine_done(Notifier *notifier, void *data)virt_build_smbios (s);if (virt_is_acpi_enabled (s)) { -virt_acpi_setup (s); +riscv_virt_acpi_setup (s); } }
include/hw/riscv/virt.h +1 -1
@@ -122,7 +122,7 @@ enum { (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE)bool virt_is_iommu_sys_enabled (RISCVVirtState *s); -void virt_acpi_setup (RISCVVirtState *vms); +void riscv_virt_acpi_setup (RISCVVirtState *vms);/* * The virt machine physical address space used by some of the devices
Signature · 1 line
2.43.0
PATCH v3 6/9 target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets
In reply to Pierrick Bouvier$ ./build/tests/unit/test-multi-target Type 'tcg-accel-riscv-cpu' is missing its parent 'accel-riscv-cpu' Aborted
Parent type is conditionally registered from current target:register_accel_target_type uses '"accel-" + target_cpu_type()' as type name. Multi-target test takes the first target available, which is not riscv in current state.
--- target/riscv/tcg/tcg-cpu.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/tcg/tcg-cpu.c +1 -0
@@ -1749,6 +1749,7 @@ static const TypeInfo riscv_tcg_cpu_accel_type_info = { .parent = TYPE_ACCEL_CPU, .class_init = riscv_tcg_cpu_accel_class_init, + .is_available = target_base_riscv, .abstract = true, };
Signature · 1 line
2.43.0
PATCH v3 7/9 target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets
In reply to Pierrick BouvierOn riscv hosts:
$ ./build/tests/unit/test-multi-target Type 'kvm-accel-riscv-cpu' is missing its parent 'accel-riscv-cpu' Aborted
Parent type is conditionally registered from current target:register_accel_target_type uses '"accel-" + target_cpu_type()' as type name. Thus, accelerator specific cpu types must only be registered for riscv targets.
--- target/riscv/kvm/kvm-cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/riscv/kvm/kvm-cpu.c +2 -0
@@ -26,6 +26,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qemu/target-info.h" #include "qapi/visitor.h" #include "system/system.h" #include "system/kvm.h"
@@ -2208,6 +2209,7 @@ static const TypeInfo kvm_cpu_accel_type_info = { .parent = TYPE_ACCEL_CPU, .class_init = kvm_cpu_accel_class_init, + .is_available = target_base_riscv, .abstract = true, };static void kvm_cpu_accel_register_types (void )
Signature · 1 line
2.43.0
Re: [PATCH v3 7/9] target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets
Quoted 37 lines · Pierrick Bouvier
On riscv hosts:
$ ./build/tests/unit/test-multi-target Type 'kvm-accel-riscv-cpu' is missing its parent 'accel-riscv-cpu' AbortedParent type is conditionally registered from current target:
register_accel_target_typeuses '"accel-" +target_cpu_type()' as type name. Thus, accelerator specific cpu types must only be registered for riscv targets.Signed-off-by Pierrick Bouvier <[email protected]>--- target/riscv/kvm/kvm-cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/riscv/kvm/kvm-cpu.c +2
-1@@ -26,6 +26,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qemu/target-info.h" #include "qapi/visitor.h" #include "system/system.h" #include "system/kvm.h" @@ -2208,6 +2209,7 @@ static const TypeInfo kvm_cpu_accel_type_info = { .parent = TYPE_ACCEL_CPU, .class_init = kvm_cpu_accel_class_init, + .is_available = target_base_riscv, .abstract = true, };static void kvm_cpu_accel_register_types (void ) --
Quoted 3 lines
2.43.0
This is my way
[PATCH 07/34] target-info: prepare the QOM target list before module_call_init(MODULE_INIT_QOM)
https://lore.kernel.org/qemu-devel/[email protected]/
[PATCH 09/34] accel: register CPU parent for each target
https://lore.kernel.org/qemu-devel/[email protected]/
with this, you have no need to repeat the.is_available = target_base_riscv, work and then remove the latter.
prepare the QOM target list before module_call_init(MODULE_INIT_QOM) is needed
because we can not query the target list within the type_init.
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
PATCH v3 8/9 meson.build: add riscv64-softmmu to multi-target
In reply to Pierrick Bouvier--- meson.build | 1 + 1 file changed, 1 insertion(+)
meson.build +1 -0
@@ -4271,6 +4271,7 @@ multi_target_supported_targets = [ 'm68k-softmmu', 'microblaze-softmmu', 'or1k-softmmu', + 'riscv64-softmmu', 'rx-softmmu', 'tricore-softmmu', ]
Signature · 1 line
2.43.0
PATCH v3 9/9 meson.build: list all remaining softmmu targets as comments
In reply to Pierrick Bouvier--- meson.build | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
meson.build +17 -0
@@ -4268,12 +4268,29 @@ multi_target_supported_targets = [ 'avr-softmmu', 'hexagon-softmmu', 'hppa-softmmu', + # 'i386-softmmu', + # 'loongarch64-softmmu', 'm68k-softmmu', 'microblaze-softmmu', + # 'mips-softmmu', + # 'mips64-softmmu', + # 'mips64el-softmmu', + # 'mipsel-softmmu', 'or1k-softmmu', + # 'ppc-softmmu', + # 'ppc64-softmmu', + # 'riscv32-softmmu', 'riscv64-softmmu', 'rx-softmmu', + # 's390x-softmmu', + # 'sh4-softmmu', + # 'sh4eb-softmmu', + # 'sparc-softmmu', + # 'sparc64-softmmu', 'tricore-softmmu', + # 'x86_64-softmmu', + # 'xtensa-softmmu', + # 'xtensaeb-softmmu', ] emulators = {}
Signature · 1 line
2.43.0
Only patch 7 is missing review.
Regards,
Pierrick
Quoted 37 lines · Pierrick Bouvier
This series adds this target to set of multi-target.
Changes are straightforward: functions and helpers renaming, and one type restriction for this target only.Based-on: [email protected] "multi-target: prefix helpers with target prefix"
v3
--- rebase on master
- dropped the patch renaming helpers. Now based on:
[email protected] "multi-target: prefix helpers with target prefix"
- fixed issue on riscv host where kvm cpu type had no parent type in multi-target test.v2
--- make virt machine only available for riscv targets
- enhance multi-target test to detect duplicated types between all targets (we missed the virt machine since we were always picking the first target avail)
- add an additional commit with the rest of softmmu commented for future workPierrick Bouvier (9):
target-info: addtarget_base_riscv
hw/riscv/virt: make machine available for riscv targets only test/unit/multi-target: check QOM types can be initialized with any
target
hw/riscv/virt: restrict scope ofvirt_is_acpi_enabledto this file target/riscv: renamevirt_acpi_setuptoriscv_virt_acpi_setuptarget/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets meson.build: add riscv64-softmmu to multi-target meson.build: list all remaining softmmu targets as comments
Quoted 11 lines
hw/riscv/virt-acpi-build.c | 2 +- hw/riscv/virt.c | 14 ++++++++------ include/hw/riscv/virt.h | 3 +-- include/qemu/target-info.h | 7 +++++++ meson.build | 18 ++++++++++++++++++ target-info.c | 11 +++++++++++ target/riscv/kvm/kvm-cpu.c | 2 ++ target/riscv/tcg/tcg-cpu.c | 1 + tests/unit/test-multi-target.c | 34 ++++++++++++++++++++++++++-------- 9 files changed, 75 insertions(+), 17 deletions(-)
This was merged into master (2c0584588c9fedc2a8abc087c01a498ce80997d0).
Regards,
Pierrick