Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 to know
details like 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.

Signed-off-by: Ricardo Koller <ricarkol@google.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Oliver Upton <oupton@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210907180957.609966-2-ricarkol@google.com

authored by

Ricardo Koller and committed by
Marc Zyngier
ffb4ce3c 9e1ff307

+34 -22
+34 -22
tools/testing/selftests/kvm/memslot_perf_test.c
··· 127 127 pr_info(__VA_ARGS__); \ 128 128 } while (0) 129 129 130 + static void check_mmio_access(struct vm_data *vm, struct kvm_run *run) 131 + { 132 + TEST_ASSERT(vm->mmio_ok, "Unexpected mmio exit"); 133 + TEST_ASSERT(run->mmio.is_write, "Unexpected mmio read"); 134 + TEST_ASSERT(run->mmio.len == 8, 135 + "Unexpected exit mmio size = %u", run->mmio.len); 136 + TEST_ASSERT(run->mmio.phys_addr >= vm->mmio_gpa_min && 137 + run->mmio.phys_addr <= vm->mmio_gpa_max, 138 + "Unexpected exit mmio address = 0x%llx", 139 + run->mmio.phys_addr); 140 + } 141 + 130 142 static void *vcpu_worker(void *data) 131 143 { 132 144 struct vm_data *vm = data; 133 145 struct kvm_run *run; 134 146 struct ucall uc; 135 - uint64_t cmd; 136 147 137 148 run = vcpu_state(vm->vm, VCPU_ID); 138 149 while (1) { 139 150 vcpu_run(vm->vm, VCPU_ID); 140 151 141 - if (run->exit_reason == KVM_EXIT_IO) { 142 - cmd = get_ucall(vm->vm, VCPU_ID, &uc); 143 - if (cmd != UCALL_SYNC) 144 - break; 145 - 152 + switch (get_ucall(vm->vm, VCPU_ID, &uc)) { 153 + case UCALL_SYNC: 154 + TEST_ASSERT(uc.args[1] == 0, 155 + "Unexpected sync ucall, got %lx", 156 + (ulong)uc.args[1]); 146 157 sem_post(&vcpu_ready); 147 158 continue; 148 - } 149 - 150 - if (run->exit_reason != KVM_EXIT_MMIO) 159 + case UCALL_NONE: 160 + if (run->exit_reason == KVM_EXIT_MMIO) 161 + check_mmio_access(vm, run); 162 + else 163 + goto done; 151 164 break; 152 - 153 - TEST_ASSERT(vm->mmio_ok, "Unexpected mmio exit"); 154 - TEST_ASSERT(run->mmio.is_write, "Unexpected mmio read"); 155 - TEST_ASSERT(run->mmio.len == 8, 156 - "Unexpected exit mmio size = %u", run->mmio.len); 157 - TEST_ASSERT(run->mmio.phys_addr >= vm->mmio_gpa_min && 158 - run->mmio.phys_addr <= vm->mmio_gpa_max, 159 - "Unexpected exit mmio address = 0x%llx", 160 - run->mmio.phys_addr); 165 + case UCALL_ABORT: 166 + TEST_FAIL("%s at %s:%ld, val = %lu", 167 + (const char *)uc.args[0], 168 + __FILE__, uc.args[1], uc.args[2]); 169 + break; 170 + case UCALL_DONE: 171 + goto done; 172 + default: 173 + TEST_FAIL("Unknown ucall %lu", uc.cmd); 174 + } 161 175 } 162 176 163 - if (run->exit_reason == KVM_EXIT_IO && cmd == UCALL_ABORT) 164 - TEST_FAIL("%s at %s:%ld, val = %lu", (const char *)uc.args[0], 165 - __FILE__, uc.args[1], uc.args[2]); 166 - 177 + done: 167 178 return NULL; 168 179 } 169 180 ··· 279 268 TEST_ASSERT(data->hva_slots, "malloc() fail"); 280 269 281 270 data->vm = vm_create_default(VCPU_ID, mempages, guest_code); 271 + ucall_init(data->vm, NULL); 282 272 283 273 pr_info_v("Adding slots 1..%i, each slot with %"PRIu64" pages + %"PRIu64" extra pages last\n", 284 274 max_mem_slots - 1, data->pages_per_slot, rempages);