[PATCH v2 110/144] KVM: selftests: Convert triple_fault_event_test away from VCPU_ID

From: Sean Christopherson
Date: Thu Jun 02 2022 - 21:02:21 EST


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@xxxxxxxxxx>
---
.../kvm/x86_64/triple_fault_event_test.c | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c b/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
index 68e0f1c5ec5a..2b0f19ddbc8b 100644
--- a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
+++ b/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
@@ -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:
--
2.36.1.255.ge46751e96f-goog