Re: [PATCH v2 06/16] KVM: x86/pmu: Drop nr_arch_{gp,fixed}_counters from kvm_pmu
From: Chen, Zide
Date: Wed Oct 28 2026 - 13:04:53 EST
On 10/28/2026 9:49 AM, Jim Mattson wrote:
> On Thu, Aug 27, 2026 at 3:48 PM Zide Chen <zide.chen@xxxxxxxxx> wrote:
>>
>> From: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
>>
>> This is a preparatory step toward fully bitmap-based PMU capability
>> handling. Later patches switch KVM's view of host PMU capabilities from
>> counter counts to counter bitmaps.
>>
>> Populate and use pmc_exists directly when walking guest-visible PMCs,
>> instead of relying on pmu->nr_arch_{gp,fixed}_counters as intermediate
>> state.
>>
>> Iterate counters via the newly added pmc_exists based helpers, and
>> remove the now-redundant nr_arch_{gp,fixed}_counters fields from struct
>> kvm_pmu.
>>
>> Note: {vmx,svm}_recalc_pmu_msr_intercepts() may leave stale intercepts
>> on GP MSRs after CPUID narrowing. This corner case is resolved by the
>> following patch: "KVM: x86/pmu: Switch to bitmask-based KVM PMU
>> capabilities".
>
> Are you saying that you are deliberately breaking bisection?!? Shame on you!
Yeah, I feel bad about this... the other solution could be to
temporarily use for_each_clear_bit().
- for ( ; i < kvm_pmu_cap.num_counters_gp; i++) {
+ for_each_clear_bit(i, &gp_mask, kvm_pmu_cap.num_counters_gp) {
vmx_set_intercept_for_msr(vcpu, MSR_IA32_PERFCTR0 + i,
MSR_TYPE_RW, true);
And then remove for_each_clear_bit() in the coming patch when
kvm_pmu_cap.num_counters_gp is dropped:
- for_each_clear_bit(i, &gp_mask, kvm_pmu_cap.num_counters_gp) {
+ host_only_gp_mask = kvm_host_pmu.cntr_mask64 & ~gp_mask;
+ for_each_set_bit(i, &host_only_gp_mask, INTEL_PMC_MAX_GENERIC) {
>> Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
>> Co-developed-by: Zide Chen <zide.chen@xxxxxxxxx>
>> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
>> ---
>> v2:
>> - Fix AMD legacy PMU MSR intercept handling for guest PMU
>> narrowing reconfiguration by adding for_each_clear_bit_from().
>> - Re-word the stale interception changelog part.
>> ---
> [ ... ]
>> - for (i = 0; i < pmu->nr_arch_fixed_counters; i++)
>> + kvm_for_each_fixed_counter(i, fixed_mask)
>> vmx_set_intercept_for_msr(vcpu, MSR_CORE_PERF_FIXED_CTR0 + i,
>> MSR_TYPE_RW, intercept);
>> for ( ; i < kvm_pmu_cap.num_counters_fixed; i++)
>
> Doesn't this potentially leave stale intercepts on FC MSRs after CPUID
> narrowing as well?
Yes.