Skip to contentSkip to conversation

KVM: s390: selftests: CMMA: don't run if CMMA not supported

PATCH In review Nico Boehr 2 participants 2 messages Jun 6, 2023 – Jun 13, 2023

Subsystems (3)
lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

PATCH 1/1 KVM: s390: selftests: CMMA: don't run if CMMA not supported

The test at hand queried whether the kernel supports CMMA, but in addition machine support is required.

Add a check whether the machine supports CMMA.

This fixes the test under G3 (z/VM, KVM).

---
 tools/testing/selftests/kvm/s390x/cmma_test.c | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/kvm/s390x/cmma_test.c +20 -0
index 6d0751ea224b..1d73e78e8fa7 100644
@@ -660,12 +660,32 @@ struct testdef {
 	{ "GET_CMMA_BITS: holes are skipped", test_get_skip_holes },
 };
 
+/**
+ * The kernel may support CMMA, but the machine may not (i.e. if running as
+ * guest-3).
+ *
+ * In this case, the CMMA capabilities are all there, but the CMMA-related
+ * ioctls fail. To find out whether the machine supports CMMA, create a
+ * temporary VM and then query the CMMA feature of the VM.
+ */
+static int machine_has_cmma(void)
+{
+	struct kvm_vm *vm = create_vm();
+	int r;
+
+	r = !__kvm_has_device_attr(vm->fd, KVM_S390_VM_MEM_CTRL, KVM_S390_VM_MEM_ENABLE_CMMA);
+	kvm_vm_free(vm);
+
+	return r;
+}
+
 int main(int argc, char *argv[])
 {
 	int idx;
 
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_SYNC_REGS));
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_CMMA_MIGRATION));
+	TEST_REQUIRE(machine_has_cmma());
 
 	ksft_print_header();
 
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Tue, 6 Jun 2023 17:05:10 +0200 Nico Boehr <[email protected]> wrote:

The test at hand queried whether the kernel supports CMMA, but in addition machine support is required.

Add a check whether the machine supports CMMA.

This fixes the test under G3 (z/VM, KVM).

Quoted 41 lines
---
 tools/testing/selftests/kvm/s390x/cmma_test.c | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/kvm/s390x/cmma_test.c +20 -0
index 6d0751ea224b..1d73e78e8fa7 100644
@@ -660,12 +660,32 @@ struct testdef {
 	{ "GET_CMMA_BITS: holes are skipped", test_get_skip_holes },
 };
 
+/**
+ * The kernel may support CMMA, but the machine may not (i.e. if running as
+ * guest-3).
+ *
+ * In this case, the CMMA capabilities are all there, but the CMMA-related
+ * ioctls fail. To find out whether the machine supports CMMA, create a
+ * temporary VM and then query the CMMA feature of the VM.
+ */
+static int machine_has_cmma(void)
+{
+	struct kvm_vm *vm = create_vm();
+	int r;
+
+	r = !__kvm_has_device_attr(vm->fd, KVM_S390_VM_MEM_CTRL, KVM_S390_VM_MEM_ENABLE_CMMA);
+	kvm_vm_free(vm);
+
+	return r;
+}
+
 int main(int argc, char *argv[])
 {
 	int idx;
 
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_SYNC_REGS));
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_CMMA_MIGRATION));
+	TEST_REQUIRE(machine_has_cmma());
 
 	ksft_print_header();