Skip to content

Commit c747293

Browse files
mdouchametan-ucw
authored andcommitted
KVM: Allow expected KVM_RUN errors in tst_kvm_run_instance()
Add a new parameter to tst_kvm_run_instance() for expected errno value, e.g. EINTR for testing the possiblity to kill running guest. When ioctl(KVM_RUN) fails with the expected errno, tst_kvm_run_instance() will return -1 without terminating the test. Default tst_kvm_run() function expects no KVM_RUN errors. Signed-off-by: Martin Doucha <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 2bf77a4 commit c747293

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

doc/kvm-test-api.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ previously allocated guarded buffers.
194194
with at least `ram_size` bytes of memory. The VM instance info will be
195195
stored in `inst`.
196196

197-
- `void tst_kvm_run_instance(struct tst_kvm_instance *inst)` – Executes
198-
the program installed in KVM virtual machine `inst`. Any result messages
199-
returned by the VM will be automatically printed to controller program output.
197+
- `int tst_kvm_run_instance(struct tst_kvm_instance *inst, int exp_errno)` –
198+
Executes the program installed in KVM virtual machine `inst`. Any result
199+
messages returned by the VM will be automatically printed to controller
200+
program output. Returns zero. If `exp_errno` is non-zero, the VM execution
201+
syscall is allowed to fail with the `exp_errno` error code and
202+
`tst_kvm_run_instance()` will return -1 instead of terminating the test.
200203

201204
- `void tst_kvm_destroy_instance(struct tst_kvm_instance *inst)` – Deletes
202205
the KVM virtual machine `inst`. Note that the guarded buffers assigned

testcases/kernel/kvm/include/kvm_host.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ struct kvm_cpuid2 *tst_kvm_get_cpuid(int sysfd);
125125
void tst_kvm_create_instance(struct tst_kvm_instance *inst, size_t ram_size);
126126

127127
/*
128-
* Execute the given KVM instance and print results.
128+
* Execute the given KVM instance and print results. If ioctl(KVM_RUN) is
129+
* expected to fail, pass the expected error code in exp_errno, otherwise
130+
* set it to zero. Returns last value returned by ioctl(KVM_RUN).
129131
*/
130-
void tst_kvm_run_instance(struct tst_kvm_instance *inst);
132+
int tst_kvm_run_instance(struct tst_kvm_instance *inst, int exp_errno);
131133

132134
/*
133135
* Close the given KVM instance.

testcases/kernel/kvm/lib_host.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,28 @@ void tst_kvm_create_instance(struct tst_kvm_instance *inst, size_t ram_size)
234234
inst->result->message[0] = '\0';
235235
}
236236

237-
void tst_kvm_run_instance(struct tst_kvm_instance *inst)
237+
int tst_kvm_run_instance(struct tst_kvm_instance *inst, int exp_errno)
238238
{
239239
struct kvm_regs regs;
240+
int ret;
240241

241242
while (1) {
242243
inst->result->result = KVM_TNONE;
243244
inst->result->message[0] = '\0';
244-
SAFE_IOCTL(inst->vcpu_fd, KVM_RUN, 0);
245+
errno = 0;
246+
ret = ioctl(inst->vcpu_fd, KVM_RUN, 0);
247+
248+
if (ret == -1) {
249+
if (errno == exp_errno)
250+
return ret;
251+
252+
tst_brk(TBROK | TERRNO, "ioctl(KVM_RUN) failed");
253+
}
254+
255+
if (ret < 0) {
256+
tst_brk(TBROK | TERRNO,
257+
"Invalid ioctl(KVM_RUN) return value %d", ret);
258+
}
245259

246260
if (inst->vcpu_info->exit_reason != KVM_EXIT_HLT) {
247261
SAFE_IOCTL(inst->vcpu_fd, KVM_GET_REGS, &regs);
@@ -255,6 +269,8 @@ void tst_kvm_run_instance(struct tst_kvm_instance *inst)
255269

256270
tst_kvm_print_result(inst);
257271
}
272+
273+
return ret;
258274
}
259275

260276
void tst_kvm_destroy_instance(struct tst_kvm_instance *inst)
@@ -280,7 +296,7 @@ void tst_kvm_setup(void)
280296
void tst_kvm_run(void)
281297
{
282298
tst_kvm_create_instance(&test_vm, DEFAULT_RAM_SIZE);
283-
tst_kvm_run_instance(&test_vm);
299+
tst_kvm_run_instance(&test_vm, 0);
284300
tst_kvm_destroy_instance(&test_vm);
285301
tst_free_all();
286302
}

0 commit comments

Comments
 (0)