diff options
author | Vitaly Kuznetsov <vkuznets@redhat.com> | 2019-10-08 15:43:37 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-10-22 07:31:16 -0400 |
commit | 9143613ef0ba9f88d2fef9038930637a0909d35a (patch) | |
tree | 459a449bd9f6747d5eeaa598ca032ac6f0e04ea5 /tools/testing/selftests | |
parent | 700c17d9cec8712f4091692488fb63e2680f7a5d (diff) |
selftests: kvm: consolidate VMX support checks
vmx_* tests require VMX and three of them implement the same check. Move it
to vmx library.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests')
5 files changed, 15 insertions, 15 deletions
diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h index 6ae5a47fe067..f52e0ba84fed 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h | |||
@@ -580,6 +580,8 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx); | |||
580 | void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp); | 580 | void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp); |
581 | bool load_vmcs(struct vmx_pages *vmx); | 581 | bool load_vmcs(struct vmx_pages *vmx); |
582 | 582 | ||
583 | void nested_vmx_check_supported(void); | ||
584 | |||
583 | void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, | 585 | void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, |
584 | uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot); | 586 | uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot); |
585 | void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm, | 587 | void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm, |
diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c index fab8f6b0bf52..f6ec97b7eaef 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c | |||
@@ -376,6 +376,16 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp) | |||
376 | init_vmcs_guest_state(guest_rip, guest_rsp); | 376 | init_vmcs_guest_state(guest_rip, guest_rsp); |
377 | } | 377 | } |
378 | 378 | ||
379 | void nested_vmx_check_supported(void) | ||
380 | { | ||
381 | struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); | ||
382 | |||
383 | if (!(entry->ecx & CPUID_VMX)) { | ||
384 | fprintf(stderr, "nested VMX not enabled, skipping test\n"); | ||
385 | exit(KSFT_SKIP); | ||
386 | } | ||
387 | } | ||
388 | |||
379 | void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, | 389 | void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, |
380 | uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot) | 390 | uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot) |
381 | { | 391 | { |
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c index 3b0ffe01dacd..5dfb53546a26 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c | |||
@@ -53,12 +53,8 @@ static void l1_guest_code(struct vmx_pages *vmx_pages) | |||
53 | int main(int argc, char *argv[]) | 53 | int main(int argc, char *argv[]) |
54 | { | 54 | { |
55 | vm_vaddr_t vmx_pages_gva; | 55 | vm_vaddr_t vmx_pages_gva; |
56 | struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); | ||
57 | 56 | ||
58 | if (!(entry->ecx & CPUID_VMX)) { | 57 | nested_vmx_check_supported(); |
59 | fprintf(stderr, "nested VMX not enabled, skipping test\n"); | ||
60 | exit(KSFT_SKIP); | ||
61 | } | ||
62 | 58 | ||
63 | vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code); | 59 | vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code); |
64 | vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); | 60 | vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); |
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index a6d85614ae4d..9ef7fab39d48 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c | |||
@@ -224,7 +224,6 @@ int main(int argc, char *argv[]) | |||
224 | { | 224 | { |
225 | struct kvm_vm *vm; | 225 | struct kvm_vm *vm; |
226 | struct kvm_nested_state state; | 226 | struct kvm_nested_state state; |
227 | struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); | ||
228 | 227 | ||
229 | have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS); | 228 | have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS); |
230 | 229 | ||
@@ -237,10 +236,7 @@ int main(int argc, char *argv[]) | |||
237 | * AMD currently does not implement set_nested_state, so for now we | 236 | * AMD currently does not implement set_nested_state, so for now we |
238 | * just early out. | 237 | * just early out. |
239 | */ | 238 | */ |
240 | if (!(entry->ecx & CPUID_VMX)) { | 239 | nested_vmx_check_supported(); |
241 | fprintf(stderr, "nested VMX not enabled, skipping test\n"); | ||
242 | exit(KSFT_SKIP); | ||
243 | } | ||
244 | 240 | ||
245 | vm = vm_create_default(VCPU_ID, 0, 0); | 241 | vm = vm_create_default(VCPU_ID, 0, 0); |
246 | 242 | ||
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c index f36c10eba71e..5590fd2bcf87 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | |||
@@ -128,12 +128,8 @@ static void report(int64_t val) | |||
128 | int main(int argc, char *argv[]) | 128 | int main(int argc, char *argv[]) |
129 | { | 129 | { |
130 | vm_vaddr_t vmx_pages_gva; | 130 | vm_vaddr_t vmx_pages_gva; |
131 | struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); | ||
132 | 131 | ||
133 | if (!(entry->ecx & CPUID_VMX)) { | 132 | nested_vmx_check_supported(); |
134 | fprintf(stderr, "nested VMX not enabled, skipping test\n"); | ||
135 | exit(KSFT_SKIP); | ||
136 | } | ||
137 | 133 | ||
138 | vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code); | 134 | vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code); |
139 | vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); | 135 | vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); |