[PATCH v6 15/44] KVM: x86/pmu: Snapshot host (i.e. perf's) reported PMU capabilities

Sean Christopherson posted 44 patches 2 months ago
[PATCH v6 15/44] KVM: x86/pmu: Snapshot host (i.e. perf's) reported PMU capabilities
Posted by Sean Christopherson 2 months ago
Take a snapshot of the unadulterated PMU capabilities provided by perf so
that KVM can compare guest vPMU capabilities against hardware capabilities
when determining whether or not to intercept PMU MSRs (and RDPMC).

Reviewed-by: Sandipan Das <sandipan.das@amd.com>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/pmu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 487ad19a236e..7c219305b61d 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -108,6 +108,8 @@ void kvm_init_pmu_capability(const struct kvm_pmu_ops *pmu_ops)
 	bool is_intel = boot_cpu_data.x86_vendor == X86_VENDOR_INTEL;
 	int min_nr_gp_ctrs = pmu_ops->MIN_NR_GP_COUNTERS;
 
+	perf_get_x86_pmu_capability(&kvm_host_pmu);
+
 	/*
 	 * Hybrid PMUs don't play nice with virtualization without careful
 	 * configuration by userspace, and KVM's APIs for reporting supported
-- 
2.52.0.223.gf5cc29aaa4-goog
Re: [PATCH v6 15/44] KVM: x86/pmu: Snapshot host (i.e. perf's) reported PMU capabilities
Posted by Mi, Dapeng 1 month, 2 weeks ago
On 12/6/2025 8:16 AM, Sean Christopherson wrote:
> Take a snapshot of the unadulterated PMU capabilities provided by perf so
> that KVM can compare guest vPMU capabilities against hardware capabilities
> when determining whether or not to intercept PMU MSRs (and RDPMC).
>
> Reviewed-by: Sandipan Das <sandipan.das@amd.com>
> Tested-by: Xudong Hao <xudong.hao@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/kvm/pmu.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 487ad19a236e..7c219305b61d 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -108,6 +108,8 @@ void kvm_init_pmu_capability(const struct kvm_pmu_ops *pmu_ops)
>  	bool is_intel = boot_cpu_data.x86_vendor == X86_VENDOR_INTEL;
>  	int min_nr_gp_ctrs = pmu_ops->MIN_NR_GP_COUNTERS;
>  
> +	perf_get_x86_pmu_capability(&kvm_host_pmu);
> +
>  	/*
>  	 * Hybrid PMUs don't play nice with virtualization without careful
>  	 * configuration by userspace, and KVM's APIs for reporting supported

Hi Sean,

It looks a merging error here. We don't need this patch.

The original patch "51f34b1 ("KVM: x86/pmu: Snapshot host (i.e. perf's)
reported PMU capabilities")" had been merged into upstream and subsequently
we submitted a new patch "034417c1439a ("KVM: x86/pmu: Don't try to get
perf capabilities for hybrid CPUs")" to fix the warning introduced from
previous patch  "51f34b1 ("KVM: x86/pmu: Snapshot host (i.e. perf's)
reported PMU capabilities")". Thanks.

-Dapeng Mi


Re: [PATCH v6 15/44] KVM: x86/pmu: Snapshot host (i.e. perf's) reported PMU capabilities
Posted by Sean Christopherson 1 month, 1 week ago
On Thu, Dec 25, 2025, Dapeng Mi wrote:
> 
> On 12/6/2025 8:16 AM, Sean Christopherson wrote:
> > Take a snapshot of the unadulterated PMU capabilities provided by perf so
> > that KVM can compare guest vPMU capabilities against hardware capabilities
> > when determining whether or not to intercept PMU MSRs (and RDPMC).
> >
> > Reviewed-by: Sandipan Das <sandipan.das@amd.com>
> > Tested-by: Xudong Hao <xudong.hao@intel.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> >  arch/x86/kvm/pmu.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> > index 487ad19a236e..7c219305b61d 100644
> > --- a/arch/x86/kvm/pmu.c
> > +++ b/arch/x86/kvm/pmu.c
> > @@ -108,6 +108,8 @@ void kvm_init_pmu_capability(const struct kvm_pmu_ops *pmu_ops)
> >  	bool is_intel = boot_cpu_data.x86_vendor == X86_VENDOR_INTEL;
> >  	int min_nr_gp_ctrs = pmu_ops->MIN_NR_GP_COUNTERS;
> >  
> > +	perf_get_x86_pmu_capability(&kvm_host_pmu);
> > +
> >  	/*
> >  	 * Hybrid PMUs don't play nice with virtualization without careful
> >  	 * configuration by userspace, and KVM's APIs for reporting supported
> 
> Hi Sean,
> 
> It looks a merging error here. We don't need this patch.

Gah, right you are.  I overlooked it because it didn't conflict on a rebase, and
I once again forgot to test on a hybrid PMU, grr.

Thanks!

> The original patch "51f34b1 ("KVM: x86/pmu: Snapshot host (i.e. perf's)
> reported PMU capabilities")" had been merged into upstream and subsequently
> we submitted a new patch "034417c1439a ("KVM: x86/pmu: Don't try to get
> perf capabilities for hybrid CPUs")" to fix the warning introduced from
> previous patch  "51f34b1 ("KVM: x86/pmu: Snapshot host (i.e. perf's)
> reported PMU capabilities")". Thanks.
> 
> -Dapeng Mi
> 
>