Re: [PATCH v4 15/21] KVM: x86/pmu: Clamp pmu->version to kvm_pmu_cap.version

From: Yosry Ahmed

Date: Wed Nov 18 2026 - 14:37:57 EST


On Wed, Nov 18, 2026 at 11:19 AM Chen, Zide <zide.chen@xxxxxxxxx> wrote:
>
>
>
> On 11/18/2026 10:17 AM, Yosry Ahmed wrote:
> >> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> >> index 5eac64ba8832..0be9956810ae 100644
> >> --- a/arch/x86/kvm/vmx/pmu_intel.c
> >> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> >> @@ -574,7 +574,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
> >> eax.full = entry->eax;
> >> edx.full = entry->edx;
> >>
> >> - pmu->version = eax.split.version_id;
> >> + pmu->version = min_t(int, eax.split.version_id, kvm_pmu_cap.version);
> >
> > Why not AMD too?
>
> On AMD, seems pmu->version is already constrained to kvm_pmu_cap.version:
>
> 1. When vPMU is enabled, AMD has no CPUID version field. KVM sets
> version to 1, or 2 if guest_cpu_cap_has(PERFMON_V2). Userspace cannot
> force version 2 on a v1 host because svm_set_cpu_caps() clears
> PERFMON_V2 from kvm_cpu_caps whenever kvm_pmu_cap.version != 2.
>
> 2. When vPMU is disabled, kvm_pmu_refresh() sets pmu->version = 0 and
> returns before vendor refresh() is called (!vcpu->kvm->arch.enable_pmu).

I see, makes sense. Thanks.