Skip to contentSkip to conversation

arm64: KVM: fix perf cycle counter support for VHE

PATCH In review Andrew Murray 2 participants 3 messages Apr 29, 2019 – Apr 30, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: KVM: fix perf cycle counter support for VHE

The kvm_vcpu_pmu_{read,write}_evtype_direct functions do not handle the cycle counter use-case, this leads to inaccurate counts and a WARN message when using perf with the cycle counter (-e cycle).

Let's fix this by adding a use case for pmccfiltr_el0.

---
 arch/arm64/kvm/pmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm64/kvm/pmu.c +9 -2
index 4d55193ccc71..e790051ed6ae 100644
@@ -134,12 +134,15 @@ void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)
 	PMEVTYPER_##readwrite##_CASE(30)
 
 /*
- * Read a value direct from PMEVTYPER<idx>
+ * Read a value direct from PMEVTYPER<idx> where idx is 0-30
+ * or PMCCFILTR_EL0 where idx is ARMV8_PMU_CYCLE_IDX (31).
  */
 static u64 kvm_vcpu_pmu_read_evtype_direct(int idx)
 {
 	switch (idx) {
 	PMEVTYPER_CASES(READ);
+	case ARMV8_PMU_CYCLE_IDX:
+		return read_sysreg(pmccfiltr_el0);
 	default:
 		WARN_ON(1);
 	}
@@ -148,12 +151,16 @@ static u64 kvm_vcpu_pmu_read_evtype_direct(int idx)
 }
 
 /*
- * Write a value direct to PMEVTYPER<idx>
+ * Write a value direct to PMEVTYPER<idx> where idx is 0-30
+ * or PMCCFILTR_EL0 where idx is ARMV8_PMU_CYCLE_IDX (31).
  */
 static void kvm_vcpu_pmu_write_evtype_direct(int idx, u32 val)
 {
 	switch (idx) {
 	PMEVTYPER_CASES(WRITE);
+	case ARMV8_PMU_CYCLE_IDX:
+		write_sysreg(val, pmccfiltr_el0);
+		break;
 	default:
 		WARN_ON(1);
 	}
Signature · 1 line
2.21.0
#1 lore raw

[+ Christoffer, James, Julien]

Hi Andrew,

Quoted 8 lines · Andrew Murray

The kvm_vcpu_pmu_{read,write}_evtype_direct functions do not handle the cycle counter use-case, this leads to inaccurate counts and a WARN message when using perf with the cycle counter (-e cycle).

Let's fix this by adding a use case for pmccfiltr_el0.

Queued, with

Fixes 39e3406a090a ("arm64: KVM: Avoid isb's by using direct pmxevtyper

sysreg")

In the future, please cc all the KVM/arm maintainers/reviewers so that we do not risk overseeing an important patch.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#2 lore raw
Quoted 14 lines · Marc Zyngier

[+ Christoffer, James, Julien]

Hi Andrew,

Quoted 8 lines · Andrew Murray

The kvm_vcpu_pmu_{read,write}_evtype_direct functions do not handle the cycle counter use-case, this leads to inaccurate counts and a WARN message when using perf with the cycle counter (-e cycle).

Let's fix this by adding a use case for pmccfiltr_el0.

Quoted 6 lines

Queued, with

Fixes 39e3406a090a ("arm64: KVM: Avoid isb's by using direct pmxevtyper

sysreg")

In the future, please cc all the KVM/arm maintainers/reviewers so that we do not risk overseeing an important patch.

OK I will do.

Thanks,

Andrew Murray

Quoted 6 lines

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...