]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Assert that vcpu->cpuid is non-NULL when getting CPUID entries
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:33:34 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:19:28 +0000 (14:19 -0800)
Add a sanity check in __vcpu_get_cpuid_entry() to provide a friendlier
error than a segfault when a test developer tries to use a vCPU CPUID
helper on a barebones vCPU.

Link: https://lore.kernel.org/r/20241128013424.4096668-8-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/processor.h

index 9ec984cf86742eee80a20b2b0944a5297541d6ef..71aa290c583f6c689c6ed313c8dace3584ed19ad 100644 (file)
@@ -1014,6 +1014,8 @@ static inline struct kvm_cpuid_entry2 *__vcpu_get_cpuid_entry(struct kvm_vcpu *v
                                                              uint32_t function,
                                                              uint32_t index)
 {
+       TEST_ASSERT(vcpu->cpuid, "Must do vcpu_init_cpuid() first (or equivalent)");
+
        return (struct kvm_cpuid_entry2 *)get_cpuid_entry(vcpu->cpuid,
                                                          function, index);
 }