target/arm: Introduce host_cpu_feature_supported() API
v2 cover target/arm: Introduce host_cpu_feature_supported() API
Since v1:
- Addressed Richard's review comments removing 'can_emulate' arg
Hi,
Mohamed and myself are working on adding nested virtualization support to HVF Aarch64. Mohamed approach leverages the latest hardware features of the Apple M3+ Silicon chips [1], while mine falls back to emulation [2] when features are not available, as it happens with the M1 and M2 chipsets.
We want to support both methods long term, as they solve different use cases. Therefore I'm looking for a common API for methods added in both series.
In this series we propose the host_cpu_feature_supported() method to check if a feature is supported by the host, allowing fall back to TCG. KVM uses are converted, and an example -- while not really usable without other patch applied -- is provided for HVF.
Does this look reasonable enough to pursue in that direction?
Thanks,
Phil.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/
Mohamed Mediouni (2):
target/arm: Factor hvf_psci_get_target_el() out
target/arm/hvf: Sync registers used at EL2
Philippe Mathieu-Daudé (8):
accel/system: Introduce hwaccel_enabled() helper target/arm: Use generic hwaccel_enabled() to check 'host' cpu type target/arm: Restrict PMU to system mode
target/arm: Introduce host_cpu_feature_supported() target/arm: Replace kvm_arm_pmu_supported by
host_cpu_feature_supported
target/arm: Replace kvm_arm_el2_supported by
host_cpu_feature_supported
target/arm/hvf: Consider EL2 acceleration for Silicon M3+ chipsets target/arm/hvf: Allow EL2/EL3 emulation on Silicon M1 / M2
include/system/hw_accel.h | 13 ++++++++ target/arm/internals.h | 8 +++++ target/arm/kvm_arm.h | 24 -------------- hw/arm/virt.c | 8 +---- target/arm/arm-qmp-cmds.c | 5 +-- target/arm/cpu.c | 16 +++++---- target/arm/cpu64.c | 11 ++++--- target/arm/hvf/hvf.c | 69 +++++++++++++++++++++++++++++++++++++-- target/arm/kvm-stub.c | 10 ------ target/arm/kvm.c | 33 ++++++++++++++----- 10 files changed, 133 insertions(+), 64 deletions(-)
Signature · 1 line
2.49.0
PATCH v2 1/10 accel/system: Introduce hwaccel_enabled() helper
hwaccel_enabled() return whether any hardware accelerator is enabled.
--- include/system/hw_accel.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/system/hw_accel.h +13 -0
@@ -39,4 +39,17 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu);void cpu_synchronize_post_reset (CPUState *cpu);void cpu_synchronize_post_init (CPUState *cpu); +/** +* hwaccel_enabled: +* +* Returns: %true if a hardware accelerator is enabled, %false otherwise. +*/ +static inline bool hwaccel_enabled (void ) +{ +return hvf_enabled () + ||kvm_enabled () + ||nvmm_enabled () + ||whpx_enabled (); +} +#endif /* QEMU_HW_ACCEL_H */
Signature · 1 line
2.49.0
PATCH v2 2/10 target/arm: Use generic hwaccel_enabled() to check 'host' cpu type
In reply to Philippe Mathieu-DaudéWe should be able to use the 'host' CPU with any hardware accelerator.
--- target/arm/arm-qmp-cmds.c | 5 +++-- target/arm/cpu.c | 5 +++-- target/arm/cpu64.c | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-)
target/arm/arm-qmp-cmds.c +3 -2
@@ -31,6 +31,7 @@#include "qapi/qapi-commands-misc-arm.h" #include "qobject/qdict.h" #include "qom/qom-qobject.h" +#include "system/hw_accel.h" #include "cpu.h" static GICCapability *gic_cap_new (int version)
@@ -117,8 +118,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,return NULL ; } -if (!kvm_enabled () && !strcmp (model->name,"host" )) { -error_setg (errp,"The CPU type '%s' requires KVM" , model->name); +if (!hwaccel_enabled () && !strcmp (model->name,"host" )) { +error_setg (errp,"The CPU type 'host' requires hardware accelerator" );return NULL ; }
target/arm/cpu.c +3 -2
@@ -1984,8 +1984,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)* this is the first point where we can report it. */ if (cpu->host_cpu_probe_failed) { -if (!kvm_enabled () && !hvf_enabled ()) { -error_setg (errp,"The 'host' CPU type can only be used with KVM or HVF" ); +if (!hwaccel_enabled ()) { +error_setg (errp,"The 'host' CPU type can only be used with " +"hardware accelator such KVM/HVF" ); }else {error_setg (errp,"Failed to retrieve host CPU features" ); }
target/arm/cpu64.c +6 -5
@@ -26,6 +26,7 @@#include "qemu/units.h" #include "system/kvm.h" #include "system/hvf.h" +#include "system/hw_accel.h" #include "system/qtest.h" #include "system/tcg.h" #include "kvm_arm.h"
@@ -522,7 +523,7 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) isar2 =FIELD_DP64 (isar2,ID_AA64ISAR2 ,APA3 ,0 ); isar2 =FIELD_DP64 (isar2,ID_AA64ISAR2 ,GPA3 ,0 ); -if (kvm_enabled () ||hvf_enabled ()) { +if (hwaccel_enabled ()) {/* * Exit early if PAuth is enabled and fall through to disable it. * The algorithm selection properties are not present.
@@ -599,10 +600,10 @@ void aarch64_add_pauth_properties(Object *obj)/* Default to PAUTH on, with the architected algorithm on TCG. */ qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_property); -if (kvm_enabled () ||hvf_enabled ()) { +if (hwaccel_enabled ()) {/* * Mirror PAuth support from the probed sysregs back into the -* property for KVM or hvf. Is it just a bit backward? Yes it is! +* property for HW accel. Is it just a bit backward? Yes it is! * Note that prop_pauth is true whether the host CPU supports the * architected QARMA5 algorithm or the IMPDEF one. We don't * provide the separate pauth-impdef property for KVM or hvf,
@@ -780,8 +781,8 @@ static void aarch64_host_initfn(Object *obj)static void aarch64_max_initfn (Object *obj) { -if (kvm_enabled () ||hvf_enabled ()) { -/* With KVM or HVF, '-cpu max' is identical to '-cpu host' */ +if (hwaccel_enabled ()) { +/* When hardware acceleration enabled, '-cpu max' is identical to '-cpu host' */ aarch64_host_initfn (obj);return ; }
Signature · 1 line
2.49.0
PATCH v2 3/10 target/arm: Restrict PMU to system mode
In reply to Philippe Mathieu-Daudé--- target/arm/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/arm/cpu.c +3 -2
@@ -1551,7 +1551,6 @@ static const Property arm_cpu_pmsav7_dregion_property =DEFINE_PROP_UNSIGNED_NODEFAULT ("pmsav7-dregion" ,ARMCPU , pmsav7_dregion, qdev_prop_uint32, uint32_t); -#endif static bool arm_get_pmu (Object *obj,Error **errp) {
@@ -1576,6 +1575,8 @@ static void arm_set_pmu(Object *obj, bool value, Error **errp) cpu->has_pmu = value; } +#endif +static bool aarch64_cpu_get_aarch64 (Object *obj,Error **errp) {ARMCPU *cpu =ARM_CPU (obj);
@@ -1771,12 +1772,12 @@ static void arm_cpu_post_init(Object *obj)if (arm_feature (&cpu->env,ARM_FEATURE_EL2 )) {qdev_property_add_static (DEVICE (obj), &arm_cpu_has_el2_property); } -#endif if (arm_feature (&cpu->env,ARM_FEATURE_PMU )) { cpu->has_pmu = true;object_property_add_bool (obj,"pmu" , arm_get_pmu, arm_set_pmu); } +#endif /* * Allow user to turn off VFP and Neon support, but only for TCG --
Signature · 1 line
2.49.0
PATCH v2 4/10 target/arm: Factor hvf_psci_get_target_el() out
In reply to Philippe Mathieu-DaudéFrom: Mohamed Mediouni <[email protected]>
Factor hvf_psci_get_target_el() out so it will be easier to allow switching to other EL later.
--- target/arm/hvf/hvf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/arm/hvf/hvf.c +5 -2
@@ -1107,6 +1107,10 @@ static void hvf_psci_cpu_off(ARMCPU *arm_cpu)assert (ret ==QEMU_ARM_POWERCTL_RET_SUCCESS ); } +static int hvf_psci_get_target_el (CPUARMState *env) +{ +return 1 ; +}/* * Handle a PSCI call. *
@@ -1128,7 +1132,6 @@ static bool hvf_handle_psci_call(CPUState *cpu)CPUState *target_cpu_state;ARMCPU *target_cpu;target_ulong entry; -int target_el =1 ;int32_t ret =0 ; trace_hvf_psci_call(param[0], param[1], param[2], param[3],
@@ -1182,7 +1185,7 @@ static bool hvf_handle_psci_call(CPUState *cpu) entry = param[2 ]; context_id = param[3 ]; ret =arm_set_cpu_on (mpidr, entry, context_id, - target_el, target_aarch64); +hvf_psci_get_target_el (env), target_aarch64);break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF :
Signature · 1 line
2.49.0
RFC PATCH v2 5/10 target/arm: Introduce host_cpu_feature_supported()
In reply to Philippe Mathieu-DaudéIntroduce host_cpu_feature_supported() helper, returning whether a ARM feature is supported by host hardware.
--- target/arm/internals.h | 8 ++++++++ target/arm/hvf/hvf.c | 20 ++++++++++++++++++++ target/arm/kvm.c | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+)
target/arm/internals.h +8 -0
@@ -1612,6 +1612,14 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,void arm_log_exception (CPUState *cs); +/** +* host_cpu_feature_supported: +* @feature: Feature to test for support +* +* Returns: whether @feature is supported by hardware accelerator or emulator +*/ +bool host_cpu_feature_supported (enum arm_features feature); +#endif /* !CONFIG_USER_ONLY */ /*
target/arm/hvf/hvf.c +20 -0
@@ -547,6 +547,26 @@ static struct hvf_sreg_match hvf_sreg_match[] = { { HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) }, }; +bool host_cpu_feature_supported (enum arm_features feature) +{ +if (!hvf_enabled ()) { +return false; + } +switch (feature) { +case ARM_FEATURE_V8 : +case ARM_FEATURE_NEON : +case ARM_FEATURE_AARCH64 : +case ARM_FEATURE_PMU : +case ARM_FEATURE_GENERIC_TIMER : +return true; +case ARM_FEATURE_EL2 : +case ARM_FEATURE_EL3 : +return false; +default : +g_assert_not_reached (); + } +} +int hvf_get_registers (CPUState *cpu) {ARMCPU *arm_cpu =ARM_CPU (cpu);
target/arm/kvm.c +22 -0
@@ -1771,6 +1771,28 @@ void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp) } } +bool host_cpu_feature_supported (enum arm_features feature) +{ +if (!kvm_enabled ()) { +return false; + } +switch (feat) { +case ARM_FEATURE_V8 : +case ARM_FEATURE_NEON : +case ARM_FEATURE_AARCH64 : +case ARM_FEATURE_GENERIC_TIMER : +return true; +case ARM_FEATURE_PMU : +return kvm_arm_pmu_supported (); +case ARM_FEATURE_EL2 : +return kvm_arm_el2_supported (); +case ARM_FEATURE_EL3 : +return false; +default : +g_assert_not_reached (); + } +} +bool kvm_arm_aarch32_supported (void ) {return kvm_check_extension (kvm_state,KVM_CAP_ARM_EL1_32BIT );
Signature · 1 line
2.49.0
RFC PATCH v2 6/10 target/arm: Replace kvm_arm_pmu_supported by host_cpu_feature_supported
Use the generic host_cpu_feature_supported() helper to check for the PMU feature support. This will allow to expand to non-KVM accelerators such HVF.
--- target/arm/kvm_arm.h | 13 ------------- target/arm/cpu.c | 6 ++++-- target/arm/kvm-stub.c | 5 ----- target/arm/kvm.c | 9 ++------- 4 files changed, 6 insertions(+), 27 deletions(-)
target/arm/kvm_arm.h +0 -13
@@ -177,14 +177,6 @@ void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp);*/ bool kvm_arm_aarch32_supported (void ); -/** -* kvm_arm_pmu_supported: -* -* Returns: true if KVM can enable the PMU -* and false otherwise. -*/ -bool kvm_arm_pmu_supported (void ); -/** * kvm_arm_sve_supported: *
@@ -212,11 +204,6 @@ static inline bool kvm_arm_aarch32_supported(void)return false; } -static inline bool kvm_arm_pmu_supported (void ) -{ -return false; -} -static inline bool kvm_arm_sve_supported (void ) {return false;
target/arm/cpu.c +4 -2
@@ -24,6 +24,7 @@#include "qemu/log.h" #include "exec/page-vary.h" #include "target/arm/idau.h" +#include "qemu/accel.h" #include "qemu/module.h" #include "qapi/error.h" #include "cpu.h"
@@ -1564,8 +1565,9 @@ static void arm_set_pmu(Object *obj, bool value, Error **errp)ARMCPU *cpu =ARM_CPU (obj);if (value) { -if (kvm_enabled () && !kvm_arm_pmu_supported ()) { -error_setg (errp,"'pmu' feature not supported by KVM on this host" ); +if (host_cpu_feature_supported (ARM_FEATURE_PMU )) { +error_setg (errp,"'pmu' feature not supported by %s on this host" , +current_accel_name ());return ; }set_feature (&cpu->env,ARM_FEATURE_PMU );
target/arm/kvm-stub.c +0 -5
@@ -32,11 +32,6 @@ bool kvm_arm_aarch32_supported(void)return false; } -bool kvm_arm_pmu_supported (void ) -{ -return false; -} -bool kvm_arm_sve_supported (void ) {return false;
target/arm/kvm.c +2 -7
@@ -288,7 +288,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC); } -if (kvm_arm_pmu_supported ()) { +if (host_cpu_feature_supported (ARM_FEATURE_PMU )) { init.features[0 ] |=1 <<KVM_ARM_VCPU_PMU_V3 ; pmu_supported = true; features |=1ULL <<ARM_FEATURE_PMU ;
@@ -506,11 +506,6 @@ void kvm_arm_add_vcpu_properties(ARMCPU *cpu) "Set off to disable KVM steal time."); } -bool kvm_arm_pmu_supported (void ) -{ -return kvm_check_extension (kvm_state,KVM_CAP_ARM_PMU_V3 ); -} -int kvm_arm_get_max_vm_ipa_size (MachineState *ms,bool *fixed_ipa) {KVMState *s =KVM_STATE (ms->accelerator);
@@ -1783,7 +1778,7 @@ bool host_cpu_feature_supported(enum arm_features feature)case ARM_FEATURE_GENERIC_TIMER :return true;case ARM_FEATURE_PMU : -return kvm_arm_pmu_supported (); +return kvm_check_extension (kvm_state,KVM_CAP_ARM_PMU_V3 );case ARM_FEATURE_EL2 :return kvm_arm_el2_supported ();case ARM_FEATURE_EL3 :
Signature · 1 line
2.49.0
Re: [RFC PATCH v2 06/10] target/arm: Replace kvm_arm_pmu_supported by host_cpu_feature_supported
Quoted 11 lines · Philippe Mathieu-Daudé
Use the generic
host_cpu_feature_supported()helper to check for the PMU feature support. This will allow to expand to non-KVM accelerators such HVF.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/kvm_arm.h | 13 ------------- target/arm/cpu.c | 6 ++++-- target/arm/kvm-stub.c | 5 ----- target/arm/kvm.c | 9 ++------- 4 files changed, 6 insertions(+), 27 deletions(-)
r~
RFC PATCH v2 7/10 target/arm: Replace kvm_arm_el2_supported by host_cpu_feature_supported
In reply to Philippe Mathieu-DaudéUse the generic host_cpu_feature_supported() helper to check for the EL2 feature support. This will allow to expand to non-KVM accelerators such HVF.
--- target/arm/kvm_arm.h | 11 ----------- hw/arm/virt.c | 8 +------- target/arm/kvm-stub.c | 5 ----- target/arm/kvm.c | 6 +++--- 4 files changed, 4 insertions(+), 26 deletions(-)
target/arm/kvm_arm.h +0 -11
@@ -191,12 +191,6 @@ bool kvm_arm_sve_supported(void);*/ bool kvm_arm_mte_supported (void ); -/** -* kvm_arm_el2_supported: -* -* Returns true if KVM can enable EL2 and false otherwise. -*/ -bool kvm_arm_el2_supported (void );#else static inline bool kvm_arm_aarch32_supported (void )
@@ -213,11 +207,6 @@ static inline bool kvm_arm_mte_supported(void) {return false; } - -static inline bool kvm_arm_el2_supported (void ) -{ -return false; -}#endif /**
hw/arm/virt.c +1 -7
@@ -2267,13 +2267,7 @@ static void machvirt_init(MachineState *machine)exit (1 ); } -if (vms->virt &&kvm_enabled () && !kvm_arm_el2_supported ()) { -error_report ("mach-virt: host kernel KVM does not support providing " -"Virtualization extensions to the guest CPU" ); -exit (1 ); - } - -if (vms->virt && !kvm_enabled () && !tcg_enabled () && !qtest_enabled ()) { +if (vms->virt && !host_cpu_feature_supported (ARM_FEATURE_EL2 )) {error_report ("mach-virt: %s does not support providing " "Virtualization extensions to the guest CPU" ,current_accel_name ());
target/arm/kvm-stub.c +0 -5
@@ -42,11 +42,6 @@ bool kvm_arm_mte_supported(void)return false; } -bool kvm_arm_el2_supported (void ) -{ -return false; -} -/* * These functions should never actually be called without KVM support. */
target/arm/kvm.c +3 -3
@@ -274,7 +274,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)/* * Ask for EL2 if supported. */ - el2_supported =kvm_arm_el2_supported (); + el2_supported =host_cpu_feature_supported (ARM_FEATURE_EL2 );if (el2_supported) { init.features[0 ] |=1 <<KVM_ARM_VCPU_HAS_EL2 ; }
@@ -1780,7 +1780,7 @@ bool host_cpu_feature_supported(enum arm_features feature)case ARM_FEATURE_PMU :return kvm_check_extension (kvm_state,KVM_CAP_ARM_PMU_V3 );case ARM_FEATURE_EL2 : -return kvm_arm_el2_supported (); +return kvm_check_extension (kvm_state,KVM_CAP_ARM_EL2 );case ARM_FEATURE_EL3 :return false;default :
@@ -1918,7 +1918,7 @@ int kvm_arch_init_vcpu(CPUState *cs) cpu->kvm_init_features[0 ] |= (1 <<KVM_ARM_VCPU_PTRAUTH_ADDRESS |1 <<KVM_ARM_VCPU_PTRAUTH_GENERIC ); } -if (cpu->has_el2 &&kvm_arm_el2_supported ()) { +if (cpu->has_el2 &&host_cpu_feature_supported (ARM_FEATURE_EL2 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_HAS_EL2 ; }
Signature · 1 line
2.49.0
Re: [RFC PATCH v2 07/10] target/arm: Replace kvm_arm_el2_supported by host_cpu_feature_supported
Quoted 11 lines · Philippe Mathieu-Daudé
Use the generic
host_cpu_feature_supported()helper to check for the EL2 feature support. This will allow to expand to non-KVM accelerators such HVF.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/kvm_arm.h | 11 ----------- hw/arm/virt.c | 8 +------- target/arm/kvm-stub.c | 5 ----- target/arm/kvm.c | 6 +++--- 4 files changed, 4 insertions(+), 26 deletions(-)
r~
Re: [RFC PATCH v2 05/10] target/arm: Introduce host_cpu_feature_supported()
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
Introduce
host_cpu_feature_supported()helper, returning whether a ARM feature is supported by host hardware.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/internals.h | 8 ++++++++ target/arm/hvf/hvf.c | 20 ++++++++++++++++++++ target/arm/kvm.c | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+)
r~
RFC PATCH v2 8/10 target/arm/hvf: Sync registers used at EL2
In reply to Philippe Mathieu-DaudéFrom: Mohamed Mediouni <[email protected]>
When starting up the VM at EL2, more sysregs are available. Sync the state of those.
---
Extracted from bigger series as proof-of-concept
--- target/arm/hvf/hvf.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
target/arm/hvf/hvf.c +32 -0
@@ -400,6 +400,7 @@ static const struct hvf_reg_match hvf_fpreg_match[] = {struct hvf_sreg_match {int reg;uint32_t key; +bool el2;uint32_t cp_idx; };
@@ -545,6 +546,27 @@ static struct hvf_sreg_match hvf_sreg_match[] = { { HV_SYS_REG_CNTV_CTL_EL0, HVF_SYSREG(14, 3, 3, 3, 1) }, { HV_SYS_REG_CNTV_CVAL_EL0, HVF_SYSREG(14, 3, 3, 3, 2) }, { HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) }, +/* EL2 */ + { HV_SYS_REG_CPTR_EL2, HVF_SYSREG(1, 1, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_ELR_EL2, HVF_SYSREG(4, 0, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_ESR_EL2, HVF_SYSREG(5, 2, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_FAR_EL2, HVF_SYSREG(6, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_HCR_EL2, HVF_SYSREG(1, 1, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_HPFAR_EL2, HVF_SYSREG(6, 0, 3, 4, 4), .el2 = true }, + { HV_SYS_REG_MAIR_EL2, HVF_SYSREG(10, 2, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_MDCR_EL2, HVF_SYSREG(1, 1, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_SCTLR_EL2, HVF_SYSREG(1, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_SPSR_EL2, HVF_SYSREG(4, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_SP_EL2, HVF_SYSREG(4, 1, 3, 6, 0), .el2 = true}, + { HV_SYS_REG_TCR_EL2, HVF_SYSREG(2, 0, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_TPIDR_EL2, HVF_SYSREG(13, 0, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_TTBR0_EL2, HVF_SYSREG(2, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_TTBR1_EL2, HVF_SYSREG(2, 0, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_VBAR_EL2, HVF_SYSREG(12, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_VMPIDR_EL2, HVF_SYSREG(0, 0, 3, 4, 5), .el2 = true }, + { HV_SYS_REG_VPIDR_EL2, HVF_SYSREG(0, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_VTCR_EL2, HVF_SYSREG(2, 1, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_VTTBR_EL2, HVF_SYSREG(2, 1, 3, 4, 0), .el2 = true }, };bool host_cpu_feature_supported (enum arm_features feature)
@@ -608,6 +630,11 @@ int hvf_get_registers(CPUState *cpu)continue ; } +if (hvf_sreg_match[i].el2 + && !host_cpu_feature_supported (ARM_FEATURE_EL2 )) { +continue ; + } +if (cpu->accel->guest_debug_enabled) {/* Handle debug registers */ switch (hvf_sreg_match[i].reg) {
@@ -745,6 +772,11 @@ int hvf_put_registers(CPUState *cpu)continue ; } +if (hvf_sreg_match[i].el2 + && !host_cpu_feature_supported (ARM_FEATURE_EL2 )) { +continue ; + } +if (cpu->accel->guest_debug_enabled) {/* Handle debug registers */ switch (hvf_sreg_match[i].reg) {
Signature · 1 line
2.49.0
RFC PATCH v2 9/10 target/arm/hvf: Consider EL2 acceleration for Silicon M3+ chipsets
---
Just a proof-of-concept...
--- target/arm/hvf/hvf.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/arm/hvf/hvf.c +6 -0
@@ -571,6 +571,9 @@ static struct hvf_sreg_match hvf_sreg_match[] = {bool host_cpu_feature_supported (enum arm_features feature) { +hv_return_t ret; +bool supported; +if (!hvf_enabled ()) {return false; }
@@ -582,6 +585,9 @@ bool host_cpu_feature_supported(enum arm_features feature)case ARM_FEATURE_GENERIC_TIMER :return true;case ARM_FEATURE_EL2 : + ret =hv_vm_config_get_el2_supported (&supported); +assert_hvf_ok (ret); +return supported;case ARM_FEATURE_EL3 :return false;default :
Signature · 1 line
2.49.0
Re: [RFC PATCH v2 09/10] target/arm/hvf: Consider EL2 acceleration for Silicon M3+ chipsets
Quoted 6 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
Just a proof-of-concept...--- target/arm/hvf/hvf.c | 6 ++++++ 1 file changed, 6 insertions(+)
r~
Re: [RFC PATCH v2 08/10] target/arm/hvf: Sync registers used at EL2
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
target/arm/hvf/hvf.c +10
-0+ { HV_SYS_REG_CPTR_EL2, HVF_SYSREG(1, 1, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_ELR_EL2, HVF_SYSREG(4, 0, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_ESR_EL2, HVF_SYSREG(5, 2, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_FAR_EL2, HVF_SYSREG(6, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_HCR_EL2, HVF_SYSREG(1, 1, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_HPFAR_EL2, HVF_SYSREG(6, 0, 3, 4, 4), .el2 = true }, + { HV_SYS_REG_MAIR_EL2, HVF_SYSREG(10, 2, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_MDCR_EL2, HVF_SYSREG(1, 1, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_SCTLR_EL2, HVF_SYSREG(1, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_SPSR_EL2, HVF_SYSREG(4, 0, 3, 4, 0), .el2 = true },
target/arm/hvf/hvf.c static struct hvf_sreg_match hvf_sreg_match[] = { · line 569
Quoted 10 lines
target/arm/hvf/hvf.c +10
-0+ { HV_SYS_REG_SP_EL2, HVF_SYSREG(4, 1, 3, 6, 0), .el2 = true}, + { HV_SYS_REG_TCR_EL2, HVF_SYSREG(2, 0, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_TPIDR_EL2, HVF_SYSREG(13, 0, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_TTBR0_EL2, HVF_SYSREG(2, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_TTBR1_EL2, HVF_SYSREG(2, 0, 3, 4, 1), .el2 = true }, + { HV_SYS_REG_VBAR_EL2, HVF_SYSREG(12, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_VMPIDR_EL2, HVF_SYSREG(0, 0, 3, 4, 5), .el2 = true }, + { HV_SYS_REG_VPIDR_EL2, HVF_SYSREG(0, 0, 3, 4, 0), .el2 = true }, + { HV_SYS_REG_VTCR_EL2, HVF_SYSREG(2, 1, 3, 4, 2), .el2 = true }, + { HV_SYS_REG_VTTBR_EL2, HVF_SYSREG(2, 1, 3, 4, 0), .el2 = true },
Again, el2 = op2 == 4.
target/arm/hvf/hvf.c int hvf_get_registers(CPUState *cpu) · line 636
Quoted 8 lines
target/arm/hvf/hvf.c +4
-0@@ -608,6 +630,11 @@ int hvf_get_registers(CPUState *cpu)continue ; } +if (hvf_sreg_match[i].el2 + && !host_cpu_feature_supported (ARM_FEATURE_EL2 )) { +continue ; + }
I thought you were going to change this to arm_feature(&cpu->env, ARM_FEATURE_EL2).
r~
Re: [RFC PATCH v2 08/10] target/arm/hvf: Sync registers used at EL2
Quoted 22 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé
+ {
HV_SYS_REG_CPTR_EL2,HVF_SYSREG(1, 1, 3, 4, 2), .el2 = true }, + {HV_SYS_REG_ELR_EL2,HVF_SYSREG(4, 0, 3, 4, 1), .el2 = true }, + {HV_SYS_REG_ESR_EL2,HVF_SYSREG(5, 2, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_FAR_EL2,HVF_SYSREG(6, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_HCR_EL2,HVF_SYSREG(1, 1, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_HPFAR_EL2,HVF_SYSREG(6, 0, 3, 4, 4), .el2 = true }, + {HV_SYS_REG_MAIR_EL2,HVF_SYSREG(10, 2, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_MDCR_EL2,HVF_SYSREG(1, 1, 3, 4, 1), .el2 = true }, + {HV_SYS_REG_SCTLR_EL2,HVF_SYSREG(1, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_SPSR_EL2,HVF_SYSREG(4, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_SP_EL2,HVF_SYSREG(4, 1, 3, 6, 0), .el2 = true}, + {HV_SYS_REG_TCR_EL2,HVF_SYSREG(2, 0, 3, 4, 2), .el2 = true },Quoted 8 lines
+ {
HV_SYS_REG_TPIDR_EL2,HVF_SYSREG(13, 0, 3, 4, 2), .el2 = true }, + {HV_SYS_REG_TTBR0_EL2,HVF_SYSREG(2, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_TTBR1_EL2,HVF_SYSREG(2, 0, 3, 4, 1), .el2 = true }, + {HV_SYS_REG_VBAR_EL2,HVF_SYSREG(12, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_VMPIDR_EL2,HVF_SYSREG(0, 0, 3, 4, 5), .el2 = true }, + {HV_SYS_REG_VPIDR_EL2,HVF_SYSREG(0, 0, 3, 4, 0), .el2 = true }, + {HV_SYS_REG_VTCR_EL2,HVF_SYSREG(2, 1, 3, 4, 2), .el2 = true }, + {HV_SYS_REG_VTTBR_EL2,HVF_SYSREG(2, 1, 3, 4, 0), .el2 = true },
Quoted 1 line
Again, el2 = op2 == 4.
Sorry I forgot about this :/
Quoted 10 lines
target/arm/hvf/hvf.c int hvf_get_registers(CPUState *cpu) · line 635
Quoted 8 lines
target/arm/hvf/hvf.c +4
-0@@ -608,6 +630,11 @@ int hvf_get_registers(CPUState *cpu) continue; } + if (hvf_sreg_match[i].el2 + && !host_cpu_feature_supported(ARM_FEATURE_EL2)) { + continue; + }I thought you were going to change this to
arm_feature(&cpu->env, ARM_FEATURE_EL2).
Replied in v1:
https://lore.kernel.org/qemu-devel/[email protected]/
Re: [RFC PATCH v2 08/10] target/arm/hvf: Sync registers used at EL2
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines
target/arm/hvf/hvf.c int hvf_get_registers(CPUState *cpu) · line 635
Quoted 7 lines
target/arm/hvf/hvf.c +4
-0@@ -608,6 +630,11 @@ int hvf_get_registers(CPUState *cpu) continue; } + if (hvf_sreg_match[i].el2 + && !host_cpu_feature_supported(ARM_FEATURE_EL2)) { + continue; + }I thought you were going to change this to
arm_feature(&cpu->env, ARM_FEATURE_EL2).
Quoted 2 lines
Replied in v1:
https://lore.kernel.org/qemu-devel/[email protected]/
Hmm, missed this somehow.
In which case you are going to want to cache this particular value, because you don't want the syscall for every read/write. It need not be more complicated than a file-scope 'static bool'.
r~
RFC PATCH v2 10/10 target/arm/hvf: Allow EL2/EL3 emulation on Silicon M1 / M2
In reply to Philippe Mathieu-Daudé---
Another API PoC.
--- target/arm/hvf/hvf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/arm/hvf/hvf.c +5 -1
@@ -17,6 +17,7 @@#include "system/hvf.h" #include "system/hvf_int.h" #include "system/hw_accel.h" +#include "system/tcg.h" #include "hvf_arm.h" #include "cpregs.h" #include "cpu-sysregs.h"
@@ -585,11 +586,14 @@ bool host_cpu_feature_supported(enum arm_features feature)case ARM_FEATURE_GENERIC_TIMER :return true;case ARM_FEATURE_EL2 : +if (tcg_enabled ()) { +return true; + } ret =hv_vm_config_get_el2_supported (&supported);assert_hvf_ok (ret);return supported;case ARM_FEATURE_EL3 : -return false; +return tcg_enabled ();default :g_assert_not_reached (); }
Signature · 1 line
2.49.0
Re: [RFC PATCH v2 10/10] target/arm/hvf: Allow EL2/EL3 emulation on Silicon M1 / M2
Quoted 7 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Another API PoC.--- target/arm/hvf/hvf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
I imagine this waits until accel/split is present? If so,
r~
Quoted 28 lines
target/arm/hvf/hvf.c +5
-1@@ -17,6 +17,7 @@#include "system/hvf.h" #include "system/hvf_int.h" #include "system/hw_accel.h" +#include "system/tcg.h" #include "hvf_arm.h" #include "cpregs.h" #include "cpu-sysregs.h" @@ -585,11 +586,14 @@ bool host_cpu_feature_supported(enum arm_features feature)case ARM_FEATURE_GENERIC_TIMER :return true;case ARM_FEATURE_EL2 : +if (tcg_enabled ()) { +return true; + } ret =hv_vm_config_get_el2_supported (&supported);assert_hvf_ok (ret);return supported;case ARM_FEATURE_EL3 : -return false; +return tcg_enabled ();default :g_assert_not_reached (); }
Re: [RFC PATCH v2 10/10] target/arm/hvf: Allow EL2/EL3 emulation on Silicon M1 / M2
Quoted 10 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Another API PoC.
---
target/arm/hvf/hvf.c| 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)I imagine this waits until accel/split is present?
Clearly, but I wanted to get host_cpu_feature_supported() right first, to not keep rebasing / reposting 183 patches...
Quoted 3 lines
If so,
Reviewed-by Richard Henderson <[email protected]>
Thanks!