1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2022, Google LLC.
4 *
5 * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE.
6 */
7
8 #define _GNU_SOURCE /* for program_invocation_short_name */
9
10 #include "flds_emulation.h"
11
12 #include "test_util.h"
13
14 #define MMIO_GPA 0x700000000
15 #define MMIO_GVA MMIO_GPA
16
guest_code(void)17 static void guest_code(void)
18 {
19 /* Execute flds with an MMIO address to force KVM to emulate it. */
20 flds(MMIO_GVA);
21 GUEST_DONE();
22 }
23
main(int argc,char * argv[])24 int main(int argc, char *argv[])
25 {
26 struct kvm_vcpu *vcpu;
27 struct kvm_vm *vm;
28
29 TEST_REQUIRE(kvm_has_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE));
30
31 vm = vm_create_with_one_vcpu(&vcpu, guest_code);
32 vm_enable_cap(vm, KVM_CAP_EXIT_ON_EMULATION_FAILURE, 1);
33 virt_map(vm, MMIO_GVA, MMIO_GPA, 1);
34
35 vcpu_run(vcpu);
36 handle_flds_emulation_failure_exit(vcpu);
37 vcpu_run(vcpu);
38 TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);
39
40 kvm_vm_free(vm);
41 return 0;
42 }
43