arm64: perf: Add support for ARMv8.5-PMU 64-bit counters
Subsystems (4)
v3 cover arm64: perf: Add support for ARMv8.5-PMU 64-bit counters
At present ARMv8 event counters are limited to 32-bits, though by using the CHAIN event it's possible to combine adjacent counters to achieve 64-bits. The perf config1:0 bit can be set to use such a configuration.
With the introduction of ARMv8.5-PMU support, all event counters can now be used as 64-bit counters. Let's add support for 64-bit event counters.
As KVM doesn't yet support 64-bit event counters, we also trap and emulate the Debug Feature Registers to limit the PMU version a guest sees to PMUv3 for ARMv8.4.
Tested by running the following perf command on both guest and host and ensuring that the figures are very similar:
perf stat -e armv8_pmuv3/inst_retired,long=1/ \
-e armv8_pmuv3/inst_retired,long=0/ -e cycles
Changes since v2:
- Rebased onto v5.5-rc4
- Mask 'cap' value to 'width' in cpuid_feature_cap_signed_field_width
Changes since v1:
- Rebased onto v5.5-rc1
Andrew Murray (3):
arm64: cpufeature: Extract capped fields
KVM: arm64: limit PMU version to ARMv8.4
arm64: perf: Add support for ARMv8.5-PMU 64-bit counters
arch/arm64/include/asm/cpufeature.h | 16 ++++++ arch/arm64/include/asm/perf_event.h | 3 +- arch/arm64/include/asm/sysreg.h | 4 ++ arch/arm64/kernel/perf_event.c | 86 +++++++++++++++++++++++------ arch/arm64/kvm/sys_regs.c | 36 +++++++++++- include/linux/perf/arm_pmu.h | 1 + 6 files changed, 126 insertions(+), 20 deletions(-)
Signature · 6 lines
2.21.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v3 1/3 arm64: cpufeature: Extract capped fields
When emulating ID registers there is often a need to cap the version bits of a feature such that the guest will not use features that do not yet exist.
Let's add a helper that extracts a field and caps the version to a given value.
--- arch/arm64/include/asm/cpufeature.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm64/include/asm/cpufeature.h +16 -0
@@ -447,6 +447,22 @@ cpuid_feature_extract_unsigned_field(u64 features, int field)return cpuid_feature_extract_unsigned_field_width (features, field,4 ); } +static inline u64 __attribute_const__ +cpuid_feature_cap_signed_field_width (u64 features,int field,int width, +s64 cap) +{ +s64 val =cpuid_feature_extract_signed_field_width (features, field, + width); +u64 mask =GENMASK_ULL (field + width -1 , field); + +if (val > cap) { + features &= ~mask; + features |= (cap << field) & mask; + } + +return features; +} +static inline u64 arm64_ftr_mask (const struct arm64_ftr_bits *ftrp) {return (u64 )GENMASK (ftrp->shift + ftrp->width -1 , ftrp->shift);
Signature · 6 lines
2.21.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v3 2/3 KVM: arm64: limit PMU version to ARMv8.4
In reply to Andrew MurrayARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)
arch/arm64/include/asm/sysreg.h +4 -0
@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12
arch/arm64/kvm/sys_regs.c +34 -2
@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu)return check_pmu_access_disabled (vcpu,ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_AA64DFR0_PMUVER_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 ); + +return p->regval; +} + +static bool access_id_dfr0_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_DFR0_PERFMON_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 ); + +return p->regval; +} +static bool access_pmcr (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r) {
@@ -1409,7 +1440,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {/* CRm=1 */ ID_SANITISED (ID_PFR0_EL1 ),ID_SANITISED (ID_PFR1_EL1 ), -ID_SANITISED (ID_DFR0_EL1 ), + { SYS_DESC(SYS_ID_DFR0_EL1), access_id_dfr0_el1 }, +ID_HIDDEN (ID_AFR0_EL1 ),ID_SANITISED (ID_MMFR0_EL1 ), ID_SANITISED(ID_MMFR1_EL1),
@@ -1448,7 +1480,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_UNALLOCATED (4 ,7 ),/* CRm=5 */ -ID_SANITISED (ID_AA64DFR0_EL1 ), + { SYS_DESC(SYS_ID_AA64DFR0_EL1), access_id_aa64dfr0_el1 },ID_SANITISED (ID_AA64DFR1_EL1 ),ID_UNALLOCATED (5 ,2 ), ID_UNALLOCATED(5,3),
Signature · 6 lines
2.21.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v3 3/3 arm64: perf: Add support for ARMv8.5-PMU 64-bit counters
In reply to Andrew MurrayAt present ARMv8 event counters are limited to 32-bits, though by using the CHAIN event it's possible to combine adjacent counters to achieve 64-bits. The perf config1:0 bit can be set to use such a configuration.
With the introduction of ARMv8.5-PMU support, all event counters can now be used as 64-bit counters.
Let's enable 64-bit event counters where support exists. Unless the user sets config1:0 we will adjust the counter value such that it overflows upon 32-bit overflow. This follows the same behaviour as the cycle counter which has always been (and remains) 64-bits.
--- arch/arm64/include/asm/perf_event.h | 3 +- arch/arm64/kernel/perf_event.c | 86 +++++++++++++++++++++++------ include/linux/perf/arm_pmu.h | 1 + 3 files changed, 72 insertions(+), 18 deletions(-)
arch/arm64/include/asm/perf_event.h +2 -1
@@ -176,9 +176,10 @@#define ARMV8_PMU_PMCR_X (1 << 4)/* Export to ETM */ #define ARMV8_PMU_PMCR_DP (1 << 5)/* Disable CCNT if non-invasive debug*/ #define ARMV8_PMU_PMCR_LC (1 << 6)/* Overflow on 64 bit cycle counter */ +#define ARMV8_PMU_PMCR_LP (1 << 7)/* Long event counter enable */ #define ARMV8_PMU_PMCR_N_SHIFT 11/* Number of counters supported */ #define ARMV8_PMU_PMCR_N_MASK 0x1f -#define ARMV8_PMU_PMCR_MASK 0x7f/* Mask for writable bits */ +#define ARMV8_PMU_PMCR_MASK 0xff/* Mask for writable bits */ /* * PMOVSR: counters overflow flag status reg
arch/arm64/kernel/perf_event.c +69 -17
155 lines not on this page · raw message
include/linux/perf/arm_pmu.h +1 -0
@@ -80,6 +80,7 @@ struct arm_pmu {struct pmu pmu;cpumask_t supported_cpus;char *name; +int pmuver;irqreturn_t (*handle_irq)(struct arm_pmu *pmu);void (*enable)(struct perf_event *event);void (*disable)(struct perf_event *event);
Signature · 6 lines
2.21.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v3 1/3] arm64: cpufeature: Extract capped fields
In reply to Andrew MurrayQuoted 8 lines · Andrew Murray
When emulating ID registers there is often a need to cap the version bits of a feature such that the guest will not use features that do not yet exist.
Let's add a helper that extracts a field and caps the version to a given value.
Signed-off-by Andrew Murray <[email protected]>
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Will Deacon
maintainerRe: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
In reply to Andrew MurrayQuoted 10 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)
I'll need an ack from the kvm side for this.
Quoted 25 lines
arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +2
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu)return check_pmu_access_disabled (vcpu,ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, + struct sys_reg_params *p,
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 682
Quoted 10 lines
arch/arm64/kvm/sys_regs.c +10
-0+ const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_AA64DFR0_PMUVER_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 );
nit: I'd probably have a separate define for the field value of the 64-bit register, since there's no guarantee other values will be encoded the same way. (i.e. add ID_AA64DFR0_PMUVER_8_4 as well).
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 695
Quoted 13 lines
arch/arm64/kvm/sys_regs.c +13
-0+ +return p->regval; +} + +static bool access_id_dfr0_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_DFR0_EL1 ); + p->regval = cpuid_feature_cap_signed_field_width(p->regval,
You could just return the result here (same above).
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Marc Zyngier
maintainerRe: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
In reply to Andrew MurrayQuoted 40 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +4
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{
arch/arm64/kvm/sys_regs.c static bool · line 686
Quoted 10 lines
arch/arm64/kvm/sys_regs.c +10
-0+if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_AA64DFR0_PMUVER_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 ); + +return p->regval;
If feels very odd to return the register value in place of a something that actually indicates whether we should update the PC or not. I have no idea what is happening here in this case.
Quoted 6 lines
arch/arm64/kvm/sys_regs.c +5
-0+} + +static bool access_id_dfr0_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 699
Quoted 10 lines
arch/arm64/kvm/sys_regs.c +10
-0+if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_DFR0_PERFMON_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 ); + +return p->regval;
Same here.
arch/arm64/kvm/sys_regs.c static const struct sys_reg_desc sys_reg_descs[] · line 1444
Quoted 13 lines
arch/arm64/kvm/sys_regs.c +2
-0+} +static bool access_pmcr(struct
kvm_vcpu*vcpu, structsys_reg_params
*p,arch/arm64/kvm/sys_regs.c +1
-1const struct sys_reg_desc *r) {@@ -1409,7 +1440,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {/* CRm=1 */ ID_SANITISED (ID_PFR0_EL1 ),ID_SANITISED (ID_PFR1_EL1 ), - ID_SANITISED(ID_DFR0_EL1), + { SYS_DESC(SYS_ID_DFR0_EL1), access_id_dfr0_el1 },
How about the .get_user and .set_user accessors that were provided by ID_SANITISED and that are now dropped? You should probably define a new wrapper that allows you to override the .access method.
Quoted 13 lines
arch/arm64/kvm/sys_regs.c +1
-0+ID_HIDDEN (ID_AFR0_EL1 ), ID_SANITISED(ID_MMFR0_EL1),arch/arm64/kvm/sys_regs.c +1
-1ID_SANITISED(ID_MMFR1_EL1),@@ -1448,7 +1480,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_UNALLOCATED (4 ,7 ),/* CRm=5 */ -ID_SANITISED (ID_AA64DFR0_EL1 ), + { SYS_DESC(SYS_ID_AA64DFR0_EL1), access_id_aa64dfr0_el1 },ID_SANITISED (ID_AA64DFR1_EL1 ), ID_UNALLOCATED(5,2),
Quoted 1 line
ID_UNALLOCATED(5,3),
Thanks,
M.
Signature · 6 lines
Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
Quoted 48 lines · Marc Zyngier
Quoted 47 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +10
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval = cpuid_feature_cap_signed_field_width(p->regval,
Quoted 8 lines
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 684
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +4
-0+ID_AA64DFR0_PMUVER_SHIFT , + 4, ID_DFR0_EL1_PMUVER_8_4); + +return p->regval;If feels very odd to return the register value in place of a something that actually indicates whether we should update the PC or not. I have no idea what is happening here in this case.
Crikey, yes, I missed that and it probably explains why the code looks so odd. Andrew -- is there a missing hunk or something here?
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
Quoted 58 lines · Will Deacon
Quoted 48 lines · Marc Zyngier
Quoted 47 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +10
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval = cpuid_feature_cap_signed_field_width(p->regval,Quoted 8 lines
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 684
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +4
-0+ID_AA64DFR0_PMUVER_SHIFT , + 4, ID_DFR0_EL1_PMUVER_8_4); + +return p->regval;If feels very odd to return the register value in place of a something that actually indicates whether we should update the PC or not. I have no idea what is happening here in this case.
Quoted 2 lines
Crikey, yes, I missed that and it probably explains why the code looks so odd. Andrew -- is there a missing hunk or something here?
Doh, it should always return true.
Nothing missing here - sometimes I also look at my own code and have no idea what I was thinking.
Thanks,
Andrew Murray
Quoted 2 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
In reply to Marc ZyngierQuoted 48 lines · Marc Zyngier
Quoted 47 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +10
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); } +static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval = cpuid_feature_cap_signed_field_width(p->regval,
Quoted 8 lines
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 684
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +4
-0+ID_AA64DFR0_PMUVER_SHIFT , + 4, ID_DFR0_EL1_PMUVER_8_4); + +return p->regval;If feels very odd to return the register value in place of a something that actually indicates whether we should update the PC or not. I have no idea what is happening here in this case.
This should have returned true. I have no idea why I did this.
Quoted 29 lines
Quoted 7 lines
arch/arm64/kvm/sys_regs.c +5
-0+} + +static bool access_id_dfr0_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 699
Quoted 10 lines
arch/arm64/kvm/sys_regs.c +10
-0+if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_DFR0_PERFMON_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 ); + +return p->regval;Same here.
Quoted 9 lines
arch/arm64/kvm/sys_regs.c +2
-0+} +static bool access_pmcr(struct
kvm_vcpu*vcpu, structsys_reg_params
*p,arch/arm64/kvm/sys_regs.c +0
-0const struct sys_reg_desc *r) {@@ -1409,7 +1440,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {/* CRm=1 */
Quoted 8 lines
arch/arm64/kvm/sys_regs.c static const struct sys_reg_desc sys_reg_descs[] = { · line 1443
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +1
-1ID_SANITISED (ID_PFR0_EL1 ),ID_SANITISED (ID_PFR1_EL1 ), - ID_SANITISED(ID_DFR0_EL1), + { SYS_DESC(SYS_ID_DFR0_EL1), access_id_dfr0_el1 },How about the .get_user and .set_user accessors that were provided by
ID_SANITISEDand that are now dropped? You should probably define a new wrapper that allows you to override the .access method.
Yes I can do that, thus ensuring we continue to return sanitised values rather than the current vcpu value.
However should I also update read_id_reg - thus ensuring the host sees the same value that the guest sees? (I see this already does something similar with AA64PFR0 and AA64ISAR1).
Thanks,
Andrew Murray
Quoted 18 lines
Quoted 14 lines
arch/arm64/kvm/sys_regs.c +1
-0+ID_HIDDEN (ID_AFR0_EL1 ), ID_SANITISED(ID_MMFR0_EL1),arch/arm64/kvm/sys_regs.c +1
-1ID_SANITISED(ID_MMFR1_EL1),@@ -1448,7 +1480,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_UNALLOCATED (4 ,7 ),/* CRm=5 */ -ID_SANITISED (ID_AA64DFR0_EL1 ), + { SYS_DESC(SYS_ID_AA64DFR0_EL1), access_id_aa64dfr0_el1 },ID_SANITISED (ID_AA64DFR1_EL1 ), ID_UNALLOCATED(5,2),Quoted 1 line
ID_UNALLOCATED(5,3),Thanks,
Quoted 3 lines
M.Signature · 1 line
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v3 2/3] KVM: arm64: limit PMU version to ARMv8.4
In reply to Will DeaconQuoted 37 lines · Will Deacon
Quoted 10 lines · Andrew Murray
ARMv8.5-PMU introduces 64-bit event counters, however KVM doesn't yet support this. Let's trap the Debug Feature Registers in order to limit PMUVer/PerfMon in the Debug Feature Registers to PMUv3 for ARMv8.4.
Signed-off-by Andrew Murray <[email protected]>Reviewed-by Suzuki K Poulose <[email protected]>--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/sys_regs.c | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)I'll need an ack from the kvm side for this.
Quoted 23 lines
arch/arm64/include/asm/sysreg.h +4
-0@@ -672,6 +672,10 @@#define ID_AA64DFR0_TRACEVER_SHIFT 4#define ID_AA64DFR0_DEBUGVER_SHIFT 0 +#define ID_DFR0_PERFMON_SHIFT 24 + +#define ID_DFR0_EL1_PMUVER_8_4 5 +#define ID_ISAR5_RDM_SHIFT 24#define ID_ISAR5_CRC32_SHIFT 16#define ID_ISAR5_SHA2_SHIFT 12arch/arm64/kvm/sys_regs.c +0
-0@@ -668,6 +668,37 @@ static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu)return check_pmu_access_disabled (vcpu,ARMV8_PMU_USERENR_ER |ARMV8_PMU_USERENR_EN ); }
Quoted 16 lines
arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 682
Quoted 12 lines
arch/arm64/kvm/sys_regs.c +12
-0+static bool access_id_aa64dfr0_el1 (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_AA64DFR0_EL1 ); + p->regval =cpuid_feature_cap_signed_field_width (p->regval, +ID_AA64DFR0_PMUVER_SHIFT , +4 ,ID_DFR0_EL1_PMUVER_8_4 );nit: I'd probably have a separate define for the field value of the 64-bit register, since there's no guarantee other values will be encoded the same way. (i.e. add
ID_AA64DFR0_PMUVER_8_4as well).
Yes that seems reasonable, i'll update it.
Quoted 16 lines
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +3
-0+ +return p->regval; +}arch/arm64/kvm/sys_regs.c static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) · line 695
Quoted 10 lines
arch/arm64/kvm/sys_regs.c +10
-0+ +static bool access_id_dfr0_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *rd) +{ +if (p->is_write) +return write_to_read_only (vcpu, p, rd); + +/* Limit guests to PMUv3 for ARMv8.4 */ + p->regval =read_sanitised_ftr_reg (SYS_ID_DFR0_EL1 ); + p->regval = cpuid_feature_cap_signed_field_width(p->regval,You could just return the result here (same above).
Or perhaps a bool - sigh.
Thanks,
Andrew Murray
Quoted 2 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm