target/arm: Add vSPE support to KVM guest
v3 cover target/arm: Add vSPE support to KVM guest
v3:
- Moved the patch 11 kernel header change to patch 01
- Removed doc for vSPE
- Moved the assignment of has_spe into aarch64_add_spe_properties
- Only enable spe properties in KVM mode
- Only trigger the kvm_arm_spe_init with in-kernel irqchip support to avoid breaking bisection
- Set the PMSVER bit in ID register if spe was enabled by usespace
Again, many thanks to Andrew, Richard, Philippe and Auger for their comments.
This series add support for SPE(Statistical Profiling Extension)[1] in KVM guest. It's based on Andrew Murray's kernel KVM patches V2[2], and has been tested to ensure that guest can use SPE with valid data. E.g.
In host:
$ ./qemu-system-aarch64 \
-cpu host -M virt,accel=kvm,gic-version=3 -nographic -m 2048M \
-kernel ./Image-new \
-initrd /boot/initrd.img-5.6.0-rc2+ \
-append "root=/dev/vda rw console=ttyAMA0" -nodefaults -serial stdio\
-drive if=none,file=./xenial.rootfs.ext4,id=hd0,format=raw \
-device virtio-blk-device,drive=hd0 \In guest:
$ perf record -e arm_spe/ts_enable=1,pa_enable=1,pct_enable=1/ \
dd if=/dev/zero of=/dev/null count=1000
$ perf report --dump-raw-trace > spe_buf.txtThe spe_buf.txt should contain similar data as below:
. ... ARM SPE data: size 135944 bytes
. 00000000: b0 f4 d3 29 10 00 80 ff a0 PC 0xff80001029d3f4 el1 ns=1 . 00000009: 99 0b 00 LAT 11 ISSUE . 0000000c: 98 0d 00 LAT 13 TOT . 0000000f: 52 16 00 EV RETIRED L1D-ACCESS TLB-ACCESS . 00000012: 49 00 LD . 00000014: b2 d0 40 d8 70 00 00 ff 00 VA 0xff000070d840d0 . 0000001d: 9a 01 00 LAT 1 XLAT . 00000020: 00 00 00 PAD . 00000023: 71 a5 1f b3 20 14 00 00 00 TS 86447955877 . 0000002c: b0 7c f9 29 10 00 80 ff a0 PC 0xff80001029f97c el1 ns=1 . 00000035: 99 02 00 LAT 2 ISSUE . 00000038: 98 03 00 LAT 3 TOT . 0000003b: 52 02 00 EV RETIRED . 0000003e: 48 00 INSN-OTHER . 00000040: 00 00 00 PAD . 00000043: 71 ef 1f b3 20 14 00 00 00 TS 86447955951 . 0000004c: b0 f0 e9 29 10 00 80 ff a0 PC 0xff80001029e9f0 el1 ns=1 . 00000055: 99 02 00 LAT 2 ISSUE . 00000058: 98 03 00 LAT 3 TOT . 0000005b: 52 02 00 EV RETIRED
If you want to disable the vSPE support, you can use the 'spe=off' cpu property:
./qemu-system-aarch64 \
-cpu host,spe=off -M virt,accel=kvm,gic-version=3 -nographic -m 2048M \
-kernel ./Image-new \
-initrd /boot/initrd.img-5.6.0-rc2+ \
-append "root=/dev/vda rw console=ttyAMA0" -nodefaults -serial stdio\
-drive if=none,file=./xenial.rootfs.ext4,id=hd0,format=raw \
-device virtio-blk-device,drive=hd0 \Note:
(1) Since the kernel patches are still under review, some of the macros in the header files may be changed after merging. We may need to update them accordingly. To be specific, if you want to have a try on this patch series, you needs to replace on the kernel 5.5-rc2 based series, and do minor changes:
-#define KVM_CAP_ARM_SPE_V1 179
+#define KVM_CAP_ARM_SPE_V1 184
(2) These patches only add vSPE support in KVM mode, for TCG mode, I'm not sure whether we need to support it.
(3) Just followed the 'sve' property, we only allow this feature to be removed from CPUs which enable it by default when the host cpu support it.
[1]https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/
posts/statistical-profiling-extension-for-armv8-a
[2]https://www.spinics.net/lists/arm-kernel/msg776228.html [3]https://www.mail-archive.com/[email protected]/msg727588.html
Haibo Xu (12):
update Linux headers with new vSPE macros
target/arm/kvm: spe: Add helper to detect SPE when using KVM target/arm/cpu: spe: Add an option to turn on/off vSPE support target/arm: spe: Only enable SPE from 5.2 compat machines. target/arm/kvm: spe: Unify device attr operation helper target/arm/kvm: spe: Add device init and set_irq operations hw/arm/virt: Move post cpu realize check into its own function hw/arm/virt: Move kvm pmu setup to virt_cpu_post_init hw/arm/virt: spe: Add vSPE device and corresponding interrupt support target/arm/cpu: spe: Enable spe to work with host cpu target/arm/kvm: spe: Enable userspace irqchip support. target/arm: spe: Add corresponding test.
hw/arm/virt-acpi-build.c | 3 + hw/arm/virt.c | 116 ++++++++++++++++++++++++--------- include/hw/acpi/acpi-defs.h | 3 + include/hw/arm/virt.h | 2 + linux-headers/asm-arm64/kvm.h | 4 ++ linux-headers/linux/kvm.h | 2 + target/arm/cpu.c | 9 +++ target/arm/cpu.h | 17 +++++ target/arm/cpu64.c | 56 ++++++++++++++++ target/arm/kvm.c | 10 +++ target/arm/kvm64.c | 56 ++++++++++++++-- target/arm/kvm_arm.h | 18 +++++ target/arm/monitor.c | 2 +- tests/qtest/arm-cpu-features.c | 9 +++ 14 files changed, 271 insertions(+), 36 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/12 update Linux headers with new vSPE macros
--- linux-headers/asm-arm64/kvm.h | 4 ++++ linux-headers/linux/kvm.h | 2 ++ 2 files changed, 6 insertions(+)
linux-headers/asm-arm64/kvm.h +4 -0
@@ -106,6 +106,7 @@ struct kvm_regs {#define KVM_ARM_VCPU_SVE 4/* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5/* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6/* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_SPE_V1 7/* Support guest SPEv1 */ struct kvm_vcpu_init {__u32 target;
@@ -334,6 +335,9 @@ struct kvm_vcpu_events {#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1#define KVM_ARM_VCPU_PVTIME_CTRL 2#define KVM_ARM_VCPU_PVTIME_IPA 0 +#define KVM_ARM_VCPU_SPE_V1_CTRL 3 +#define KVM_ARM_VCPU_SPE_V1_IRQ 0 +#define KVM_ARM_VCPU_SPE_V1_INIT 1/* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_VCPU2_SHIFT 28
linux-headers/linux/kvm.h +2 -0
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_SECURE_GUEST 181#define KVM_CAP_HALT_POLL 182#define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_ARM_SPE_V1 184#ifdef KVM_CAP_IRQ_ROUTING
@@ -1671,6 +1672,7 @@ struct kvm_assigned_msix_entry {#define KVM_ARM_DEV_EL1_VTIMER (1 << 0)#define KVM_ARM_DEV_EL1_PTIMER (1 << 1)#define KVM_ARM_DEV_PMU (1 << 2) +#define KVM_ARM_DEV_SPE (1 << 3)struct kvm_hyperv_eventfd {__u32 conn_id;
Signature · 1 line
2.17.1
PATCH v3 2/12 target/arm/kvm: spe: Add helper to detect SPE when using KVM
In reply to Haibo Xu--- target/arm/kvm.c | 5 +++++ target/arm/kvm_arm.h | 13 +++++++++++++ 2 files changed, 18 insertions(+)
target/arm/kvm.c +5 -0
@@ -214,6 +214,11 @@ bool kvm_arm_pmu_supported(void)return kvm_check_extension (kvm_state,KVM_CAP_ARM_PMU_V3 ); } +bool kvm_arm_spe_supported (void ) +{ +return kvm_check_extension (kvm_state,KVM_CAP_ARM_SPE_V1 ); +} +int kvm_arm_get_max_vm_ipa_size (MachineState *ms) {KVMState *s =KVM_STATE (ms->accelerator);
target/arm/kvm_arm.h +13 -0
@@ -283,6 +283,14 @@ bool kvm_arm_aarch32_supported(void);*/ bool kvm_arm_pmu_supported (void ); +/** +* kvm_arm_spe_supported: +* +* Returns: true if the KVM VCPU can enable its SPE +* and false otherwise. +*/ +bool kvm_arm_spe_supported (void ); +/** * kvm_arm_sve_supported: *
@@ -366,6 +374,11 @@ static inline bool kvm_arm_pmu_supported(void)return false; } +static inline bool kvm_arm_spe_supported (void ) +{ +return false; +} +static inline bool kvm_arm_sve_supported (void ) {return false;
Signature · 1 line
2.17.1
PATCH v3 3/12 target/arm/cpu: spe: Add an option to turn on/off vSPE support
In reply to Haibo XuAdds a spe=[on/off] option to enable/disable vSPE support in guest vCPU.
--- target/arm/cpu.c | 6 ++++++ target/arm/cpu.h | 13 ++++++++++++ target/arm/cpu64.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
target/arm/cpu.c +6 -0
@@ -1310,6 +1310,12 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)error_propagate (errp, local_err);return ; } + +arm_cpu_spe_finalize (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } }
target/arm/cpu.h +13 -0
@@ -24,6 +24,7 @@#include "hw/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-defs.h" +#include "qapi/qapi-types-common.h" /* ARM processors have a weak memory model */ #define TCG_GUEST_DEFAULT_MO (0)
@@ -196,9 +197,11 @@ typedef struct {#ifdef TARGET_AARCH64 # define ARM_MAX_VQ 16void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp);#else # define ARM_MAX_VQ 1static inline void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp) { } +static inline void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp) { }#endif typedef struct ARMVectorReg {
@@ -829,6 +832,8 @@ struct ARMCPU {bool has_el3;/* CPU has PMU (Performance Monitor Unit) */ bool has_pmu; +/* CPU has SPE (Statistical Profiling Extension) */ +OnOffAuto has_spe;/* CPU has VFP */ bool has_vfp;/* CPU has Neon */
@@ -3869,6 +3874,14 @@ static inline bool isar_feature_aa64_pmu_8_4(const ARMISARegisters *id)FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMUVER ) !=0xf ; } +/* +* Currently we don't differentiate between the ARMv8.2-SPE and ARMv8.3-SPE. +*/ +static inline bool isar_feature_aa64_spe (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMSVER ) !=0 ; +} +static inline bool isar_feature_aa64_rcpc_8_3 (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,LRCPC ) !=0 ;
target/arm/cpu64.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 03/12] target/arm/cpu: spe: Add an option to turn on/off vSPE support
Quoted 137 lines · Haibo Xu
Adds a spe=[on/off] option to enable/disable vSPE support in guest vCPU.
Reviewed-by Andrew Jones <[email protected]>Signed-off-by Haibo Xu <[email protected]>--- target/arm/cpu.c | 6 ++++++ target/arm/cpu.h | 13 ++++++++++++ target/arm/cpu64.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)target/arm/cpu.c +6
-0@@ -1310,6 +1310,12 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)error_propagate (errp, local_err);return ; } + +arm_cpu_spe_finalize (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } }target/arm/cpu.h +13
-0@@ -24,6 +24,7 @@#include "hw/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-defs.h" +#include "qapi/qapi-types-common.h" /* ARM processors have a weak memory model */ #define TCG_GUEST_DEFAULT_MO (0)@@ -196,9 +197,11 @@ typedef struct {#ifdef TARGET_AARCH64 # define ARM_MAX_VQ 16void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp);#else # define ARM_MAX_VQ 1static inline void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp) { } +static inline void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp) { }#endif typedef struct ARMVectorReg {@@ -829,6 +832,8 @@ struct ARMCPU {bool has_el3;/* CPU has PMU (Performance Monitor Unit) */ bool has_pmu; +/* CPU has SPE (Statistical Profiling Extension) */ +OnOffAuto has_spe;/* CPU has VFP */ bool has_vfp;/* CPU has Neon */ @@ -3869,6 +3874,14 @@ static inline bool isar_feature_aa64_pmu_8_4(const ARMISARegisters *id)FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMUVER ) !=0xf ; } +/* +* Currently we don't differentiate between the ARMv8.2-SPE and ARMv8.3-SPE. +*/ +static inline bool isar_feature_aa64_spe (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMSVER ) !=0 ; +} +static inline bool isar_feature_aa64_rcpc_8_3 (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,LRCPC ) !=0 ;target/arm/cpu64.c +49
-0@@ -572,6 +572,55 @@ void aarch64_add_sve_properties(Object *obj) } } +void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp) +{ +uint64_t t; +uint32_t value =0 ; + +if (cpu->has_spe ==ON_OFF_AUTO_AUTO ) { +if (kvm_enabled () &&kvm_arm_spe_supported ()) { + cpu->has_spe =ON_OFF_AUTO_ON ; + }else { + cpu->has_spe =ON_OFF_AUTO_OFF ; + } + }else if (cpu->has_spe ==ON_OFF_AUTO_ON ) { +if (!kvm_enabled () || !kvm_arm_spe_supported ()) { +error_setg (errp,"'spe' cannot be enabled on this host" ); +return ; + } + } + +/* +* According to the ARM ARM, the ID_AA64DFR0[PMSVER] currently +* support 3 values: +* +* 0b0000: SPE not implemented +* 0b0001: ARMv8.2-SPE implemented +* 0b0010: ARMv8.3-SPE implemented +* +* But the kernel KVM API didn't expose all these 3 values, and +* we can only get whether the SPE feature is supported or not. +* So here we just set the PMSVER to 1 if this feature was supported. +*/ +if (cpu->has_spe ==ON_OFF_AUTO_ON ) { + value =1 ; + } + + t = cpu->isar.id_aa64dfr0; + t =FIELD_DP64 (t,ID_AA64DFR0 ,PMSVER , value); + cpu->isar.id_aa64dfr0 = t; +} + +static bool arm_spe_get (Object *obj,Error **errp) +{ +return ARM_CPU (obj)->has_spe !=ON_OFF_AUTO_OFF ; +} + +static void arm_spe_set (Object *obj,bool value,Error **errp) +{ +ARM_CPU (obj)->has_spe = value ?ON_OFF_AUTO_ON :ON_OFF_AUTO_OFF ; +} +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
target/arm/cpu64.c static void aarch64_max_initfn(Object *obj) · line 776
Quoted 7 lines
target/arm/cpu64.c +3
-0@@ -721,6 +770,9 @@ static void aarch64_max_initfn(Object *obj)aarch64_add_sve_properties (obj);object_property_add (obj,"sve-max-vq" ,"uint32" , cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq,NULL ,NULL ); + + cpu->has_spe =ON_OFF_AUTO_AUTO ; +object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); }
The cover-letter says we're only providing the 'spe' property for KVM enabled guests, but we're adding it here in the common part of the max init function. It should be added in the kvm_enabled() part only.
Thanks,
drew
Quoted 6 lines
target/arm/cpu64.c +0
-0static const ARMCPUInfo aarch64_cpus[] = {Signature · 1 line
2.17.1
Re: [PATCH v3 03/12] target/arm/cpu: spe: Add an option to turn on/off vSPE support
Quoted 151 lines · Andrew Jones
Quoted 137 lines · Haibo Xu
Adds a spe=[on/off] option to enable/disable vSPE support in guest vCPU.
Reviewed-by Andrew Jones <[email protected]>Signed-off-by Haibo Xu <[email protected]>--- target/arm/cpu.c | 6 ++++++ target/arm/cpu.h | 13 ++++++++++++ target/arm/cpu64.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)target/arm/cpu.c +6
-0@@ -1310,6 +1310,12 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)error_propagate (errp, local_err);return ; } + +arm_cpu_spe_finalize (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } }target/arm/cpu.h +13
-0@@ -24,6 +24,7 @@#include "hw/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-defs.h" +#include "qapi/qapi-types-common.h" /* ARM processors have a weak memory model */ #define TCG_GUEST_DEFAULT_MO (0)@@ -196,9 +197,11 @@ typedef struct {#ifdef TARGET_AARCH64 # define ARM_MAX_VQ 16void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp); +void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp);#else # define ARM_MAX_VQ 1static inline void arm_cpu_sve_finalize (ARMCPU *cpu,Error **errp) { } +static inline void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp) { }#endif typedef struct ARMVectorReg {@@ -829,6 +832,8 @@ struct ARMCPU {bool has_el3;/* CPU has PMU (Performance Monitor Unit) */ bool has_pmu; +/* CPU has SPE (Statistical Profiling Extension) */ +OnOffAuto has_spe;/* CPU has VFP */ bool has_vfp;/* CPU has Neon */ @@ -3869,6 +3874,14 @@ static inline bool isar_feature_aa64_pmu_8_4(const ARMISARegisters *id)FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMUVER ) !=0xf ; } +/* +* Currently we don't differentiate between the ARMv8.2-SPE and ARMv8.3-SPE. +*/ +static inline bool isar_feature_aa64_spe (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64dfr0,ID_AA64DFR0 ,PMSVER ) !=0 ; +} +static inline bool isar_feature_aa64_rcpc_8_3 (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,LRCPC ) !=0 ;target/arm/cpu64.c +49
-0@@ -572,6 +572,55 @@ void aarch64_add_sve_properties(Object *obj) } } +void arm_cpu_spe_finalize (ARMCPU *cpu,Error **errp) +{ +uint64_t t; +uint32_t value =0 ; + +if (cpu->has_spe ==ON_OFF_AUTO_AUTO ) { +if (kvm_enabled () &&kvm_arm_spe_supported ()) { + cpu->has_spe =ON_OFF_AUTO_ON ; + }else { + cpu->has_spe =ON_OFF_AUTO_OFF ; + } + }else if (cpu->has_spe ==ON_OFF_AUTO_ON ) { +if (!kvm_enabled () || !kvm_arm_spe_supported ()) { +error_setg (errp,"'spe' cannot be enabled on this host" ); +return ; + } + } + +/* +* According to the ARM ARM, the ID_AA64DFR0[PMSVER] currently +* support 3 values: +* +* 0b0000: SPE not implemented +* 0b0001: ARMv8.2-SPE implemented +* 0b0010: ARMv8.3-SPE implemented +* +* But the kernel KVM API didn't expose all these 3 values, and +* we can only get whether the SPE feature is supported or not. +* So here we just set the PMSVER to 1 if this feature was supported. +*/ +if (cpu->has_spe ==ON_OFF_AUTO_ON ) { + value =1 ; + } + + t = cpu->isar.id_aa64dfr0; + t =FIELD_DP64 (t,ID_AA64DFR0 ,PMSVER , value); + cpu->isar.id_aa64dfr0 = t; +} + +static bool arm_spe_get (Object *obj,Error **errp) +{ +return ARM_CPU (obj)->has_spe !=ON_OFF_AUTO_OFF ; +} + +static void arm_spe_set (Object *obj,bool value,Error **errp) +{ +ARM_CPU (obj)->has_spe = value ?ON_OFF_AUTO_ON :ON_OFF_AUTO_OFF ; +} +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; target/arm/cpu64.c static void aarch64_max_initfn(Object *obj) · line 776
Quoted 7 lines
target/arm/cpu64.c +3
-0@@ -721,6 +770,9 @@ static void aarch64_max_initfn(Object *obj)aarch64_add_sve_properties (obj);object_property_add (obj,"sve-max-vq" ,"uint32" , cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq,NULL ,NULL ); + + cpu->has_spe =ON_OFF_AUTO_AUTO ; +object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); }The cover-letter says we're only providing the 'spe' property for KVM enabled guests, but we're adding it here in the common part of the max init function. It should be added in the
kvm_enabled()part only.
Quoted 3 lines
Thanks,
drew
Yes, It should be in the kvm_enabled() part.
Will fix it in the next version.
Thanks,
Haibo
Quoted 7 lines
Quoted 6 lines
target/arm/cpu64.c +0
-1static const ARMCPUInfo aarch64_cpus[] = { --2.17.1
PATCH v3 4/12 target/arm: spe: Only enable SPE from 5.2 compat machines.
In reply to Haibo Xu--- hw/arm/virt.c | 7 +++++++ include/hw/arm/virt.h | 1 + 2 files changed, 8 insertions(+)
hw/arm/virt.c +7 -0
@@ -1830,6 +1830,10 @@ static void machvirt_init(MachineState *machine)object_property_set_bool (cpuobj,"pmu" , false,NULL ); } +if (vmc->no_spe &&object_property_find (cpuobj,"spe" ,NULL )) { +object_property_set_bool (cpuobj,"spe" , false,NULL ); + } +if (object_property_find (cpuobj,"reset-cbar" ,NULL )) { object_property_set_int(cpuobj, "reset-cbar", vms->memmap[VIRT_CPUPERIPHS].base,
@@ -2553,8 +2557,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(5, 2)static void virt_machine_5_1_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_5_2_options (mc);compat_props_add (mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); + vmc->no_spe = true; }DEFINE_VIRT_MACHINE (5 ,1 )
include/hw/arm/virt.h +1 -0
@@ -126,6 +126,7 @@ typedef struct {bool no_ged;/* Machines < 4.2 has no support for ACPI GED device */ bool kvm_no_adjvtime;bool acpi_expose_flash; +bool no_spe; } VirtMachineClass; typedef struct {
Signature · 1 line
2.17.1
PATCH v3 5/12 target/arm/kvm: spe: Unify device attr operation helper
In reply to Haibo XuFrom: Andrew Jones <[email protected]>
Rename kvm_arm_pmu_set_attr() to kvm_arm_set_device_attr(), So both the vPMU and vSPE device can share the same API.
--- target/arm/kvm64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
target/arm/kvm64.c +6 -5
@@ -397,19 +397,20 @@ static CPUWatchpoint *find_hw_watchpoint(CPUState *cpu, target_ulong addr)return NULL ; } -static bool kvm_arm_pmu_set_attr (CPUState *cs,struct kvm_device_attr *attr) +static bool kvm_arm_set_device_attr (CPUState *cs,struct kvm_device_attr *attr, +const char *name) {int err; err =kvm_vcpu_ioctl (cs,KVM_HAS_DEVICE_ATTR , attr);if (err !=0 ) { -error_report ("PMU: KVM_HAS_DEVICE_ATTR: %s" ,strerror (-err)); +error_report ("%s: KVM_HAS_DEVICE_ATTR: %s" , name,strerror (-err));return false; } err =kvm_vcpu_ioctl (cs,KVM_SET_DEVICE_ATTR , attr);if (err !=0 ) { -error_report ("PMU: KVM_SET_DEVICE_ATTR: %s" ,strerror (-err)); +error_report ("%s: KVM_SET_DEVICE_ATTR: %s" , name,strerror (-err));return false; }
@@ -426,7 +427,7 @@ void kvm_arm_pmu_init(CPUState *cs)if (!ARM_CPU (cs)->has_pmu) {return ; } -if (!kvm_arm_pmu_set_attr (cs, &attr)) { +if (!kvm_arm_set_device_attr (cs, &attr,"PMU" )) {error_report ("failed to init PMU" );abort (); }
@@ -443,7 +444,7 @@ void kvm_arm_pmu_set_irq(CPUState *cs, int irq)if (!ARM_CPU (cs)->has_pmu) {return ; } -if (!kvm_arm_pmu_set_attr (cs, &attr)) { +if (!kvm_arm_set_device_attr (cs, &attr,"PMU" )) {error_report ("failed to set irq for PMU" );abort (); }
Signature · 1 line
2.17.1
PATCH v3 6/12 target/arm/kvm: spe: Add device init and set_irq operations
In reply to Haibo Xu--- target/arm/kvm64.c | 33 +++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 5 +++++ 2 files changed, 38 insertions(+)
target/arm/kvm64.c +33 -0
@@ -450,6 +450,39 @@ void kvm_arm_pmu_set_irq(CPUState *cs, int irq) } } +void kvm_arm_spe_init (CPUState *cs) +{ +struct kvm_device_attr attr = { + .group =KVM_ARM_VCPU_SPE_V1_CTRL , + .attr =KVM_ARM_VCPU_SPE_V1_INIT , + }; + +if (!ARM_CPU (cs)->has_spe) { +return ; + } +if (!kvm_arm_set_device_attr (cs, &attr,"SPE" )) { +error_report ("failed to init SPE" ); +abort (); + } +} + +void kvm_arm_spe_set_irq (CPUState *cs,int irq) +{ +struct kvm_device_attr attr = { + .group =KVM_ARM_VCPU_SPE_V1_CTRL , + .addr = (intptr_t )&irq, + .attr =KVM_ARM_VCPU_SPE_V1_IRQ , + }; + +if (!ARM_CPU (cs)->has_spe) { +return ; + } +if (!kvm_arm_set_device_attr (cs, &attr,"SPE" )) { +error_report ("failed to set irq for SPE" ); +abort (); + } +} +static int read_sys_reg32 (int fd,uint32_t *pret,uint64_t id) {uint64_t ret;
target/arm/kvm_arm.h +5 -0
@@ -348,6 +348,8 @@ int kvm_arm_vgic_probe(void);void kvm_arm_pmu_set_irq (CPUState *cs,int irq);void kvm_arm_pmu_init (CPUState *cs); +void kvm_arm_spe_set_irq (CPUState *cs,int irq); +void kvm_arm_spe_init (CPUState *cs);int kvm_arm_set_irq (int cpu,int irqtype,int irq,int level);#else
@@ -397,6 +399,9 @@ static inline int kvm_arm_vgic_probe(void)static inline void kvm_arm_pmu_set_irq (CPUState *cs,int irq) {}static inline void kvm_arm_pmu_init (CPUState *cs) {} +static inline void kvm_arm_spe_set_irq (CPUState *cs,int irq) {} +static inline void kvm_arm_spe_init (CPUState *cs) {} +static inline void kvm_arm_sve_get_vls (CPUState *cs,unsigned long *map) {}static inline void kvm_arm_get_virtual_time (CPUState *cs) {}
Signature · 1 line
2.17.1
PATCH v3 7/12 hw/arm/virt: Move post cpu realize check into its own function
In reply to Haibo XuFrom: Andrew Jones <[email protected]>
We'll add more to this new function in coming patches so we also state the gic must be created and call it below create_gic().
No functional change intended.
--- hw/arm/virt.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
hw/arm/virt.c +22 -16
@@ -1672,6 +1672,26 @@ static void finalize_gic_version(VirtMachineState *vms) } } +static void virt_cpu_post_init (VirtMachineState *vms) +{ +bool aarch64; + + aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + +if (!kvm_enabled ()) { +if (aarch64 && vms->highmem) { +int requested_pa_size =64 -clz64 (vms->highest_gpa); +int pamax =arm_pamax (ARM_CPU (first_cpu)); + +if (pamax < requested_pa_size) { +error_report ("VCPU supports less PA bits (%d) than requested " +"by the memory map (%d)" , pamax, requested_pa_size); +exit (1 ); + } + } + } +} +static void machvirt_init (MachineState *machine) {VirtMachineState *vms =VIRT_MACHINE (machine);
@@ -1890,22 +1910,6 @@ static void machvirt_init(MachineState *machine)fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms); -if (!kvm_enabled ()) { -ARMCPU *cpu =ARM_CPU (first_cpu); -bool aarch64 =object_property_get_bool (OBJECT (cpu),"aarch64" ,NULL ); - -if (aarch64 && vms->highmem) { -int requested_pa_size, pamax =arm_pamax (cpu); - - requested_pa_size =64 -clz64 (vms->highest_gpa); -if (pamax < requested_pa_size) { -error_report ("VCPU supports less PA bits (%d) than requested " -"by the memory map (%d)" , pamax, requested_pa_size); -exit (1 ); - } - } - } -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, machine->ram);if (machine->device_memory) {
@@ -1917,6 +1921,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +virt_cpu_post_init (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 ));
Signature · 1 line
2.17.1
Re: [PATCH v3 07/12] hw/arm/virt: Move post cpu realize check into its own function
Quoted 5 lines · Haibo Xu
From: Andrew Jones <[email protected]>
We'll add more to this new function in coming patches so we also state the gic must be created and call it below
create_gic().
Quoted 7 lines
No functional change intended.
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
This still isn't the right version of this patch. You need
https://www.mail-archive.com/[email protected]/msg727591.html
Quoted 68 lines
hw/arm/virt.c +22
-16@@ -1672,6 +1672,26 @@ static void finalize_gic_version(VirtMachineState *vms) } } +static void virt_cpu_post_init (VirtMachineState *vms) +{ +bool aarch64; + + aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + +if (!kvm_enabled ()) { +if (aarch64 && vms->highmem) { +int requested_pa_size =64 -clz64 (vms->highest_gpa); +int pamax =arm_pamax (ARM_CPU (first_cpu)); + +if (pamax < requested_pa_size) { +error_report ("VCPU supports less PA bits (%d) than requested " +"by the memory map (%d)" , pamax, requested_pa_size); +exit (1 ); + } + } + } +} +static void machvirt_init (MachineState *machine) {VirtMachineState *vms =VIRT_MACHINE (machine);@@ -1890,22 +1910,6 @@ static void machvirt_init(MachineState *machine)fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms); -if (!kvm_enabled ()) { -ARMCPU *cpu =ARM_CPU (first_cpu); -bool aarch64 =object_property_get_bool (OBJECT (cpu),"aarch64" ,NULL ); - -if (aarch64 && vms->highmem) { -int requested_pa_size, pamax =arm_pamax (cpu); - - requested_pa_size =64 -clz64 (vms->highest_gpa); -if (pamax < requested_pa_size) { -error_report ("VCPU supports less PA bits (%d) than requested " -"by the memory map (%d)" , pamax, requested_pa_size); -exit (1 ); - } - } - } -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, machine->ram);if (machine->device_memory) {@@ -1917,6 +1921,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +virt_cpu_post_init (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 ));Signature · 1 line
2.17.1
Re: [PATCH v3 07/12] hw/arm/virt: Move post cpu realize check into its own function
Quoted 9 lines · Andrew Jones
Quoted 7 lines · Haibo Xu
From: Andrew Jones <[email protected]>
We'll add more to this new function in coming patches so we also state the gic must be created and call it below
create_gic().No functional change intended.
Quoted 9 lines
Quoted 5 lines
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)This still isn't the right version of this patch. You need
https://www.mail-archive.com/[email protected]/msg727591.html
My fault! Very sorry for forgetting to address that in this version. Shall I re-send this patch with the fix? Or fix it in the next version?
Quoted 69 lines
Quoted 68 lines
hw/arm/virt.c +22
-17@@ -1672,6 +1672,26 @@ static void finalize_gic_version(VirtMachineState *vms) } } +static void virt_cpu_post_init (VirtMachineState *vms) +{ +bool aarch64; + + aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + +if (!kvm_enabled ()) { +if (aarch64 && vms->highmem) { +int requested_pa_size =64 -clz64 (vms->highest_gpa); +int pamax =arm_pamax (ARM_CPU (first_cpu)); + +if (pamax < requested_pa_size) { +error_report ("VCPU supports less PA bits (%d) than requested " +"by the memory map (%d)" , pamax, requested_pa_size); +exit (1 ); + } + } + } +} +static void machvirt_init (MachineState *machine) {VirtMachineState *vms =VIRT_MACHINE (machine);@@ -1890,22 +1910,6 @@ static void machvirt_init(MachineState *machine)fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms); -if (!kvm_enabled ()) { -ARMCPU *cpu =ARM_CPU (first_cpu); -bool aarch64 =object_property_get_bool (OBJECT (cpu),"aarch64" ,NULL ); - -if (aarch64 && vms->highmem) { -int requested_pa_size, pamax =arm_pamax (cpu); - - requested_pa_size =64 -clz64 (vms->highest_gpa); -if (pamax < requested_pa_size) { -error_report ("VCPU supports less PA bits (%d) than requested " -"by the memory map (%d)" , pamax, requested_pa_size); -exit (1 ); - } - } - } -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, machine->ram);if (machine->device_memory) {@@ -1917,6 +1921,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +virt_cpu_post_init (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 )); --2.17.1
Re: [PATCH v3 07/12] hw/arm/virt: Move post cpu realize check into its own function
Quoted 16 lines · Haibo Xu
Quoted 15 lines · Andrew Jones
Quoted 12 lines · Haibo Xu
From: Andrew Jones <[email protected]>
We'll add more to this new function in coming patches so we also state the gic must be created and call it below
create_gic().No functional change intended.
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
Quoted 6 lines
Quoted 3 lines
This still isn't the right version of this patch. You need
https://www.mail-archive.com/[email protected]/msg727591.htmlMy fault! Very sorry for forgetting to address that in this version. Shall I re-send this patch with the fix? Or fix it in the next version?
I can wait. It'll be awhile before this series can be merged anyway, since the KVM patches haven't been merged yet.
Thanks,
drew
Quoted 71 lines
Quoted 70 lines
Quoted 69 lines
hw/arm/virt.c +22
-17@@ -1672,6 +1672,26 @@ static void finalize_gic_version(VirtMachineState *vms) } } +static void virt_cpu_post_init (VirtMachineState *vms) +{ +bool aarch64; + + aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + +if (!kvm_enabled ()) { +if (aarch64 && vms->highmem) { +int requested_pa_size =64 -clz64 (vms->highest_gpa); +int pamax =arm_pamax (ARM_CPU (first_cpu)); + +if (pamax < requested_pa_size) { +error_report ("VCPU supports less PA bits (%d) than requested " +"by the memory map (%d)" , pamax, requested_pa_size); +exit (1 ); + } + } + } +} +static void machvirt_init (MachineState *machine) {VirtMachineState *vms =VIRT_MACHINE (machine);@@ -1890,22 +1910,6 @@ static void machvirt_init(MachineState *machine)fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms); -if (!kvm_enabled ()) { -ARMCPU *cpu =ARM_CPU (first_cpu); -bool aarch64 =object_property_get_bool (OBJECT (cpu),"aarch64" ,NULL ); - -if (aarch64 && vms->highmem) { -int requested_pa_size, pamax =arm_pamax (cpu); - - requested_pa_size =64 -clz64 (vms->highest_gpa); -if (pamax < requested_pa_size) { -error_report ("VCPU supports less PA bits (%d) than requested " -"by the memory map (%d)" , pamax, requested_pa_size); -exit (1 ); - } - } - } -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, machine->ram);if (machine->device_memory) {@@ -1917,6 +1921,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +virt_cpu_post_init (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 )); --2.17.1
Re: [PATCH v3 07/12] hw/arm/virt: Move post cpu realize check into its own function
Quoted 22 lines · Andrew Jones
Quoted 20 lines · Haibo Xu
Quoted 18 lines · Andrew Jones
Quoted 5 lines · Haibo Xu
From: Andrew Jones <[email protected]>
We'll add more to this new function in coming patches so we also state the gic must be created and call it below
create_gic().Quoted 7 lines
No functional change intended.
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)This still isn't the right version of this patch. You need
https://www.mail-archive.com/[email protected]/msg727591.html
Quoted 9 lines
Quoted 2 lines
My fault! Very sorry for forgetting to address that in this version. Shall I re-send this patch with the fix? Or fix it in the next version?
I can wait. It'll be awhile before this series can be merged anyway, since the KVM patches haven't been merged yet.
Thanks,
drew
Ok, I will fix it in the next version.
Thanks again for the review!
Regards,
Haibo
Quoted 72 lines
Quoted 71 lines
Quoted 70 lines
Quoted 69 lines
hw/arm/virt.c +22
-17@@ -1672,6 +1672,26 @@ static void finalize_gic_version(VirtMachineState *vms) } } +static void virt_cpu_post_init (VirtMachineState *vms) +{ +bool aarch64; + + aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + +if (!kvm_enabled ()) { +if (aarch64 && vms->highmem) { +int requested_pa_size =64 -clz64 (vms->highest_gpa); +int pamax =arm_pamax (ARM_CPU (first_cpu)); + +if (pamax < requested_pa_size) { +error_report ("VCPU supports less PA bits (%d) than requested " +"by the memory map (%d)" , pamax, requested_pa_size); +exit (1 ); + } + } + } +} +static void machvirt_init (MachineState *machine) {VirtMachineState *vms =VIRT_MACHINE (machine);@@ -1890,22 +1910,6 @@ static void machvirt_init(MachineState *machine)fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms); -if (!kvm_enabled ()) { -ARMCPU *cpu =ARM_CPU (first_cpu); -bool aarch64 =object_property_get_bool (OBJECT (cpu),"aarch64" ,NULL ); - -if (aarch64 && vms->highmem) { -int requested_pa_size, pamax =arm_pamax (cpu); - - requested_pa_size =64 -clz64 (vms->highest_gpa); -if (pamax < requested_pa_size) { -error_report ("VCPU supports less PA bits (%d) than requested " -"by the memory map (%d)" , pamax, requested_pa_size); -exit (1 ); - } - } - } -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, machine->ram);if (machine->device_memory) {@@ -1917,6 +1921,8 @@ static void machvirt_init(MachineState *machine)create_gic (vms); +virt_cpu_post_init (vms); +fdt_add_pmu_nodes (vms);create_uart (vms,VIRT_UART , sysmem,serial_hd (0 )); --2.17.1
PATCH v3 8/12 hw/arm/virt: Move kvm pmu setup to virt_cpu_post_init
In reply to Haibo XuFrom: Andrew Jones <[email protected]>
Move the KVM PMU setup part of fdt_add_pmu_nodes() to virt_cpu_post_init(), which is a more appropriate location. Now fdt_add_pmu_nodes() is also named more appropriately, because it no longer does anything but fdt node creation.
No functional change intended.
--- hw/arm/virt.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
hw/arm/virt.c +18 -16
@@ -521,21 +521,12 @@ static void fdt_add_gic_node(VirtMachineState *vms)static void fdt_add_pmu_nodes (const VirtMachineState *vms) { -CPUState *cpu; -ARMCPU *armcpu; +ARMCPU *armcpu =ARM_CPU (first_cpu);uint32_t irqflags =GIC_FDT_IRQ_FLAGS_LEVEL_HI ; -CPU_FOREACH (cpu) { - armcpu =ARM_CPU (cpu); -if (!arm_feature (&armcpu->env,ARM_FEATURE_PMU )) { -return ; - } -if (kvm_enabled ()) { -if (kvm_irqchip_in_kernel ()) { -kvm_arm_pmu_set_irq (cpu,PPI (VIRTUAL_PMU_IRQ )); - } -kvm_arm_pmu_init (cpu); - } +if (!arm_feature (&armcpu->env,ARM_FEATURE_PMU )) { +assert (!object_property_get_bool (OBJECT (armcpu),"pmu" ,NULL )); +return ; }if (vms->gic_version ==VIRT_GIC_VERSION_2 ) {
@@ -544,7 +535,6 @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms) (1 << vms->smp_cpus) - 1); } - armcpu =ARM_CPU (qemu_get_cpu (0 ));qemu_fdt_add_subnode (vms->fdt,"/pmu" );if (arm_feature (&armcpu->env,ARM_FEATURE_V8 )) {const char compat[] ="arm,armv8-pmuv3" ;
@@ -1674,11 +1664,23 @@ static void finalize_gic_version(VirtMachineState *vms)static void virt_cpu_post_init (VirtMachineState *vms) { -bool aarch64; +bool aarch64, pmu; +CPUState *cpu; aarch64 =object_property_get_bool (OBJECT (first_cpu),"aarch64" ,NULL ); + pmu =object_property_get_bool (OBJECT (first_cpu),"pmu" ,NULL ); -if (!kvm_enabled ()) { +if (kvm_enabled ()) { +CPU_FOREACH (cpu) { +if (pmu) { +assert (arm_feature (&ARM_CPU (cpu)->env,ARM_FEATURE_PMU )); +if (kvm_irqchip_in_kernel ()) { +kvm_arm_pmu_set_irq (cpu,PPI (VIRTUAL_PMU_IRQ )); + } +kvm_arm_pmu_init (cpu); + } + } + }else {if (aarch64 && vms->highmem) {int requested_pa_size =64 -clz64 (vms->highest_gpa);int pamax =arm_pamax (ARM_CPU (first_cpu));
Signature · 1 line
2.17.1
PATCH v3 9/12 hw/arm/virt: spe: Add vSPE device and corresponding interrupt support
In reply to Haibo XuAdd a virtual SPE device for virt machine while using PPI 5 for SPE overflow interrupt number which has already selected in kvmtool for the in-kernel irqchip support.
--- hw/arm/virt-acpi-build.c | 3 +++ hw/arm/virt.c | 43 ++++++++++++++++++++++++++++++++++++- include/hw/acpi/acpi-defs.h | 3 +++ include/hw/arm/virt.h | 1 + target/arm/cpu.c | 2 ++ target/arm/cpu.h | 2 ++ 6 files changed, 53 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +3 -0
@@ -665,6 +665,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)if (arm_feature (&armcpu->env,ARM_FEATURE_PMU )) { gicc->performance_interrupt =cpu_to_le32 (PPI (VIRTUAL_PMU_IRQ )); } +if (cpu_isar_feature (aa64_spe, armcpu)) { + gicc->spe_interrupt =cpu_to_le32 (PPI (VIRTUAL_SPE_IRQ )); + }if (vms->virt) { gicc->vgic_interrupt =cpu_to_le32 (PPI (ARCH_GIC_MAINT_IRQ )); }
hw/arm/virt.c +42 -1
77 lines not on this page · raw message
include/hw/acpi/acpi-defs.h +3 -0
@@ -302,6 +302,9 @@ struct AcpiMadtGenericCpuInterface {uint32_t vgic_interrupt;uint64_t gicr_base_address;uint64_t arm_mpidr; +uint8_t efficiency_class; +uint8_t reserved2[1 ]; +uint16_t spe_interrupt;/* ACPI 6.3 */ }QEMU_PACKED ;typedef struct AcpiMadtGenericCpuInterface AcpiMadtGenericCpuInterface ;
include/hw/arm/virt.h +1 -0
@@ -49,6 +49,7 @@#define ARCH_TIMER_NS_EL1_IRQ 14#define ARCH_TIMER_NS_EL2_IRQ 10 +#define VIRTUAL_SPE_IRQ 5#define VIRTUAL_PMU_IRQ 7#define PPI (irq) ((irq) + 16)
target/arm/cpu.c +2 -0
@@ -1041,6 +1041,8 @@ static void arm_cpu_initfn(Object *obj) "gicv3-maintenance-interrupt", 1);qdev_init_gpio_out_named (DEVICE (cpu), &cpu->pmu_interrupt,"pmu-interrupt" ,1 ); +qdev_init_gpio_out_named (DEVICE (cpu), &cpu->spe_interrupt, +"spe-interrupt" ,1 );#endif /* DTB consumers generally don't in fact care what the 'compatible'
target/arm/cpu.h +2 -0
@@ -800,6 +800,8 @@ struct ARMCPU {qemu_irq gicv3_maintenance_interrupt;/* GPIO output for the PMU interrupt */ qemu_irq pmu_interrupt; +/* GPIO output for the SPE interrupt */ +qemu_irq spe_interrupt;/* MemoryRegion to use for secure physical accesses */ MemoryRegion *secure_memory;
Signature · 1 line
2.17.1
PATCH v3 10/12 target/arm/cpu: spe: Enable spe to work with host cpu
In reply to Haibo XuTurn on the spe cpu property by default if host cpu support it, i.e. we can now do '-cpu max|host' to add the vSPE, and '-cpu max|host,spe=off' to remove it.
--- target/arm/cpu.c | 1 + target/arm/cpu.h | 2 ++ target/arm/cpu64.c | 10 +++++++--- target/arm/kvm64.c | 12 ++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-)
target/arm/cpu.c +1 -0
@@ -2271,6 +2271,7 @@ static void arm_host_initfn(Object *obj)kvm_arm_set_cpu_features_from_host (cpu);if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {aarch64_add_sve_properties (obj); +aarch64_add_spe_properties (obj); }arm_cpu_post_init (obj); }
target/arm/cpu.h +2 -0
@@ -1040,6 +1040,7 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_add_sve_properties (Object *obj); +void aarch64_add_spe_properties (Object *obj);/* * SVE registers are encoded in KVM's memory in an endianness-invariant format.
@@ -1071,6 +1072,7 @@ static inline void aarch64_sve_change_el(CPUARMState *env, int o, int n, bool a) { }static inline void aarch64_add_sve_properties (Object *obj) { } +static inline void aarch64_add_spe_properties (Object *obj) { }#endif #if !defined(CONFIG_TCG )
target/arm/cpu64.c +7 -3
@@ -621,6 +621,12 @@ static void arm_spe_set(Object *obj, bool value, Error **errp)ARM_CPU (obj)->has_spe = value ?ON_OFF_AUTO_ON :ON_OFF_AUTO_OFF ; } +void aarch64_add_spe_properties (Object *obj) +{ +ARM_CPU (obj)->has_spe =ON_OFF_AUTO_AUTO ; +object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); +} +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
@@ -632,6 +638,7 @@ static void aarch64_max_initfn(Object *obj)if (kvm_enabled ()) {kvm_arm_set_cpu_features_from_host (cpu); +aarch64_add_spe_properties (obj); }else {uint64_t t;uint32_t u;
@@ -770,9 +777,6 @@ static void aarch64_max_initfn(Object *obj)aarch64_add_sve_properties (obj);object_property_add (obj,"sve-max-vq" ,"uint32" , cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq,NULL ,NULL ); - - cpu->has_spe =ON_OFF_AUTO_AUTO ; -object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); }static const ARMCPUInfo aarch64_cpus[] = {
target/arm/kvm64.c +12 -0
@@ -515,6 +515,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)*/ int fdarray[3 ];bool sve_supported; +bool spe_supported;uint64_t features =0 ;uint64_t t;int err;
@@ -655,6 +656,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } sve_supported =ioctl (fdarray[0 ],KVM_CHECK_EXTENSION ,KVM_CAP_ARM_SVE ) >0 ; + spe_supported =ioctl (fdarray[0 ],KVM_CHECK_EXTENSION , +KVM_CAP_ARM_SPE_V1 ) >0 ;kvm_arm_destroy_scratch_host_vcpu (fdarray);
@@ -668,6 +671,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) t =FIELD_DP64 (t,ID_AA64PFR0 ,SVE ,1 ); ahcf->isar.id_aa64pfr0 = t; } +if (spe_supported) { + t = ahcf->isar.id_aa64dfr0; + t =FIELD_DP64 (t,ID_AA64DFR0 ,PMSVER ,1 ); + ahcf->isar.id_aa64dfr0 = t; + }/* * We can assume any KVM supporting CPU is at least a v8
@@ -830,6 +838,10 @@ int kvm_arch_init_vcpu(CPUState *cs)assert (kvm_arm_sve_supported ()); cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_SVE ; } +if (cpu_isar_feature (aa64_spe, cpu)) { +assert (kvm_arm_spe_supported ()); + cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_SPE_V1 ; + }/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);
Signature · 1 line
2.17.1
Re: [PATCH v3 10/12] target/arm/cpu: spe: Enable spe to work with host cpu
Quoted 11 lines · Haibo Xu
Turn on the spe cpu property by default if host cpu support it, i.e. we can now do '-cpu max|host' to add the vSPE, and '-cpu max|host,spe=off' to remove it.
Signed-off-by Haibo Xu <[email protected]>--- target/arm/cpu.c | 1 + target/arm/cpu.h | 2 ++ target/arm/cpu64.c | 10 +++++++--- target/arm/kvm64.c | 12 ++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-)
Quoted 116 lines
target/arm/cpu.c +1
-0@@ -2271,6 +2271,7 @@ static void arm_host_initfn(Object *obj)kvm_arm_set_cpu_features_from_host (cpu);if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {aarch64_add_sve_properties (obj); +aarch64_add_spe_properties (obj); }arm_cpu_post_init (obj); }target/arm/cpu.h +2
-0@@ -1040,6 +1040,7 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_add_sve_properties (Object *obj); +void aarch64_add_spe_properties (Object *obj);/* * SVE registers are encoded in KVM's memory in an endianness-invariant format. @@ -1071,6 +1072,7 @@ static inline void aarch64_sve_change_el(CPUARMState *env, int o, int n, bool a) { }static inline void aarch64_add_sve_properties (Object *obj) { } +static inline void aarch64_add_spe_properties (Object *obj) { }#endif #if !defined(CONFIG_TCG )target/arm/cpu64.c +7
-3@@ -621,6 +621,12 @@ static void arm_spe_set(Object *obj, bool value, Error **errp)ARM_CPU (obj)->has_spe = value ?ON_OFF_AUTO_ON :ON_OFF_AUTO_OFF ; } +void aarch64_add_spe_properties (Object *obj) +{ +ARM_CPU (obj)->has_spe =ON_OFF_AUTO_AUTO ; +object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); +} +/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; @@ -632,6 +638,7 @@ static void aarch64_max_initfn(Object *obj)if (kvm_enabled ()) {kvm_arm_set_cpu_features_from_host (cpu); +aarch64_add_spe_properties (obj); }else {uint64_t t;uint32_t u;@@ -770,9 +777,6 @@ static void aarch64_max_initfn(Object *obj)aarch64_add_sve_properties (obj);object_property_add (obj,"sve-max-vq" ,"uint32" , cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq,NULL ,NULL ); - - cpu->has_spe =ON_OFF_AUTO_AUTO ; -object_property_add_bool (obj,"spe" , arm_spe_get, arm_spe_set); }static const ARMCPUInfo aarch64_cpus[] = {target/arm/kvm64.c +12
-0@@ -515,6 +515,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)*/ int fdarray[3 ];bool sve_supported; +bool spe_supported;uint64_t features =0 ;uint64_t t;int err;@@ -655,6 +656,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } sve_supported =ioctl (fdarray[0 ],KVM_CHECK_EXTENSION ,KVM_CAP_ARM_SVE ) >0 ; + spe_supported =ioctl (fdarray[0 ],KVM_CHECK_EXTENSION , +KVM_CAP_ARM_SPE_V1 ) >0 ;kvm_arm_destroy_scratch_host_vcpu (fdarray);@@ -668,6 +671,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) t =FIELD_DP64 (t,ID_AA64PFR0 ,SVE ,1 ); ahcf->isar.id_aa64pfr0 = t; } +if (spe_supported) { + t = ahcf->isar.id_aa64dfr0; + t =FIELD_DP64 (t,ID_AA64DFR0 ,PMSVER ,1 ); + ahcf->isar.id_aa64dfr0 = t; + }/* * We can assume any KVM supporting CPU is at least a v8 @@ -830,6 +838,10 @@ int kvm_arch_init_vcpu(CPUState *cs)assert (kvm_arm_sve_supported ()); cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_SVE ; } +if (cpu_isar_feature (aa64_spe, cpu)) { +assert (kvm_arm_spe_supported ()); + cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_SPE_V1 ; + }/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);Signature · 1 line
2.17.1
PATCH v3 11/12 target/arm/kvm: spe: Enable userspace irqchip support.
In reply to Haibo XuSince the current kernel patches haven't enabled the userspace irqchip support, this patch is not verified yet!
--- hw/arm/virt.c | 2 +- target/arm/kvm.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
hw/arm/virt.c +1 -1
@@ -1715,8 +1715,8 @@ static void virt_cpu_post_init(VirtMachineState *vms)assert (ARM_CPU (cpu)->has_spe ==ON_OFF_AUTO_ON );if (kvm_irqchip_in_kernel ()) {kvm_arm_spe_set_irq (cpu,PPI (VIRTUAL_SPE_IRQ )); -kvm_arm_spe_init (cpu); } +kvm_arm_spe_init (cpu); } } }else {
target/arm/kvm.c +5 -0
@@ -820,6 +820,11 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) switched_level &= ~KVM_ARM_DEV_PMU ; } +if (switched_level &KVM_ARM_DEV_SPE ) { +qemu_set_irq (cpu->spe_interrupt, + !!(run->s.regs.device_irq_level &KVM_ARM_DEV_SPE )); + switched_level &= ~KVM_ARM_DEV_SPE ; + }if (switched_level) {qemu_log_mask (LOG_UNIMP ,"%s: unhandled in-kernel device IRQ %x\n" , __func__, switched_level);
Signature · 1 line
2.17.1
PATCH v3 12/12 target/arm: spe: Add corresponding test.
In reply to Haibo Xu--- target/arm/monitor.c | 2 +- tests/qtest/arm-cpu-features.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
target/arm/monitor.c +1 -1
@@ -99,7 +99,7 @@ QEMU_BUILD_BUG_ON(ARM_MAX_VQ > 16);* then the order that considers those dependencies must be used. */ static const char *cpu_model_advertised_features[] = { -"aarch64" ,"pmu" ,"sve" , +"aarch64" ,"pmu" ,"spe" ,"sve" ,"sve128" ,"sve256" ,"sve384" ,"sve512" ,"sve640" ,"sve768" ,"sve896" ,"sve1024" ,"sve1152" ,"sve1280" ,"sve1408" ,"sve1536" ,"sve1664" ,"sve1792" ,"sve1920" ,"sve2048" ,
tests/qtest/arm-cpu-features.c +9 -0
@@ -494,6 +494,7 @@ static void test_query_cpu_model_expansion_kvm(const void *data)if (g_str_equal (qtest_get_arch (),"aarch64" )) {bool kvm_supports_sve; +bool kvm_supports_spe;char max_name[8 ], name[8 ];uint32_t max_vq, vq;uint64_t vls;
@@ -512,8 +513,10 @@ static void test_query_cpu_model_expansion_kvm(const void *data) "with KVM on this host", NULL);assert_has_feature (qts,"host" ,"sve" ); +assert_has_feature (qts,"host" ,"spe" ); resp =do_query_no_props (qts,"host" ); kvm_supports_sve =resp_get_feature (resp,"sve" ); + kvm_supports_spe =resp_get_feature (resp,"spe" ); vls =resp_get_sve_vls (resp);qobject_unref (resp);
@@ -573,10 +576,16 @@ static void test_query_cpu_model_expansion_kvm(const void *data) }else {g_assert (vls ==0 ); } + +if (kvm_supports_spe) { +assert_set_feature (qts,"host" ,"spe" , false); +assert_set_feature (qts,"host" ,"spe" , true); + } }else {assert_has_not_feature (qts,"host" ,"aarch64" );assert_has_not_feature (qts,"host" ,"pmu" );assert_has_not_feature (qts,"host" ,"sve" ); +assert_has_not_feature (qts,"host" ,"spe" ); }qtest_quit (qts);
Signature · 1 line
2.17.1