Re: [PATCH 04/15] KVM: x86/pmu: Add PMC bitmap accessor helpers
From: Sean Christopherson
Date: Tue Jul 28 2026 - 19:40:50 EST
On Tue, Jul 28, 2026, Zide Chen wrote:
> On 7/28/2026 2:28 PM, Sean Christopherson wrote:
> > On Tue, Jul 07, 2026, Zide Chen wrote:
> >> @@ -120,6 +146,17 @@ static inline struct kvm_pmc *kvm_pmc_idx_to_pmc(struct kvm_pmu *pmu, int idx)
> >> continue; \
> >> else \
> >>
> >> +/*
> >> + * @mask must be an lvalue of type unsigned long because for_each_set_bit()
> >> + * takes its address.
> >> + *
> >> + * @type is token-pasted into KVM_MAX_NR_##type##_COUNTERS to match one of the
> >> + * counter defines, e.g. GP, FIXED, AMD_GP, INTEL_GP, or INTEL_FIXED. This
> >> + * reflects what KVM supports, not the underlying host's PMU capabilities.
> >> + */
> >> +#define kvm_for_each_set_pmc_idx(i, mask, type) \
> >> + for_each_set_bit((i), &(mask), KVM_MAX_NR_##type##_COUNTERS)
> >
> >
> > Provide dedciated macros instead of requiring the caller to pass in a type and
> > then doing token pasting, e.g.
> >
> > #define kvm_for_each_gp_counter()
> >
> > #define kvm_for_each_fixed_counter()
>
> Do you mean having only two macros, and using
> KVM_MAX_NR_{GP,FIXED}_COUNTERS for Intel, AMD, and the common PMU code?
>
> That should work, since all_valid_pmc_mask64 is already constrained by
> KVM_MAX_NR_{AMD,INTEL}_{GP,FIXED}_COUNTERS, so iterating up to
> KVM_MAX_NR_{GP,FIXED}_COUNTERS would be safe.
Yep, exactly.