Skip to content

Commit 47e0f19

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 3f56f4f commit 47e0f19

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
@@ -673,6 +673,18 @@ static bool kvm_pmc_counts_at_el2(struct kvm_pmc *pmc)
673673
return kvm_pmc_read_evtreg(pmc) & ARMV8_PMU_INCLUDE_EL2;
674674
}
675675

676+
static u64 kvm_map_pmu_event(struct kvm *kvm, u64 eventsel)
677+
{
678+
struct arm_pmu *pmu = kvm->arch.arm_pmu;
679+
int hw_event;
680+
681+
if (!pmu->map_pmuv3_event)
682+
return eventsel;
683+
684+
hw_event = pmu->map_pmuv3_event(eventsel);
685+
return (hw_event < 0) ? eventsel : hw_event;
686+
}
687+
676688
/**
677689
* kvm_pmu_create_perf_event - create a perf event for a counter
678690
* @pmc: Counter context
@@ -711,13 +723,13 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
711723

712724
memset(&attr, 0, sizeof(struct perf_event_attr));
713725
attr.type = arm_pmu->pmu.type;
726+
attr.config = kvm_map_pmu_event(vcpu->kvm, eventsel);
714727
attr.size = sizeof(attr);
715728
attr.pinned = 1;
716729
attr.disabled = !kvm_pmu_counter_is_enabled(pmc);
717730
attr.exclude_user = !kvm_pmc_counts_at_el0(pmc);
718731
attr.exclude_hv = 1; /* Don't count EL2 events */
719732
attr.exclude_host = 1; /* Don't count host events */
720-
attr.config = eventsel;
721733

722734
/*
723735
* Filter events at EL1 (i.e. vEL2) when in a hyp context based on the

0 commit comments

Comments
 (0)