diff options
author | Aaron Lewis <aaronlewis@google.com> | 2019-05-02 14:31:59 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-05-08 08:02:12 -0400 |
commit | 4b350aebbec80c7846f2908acb695ef029a04f64 (patch) | |
tree | 65950f68a99bf8c10ad2f42ef04ac3cd0e23fea9 | |
parent | 648a93c82b46638f3372123a18f095ddabcfc657 (diff) |
tests: kvm: Add tests for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_CPU_ID
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | tools/testing/selftests/kvm/.gitignore | 1 | ||||
-rw-r--r-- | tools/testing/selftests/kvm/Makefile | 1 | ||||
-rw-r--r-- | tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c | 70 |
3 files changed, 72 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index 6027b5f3d72d..2a9209d18684 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore | |||
@@ -1,6 +1,7 @@ | |||
1 | /x86_64/cr4_cpuid_sync_test | 1 | /x86_64/cr4_cpuid_sync_test |
2 | /x86_64/evmcs_test | 2 | /x86_64/evmcs_test |
3 | /x86_64/hyperv_cpuid | 3 | /x86_64/hyperv_cpuid |
4 | /x86_64/kvm_create_max_vcpus | ||
4 | /x86_64/platform_info_test | 5 | /x86_64/platform_info_test |
5 | /x86_64/set_sregs_test | 6 | /x86_64/set_sregs_test |
6 | /x86_64/smm_test | 7 | /x86_64/smm_test |
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index f8588cca2bef..6b7b3617d25c 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile | |||
@@ -20,6 +20,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test | |||
20 | TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid | 20 | TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid |
21 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test | 21 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test |
22 | TEST_GEN_PROGS_x86_64 += x86_64/smm_test | 22 | TEST_GEN_PROGS_x86_64 += x86_64/smm_test |
23 | TEST_GEN_PROGS_x86_64 += x86_64/kvm_create_max_vcpus | ||
23 | TEST_GEN_PROGS_x86_64 += dirty_log_test | 24 | TEST_GEN_PROGS_x86_64 += dirty_log_test |
24 | TEST_GEN_PROGS_x86_64 += clear_dirty_log_test | 25 | TEST_GEN_PROGS_x86_64 += clear_dirty_log_test |
25 | 26 | ||
diff --git a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c new file mode 100644 index 000000000000..50e92996f918 --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * kvm_create_max_vcpus | ||
3 | * | ||
4 | * Copyright (C) 2019, Google LLC. | ||
5 | * | ||
6 | * This work is licensed under the terms of the GNU GPL, version 2. | ||
7 | * | ||
8 | * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. | ||
9 | */ | ||
10 | |||
11 | #define _GNU_SOURCE /* for program_invocation_short_name */ | ||
12 | #include <fcntl.h> | ||
13 | #include <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | #include <string.h> | ||
16 | |||
17 | #include "test_util.h" | ||
18 | |||
19 | #include "kvm_util.h" | ||
20 | #include "asm/kvm.h" | ||
21 | #include "linux/kvm.h" | ||
22 | |||
23 | void test_vcpu_creation(int first_vcpu_id, int num_vcpus) | ||
24 | { | ||
25 | struct kvm_vm *vm; | ||
26 | int i; | ||
27 | |||
28 | printf("Testing creating %d vCPUs, with IDs %d...%d.\n", | ||
29 | num_vcpus, first_vcpu_id, first_vcpu_id + num_vcpus - 1); | ||
30 | |||
31 | vm = vm_create(VM_MODE_P52V48_4K, DEFAULT_GUEST_PHY_PAGES, O_RDWR); | ||
32 | |||
33 | for (i = 0; i < num_vcpus; i++) { | ||
34 | int vcpu_id = first_vcpu_id + i; | ||
35 | |||
36 | /* This asserts that the vCPU was created. */ | ||
37 | vm_vcpu_add(vm, vcpu_id, 0, 0); | ||
38 | } | ||
39 | |||
40 | kvm_vm_free(vm); | ||
41 | } | ||
42 | |||
43 | int main(int argc, char *argv[]) | ||
44 | { | ||
45 | int kvm_max_vcpu_id = kvm_check_cap(KVM_CAP_MAX_VCPU_ID); | ||
46 | int kvm_max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); | ||
47 | |||
48 | printf("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id); | ||
49 | printf("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus); | ||
50 | |||
51 | /* | ||
52 | * Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID. | ||
53 | * Userspace is supposed to use KVM_CAP_MAX_VCPUS as the maximum ID | ||
54 | * in this case. | ||
55 | */ | ||
56 | if (!kvm_max_vcpu_id) | ||
57 | kvm_max_vcpu_id = kvm_max_vcpus; | ||
58 | |||
59 | TEST_ASSERT(kvm_max_vcpu_id >= kvm_max_vcpus, | ||
60 | "KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d).", | ||
61 | kvm_max_vcpu_id, kvm_max_vcpus); | ||
62 | |||
63 | test_vcpu_creation(0, kvm_max_vcpus); | ||
64 | |||
65 | if (kvm_max_vcpu_id > kvm_max_vcpus) | ||
66 | test_vcpu_creation( | ||
67 | kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus); | ||
68 | |||
69 | return 0; | ||
70 | } | ||