Skip to content

Commit ffb4ce3

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
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 <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9e1ff30 commit ffb4ce3

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

tools/testing/selftests/kvm/memslot_perf_test.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,43 +127,54 @@ static bool verbose;
127127
pr_info(__VA_ARGS__); \
128128
} while (0)
129129

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+
130142
static void *vcpu_worker(void *data)
131143
{
132144
struct vm_data *vm = data;
133145
struct kvm_run *run;
134146
struct ucall uc;
135-
uint64_t cmd;
136147

137148
run = vcpu_state(vm->vm, VCPU_ID);
138149
while (1) {
139150
vcpu_run(vm->vm, VCPU_ID);
140151

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]);
146157
sem_post(&vcpu_ready);
147158
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;
151164
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+
}
161175
}
162176

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:
167178
return NULL;
168179
}
169180

@@ -268,6 +279,7 @@ static bool prepare_vm(struct vm_data *data, int nslots, uint64_t *maxslots,
268279
TEST_ASSERT(data->hva_slots, "malloc() fail");
269280

270281
data->vm = vm_create_default(VCPU_ID, mempages, guest_code);
282+
ucall_init(data->vm, NULL);
271283

272284
pr_info_v("Adding slots 1..%i, each slot with %"PRIu64" pages + %"PRIu64" extra pages last\n",
273285
max_mem_slots - 1, data->pages_per_slot, rempages);

0 commit comments

Comments
 (0)