]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Convert triple_fault_event_test away from VCPU_ID
authorSean Christopherson <seanjc@google.com>
Wed, 1 Jun 2022 20:43:40 +0000 (13:43 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:47:08 +0000 (11:47 -0400)
Convert triple_fault_event_test to use vm_create_with_one_vcpu() and pull
the vCPU's ID from 'struct kvm_vcpu'.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c

index 68e0f1c5ec5a5e3054362631918f853458de0037..2b0f19ddbc8bf372b03235d622f5c388763d067f 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "kselftest.h"
 
-#define VCPU_ID                        0
 #define ARBITRARY_IO_PORT      0x2000
 
 /* The virtual machine object. */
@@ -41,6 +40,7 @@ void l1_guest_code(struct vmx_pages *vmx)
 
 int main(void)
 {
+       struct kvm_vcpu *vcpu;
        struct kvm_run *run;
        struct kvm_vcpu_events events;
        vm_vaddr_t vmx_pages_gva;
@@ -56,13 +56,13 @@ int main(void)
                exit(KSFT_SKIP);
        }
 
-       vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
+       vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
        vm_enable_cap(vm, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 1);
 
-       run = vcpu_state(vm, VCPU_ID);
+       run = vcpu->run;
        vcpu_alloc_vmx(vm, &vmx_pages_gva);
-       vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
-       vcpu_run(vm, VCPU_ID);
+       vcpu_args_set(vm, vcpu->id, 1, vmx_pages_gva);
+       vcpu_run(vm, vcpu->id);
 
        TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
                    "Expected KVM_EXIT_IO, got: %u (%s)\n",
@@ -70,21 +70,21 @@ int main(void)
        TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT,
                    "Expected IN from port %d from L2, got port %d",
                    ARBITRARY_IO_PORT, run->io.port);
-       vcpu_events_get(vm, VCPU_ID, &events);
+       vcpu_events_get(vm, vcpu->id, &events);
        events.flags |= KVM_VCPUEVENT_VALID_TRIPLE_FAULT;
        events.triple_fault.pending = true;
-       vcpu_events_set(vm, VCPU_ID, &events);
+       vcpu_events_set(vm, vcpu->id, &events);
        run->immediate_exit = true;
-       vcpu_run_complete_io(vm, VCPU_ID);
+       vcpu_run_complete_io(vm, vcpu->id);
 
-       vcpu_events_get(vm, VCPU_ID, &events);
+       vcpu_events_get(vm, vcpu->id, &events);
        TEST_ASSERT(events.flags & KVM_VCPUEVENT_VALID_TRIPLE_FAULT,
                    "Triple fault event invalid");
        TEST_ASSERT(events.triple_fault.pending,
                    "No triple fault pending");
-       vcpu_run(vm, VCPU_ID);
+       vcpu_run(vm, vcpu->id);
 
-       switch (get_ucall(vm, VCPU_ID, &uc)) {
+       switch (get_ucall(vm, vcpu->id, &uc)) {
        case UCALL_DONE:
                break;
        case UCALL_ABORT: