]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Convert vmx_apic_access_test away from VCPU_ID
authorSean Christopherson <seanjc@google.com>
Wed, 16 Feb 2022 00:27:47 +0000 (16:27 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:46:48 +0000 (11:46 -0400)
Convert vmx_apic_access_test to use vm_create_with_one_vcpu() and pass
around a 'struct kvm_vcpu' object instead of using a global VCPU_ID.

Opportunistically make the "vm" variable local, it is unused outside of
main().

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

index d438c4d3228a4c82312462e6a163da2f1f5c4afd..10f9c86029e6332b18d83f3707f4a2574eb27aff 100644 (file)
 
 #include "kselftest.h"
 
-#define VCPU_ID                0
-
-/* The virtual machine object. */
-static struct kvm_vm *vm;
-
 static void l2_guest_code(void)
 {
        /* Exit to L1 */
@@ -84,9 +79,12 @@ int main(int argc, char *argv[])
        struct vmx_pages *vmx;
        bool done = false;
 
+       struct kvm_vcpu *vcpu;
+       struct kvm_vm *vm;
+
        nested_vmx_check_supported();
 
-       vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
+       vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
 
        kvm_get_cpu_address_width(&paddr_width, &vaddr_width);
        high_gpa = (1ul << paddr_width) - getpagesize();
@@ -97,13 +95,13 @@ int main(int argc, char *argv[])
 
        vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva);
        prepare_virtualize_apic_accesses(vmx, vm);
-       vcpu_args_set(vm, VCPU_ID, 2, vmx_pages_gva, high_gpa);
+       vcpu_args_set(vm, vcpu->id, 2, vmx_pages_gva, high_gpa);
 
        while (!done) {
-               volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID);
+               volatile struct kvm_run *run = vcpu->run;
                struct ucall uc;
 
-               vcpu_run(vm, VCPU_ID);
+               vcpu_run(vm, vcpu->id);
                if (apic_access_addr == high_gpa) {
                        TEST_ASSERT(run->exit_reason ==
                                    KVM_EXIT_INTERNAL_ERROR,
@@ -121,7 +119,7 @@ int main(int argc, char *argv[])
                            run->exit_reason,
                            exit_reason_str(run->exit_reason));
 
-               switch (get_ucall(vm, VCPU_ID, &uc)) {
+               switch (get_ucall(vm, vcpu->id, &uc)) {
                case UCALL_ABORT:
                        TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
                                  __FILE__, uc.args[1]);