Re: [PATCH v2 15/16] KVM: x86/pmu: Advertise PerfMon version 5 on Intel hosts

From: Jim Mattson

Date: Wed Oct 28 2026 - 18:05:20 EST


On Thu, Aug 27, 2026 at 3:48 PM Zide Chen <zide.chen@xxxxxxxxx> wrote:
>
> From: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
>
> KVM currently caps the guest PerfMon version at 2 for all Intel
> platforms. Now that KVM emulates the basic architectural PMU features
> introduced in PerfMon versions 3 through 5, raise the guest PerfMon
> version to 5. Features that require additional emulation support, e.g.
> architectural LBR will be enabled separately.
>
> PerfMon versions 3 and 4 continue to be exposed as version 2 because
> KVM cannot safely virtualize AnyThread due to cross-VM information
> leakage. PerfMon v5 is supported because it provides the
> AnyThread-deprecated capability, allowing KVM to indicate that
> AnyThread is deprecated.
>
> When enable_mediated_pmu is disabled or in the non-Intel paths, KVM
> retains the existing cap of version 2.
>
> Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
> ---
> v2:
> - Cap vPMU v3/v4 to v2, as AnyThread cannot be safely virtualized.
> (Sashiko)
> ---
> arch/x86/kvm/pmu.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 4cb7c796daac..1a7be7d73b62 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -175,7 +175,21 @@ void kvm_init_pmu_capability(struct kvm_pmu_ops *pmu_ops)
> }
>
> memcpy(&kvm_pmu_cap, &kvm_host_pmu, sizeof(kvm_host_pmu));
> - kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2);
> +
> + if (is_intel && enable_mediated_pmu) {
> + kvm_pmu_cap.version = min(kvm_pmu_cap.version, 5);
> +
> + /*
> + * PMU v3/v4 has AnyThread support, which KVM cannot safely
> + * virtualize. Expose PMU v2 instead of advertising a partially
> + * functional PMU v3/v4 to guests.
> + */
> + if (kvm_pmu_cap.version == 3 || kvm_pmu_cap.version == 4)
> + kvm_pmu_cap.version = 2;

Nit: on Intel, enable_mediated_pmu already requires host_pmu->version >= 4
(see intel_is_mediated_pmu_supported()), so kvm_pmu_cap.version == 3 is
impossible when (is_intel && enable_mediated_pmu) is true. Hence, I think this
can be simplified to:

if (is_intel && enable_mediated_pmu && kvm_pmu_cap.version >= 5)
kvm_pmu_cap.version = 5;
else
kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2);