[PATCH v2 0/8] KVM: selftests: Test the consistency of the PMU's CPUID and its features

From: Jinrong Liang
Date: Tue May 30 2023 - 09:43:21 EST


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.

Please feel free to add more tests or share valuable comments.


- Rebased to 5c291b93e5d6(tag: kvm-x86-next-2023.04.26)
- Added a new patch to add macros to processor.h to obtain the number of fixed
counters and fixed counters bit mask. (Sean)
- Added a new patch to introduce a new pmu.h header file to better organize the
PMU performance event constants and common masks. (Sean)
- Changed the file name to pmu_basic_functionality_test. (Sean)
- Replaced new_vcpu() with the new function pmu_vm_create_with_one_vcpu() and
replaced free_vcpu() wrapper with kvm_vm_free(). (Sean)
- Modified the run_vcpu() wrapper to return the first ucall param. (Sean)
- Defined KVM_X86_CPU_PROPERTY macros where possible to avoid opening code in
multiple places. (Sean)
- Optimized the comment. (Sean, Jim)
- Modified the guest logic to have the guest return the counter value and
perform the assert in kvm user space. (Sean)
- Used goto instead of the ternary operator in intel_guest_run_arch_event(). (Sean)
- Added a test to check that KVM drops writes to MSR_P6_PERFCTR[0|1]. (Sean)
- Used rdmsr_safe() and/or wrmsr_safe() instead of installing a dedicated handler. (Sean)
- Optimized variables that do not need to be initialized. (Sean)
- Removed patch KVM: selftests: Test Intel counters' bit width emulation.


Jinrong Liang (5):
KVM: selftests: Add macros for fixed counters in processor.h
KVM: selftests: Add pmu.h for PMU events and common masks
KVM: selftests: Test Intel PMU architectural events on fixed counters
KVM: selftests: Test consistency of CPUID with num of fixed counters
KVM: selftests: Test consistency of PMU MSRs with Intel PMU version

Like Xu (3):
KVM: selftests: Test Intel PMU architectural events on gp counters
KVM: selftests: Test consistency of CPUID with num of gp counters
KVM: selftests: Test Intel supported fixed counters bit mask

tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/include/x86_64/pmu.h | 56 +++
.../selftests/kvm/include/x86_64/processor.h | 2 +
.../kvm/x86_64/pmu_basic_functionality_test.c | 455 ++++++++++++++++++
4 files changed, 514 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: 5c291b93e5d665380dbecc6944973583f9565ee5