KVM: x86/pmu: Snapshot event selectors that KVM emulates in software
authorSean Christopherson <seanjc@google.com>
Fri, 10 Nov 2023 02:28:54 +0000 (18:28 -0800)
committerSean Christopherson <seanjc@google.com>
Thu, 1 Feb 2024 17:35:48 +0000 (09:35 -0800)
commitf19063b1ca058b3971d6883b5ec45955b7f53f9c
treec9735124a691431474aec14d1a00aaa74a22e68a
parentd2b321ea9380564510d281d45ccd2b424da14e7f
KVM: x86/pmu: Snapshot event selectors that KVM emulates in software

Snapshot the event selectors for the events that KVM emulates in software,
which is currently instructions retired and branch instructions retired.
The event selectors a tied to the underlying CPU, i.e. are constant for a
given platform even though perf doesn't manage the mappings as such.

Getting the event selectors from perf isn't exactly cheap, especially if
mitigations are enabled, as at least one indirect call is involved.

Snapshot the values in KVM instead of optimizing perf as working with the
raw event selectors will be required if KVM ever wants to emulate events
that aren't part of perf's uABI, i.e. that don't have an "enum perf_hw_id"
entry.

Link: https://lore.kernel.org/r/20231110022857.1273836-8-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/pmu.c
arch/x86/kvm/pmu.h
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/x86.c