[PATCH] KVM: selftests: x86: Skip unsupported test when Arch LBR is available

From: Yang Weijiang
Date: Mon May 09 2022 - 23:51:01 EST


On Arch LBR capable platforms, LBR_FMT in perf capability msr is 0x3f,
so skip invalid format test if it's running on these platforms.
Opportunistically change the file name to reflect the tests actually
carried out.

Signed-off-by: Yang Weijiang <weijiang.yang@xxxxxxxxx>
---
tools/testing/selftests/kvm/Makefile | 2 +-
.../x86_64/{vmx_pmu_msrs_test.c => vmx_pmu_caps_test.c} | 9 +++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
rename tools/testing/selftests/kvm/x86_64/{vmx_pmu_msrs_test.c => vmx_pmu_caps_test.c} (88%)

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 681b173aa87c..9a1a84803b01 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -81,7 +81,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/xapic_state_test
TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
-TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_msrs_test
+TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_caps_test
TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
similarity index 88%
rename from tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c
rename to tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
index 2454a1f2ca0c..977c268a6ad4 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
@@ -107,8 +107,13 @@ int main(int argc, char *argv[])
ASSERT_EQ(vcpu_get_msr(vm, VCPU_ID, MSR_IA32_PERF_CAPABILITIES), (u64)host_cap.lbr_format);

/* testcase 3, check invalid LBR format is rejected */
- ret = _vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, PMU_CAP_LBR_FMT);
- TEST_ASSERT(ret == 0, "Bad PERF_CAPABILITIES didn't fail.");
+ /* Note, on Arch LBR capable platforms, LBR_FMT in perf capability msr is 0x3f,
+ * so skip below test if running on these platforms. */
+ if (host_cap.lbr_format != PMU_CAP_LBR_FMT) {
+ ret = _vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, PMU_CAP_LBR_FMT);
+ TEST_ASSERT(ret == 0, "Bad PERF_CAPABILITIES didn't fail.");
+ }

+ printf("Completed pmu capability tests successfully.\n");
kvm_vm_free(vm);
}
--
2.27.0