Commit 71bcb951 authored by Sean Christopherson's avatar Sean Christopherson

KVM: selftests: Verify that kvm_cpuid2.entries layout is unchanged by KVM

In the CPUID test, verify that KVM doesn't modify the kvm_cpuid2.entries
layout, i.e. that the order of entries and their flags is identical
between what the test provides via KVM_SET_CPUID2 and what KVM returns
via KVM_GET_CPUID2.

Asserting that the layouts match simplifies the test as there's no need
to iterate over both arrays.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20220614200707.3315957-17-seanjc@google.com
parent 3c67f820
......@@ -79,41 +79,34 @@ static bool is_cpuid_mangled(struct kvm_cpuid_entry2 *entrie)
return false;
}
static void check_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *entrie)
static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *cpuid2)
{
struct kvm_cpuid_entry2 *e1, *e2;
int i;
for (i = 0; i < cpuid->nent; i++) {
if (cpuid->entries[i].function == entrie->function &&
cpuid->entries[i].index == entrie->index) {
if (is_cpuid_mangled(entrie))
return;
TEST_ASSERT(cpuid->entries[i].eax == entrie->eax &&
cpuid->entries[i].ebx == entrie->ebx &&
cpuid->entries[i].ecx == entrie->ecx &&
cpuid->entries[i].edx == entrie->edx,
"CPUID 0x%x.%x differ: 0x%x:0x%x:0x%x:0x%x vs 0x%x:0x%x:0x%x:0x%x",
entrie->function, entrie->index,
cpuid->entries[i].eax, cpuid->entries[i].ebx,
cpuid->entries[i].ecx, cpuid->entries[i].edx,
entrie->eax, entrie->ebx, entrie->ecx, entrie->edx);
return;
}
}
TEST_ASSERT(cpuid1->nent == cpuid2->nent,
"CPUID nent mismatch: %d vs. %d", cpuid1->nent, cpuid2->nent);
TEST_ASSERT(false, "CPUID 0x%x.%x not found", entrie->function, entrie->index);
}
for (i = 0; i < cpuid1->nent; i++) {
e1 = &cpuid1->entries[i];
e2 = &cpuid2->entries[i];
static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *cpuid2)
{
int i;
TEST_ASSERT(e1->function == e2->function &&
e1->index == e2->index && e1->flags == e2->flags,
"CPUID entries[%d] mismtach: 0x%x.%d.%x vs. 0x%x.%d.%x\n",
i, e1->function, e1->index, e1->flags,
e2->function, e2->index, e2->flags);
for (i = 0; i < cpuid1->nent; i++)
check_cpuid(cpuid2, &cpuid1->entries[i]);
if (is_cpuid_mangled(e1))
continue;
for (i = 0; i < cpuid2->nent; i++)
check_cpuid(cpuid1, &cpuid2->entries[i]);
TEST_ASSERT(e1->eax == e2->eax && e1->ebx == e2->ebx &&
e1->ecx == e2->ecx && e1->edx == e2->edx,
"CPUID 0x%x.%x differ: 0x%x:0x%x:0x%x:0x%x vs 0x%x:0x%x:0x%x:0x%x",
e1->function, e1->index,
e1->eax, e1->ebx, e1->ecx, e1->edx,
e2->eax, e2->ebx, e2->ecx, e2->edx);
}
}
static void run_vcpu(struct kvm_vcpu *vcpu, int stage)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment