kvm selftests and MAX_VCPU_ID
Subsystems (4)
cover kvm selftests and MAX_VCPU_ID
I've been experimenting with the kvm selftests to see if I can enable them for powerpc and get some useful coverage going.
This series is just the initial boilerplate to get the simplest of the tests to run. The test is arch agnostic and is already in the tree. It just tries to start a vm with the maximum number of vcpus. It fails on a P9:
$ cd tools/selftests/kvm
$ make ARCH=powerpc
$ ulimit -n
4096
$ ./kvm_create_max_vcpus
KVM_CAP_MAX_VCPU_ID: 16384
KVM_CAP_MAX_VCPUS: 2048
Testing creating 2048 vCPUs, with IDs 0...2047.
Testing creating 2048 vCPUs, with IDs 14336...16383.
== Test Assertion Failure ==
lib/kvm_util.c:983: vcpu->fd >= 0
pidt066 tidt066 - Invalid argument
1 0x0000000010002813: vm_vcpu_add at kvm_util.c:982
2 0x000000001000176f: test_vcpu_creation at kvm_create_max_vcpus.c:34 (discriminator 3)
3 0x00000000100014e7: main at kvm_create_max_vcpus.c:62
4 0x00007fff89454077: ?? ??:0
5 0x00007fff89454263: ?? ??:0
KVM_CREATE_VCPU failed, rc: -1 errno: 22The second patch is my attempt at improving the situation which, admittedly, is mostly harmless, caused by the fact that KVM_MAX_VCPU_IDS is set to a large value that is not always supported by P9 so KVM HV aborts with -EINVAL.
I intended to get this first patch/test to work before implementing the rest of the selftest infrastructure and adding more tests so I thought it would be best to get some feedback before I delve in too deep.
Fabiano Rosas (2):
KVM: selftests: Add max vcpus test for ppc64le
KVM: PPC: Book3S HV: Provide a more accurate MAX_VCPU_ID in P9
arch/powerpc/kvm/powerpc.c | 5 ++- tools/testing/selftests/kvm/Makefile | 7 +++ .../testing/selftests/kvm/include/kvm_util.h | 7 +++ .../selftests/kvm/include/powerpc/processor.h | 7 +++ tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++ .../selftests/kvm/lib/powerpc/processor.c | 44 +++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/include/powerpc/processor.h create mode 100644 tools/testing/selftests/kvm/lib/powerpc/processor.c
--
2.29.2
RFC PATCH 1/2 KVM: selftests: Add max vcpus test for ppc64le
$ cd tools/selftests/kvm $ make ARCH=powerpc $ ulimit -n 4096 $ ./kvm_create_max_vcpus
Note the test currently fails in P9 with:
KVM_CAP_MAX_VCPU_ID: 16384KVM_CAP_MAX_VCPUS: 2048
Testing creating 2048 vCPUs, with IDs 0...2047. Testing creating 2048 vCPUs, with IDs 14336...16383. == Test Assertion Failure ==
lib/kvm_util.c:983: vcpu->fd >= 0
pidt066 tidt066 - Invalid argument
1 0x0000000010002813: vm_vcpu_add at kvm_util.c:982
2 0x000000001000176f: test_vcpu_creation at
kvm_create_max_vcpus.c:34 (discriminator 3)
3 0x00000000100014e7: main at kvm_create_max_vcpus.c:62
4 0x00007fff89454077: ?? ??:0
5 0x00007fff89454263: ?? ??:0 KVM_CREATE_VCPU failed, rc: -1 errno: 22
Signed-off-by Fabiano Rosas <[email protected]>
--- tools/testing/selftests/kvm/Makefile | 7 +++ .../testing/selftests/kvm/include/kvm_util.h | 7 +++ .../selftests/kvm/include/powerpc/processor.h | 7 +++ tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++ .../selftests/kvm/lib/powerpc/processor.c | 44 +++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/powerpc/processor.h create mode 100644 tools/testing/selftests/kvm/lib/powerpc/processor.c
tools/testing/selftests/kvm/Makefile +7 -0
@@ -33,10 +33,15 @@ ifeq ($(ARCH),s390) UNAME_M := s390x endif +ifeq ($(ARCH),powerpc) + UNAME_M := powerpc +endif + LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c +LIBKVM_powerpc = lib/powerpc/processor.c TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features
@@ -93,6 +98,8 @@ TEST_GEN_PROGS_s390x += dirty_log_test TEST_GEN_PROGS_s390x += kvm_create_max_vcpus TEST_GEN_PROGS_s390x += set_memory_region_test +TEST_GEN_PROGS_powerpc += kvm_create_max_vcpus + TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) LIBKVM += $(LIBKVM_$(UNAME_M))
tools/testing/selftests/kvm/include/kvm_util.h +7 -0
@@ -43,6 +43,7 @@ enum vm_guest_mode {VM_MODE_P40V48_4K ,VM_MODE_P40V48_64K ,VM_MODE_PXXV48_4K ,/* For 48bits VA but ANY bits PA */ +VM_MODE_P51V52_64K ,/* ???: include/asm/book3s/64/pgtable.h says P53 */ NUM_VM_MODES, };
@@ -64,6 +65,12 @@ enum vm_guest_mode {#define MIN_PAGE_SHIFT 12U#define ptes_per_page (page_size) ((page_size) / 16) +#elif defined(__powerpc__) + +#define VM_MODE_DEFAULT VM_MODE_P51V52_64K +#define MIN_PAGE_SHIFT 16U +#define ptes_per_page (page_size) ((page_size) / 8) +#endif #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT)
tools/testing/selftests/kvm/include/powerpc/processor.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* powerpc processor specific defines +*/ +#ifndef SELFTEST_KVM_PROCESSOR_H +#define SELFTEST_KVM_PROCESSOR_H +#endif
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
@@ -151,6 +151,7 @@ const char * const vm_guest_mode_string[] = {"PA-bits:40, VA-bits:48, 4K pages" ,"PA-bits:40, VA-bits:48, 64K pages" ,"PA-bits:ANY, VA-bits:48, 4K pages" , +"PA-bits:51, VA-bits:52, 64K pages" , }; _Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) = NUM_VM_MODES,"Missing new mode strings?" );
@@ -163,6 +164,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { { 40, 48, 0x1000, 12 }, { 40, 48, 0x10000, 16 }, { 0, 0, 0x1000, 12 }, + { 51, 52, 0x10000, 16 }, }; _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) = NUM_VM_MODES,"Missing new mode params?" );
@@ -246,6 +248,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)TEST_FAIL ("VM_MODE_PXXV48_4K not supported on non-x86 platforms" );#endif break ; +case VM_MODE_P51V52_64K : + vm->pgtable_levels =4 ; +break ;default :TEST_FAIL ("Unknown guest mode, mode: 0x%x" , mode); }
tools/testing/selftests/kvm/lib/powerpc/processor.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.29.2
RFC PATCH 2/2 KVM: PPC: Book3S HV: Provide a more accurate MAX_VCPU_ID in P9
In reply to Fabiano RosasThe KVM_CAP_MAX_VCPU_ID capability was added by commit 0b1b1dfd52a6 ("kvm: introduce KVM_MAX_VCPU_ID") to allow for vcpu ids larger than KVM_MAX_VCPU in powerpc.
For a P9 host we depend on the guest VSMT value to know what is the maximum number of vcpu id we can support:
kvmppc_core_vcpu_create_hv:
(...)
if (cpu_has_feature(CPU_FTR_ARCH_300)) {
--> if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) {
pr_devel("KVM: VCPU ID too high\n");
core = KVM_MAX_VCORES;
} else {
BUG_ON(kvm->arch.smt_mode != 1);
core = kvmppc_pack_vcpu_id(kvm, id);
}
} else {
core = id / kvm->arch.smt_mode;
}which means that the value being returned by the capability today for a given guest is potentially way larger than what we actually support:
\#define KVM_MAX_VCPU_ID (MAX_SMT_THREADS * KVM_MAX_VCORES)
If the capability is queried before userspace enables the KVM_CAP_PPC_SMT ioctl there is not much we can do, but if the emulated smt mode is already known we could provide a more accurate value.
The only practical effect of this change today is to make the kvm_create_max_vcpus test pass for powerpc. The QEMU spapr machine has a lower max vcpu than what KVM allows so even KVM_MAX_VCPU is not reached.
---
I see that for ppc, QEMU uses the capability after enabling KVM_CAP_PPC_SMT, so we could change QEMU to issue the check extension on the vm fd so that it would get the more accurate value.
--- arch/powerpc/kvm/powerpc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kvm/powerpc.c +4 -1
@@ -649,7 +649,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =KVM_MAX_VCPUS ;break ;case KVM_CAP_MAX_VCPU_ID : - r =KVM_MAX_VCPU_ID ; +if (hv_enabled &&cpu_has_feature (CPU_FTR_ARCH_300 )) + r =KVM_MAX_VCPUS * ((kvm) ? kvm->arch.emul_smt_mode :1 ); +else + r =KVM_MAX_VCPU_ID ;break ;#ifdef CONFIG_PPC_BOOK3S_64 case KVM_CAP_PPC_GET_SMMU_INFO :
Signature · 1 line
2.29.2
Re: [RFC PATCH 2/2] KVM: PPC: Book3S HV: Provide a more accurate MAX_VCPU_ID in P9
Le 13/04/2021 à 00:26, Fabiano Rosas a écrit :
Quoted 30 lines
The
KVM_CAP_MAX_VCPU_IDcapability was added by commit0b1b1dfd52a6("kvm: introduceKVM_MAX_VCPU_ID") to allow for vcpu ids larger thanKVM_MAX_VCPUin powerpc.For a P9 host we depend on the guest VSMT value to know what is the maximum number of vcpu id we can support:
kvmppc_core_vcpu_create_hv:(...) if (cpu_has_feature(CPU_FTR_ARCH_300)) { --> if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) { pr_devel("KVM: VCPU ID too high\n"); core = KVM_MAX_VCORES; } else { BUG_ON(kvm->arch.smt_mode != 1); core = kvmppc_pack_vcpu_id(kvm, id); } } else { core = id / kvm->arch.smt_mode; }which means that the value being returned by the capability today for a given guest is potentially way larger than what we actually support:
\#define
KVM_MAX_VCPU_ID(MAX_SMT_THREADS*KVM_MAX_VCORES)If the capability is queried before userspace enables the
KVM_CAP_PPC_SMTioctl there is not much we can do, but if the emulated smt mode is already known we could provide a more accurate value.
Quoted 6 lines
The only practical effect of this change today is to make the
kvm_create_max_vcpustest pass for powerpc. The QEMU spapr machine has a lower max vcpu than what KVM allows so evenKVM_MAX_VCPUis not reached.Signed-off-by Fabiano Rosas <[email protected]>
This patch won't apply after commit a1c42ddedf35 ("kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS")
Feel free to resubmit if still applicable.
Christsophe
Quoted 25 lines
---
I see that for ppc, QEMU uses the capability after enablingKVM_CAP_PPC_SMT, so we could change QEMU to issue the check extension on the vm fd so that it would get the more accurate value.--- arch/powerpc/kvm/powerpc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/powerpc/kvm/powerpc.c +4
-1@@ -649,7 +649,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =KVM_MAX_VCPUS ;break ;case KVM_CAP_MAX_VCPU_ID : - r =KVM_MAX_VCPU_ID ; +if (hv_enabled &&cpu_has_feature (CPU_FTR_ARCH_300 )) + r =KVM_MAX_VCPUS * ((kvm) ? kvm->arch.emul_smt_mode :1 ); +else + r =KVM_MAX_VCPU_ID ;break ;#ifdef CONFIG_PPC_BOOK3S_64 case KVM_CAP_PPC_GET_SMMU_INFO :
Re: [RFC PATCH 2/2] KVM: PPC: Book3S HV: Provide a more accurate MAX_VCPU_ID in P9
Quoted 36 lines · Christophe Leroy
Le 13/04/2021 à 00:26, Fabiano Rosas a écrit :
Quoted 35 lines
The
KVM_CAP_MAX_VCPU_IDcapability was added by commit0b1b1dfd52a6("kvm: introduceKVM_MAX_VCPU_ID") to allow for vcpu ids larger thanKVM_MAX_VCPUin powerpc.For a P9 host we depend on the guest VSMT value to know what is the maximum number of vcpu id we can support:
kvmppc_core_vcpu_create_hv:(...) if (cpu_has_feature(CPU_FTR_ARCH_300)) { --> if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) { pr_devel("KVM: VCPU ID too high\n"); core = KVM_MAX_VCORES; } else { BUG_ON(kvm->arch.smt_mode != 1); core = kvmppc_pack_vcpu_id(kvm, id); } } else { core = id / kvm->arch.smt_mode; }which means that the value being returned by the capability today for a given guest is potentially way larger than what we actually support:
\#define
KVM_MAX_VCPU_ID(MAX_SMT_THREADS*KVM_MAX_VCORES)If the capability is queried before userspace enables the
KVM_CAP_PPC_SMTioctl there is not much we can do, but if the emulated smt mode is already known we could provide a more accurate value.The only practical effect of this change today is to make the
kvm_create_max_vcpustest pass for powerpc. The QEMU spapr machine has a lower max vcpu than what KVM allows so evenKVM_MAX_VCPUis not reached.
Quoted 6 lines
Quoted 1 line
Signed-off-by Fabiano Rosas <[email protected]>This patch won't apply after commit
a1c42ddedf35("kvm: renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDS")Feel free to resubmit if still applicable.
Thanks for the reminder, Christophe.
I was focusing on enabling the rest of the kvm-selftests:
https://lore.kernel.org/r/[email protected]
I'm preparing a v2 for that series and will try to include these patches as well.