Skip to contentSkip to conversation

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

PATCH In review Yang Weijiang 2 participants 3 messages May 10, 2022 – May 11, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: selftests: x86: Skip unsupported test when Arch LBR is available

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.

---
 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%)
tools/testing/selftests/kvm/Makefile +1 -1
index 681b173aa87c..9a1a84803b01 100644
@@ -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
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c renamed from tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c +7 -2
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
@@ -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);
 }
Signature · 1 line
2.27.0
maintainer
#1 lore raw

Hi,

tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c int main(int argc, char *argv[]) · line 115

Quoted 8 lines
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c renamed from tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c +6 -2
-	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.");
+	}

Why not try a different value?

Paolo

#2 lore raw
Quoted 11 lines · Paolo Bonzini

Hi,

tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c int main(int argc, char *argv[]) · line 115

Quoted 8 lines
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c renamed from tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c +6 -2
-	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.");
+	}

Why not try a different value?

OK, I'll select a "real" invalid format and re-post the patch, thanks!

Quoted 4 lines

Paolo