Re: [PATCH v9 12/12] KVM: x86/pmu: Support RDPMC Metrics Clear Mode
From: Chen, Zide
Date: Tue Oct 27 2026 - 18:17:41 EST
On 10/23/2026 1:55 PM, Jim Mattson wrote:
> 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.
Agreed. If kvm_vcpu_has_perf_metrics() requires FC3, then the NULL check
can be dropped.
> [...]
>
>> + 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.
Yes, since now FC3 check is added to kvm_vcpu_has_perf_metrics(), then
it makes sense to gate the unmasking on it as well.
>
> [...]
>
>> + 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.
Agreed, dropped this check from vmx_set_msr(). Since intel_pmu_refresh()
gates unmasking METRICS_CLEAR_EN on kvm_vcpu_has_perf_metrics(vcpu),
userspace setting RDPMC_METRICS_CLEAR without PERF_METRICS will simply
have no effect and bit 14 remains reserved for the guest.