Skip to content

Commit cb5faa8

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/pmu-fixes into kvmarm-master/next
Fixes for the PMUv3 emulation of PMCR_EL0: - Don't spuriously reset the cycle counter when resetting other counters - Force PMCR_EL0 to become effective after having restored it * kvm-arm64/pmu-fixes: KVM: arm64: Restore PMU configuration on first run KVM: arm64: Don't zero the cycle count register when PMCR_EL0.P is set
2 parents b88835a + d0c94c4 commit cb5faa8

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define KVM_REQ_VCPU_RESET KVM_ARCH_REQ(2)
4747
#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3)
4848
#define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4)
49+
#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5)
4950

5051
#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
5152
KVM_DIRTY_LOG_INITIALLY_SET)

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)
689689
vgic_v4_load(vcpu);
690690
preempt_enable();
691691
}
692+
693+
if (kvm_check_request(KVM_REQ_RELOAD_PMU, vcpu))
694+
kvm_pmu_handle_pmcr(vcpu,
695+
__vcpu_sys_reg(vcpu, PMCR_EL0));
692696
}
693697
}
694698

arch/arm64/kvm/pmu-emul.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
578578
kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
579579

580580
if (val & ARMV8_PMU_PMCR_P) {
581+
mask &= ~BIT(ARMV8_PMU_CYCLE_IDX);
581582
for_each_set_bit(i, &mask, 32)
582583
kvm_pmu_set_counter_value(vcpu, i, 0);
583584
}
@@ -850,6 +851,9 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
850851
return -EINVAL;
851852
}
852853

854+
/* One-off reload of the PMU on first run */
855+
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
856+
853857
return 0;
854858
}
855859

0 commit comments

Comments
 (0)