Skip to content

Commit 4e88836

Browse files
ouptonjannau
authored andcommitted
KVM: arm64: Remap PMUv3 events onto hardware
Use the provided helper to map PMUv3 event IDs onto hardware, if the driver exposes such a helper. This is expected to be quite rare, and only useful for non-PMUv3 hardware. Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 9a7449a commit 4e88836

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

arch/arm64/kvm/pmu-emul.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc)
589589
(__vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & BIT(pmc->idx));
590590
}
591591

592+
static u64 kvm_map_pmu_event(struct kvm *kvm, u64 eventsel)
593+
{
594+
struct arm_pmu *pmu = kvm->arch.arm_pmu;
595+
int hw_event;
596+
597+
if (!pmu->map_pmuv3_event)
598+
return eventsel;
599+
600+
hw_event = pmu->map_pmuv3_event(eventsel);
601+
return (hw_event < 0) ? eventsel : hw_event;
602+
}
603+
592604
/**
593605
* kvm_pmu_create_perf_event - create a perf event for a counter
594606
* @pmc: Counter context
@@ -634,14 +646,14 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
634646

635647
memset(&attr, 0, sizeof(struct perf_event_attr));
636648
attr.type = arm_pmu->pmu.type;
649+
attr.config = kvm_map_pmu_event(vcpu->kvm, eventsel);
637650
attr.size = sizeof(attr);
638651
attr.pinned = 1;
639652
attr.disabled = !kvm_pmu_counter_is_enabled(pmc);
640653
attr.exclude_user = (u != nsu);
641654
attr.exclude_kernel = (p != nsk);
642655
attr.exclude_hv = 1; /* Don't count EL2 events */
643656
attr.exclude_host = 1; /* Don't count host events */
644-
attr.config = eventsel;
645657

646658
/*
647659
* If counting with a 64bit counter, advertise it to the perf

0 commit comments

Comments
 (0)