Commit 0ea0d631 authored by Dapeng Mi's avatar Dapeng Mi Committed by Sean Christopherson
Browse files

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: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarDapeng Mi <dapeng1.mi@linux.intel.com>
Co-developed-by: default avatarMingwei Zhang <mizhang@google.com>
Signed-off-by: default avatarMingwei Zhang <mizhang@google.com>
[sean: split from event filtering change, write shortlog+changelog]
Reviewed-by: default avatarSandipan Das <sandipan.das@amd.com>
Tested-by: default avatarXudong Hao <xudong.hao@intel.com>
Tested-by: default avatarManali Shukla <manali.shukla@amd.com>
Link: https://patch.msgid.link/20251206001720.468579-24-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 2904df66
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -379,6 +379,11 @@ static void pmc_update_sample_period(struct kvm_pmc *pmc)

void pmc_write_counter(struct kvm_pmc *pmc, u64 val)
{
	if (kvm_vcpu_has_mediated_pmu(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
+3 −0
Original line number Diff line number Diff line
@@ -111,6 +111,9 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc)
{
	u64 counter, enabled, running;

	if (kvm_vcpu_has_mediated_pmu(pmc->vcpu))
		return pmc->counter & pmc_bitmask(pmc);

	counter = pmc->counter + pmc->emulated_counter;

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