[PATCH 5/8] KVM: selftests: Skip PERF_CAPABILITIES vCPU checks without PDCM

"Ewan Hai-oc" <[email protected]>
Newsgroups org.kernel.vger.linux-kselftest,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
From: Frank Zhu <[email protected]>

KVM allows userspace to query MSR_IA32_PERF_CAPABILITIES through
KVM_GET_MSRS even when PDCM is not exposed in KVM_GET_SUPPORTED_CPUID.
However, vCPU accesses to the MSR fail without PDCM.

Keep the feature MSR query, but skip its checks when KVM does not
expose PDCM, allowing feature_msrs_test to continue checking the
remaining feature MSRs.

Signed-off-by: Frank Zhu <[email protected]>
Signed-off-by: Ewan Hai <[email protected]>
---
 tools/testing/selftests/kvm/x86/feature_msrs_test.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/kvm/x86/feature_msrs_test.c b/tools/testing/selftests/kvm/x86/feature_msrs_test.c
index 158550701771..9602e29bf9cc 100644
--- a/tools/testing/selftests/kvm/x86/feature_msrs_test.c
+++ b/tools/testing/selftests/kvm/x86/feature_msrs_test.c
@@ -54,6 +54,19 @@ static void test_feature_msr(u32 msr)
 	if (is_kvm_controlled_msr(msr))
 		return;
 
+	/*
+	 * KVM allows userspace to query MSR_IA32_PERF_CAPABILITIES as a
+	 * feature MSR even if KVM doesn't expose PDCM, but vCPU accesses to
+	 * the MSR will fail in that case. Skip the vCPU checks so that the
+	 * remaining feature MSRs can be tested.
+	 */
+	if (msr == MSR_IA32_PERF_CAPABILITIES &&
+	    !kvm_cpu_has(X86_FEATURE_PDCM)) {
+		printf("KVM does not expose PDCM, skipping vCPU checks for "
+		       "MSR_IA32_PERF_CAPABILITIES (0x%x).\n", msr);
+		return;
+	}
+
 	/*
 	 * More goofy behavior.  KVM reports the host CPU's actual revision ID,
 	 * but initializes the vCPU's revision ID to an arbitrary value.
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.