Skip to content

Commit c01d6a1

Browse files
eaugerMarc Zyngier
authored andcommitted
KVM: arm64: pmu: Only handle supported event counters
Let the code never use unsupported event counters. Change kvm_pmu_handle_pmcr() to only reset supported counters and kvm_pmu_vcpu_reset() to only stop supported counters. Other actions are filtered on the supported counters in kvm/sysregs.c Signed-off-by: Eric Auger <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aa76829 commit c01d6a1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

virt/kvm/arm/pmu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu)
247247
*/
248248
void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
249249
{
250-
int i;
250+
unsigned long mask = kvm_pmu_valid_counter_mask(vcpu);
251251
struct kvm_pmu *pmu = &vcpu->arch.pmu;
252+
int i;
252253

253-
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
254+
for_each_set_bit(i, &mask, 32)
254255
kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]);
255256

256257
bitmap_zero(vcpu->arch.pmu.chained, ARMV8_PMU_MAX_COUNTER_PAIRS);
@@ -527,10 +528,9 @@ void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val)
527528
*/
528529
void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
529530
{
530-
u64 mask;
531+
unsigned long mask = kvm_pmu_valid_counter_mask(vcpu);
531532
int i;
532533

533-
mask = kvm_pmu_valid_counter_mask(vcpu);
534534
if (val & ARMV8_PMU_PMCR_E) {
535535
kvm_pmu_enable_counter_mask(vcpu,
536536
__vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask);
@@ -542,7 +542,7 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
542542
kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
543543

544544
if (val & ARMV8_PMU_PMCR_P) {
545-
for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++)
545+
for_each_set_bit(i, &mask, 32)
546546
kvm_pmu_set_counter_value(vcpu, i, 0);
547547
}
548548
}

0 commit comments

Comments
 (0)