Skip to content

Commit 0ea0d63

Browse files
Dapeng Misean-jc
authored andcommitted
KVM: x86/pmu: Bypass perf checks when emulating mediated PMU counter accesses
When emulating a PMC counter read or write for a mediated PMU, bypass the perf checks and emulated_counter logic as the counters aren't proxied through perf, i.e. pmc->counter always holds the guest's up-to-date value, and thus there's no need to defer emulated overflow checks. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Co-developed-by: Mingwei Zhang <mizhang@google.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> [sean: split from event filtering change, write shortlog+changelog] Reviewed-by: Sandipan Das <sandipan.das@amd.com> Tested-by: Xudong Hao <xudong.hao@intel.com> Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-24-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 2904df6 commit 0ea0d63

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

arch/x86/kvm/pmu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ static void pmc_update_sample_period(struct kvm_pmc *pmc)
379379

380380
void pmc_write_counter(struct kvm_pmc *pmc, u64 val)
381381
{
382+
if (kvm_vcpu_has_mediated_pmu(pmc->vcpu)) {
383+
pmc->counter = val & pmc_bitmask(pmc);
384+
return;
385+
}
386+
382387
/*
383388
* Drop any unconsumed accumulated counts, the WRMSR is a write, not a
384389
* read-modify-write. Adjust the counter value so that its value is

arch/x86/kvm/pmu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc)
111111
{
112112
u64 counter, enabled, running;
113113

114+
if (kvm_vcpu_has_mediated_pmu(pmc->vcpu))
115+
return pmc->counter & pmc_bitmask(pmc);
116+
114117
counter = pmc->counter + pmc->emulated_counter;
115118

116119
if (pmc->perf_event && !pmc->is_paused)

0 commit comments

Comments
 (0)