From: Sandipan Das <sandipan.das@amd.com>
To: <kvm@vger.kernel.org>, <linux-perf-users@vger.kernel.org>
Cc: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Kan Liang <kan.liang@linux.intel.com>,
Mingwei Zhang <mizhang@google.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
"Nikunj A . Dadhania" <nikunj@amd.com>,
"Manali Shukla" <manali.shukla@amd.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
"Ananth Narayan" <ananth.narayan@amd.com>,
Sandipan Das <sandipan.das@amd.com>
Subject: [RFC PATCH 0/7] KVM: SVM: Support for PMC virtualization
Date: Thu, 13 Nov 2025 11:48:20 +0530 [thread overview]
Message-ID: <cover.1762960531.git.sandipan.das@amd.com> (raw)
AMD Zen 5 processors introduced PMC virtualization. When the feature is
enabled, hardware can restore and save the guest PMU state at VM-Entry
and VM-Exit respectively. The host PMU state still needs to be managed
by software and this is done with the help of the Mediated PMU framework
which can schedule the host perf events in or out.
This feature is documented under Section 15.39 in Volume 2 of the AMD64
Architecture Programmer’s Manual which can be found below.
https://bugzilla.kernel.org/attachment.cgi?id=306250
The guest PMU state is saved in the VMCB. Hence, struct kvm_pmu goes out
of sync and does not have the latest PMU state. In some cases, such as
during event filtering or instruction emulation, the VMCB needs to be
accessed for reading or writing the current register state. This is done
using host-initiated MSR accesses but the method may not be ideal and
perhaps requires additional PMU ops to be introduced. The goal is to
have data in vendor-specific structures like VMCB functions accessible
to some of the common KVM x86 PMU functions.
Any feedback is appreciated.
Patch Summary
* The first three patches add new feature bits and capability flags
to detect and advertise support for hardware PMU virtualization.
* The fourth patch extends Mediated PMU to make use of hardware PMU
virtualization.
* The remaining patches add the vendor-specific changes for PMC
virtualization.
TODOs
* Add appropriate KVM PMU ops to access MSR states from the VMCB.
* Make MSR states in the VMCB accessible via KVM_{GET,SET}_MSRS.
* Support for SEV-ES and SEV-SNP guests.
* Support for nested guests (nSVM).
* Support for the IRPerfCount register which is a free-running
instructions retired counter.
Testing
* Used three different guest PMU configurations.
* PerfMonV2 capable - 6 counters with Global Control and Status
registers (Zen 4 and later).
* PerfCtrExtCore capable - 6 counters but no Global Control and
Status registers (Zen 3 and older).
* Legacy Guest - 4 counters only (pre-Zen, older than Family 15h).
* KVM Unit Tests passed.
* Perf Fuzzer passed.
The patches should be applied over v5 of the Mediated PMU series [1]
along with an RDPMC interception fix [2].
[1] https://lore.kernel.org/all/20250806195706.1650976-1-seanjc@google.com/
[2] https://lore.kernel.org/all/aN1vfykNs8Dmv_g0@google.com/
Sandipan Das (7):
perf: Add a capability for hardware virtualized PMUs
x86/cpufeatures: Add PerfCtrVirt feature bit
perf/x86/amd/core: Set PERF_PMU_CAP_VIRTUALIZED_VPMU
KVM: x86/pmu: Add support for hardware virtualized PMUs
KVM: SVM: Add VMCB fields for PMC virtualization
KVM: SVM: Add support for PMC virtualization
KVM: SVM: Adjust MSR index for legacy guests
arch/x86/events/amd/core.c | 3 +
arch/x86/events/core.c | 1 +
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/perf_event.h | 1 +
arch/x86/include/asm/svm.h | 12 ++-
arch/x86/kvm/pmu.c | 94 ++++++++++++++++++-----
arch/x86/kvm/pmu.h | 6 ++
arch/x86/kvm/svm/pmu.c | 115 +++++++++++++++++++++++++++++
arch/x86/kvm/svm/svm.c | 52 +++++++++++++
arch/x86/kvm/svm/svm.h | 1 +
arch/x86/kvm/vmx/pmu_intel.c | 1 +
arch/x86/kvm/x86.c | 4 +
arch/x86/kvm/x86.h | 1 +
include/linux/perf_event.h | 1 +
14 files changed, 273 insertions(+), 20 deletions(-)
--
2.43.0
next reply other threads:[~2025-11-13 6:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 6:18 Sandipan Das [this message]
2025-11-13 6:18 ` [RFC PATCH 1/7] perf: Add a capability for hardware virtualized PMUs Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 2/7] x86/cpufeatures: Add PerfCtrVirt feature bit Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 3/7] perf/x86/amd/core: Set PERF_PMU_CAP_VIRTUALIZED_VPMU Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 4/7] KVM: x86/pmu: Add support for hardware virtualized PMUs Sandipan Das
2025-11-14 6:28 ` Mi, Dapeng
2025-11-14 6:38 ` Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 5/7] KVM: SVM: Add VMCB fields for PMC virtualization Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 6/7] KVM: SVM: Add support " Sandipan Das
2025-11-13 6:18 ` [RFC PATCH 7/7] KVM: SVM: Adjust MSR index for legacy guests Sandipan Das
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1762960531.git.sandipan.das@amd.com \
--to=sandipan.das@amd.com \
--cc=ananth.narayan@amd.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=kan.liang@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=manali.shukla@amd.com \
--cc=mizhang@google.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).