Skip to content

Commit 0883371

Browse files
committed
KVM: selftests: Assert that vcpu->cpuid is non-NULL when getting CPUID entries
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>
1 parent bf4dfc3 commit 0883371

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/testing/selftests/kvm/include/x86/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@ static inline struct kvm_cpuid_entry2 *__vcpu_get_cpuid_entry(struct kvm_vcpu *v
10141014
uint32_t function,
10151015
uint32_t index)
10161016
{
1017+
TEST_ASSERT(vcpu->cpuid, "Must do vcpu_init_cpuid() first (or equivalent)");
1018+
10171019
return (struct kvm_cpuid_entry2 *)get_cpuid_entry(vcpu->cpuid,
10181020
function, index);
10191021
}

0 commit comments

Comments
 (0)