From: Thomas Huth Date: Thu, 23 May 2019 16:43:09 +0000 (+0200) Subject: KVM: selftests: Move kvm_create_max_vcpus test to generic code X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=49fe9a5d16386310b15abcfe47343c26c3cc05f2;p=openwrt%2Fstaging%2Fblogic.git KVM: selftests: Move kvm_create_max_vcpus test to generic code There is nothing x86-specific in the test apart from the VM_MODE_P52V48_4K which we can now replace with VM_MODE_DEFAULT. Thus let's move the file to the main folder and enable it for aarch64 and s390x, too. Reviewed-by: Andrew Jones Reviewed-by: David Hildenbrand Signed-off-by: Thomas Huth Message-Id: <20190523164309.13345-10-thuth@redhat.com> Signed-off-by: Christian Borntraeger --- diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index ed8eb6007566..05a94a13a0a3 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -22,15 +22,17 @@ TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test TEST_GEN_PROGS_x86_64 += x86_64/smm_test -TEST_GEN_PROGS_x86_64 += x86_64/kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test +TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += dirty_log_test TEST_GEN_PROGS_x86_64 += clear_dirty_log_test TEST_GEN_PROGS_aarch64 += dirty_log_test TEST_GEN_PROGS_aarch64 += clear_dirty_log_test +TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus TEST_GEN_PROGS_s390x += s390x/sync_regs_test +TEST_GEN_PROGS_s390x += kvm_create_max_vcpus TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) LIBKVM += $(LIBKVM_$(UNAME_M)) diff --git a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c new file mode 100644 index 000000000000..db78ce07c416 --- /dev/null +++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * kvm_create_max_vcpus + * + * Copyright (C) 2019, Google LLC. + * + * This work is licensed under the terms of the GNU GPL, version 2. + * + * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. + */ + +#define _GNU_SOURCE /* for program_invocation_short_name */ +#include +#include +#include +#include + +#include "test_util.h" + +#include "kvm_util.h" +#include "asm/kvm.h" +#include "linux/kvm.h" + +void test_vcpu_creation(int first_vcpu_id, int num_vcpus) +{ + struct kvm_vm *vm; + int i; + + printf("Testing creating %d vCPUs, with IDs %d...%d.\n", + num_vcpus, first_vcpu_id, first_vcpu_id + num_vcpus - 1); + + vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR); + + for (i = 0; i < num_vcpus; i++) { + int vcpu_id = first_vcpu_id + i; + + /* This asserts that the vCPU was created. */ + vm_vcpu_add(vm, vcpu_id, 0, 0); + } + + kvm_vm_free(vm); +} + +int main(int argc, char *argv[]) +{ + int kvm_max_vcpu_id = kvm_check_cap(KVM_CAP_MAX_VCPU_ID); + int kvm_max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); + + printf("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id); + printf("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus); + + /* + * Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID. + * Userspace is supposed to use KVM_CAP_MAX_VCPUS as the maximum ID + * in this case. + */ + if (!kvm_max_vcpu_id) + kvm_max_vcpu_id = kvm_max_vcpus; + + TEST_ASSERT(kvm_max_vcpu_id >= kvm_max_vcpus, + "KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d).", + kvm_max_vcpu_id, kvm_max_vcpus); + + test_vcpu_creation(0, kvm_max_vcpus); + + if (kvm_max_vcpu_id > kvm_max_vcpus) + test_vcpu_creation( + kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus); + + return 0; +} 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 deleted file mode 100644 index 50e92996f918..000000000000 --- a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * kvm_create_max_vcpus - * - * Copyright (C) 2019, Google LLC. - * - * This work is licensed under the terms of the GNU GPL, version 2. - * - * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. - */ - -#define _GNU_SOURCE /* for program_invocation_short_name */ -#include -#include -#include -#include - -#include "test_util.h" - -#include "kvm_util.h" -#include "asm/kvm.h" -#include "linux/kvm.h" - -void test_vcpu_creation(int first_vcpu_id, int num_vcpus) -{ - struct kvm_vm *vm; - int i; - - printf("Testing creating %d vCPUs, with IDs %d...%d.\n", - num_vcpus, first_vcpu_id, first_vcpu_id + num_vcpus - 1); - - vm = vm_create(VM_MODE_P52V48_4K, DEFAULT_GUEST_PHY_PAGES, O_RDWR); - - for (i = 0; i < num_vcpus; i++) { - int vcpu_id = first_vcpu_id + i; - - /* This asserts that the vCPU was created. */ - vm_vcpu_add(vm, vcpu_id, 0, 0); - } - - kvm_vm_free(vm); -} - -int main(int argc, char *argv[]) -{ - int kvm_max_vcpu_id = kvm_check_cap(KVM_CAP_MAX_VCPU_ID); - int kvm_max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); - - printf("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id); - printf("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus); - - /* - * Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID. - * Userspace is supposed to use KVM_CAP_MAX_VCPUS as the maximum ID - * in this case. - */ - if (!kvm_max_vcpu_id) - kvm_max_vcpu_id = kvm_max_vcpus; - - TEST_ASSERT(kvm_max_vcpu_id >= kvm_max_vcpus, - "KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d).", - kvm_max_vcpu_id, kvm_max_vcpus); - - test_vcpu_creation(0, kvm_max_vcpus); - - if (kvm_max_vcpu_id > kvm_max_vcpus) - test_vcpu_creation( - kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus); - - return 0; -}