Skip to contentSkip to conversation

KVM: selftests: enable the memslot tests in ARM64

PATCH Superseded Ricardo Koller 4 participants 11 messages Sep 3, 2021 – Sep 7, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover KVM: selftests: enable the memslot tests in ARM64

Enable memslot_modification_stress_test and memslot_perf_test in ARM64 (second patch). memslot_modification_stress_test builds and runs in aarch64 without any modification. memslot_perf_test needs some nits regarding ucalls (first patch).

Ricardo Koller (2):
KVM: selftests: make memslot_perf_test arch independent
KVM: selftests: build the memslot tests for arm64

 tools/testing/selftests/kvm/Makefile          |  2 +
 .../testing/selftests/kvm/memslot_perf_test.c | 56 +++++++++++--------
 2 files changed, 36 insertions(+), 22 deletions(-)
Signature · 1 line
2.33.0.153.gba50c8fa24-goog
#1 lore raw

PATCH 1/2 KVM: selftests: make memslot_perf_test arch independent

memslot_perf_test uses ucalls for synchronization between guest and host. Ucalls API is architecture independent: tests do not need know what kind of exit they generate on a specific arch. More specifically, there is no need to check whether an exit is KVM_EXIT_IO in x86 for the host to know that the exit is ucall related, as get_ucall() already makes that check.

Change memslot_perf_test to not require specifying what exit does a ucall generate. Also add a missing ucall_init.

---
 .../testing/selftests/kvm/memslot_perf_test.c | 56 +++++++++++--------
 1 file changed, 34 insertions(+), 22 deletions(-)
tools/testing/selftests/kvm/memslot_perf_test.c +34 -22
index d6e381e01db7..1727f75e0c2c 100644
@@ -127,43 +127,54 @@ static bool verbose;
 			pr_info(__VA_ARGS__);	\
 	} while (0)
 
+static void check_mmio_access(struct vm_data *vm, struct kvm_run *run)
+{
+	TEST_ASSERT(vm->mmio_ok, "Unexpected mmio exit");
+	TEST_ASSERT(run->mmio.is_write, "Unexpected mmio read");
+	TEST_ASSERT(run->mmio.len == 8,
+		    "Unexpected exit mmio size = %u", run->mmio.len);
+	TEST_ASSERT(run->mmio.phys_addr >= vm->mmio_gpa_min &&
+		    run->mmio.phys_addr <= vm->mmio_gpa_max,
+		    "Unexpected exit mmio address = 0x%llx",
+		    run->mmio.phys_addr);
+}
+
 static void *vcpu_worker(void *data)
 {
 	struct vm_data *vm = data;
 	struct kvm_run *run;
 	struct ucall uc;
-	uint64_t cmd;
 
 	run = vcpu_state(vm->vm, VCPU_ID);
 	while (1) {
 		vcpu_run(vm->vm, VCPU_ID);
 
-		if (run->exit_reason == KVM_EXIT_IO) {
-			cmd = get_ucall(vm->vm, VCPU_ID, &uc);
-			if (cmd != UCALL_SYNC)
-				break;
-
+		switch (get_ucall(vm->vm, VCPU_ID, &uc)) {
+		case UCALL_SYNC:
+			TEST_ASSERT(uc.args[1] == 0,
+				"Unexpected sync ucall, got %lx",
+				(ulong)uc.args[1]);
 			sem_post(&vcpu_ready);
 			continue;
-		}
-
-		if (run->exit_reason != KVM_EXIT_MMIO)
+		case UCALL_NONE:
+			if (run->exit_reason == KVM_EXIT_MMIO)
+				check_mmio_access(vm, run);
+			else
+				goto done;
 			break;
-
-		TEST_ASSERT(vm->mmio_ok, "Unexpected mmio exit");
-		TEST_ASSERT(run->mmio.is_write, "Unexpected mmio read");
-		TEST_ASSERT(run->mmio.len == 8,
-			    "Unexpected exit mmio size = %u", run->mmio.len);
-		TEST_ASSERT(run->mmio.phys_addr >= vm->mmio_gpa_min &&
-			    run->mmio.phys_addr <= vm->mmio_gpa_max,
-			    "Unexpected exit mmio address = 0x%llx",
-			    run->mmio.phys_addr);
+		case UCALL_ABORT:
+			TEST_FAIL("%s at %s:%ld, val = %lu",
+					(const char *)uc.args[0],
+					__FILE__, uc.args[1], uc.args[2]);
+			break;
+		case UCALL_DONE:
+			goto done;
+		default:
+			TEST_FAIL("Unknown ucall %lu", uc.cmd);
+		}
 	}
 
-	if (run->exit_reason == KVM_EXIT_IO && cmd == UCALL_ABORT)
-		TEST_FAIL("%s at %s:%ld, val = %lu", (const char *)uc.args[0],
-			  __FILE__, uc.args[1], uc.args[2]);
-
+done:
 	return NULL;
 }
 
@@ -268,6 +279,7 @@ static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots,
 	TEST_ASSERT(data->hva_slots, "malloc() fail");
 
 	data->vm = vm_create_default(VCPU_ID, mempages, guest_code);
+	ucall_init(data->vm, NULL);
 
 	pr_info_v("Adding slots 1..%i, each slot with %"PRIu64" pages + %"PRIu64" extra pages last\n",
 		max_mem_slots - 1, data->pages_per_slot, rempages);
Signature · 1 line
2.33.0.153.gba50c8fa24-goog
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] KVM: selftests: make memslot_perf_test arch independent

Quoted 7 lines · Ricardo Koller

memslot_perf_test uses ucalls for synchronization between guest and host. Ucalls API is architecture independent: tests do not need know what kind of exit they generate on a specific arch. More specifically, there is no need to check whether an exit is KVM_EXIT_IO in x86 for the host to know that the exit is ucall related, as get_ucall() already makes that check.

Quoted 8 lines

Change memslot_perf_test to not require specifying what exit does a ucall generate. Also add a missing ucall_init.

---
 .../testing/selftests/kvm/memslot_perf_test.c | 56 +++++++++++--------
 1 file changed, 34 insertions(+), 22 deletions(-)
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] KVM: selftests: make memslot_perf_test arch independent

In reply to Ricardo Koller
Quoted 7 lines · Ricardo Koller

memslot_perf_test uses ucalls for synchronization between guest and host. Ucalls API is architecture independent: tests do not need know what kind of exit they generate on a specific arch. More specifically, there is no need to check whether an exit is KVM_EXIT_IO in x86 for the host to know that the exit is ucall related, as get_ucall() already makes that check.

Quoted 5 lines

Change memslot_perf_test to not require specifying what exit does a ucall generate. Also add a missing ucall_init.

---

Thanks,
Maciej

Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] KVM: selftests: make memslot_perf_test arch independent

In reply to Ricardo Koller
Quoted 8 lines · Ricardo Koller

memslot_perf_test uses ucalls for synchronization between guest and host. Ucalls API is architecture independent: tests do not need know what kind of exit they generate on a specific arch. More specifically, there is no need to check whether an exit is KVM_EXIT_IO in x86 for the host to know that the exit is ucall related, as get_ucall() already makes that check.

Quoted 7 lines

Change memslot_perf_test to not require specifying what exit does a ucall generate. Also add a missing ucall_init.

---
 .../testing/selftests/kvm/memslot_perf_test.c | 56 +++++++++++--------
 1 file changed, 34 insertions(+), 22 deletions(-)
#5 lore raw

PATCH 2/2 KVM: selftests: build the memslot tests for arm64

In reply to Ricardo Koller

Add memslot_perf_test and memslot_modification_stress_test to the list of aarch64 selftests.

---
 tools/testing/selftests/kvm/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/Makefile +2 -0
index 5832f510a16c..e6e88575c40b 100644
@@ -84,6 +84,8 @@ TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
 
+TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
+TEST_GEN_PROGS_aarch64 += memslot_perf_test
 TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
 TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
Signature · 6 lines
2.33.0.153.gba50c8fa24-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#6 lore raw

Re: [PATCH 2/2] KVM: selftests: build the memslot tests for arm64

Quoted 13 lines · Ricardo Koller

Add memslot_perf_test and memslot_modification_stress_test to the list of aarch64 selftests.

---
 tools/testing/selftests/kvm/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/Makefile +0 -0
index 5832f510a16c..e6e88575c40b 100644

tools/testing/selftests/kvm/Makefile TEST_GEN_PROGS_x86_64 += set_memory_region_test · line 91

Quoted 8 lines
tools/testing/selftests/kvm/Makefile +2 -0
@@ -84,6 +84,8 @@ TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
 
+TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
+TEST_GEN_PROGS_aarch64 += memslot_perf_test
 TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
 TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_init

These tests need to be added below the aarch64/* tests and in alphabetical order.

Thanks,
drew

Quoted 3 lines
Signature · 1 line
2.33.0.153.gba50c8fa24-goog
#7 lore raw

Re: [PATCH 2/2] KVM: selftests: build the memslot tests for arm64

Quoted 17 lines · Andrew Jones
Quoted 16 lines · Ricardo Koller

Add memslot_perf_test and memslot_modification_stress_test to the list of aarch64 selftests.

---
 tools/testing/selftests/kvm/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/Makefile +0 -0
index 5832f510a16c..e6e88575c40b 100644
@@ -84,6 +84,8 @@ TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
 
Quoted 9 lines

tools/testing/selftests/kvm/Makefile TEST_GEN_PROGS_x86_64 += set_memory_region_test · line 91

Quoted 5 lines
tools/testing/selftests/kvm/Makefile +2 -0
+TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test
+TEST_GEN_PROGS_aarch64 += memslot_perf_test
 TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
 TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_init

These tests need to be added below the aarch64/* tests and in alphabetical order.

Sure, will fix this in v2.

Thanks,
Ricardo

Quoted 7 lines

Thanks,
drew

Quoted 3 lines
Signature · 1 line
2.33.0.153.gba50c8fa24-goog
Reviewed-by on v1 2/2
#9 lore raw

Re: [PATCH 2/2] KVM: selftests: build the memslot tests for arm64

In reply to Ricardo Koller

Ricardo,

Quoted 5 lines · Ricardo Koller

Add memslot_perf_test and memslot_modification_stress_test to the list of aarch64 selftests.

There isn't anything that prevents these tests from being used for s390x too right? Of course, we haven't anything to test on but just a thought.

Besides Drew's comments:

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

#10 lore raw

Re: [PATCH 2/2] KVM: selftests: build the memslot tests for arm64

Quoted 4 lines · Oliver Upton

Ricardo,

Quoted 1 line · Ricardo Koller
Quoted 8 lines
Quoted 4 lines

Add memslot_perf_test and memslot_modification_stress_test to the list of aarch64 selftests.

There isn't anything that prevents these tests from being used for s390x too right? Of course, we haven't anything to test on but just a thought.

Tbh I'm not sure. Will ask if somebody can try it in the cover letter for v2.

Thanks,
Ricardo

Quoted 4 lines

Besides Drew's comments: