Re: [PATCH v3 04/18] KVM: x86/pmu: Add PMC bitmap accessor helpers
From: Yosry Ahmed
Date: Mon Nov 09 2026 - 17:07:47 EST
> > diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
> > index 98e6f2443b82e..37a6664fdb9c9 100644
> > --- a/arch/x86/kvm/pmu.h
> > +++ b/arch/x86/kvm/pmu.h
> > @@ -149,11 +149,11 @@ static inline struct kvm_pmc *kvm_pmc_idx_to_pmc(struct kvm_pmu *pmu, int idx)
> > * which is already constrained by KVM_MAX_NR_{AMD,INTEL}_{GP,FIXED}_COUNTERS,
> > * so iteration up to KVM's maximum counter count is safe.
> > */
> > -#define kvm_for_each_gp_counter(i, mask) \
> > - for_each_set_bit((i), &(mask), KVM_MAX_NR_GP_COUNTERS)
> > +#define kvm_for_each_gp_counter(i, pmu) \
> > + for_each_set_bit((i), &(unsigned long){ kvm_gp_pmc_mask(pmu) }, KVM_MAX_NR_GP_COUNTERS)
> >
> > -#define kvm_for_each_fixed_counter(i, mask) \
> > - for_each_set_bit((i), &(mask), KVM_MAX_NR_FIXED_COUNTERS)
> > +#define kvm_for_each_fixed_counter(i, pmu) \
> > + for_each_set_bit((i), &(unsigned long){ kvm_fixed_pmc_mask(pmu) }, KVM_MAX_NR_FIXED_COUNTERS)
>
> Right, I didn't realize C99 compound literals could be used here.
>
> However, with this suggested code, kvm_gp_pmc_mask() would be
> re-evaluated on every iteration. It seems this “expression with side
> effects evaluated more than once” is not encouraged by the coding style,
> is it?
kvm_gp_pmc_mask() and kvm_fixed_pmc_mask() have no side effects, right?