@@ -305,6 +305,11 @@ static void pmc_update_sample_period(struct kvm_pmc *pmc)
void pmc_write_counter(struct kvm_pmc *pmc, u64 val)
{
+ if (kvm_mediated_pmu_enabled(pmc->vcpu)) {
+ pmc->counter = val & pmc_bitmask(pmc);
+ return;
+ }
+
/*
* Drop any unconsumed accumulated counts, the WRMSR is a write, not a
* read-modify-write. Adjust the counter value so that its value is
@@ -455,6 +460,28 @@ static int reprogram_counter(struct kvm_pmc *pmc)
bool emulate_overflow;
u8 fixed_ctr_ctrl;
+ if (kvm_mediated_pmu_enabled(pmu_to_vcpu(pmu))) {
+ bool allowed = check_pmu_event_filter(pmc);
+
+ if (pmc_is_gp(pmc)) {
+ if (allowed)
+ pmc->eventsel_hw |= pmc->eventsel &
+ ARCH_PERFMON_EVENTSEL_ENABLE;
+ else
+ pmc->eventsel_hw &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
+ } else {
+ int idx = pmc->idx - KVM_FIXED_PMC_BASE_IDX;
+
+ if (allowed)
+ pmu->fixed_ctr_ctrl_hw = pmu->fixed_ctr_ctrl;
+ else
+ pmu->fixed_ctr_ctrl_hw &=
+ ~intel_fixed_bits_by_idx(idx, 0xf);
+ }
+
+ return 0;
+ }
+
emulate_overflow = pmc_pause_counter(pmc);
if (!pmc_event_is_allowed(pmc))
@@ -113,6 +113,9 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc)
{
u64 counter, enabled, running;
+ if (kvm_mediated_pmu_enabled(pmc->vcpu))
+ return pmc->counter & pmc_bitmask(pmc);
+
counter = pmc->counter + pmc->emulated_counter;
if (pmc->perf_event && !pmc->is_paused)