Re: [PATCH v3 5/5] KVM: selftests: Handle Intel Atom errata that leads to PMU event overcount
From: Sean Christopherson
Date: Fri Sep 19 2025 - 10:55:11 EST
On Fri, Sep 19, 2025, Dapeng Mi wrote:
>
> On 9/19/2025 8:45 AM, Sean Christopherson wrote:
> > diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
> > index baa7b8a2d459..acb5a5c37296 100644
> > --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c
> > +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
> > @@ -163,10 +163,18 @@ static void guest_assert_event_count(uint8_t idx, uint32_t pmc, uint32_t pmc_msr
> >
> > switch (idx) {
> > case INTEL_ARCH_INSTRUCTIONS_RETIRED_INDEX:
> > - GUEST_ASSERT_EQ(count, NUM_INSNS_RETIRED);
> > + /* Relax precise count check due to VM-EXIT/VM-ENTRY overcount issue */
> > + if (this_pmu_has_errata(INSTRUCTIONS_RETIRED_OVERCOUNT))
>
> The pmu_errata_mask is a bitmap, so the argument should be
> BIT_ULL(INSTRUCTIONS_RETIRED_OVERCOUNT) instead of
> INSTRUCTIONS_RETIRED_OVERCOUNT?
Gah, I just forgot to use BIT_ULL() in this_pmu_has_errata().
diff --git a/tools/testing/selftests/kvm/include/x86/pmu.h b/tools/testing/selftests/kvm/include/x86/pmu.h
index 25d2b476daf4..308c9f6f0d57 100644
--- a/tools/testing/selftests/kvm/include/x86/pmu.h
+++ b/tools/testing/selftests/kvm/include/x86/pmu.h
@@ -115,7 +115,7 @@ void kvm_init_pmu_errata(void);
static inline bool this_pmu_has_errata(enum pmu_errata errata)
{
- return pmu_errata_mask & errata;
+ return pmu_errata_mask & BIT_ULL(errata);
}
#endif /* SELFTEST_KVM_PMU_H */
>
> Or better, directly define INSTRUCTIONS_RETIRED_OVERCOUNT as a bitmap, like
> this.
>
> diff --git a/tools/testing/selftests/kvm/include/x86/pmu.h
> b/tools/testing/selftests/kvm/include/x86/pmu.h
> index 25d2b476daf4..9af448129597 100644
> --- a/tools/testing/selftests/kvm/include/x86/pmu.h
> +++ b/tools/testing/selftests/kvm/include/x86/pmu.h
> @@ -106,8 +106,8 @@ extern const uint64_t intel_pmu_arch_events[];
> extern const uint64_t amd_pmu_zen_events[];
>
> enum pmu_errata {
> - INSTRUCTIONS_RETIRED_OVERCOUNT,
> - BRANCHES_RETIRED_OVERCOUNT,
> + INSTRUCTIONS_RETIRED_OVERCOUNT = (1 << 0),
> + BRANCHES_RETIRED_OVERCOUNT = (1 << 1),
I want to utilize the auto-incrementing behavior of enums, without having to
resort to double-defines or anything.