Commit fb0cb6a8 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

KVM: selftests: update hyperv_cpuid with SynDBG tests

Update tests to reflect new CPUID capabilities with SYNDBG.
Check that we get the right number of entries and that
0x40000000.EAX always returns the correct max leaf.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarJon Doron <arilou@gmail.com>
Message-Id: <20200529134543.1127440-7-arilou@gmail.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent b187038b
...@@ -26,18 +26,18 @@ static void guest_code(void) ...@@ -26,18 +26,18 @@ static void guest_code(void)
{ {
} }
static int smt_possible(void) static bool smt_possible(void)
{ {
char buf[16]; char buf[16];
FILE *f; FILE *f;
bool res = 1; bool res = true;
f = fopen("/sys/devices/system/cpu/smt/control", "r"); f = fopen("/sys/devices/system/cpu/smt/control", "r");
if (f) { if (f) {
if (fread(buf, sizeof(*buf), sizeof(buf), f) > 0) { if (fread(buf, sizeof(*buf), sizeof(buf), f) > 0) {
if (!strncmp(buf, "forceoff", 8) || if (!strncmp(buf, "forceoff", 8) ||
!strncmp(buf, "notsupported", 12)) !strncmp(buf, "notsupported", 12))
res = 0; res = false;
} }
fclose(f); fclose(f);
} }
...@@ -46,29 +46,31 @@ static int smt_possible(void) ...@@ -46,29 +46,31 @@ static int smt_possible(void)
} }
static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries, static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries,
int evmcs_enabled) bool evmcs_enabled)
{ {
int i; int i;
int nent = 9;
u32 test_val;
if (!evmcs_enabled) if (evmcs_enabled)
TEST_ASSERT(hv_cpuid_entries->nent == 6, nent += 1; /* 0x4000000A */
"KVM_GET_SUPPORTED_HV_CPUID should return 6 entries"
" when Enlightened VMCS is disabled (returned %d)", TEST_ASSERT(hv_cpuid_entries->nent == nent,
hv_cpuid_entries->nent); "KVM_GET_SUPPORTED_HV_CPUID should return %d entries"
else " with evmcs=%d (returned %d)",
TEST_ASSERT(hv_cpuid_entries->nent == 7, nent, evmcs_enabled, hv_cpuid_entries->nent);
"KVM_GET_SUPPORTED_HV_CPUID should return 7 entries"
" when Enlightened VMCS is enabled (returned %d)",
hv_cpuid_entries->nent);
for (i = 0; i < hv_cpuid_entries->nent; i++) { for (i = 0; i < hv_cpuid_entries->nent; i++) {
struct kvm_cpuid_entry2 *entry = &hv_cpuid_entries->entries[i]; struct kvm_cpuid_entry2 *entry = &hv_cpuid_entries->entries[i];
TEST_ASSERT((entry->function >= 0x40000000) && TEST_ASSERT((entry->function >= 0x40000000) &&
(entry->function <= 0x4000000A), (entry->function <= 0x40000082),
"function %x is our of supported range", "function %x is our of supported range",
entry->function); entry->function);
TEST_ASSERT(evmcs_enabled || (entry->function != 0x4000000A),
"0x4000000A leaf should not be reported");
TEST_ASSERT(entry->index == 0, TEST_ASSERT(entry->index == 0,
".index field should be zero"); ".index field should be zero");
...@@ -78,12 +80,23 @@ static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries, ...@@ -78,12 +80,23 @@ static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries,
TEST_ASSERT(!entry->padding[0] && !entry->padding[1] && TEST_ASSERT(!entry->padding[0] && !entry->padding[1] &&
!entry->padding[2], "padding should be zero"); !entry->padding[2], "padding should be zero");
if (entry->function == 0x40000004) { switch (entry->function) {
int nononarchcs = !!(entry->eax & (1UL << 18)); case 0x40000000:
test_val = 0x40000082;
TEST_ASSERT(entry->eax == test_val,
"Wrong max leaf report in 0x40000000.EAX: %x"
" (evmcs=%d)",
entry->eax, evmcs_enabled
);
break;
case 0x40000004:
test_val = entry->eax & (1UL << 18);
TEST_ASSERT(nononarchcs == !smt_possible(), TEST_ASSERT(!!test_val == !smt_possible(),
"NoNonArchitecturalCoreSharing bit" "NoNonArchitecturalCoreSharing bit"
" doesn't reflect SMT setting"); " doesn't reflect SMT setting");
break;
} }
/* /*
...@@ -133,8 +146,9 @@ struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(struct kvm_vm *vm) ...@@ -133,8 +146,9 @@ struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(struct kvm_vm *vm)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct kvm_vm *vm; struct kvm_vm *vm;
int rv; int rv, stage;
struct kvm_cpuid2 *hv_cpuid_entries; struct kvm_cpuid2 *hv_cpuid_entries;
bool evmcs_enabled;
/* Tell stdout not to buffer its content */ /* Tell stdout not to buffer its content */
setbuf(stdout, NULL); setbuf(stdout, NULL);
...@@ -145,36 +159,31 @@ int main(int argc, char *argv[]) ...@@ -145,36 +159,31 @@ int main(int argc, char *argv[])
exit(KSFT_SKIP); exit(KSFT_SKIP);
} }
/* Create VM */ for (stage = 0; stage < 3; stage++) {
vm = vm_create_default(VCPU_ID, 0, guest_code); evmcs_enabled = false;
vm = vm_create_default(VCPU_ID, 0, guest_code);
switch (stage) {
case 0:
test_hv_cpuid_e2big(vm); test_hv_cpuid_e2big(vm);
continue;
hv_cpuid_entries = kvm_get_supported_hv_cpuid(vm); case 1:
if (!hv_cpuid_entries) break;
return 1; case 2:
test_hv_cpuid(hv_cpuid_entries, 0);
free(hv_cpuid_entries);
if (!kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { if (!kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) {
print_skip("Enlightened VMCS is unsupported"); print_skip("Enlightened VMCS is unsupported");
goto vm_free; continue;
} }
vcpu_enable_evmcs(vm, VCPU_ID); vcpu_enable_evmcs(vm, VCPU_ID);
evmcs_enabled = true;
break;
}
hv_cpuid_entries = kvm_get_supported_hv_cpuid(vm); hv_cpuid_entries = kvm_get_supported_hv_cpuid(vm);
if (!hv_cpuid_entries) test_hv_cpuid(hv_cpuid_entries, evmcs_enabled);
return 1;
test_hv_cpuid(hv_cpuid_entries, 1);
free(hv_cpuid_entries); free(hv_cpuid_entries);
vm_free:
kvm_vm_free(vm); kvm_vm_free(vm);
}
return 0; return 0;
} }
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