[PATCH 4/9] KVM: arm64: PMU: Add counter_index_to_*reg() helpers

Oliver Upton oliver.upton at linux.dev
Wed Aug 10 10:23:34 PDT 2022


On Wed, Aug 10, 2022 at 02:17:52AM -0500, Oliver Upton wrote:
> On Fri, Aug 05, 2022 at 02:58:08PM +0100, Marc Zyngier wrote:
> > In order to reduce the boilerplate code, add two helpers returning
> > the counter register index (resp. the event register) in the vcpu
> > register file from the counter index.
> > 
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
> 
> Reviewed-by: Oliver Upton <oliver.upton at linux.dev>
> 
> > ---
> >  arch/arm64/kvm/pmu-emul.c | 27 +++++++++++++++------------
> >  1 file changed, 15 insertions(+), 12 deletions(-)
> > 
> > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
> > index 0ab6f59f433c..9be485d23416 100644
> > --- a/arch/arm64/kvm/pmu-emul.c
> > +++ b/arch/arm64/kvm/pmu-emul.c
> > @@ -75,6 +75,16 @@ static struct kvm_vcpu *kvm_pmc_to_vcpu(struct kvm_pmc *pmc)
> >  	return container_of(vcpu_arch, struct kvm_vcpu, arch);
> >  }
> >  
> > +static u32 counter_index_to_reg(u64 idx)
> > +{
> > +	return (idx == ARMV8_PMU_CYCLE_IDX) ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + idx;
> > +}
> > +
> > +static u32 counter_index_to_evtreg(u64 idx)
> > +{
> > +	return (idx == ARMV8_PMU_CYCLE_IDX) ? PMCCFILTR_EL0 : PMEVTYPER0_EL0 + idx;
> > +}
> > +

After reading the series, do you think these helpers could be applied to
kvm_pmu_counter_increment() as well?

--
Thanks,
Oliver



More information about the linux-arm-kernel mailing list