[PATCH v3 00/11] KVM: selftests: Test the consistency of the PMU's CPUID and its features

From: Jinrong Liang
Date: Mon Aug 14 2023 - 07:52:01 EST


Hi,

The KVM selftests show advantages over KUT in terms of finding defects through
flexible and varied guest settings from the KVM user space.

This patchset tests whether the Intel vPMU works properly with different Intel
CPUID.0xA configurations. It also provides test scaffolding and a sufficient
number of PMU test cases to subsequently offer adequate code coverage of AMD
vPMU or Intel complex features, such as LBR or PEBS, in selftests.

All patches have been tested on both Intel and AMD machines, with one exception
patch 11 "KVM: selftests: Test AMD Guest PerfMonV2" has not been tested on my
AMD machine, as does not support PerfMonV2.

Any feedback or suggestions are greatly appreciated.

Sincerely,
Jinrong Liang

Please note that following patch should be applied before this patch series:

https://lore.kernel.org/kvm/20230810090945.16053-2-cloudliang@xxxxxxxxxxx/

Changelog:

v3:
- Rebased to 74c2185c5b74(tag: kvm-x86-next-2023.08.02)
- Add a new patch to test AMD PMU legacy four performance counters.
- Add a new patch to test AMD Guest PerfMonV2.
- Refactor code to simplify logic and improve readability.
- Use TEST_ASSERT_EQ() instead of ASSERT_EQ() when checking return values.
- Add vcpu_set_cpuid_property() helper for setting properties. (Sean)
- Add arch_event_is_supported() helper to check if an event is supported. (Sean)
- Add fixed_counter_is_supported() helper to check if a fixed counter is supported. (Sean)
- Drop macros that hides important details. (Sean)
- Use enumerations to avoid performance events magic numbers. (Sean)
- TEST_FAIL() instead of TEST_ASSERT() in run_vcpu() wrapper. (Sean)
- Update variable names for better readability and consistency. (Sean)
- Rename functions to better reflect their purpose. (Sean)
- Improve comments for better clarity and understanding of the code. (Sean, Jim)

v2:
https://lore.kernel.org/kvm/20230530134248.23998-1-cloudliang@xxxxxxxxxxx/T/

Jinrong Liang (11):
KVM: selftests: Add vcpu_set_cpuid_property() to set properties
KVM: selftests: Add pmu.h for PMU events and common masks
KVM: selftests: Test Intel PMU architectural events on gp counters
KVM: selftests: Test Intel PMU architectural events on fixed counters
KVM: selftests: Test consistency of CPUID with num of gp counters
KVM: selftests: Test consistency of CPUID with num of fixed counters
KVM: selftests: Test Intel supported fixed counters bit mask
KVM: selftests: Test consistency of PMU MSRs with Intel PMU version
KVM: selftests: Add x86 feature and properties for AMD PMU in
processor.h
KVM: selftests: Test AMD PMU events on legacy four performance
counters
KVM: selftests: Test AMD Guest PerfMonV2

tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/include/x86_64/pmu.h | 124 +++++
.../selftests/kvm/include/x86_64/processor.h | 11 +
.../selftests/kvm/lib/x86_64/processor.c | 14 +
.../kvm/x86_64/pmu_basic_functionality_test.c | 505 ++++++++++++++++++
5 files changed, 655 insertions(+)
create mode 100644 tools/testing/selftests/kvm/include/x86_64/pmu.h
create mode 100644 tools/testing/selftests/kvm/x86_64/pmu_basic_functionality_test.c


base-commit: 74c2185c5b74fd0ae91133ad5afe8684f6a02b91
prerequisite-patch-id: 8718ffb8c05e453db9aae9896787cb6650d3cd52
--
2.39.3