Re: [PATCH v9 12/12] KVM: x86/pmu: Support RDPMC Metrics Clear Mode

From: Jim Mattson

Date: Fri Oct 23 2026 - 14:56:03 EST


On Fri, Sep 18, 2026 at 12:39 PM Zide Chen <zide.chen@xxxxxxxxx> wrote:
>
> + pmc = kvm_pmc_idx_to_pmc(pmu, INTEL_PMC_IDX_FIXED_SLOTS);
> + if (pmc && intel_pmu_metrics_clear_enabled(pmu)) {

If kvm_vcpu_has_perf_metrics() requires fixed counter 3 (see my reply
to 5/12), pmc can't be NULL here.

[...]

> + if (perf_capabilities & PERF_CAP_RDPMC_METRICS_CLEAR)
> + pmu->fixed_ctr_ctrl_rsvd &=
> + ~intel_fixed_bits_by_idx(INTEL_FIXED_SLOTS_IDX,
> + INTEL_FIXED_3_METRICS_CLEAR);

This should be predicated on the guest actually having fixed counter 3
(and PERF_METRICS). intel_pmu_enable_fixed_counter_bits() only unmasks
bits for counters below nr_arch_fixed_counters.

[...]

> + if ((data & PERF_CAP_RDPMC_METRICS_CLEAR) &&
> + !(data & PERF_CAP_PERF_METRICS))
> + return 1;

If IA32_FIXED_CTR_CTRL.METRICS_CLEAR_EN[14] is only unmasked when the
vCPU has PERF_METRICS, is this check still necessary? KVM generally
doesn't police userspace's feature combinations unless it has to.