Re: [PATCH v4 15/21] KVM: x86/pmu: Clamp pmu->version to kvm_pmu_cap.version
From: Yosry Ahmed
Date: Wed Nov 18 2026 - 11:17:44 EST
On Thu, Nov 12, 2026 at 01:32:21PM -0700, Zide Chen wrote:
> KVM's policy of not policing guest CPUID allows userspace to configure
> an arbitrary PMU version without KVM rejecting the ioctl or mutating
> guest CPUID entries. As userspace is responsible for validating its
> configuration against KVM_GET_SUPPORTED_CPUID, userspace is entitled to
> "shoot itself in the foot" by presenting an unsupported virtual CPU
> model.
>
> Clamp pmu->version to kvm_pmu_cap.version so that KVM's internal state
> tracks the effective PMU version that KVM supports, and avoid exposing
> or emulating features that KVM does not support (such as MSRs gated on
> higher PMU versions).
>
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Suggested-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
> ---
> v4:
> - New patch. (Sean, Yosry)
> ---
> arch/x86/kvm/vmx/pmu_intel.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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?
> if (!pmu->version)
> return;
>
> --
> 2.56.1
>