]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Convert fix_hypercall_test away from VCPU_ID
authorSean Christopherson <seanjc@google.com>
Mon, 18 Apr 2022 18:50:15 +0000 (11:50 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:47:01 +0000 (11:47 -0400)
Convert fix_hypercall_test to use vm_create_with_one_vcpu() and pass
around a 'struct kvm_vcpu' object instead of using a global VCPU_ID.

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

index 81f9f5b1f655661322fdfec1886ef0ca402ee86c..108c3f75361d67556f1334a46f5317dd34df09ec 100644 (file)
@@ -14,8 +14,6 @@
 #include "kvm_util.h"
 #include "processor.h"
 
-#define VCPU_ID 0
-
 static bool ud_expected;
 
 static void guest_ud_handler(struct ex_regs *regs)
@@ -94,22 +92,20 @@ static void guest_main(void)
        GUEST_DONE();
 }
 
-static void setup_ud_vector(struct kvm_vm *vm)
+static void setup_ud_vector(struct kvm_vcpu *vcpu)
 {
-       vm_init_descriptor_tables(vm);
-       vcpu_init_descriptor_tables(vm, VCPU_ID);
-       vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
+       vm_init_descriptor_tables(vcpu->vm);
+       vcpu_init_descriptor_tables(vcpu->vm, vcpu->id);
+       vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler);
 }
 
-static void enter_guest(struct kvm_vm *vm)
+static void enter_guest(struct kvm_vcpu *vcpu)
 {
-       struct kvm_run *run;
+       struct kvm_run *run = vcpu->run;
        struct ucall uc;
 
-       run = vcpu_state(vm, VCPU_ID);
-
-       vcpu_run(vm, VCPU_ID);
-       switch (get_ucall(vm, VCPU_ID, &uc)) {
+       vcpu_run(vcpu->vm, vcpu->id);
+       switch (get_ucall(vcpu->vm, vcpu->id, &uc)) {
        case UCALL_SYNC:
                pr_info("%s: %016lx\n", (const char *)uc.args[2], uc.args[3]);
                break;
@@ -125,25 +121,27 @@ static void enter_guest(struct kvm_vm *vm)
 
 static void test_fix_hypercall(void)
 {
+       struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
 
-       vm = vm_create_default(VCPU_ID, 0, guest_main);
-       setup_ud_vector(vm);
+       vm = vm_create_with_one_vcpu(&vcpu, guest_main);
+       setup_ud_vector(vcpu);
 
        ud_expected = false;
        sync_global_to_guest(vm, ud_expected);
 
        virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
 
-       enter_guest(vm);
+       enter_guest(vcpu);
 }
 
 static void test_fix_hypercall_disabled(void)
 {
+       struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
 
-       vm = vm_create_default(VCPU_ID, 0, guest_main);
-       setup_ud_vector(vm);
+       vm = vm_create_with_one_vcpu(&vcpu, guest_main);
+       setup_ud_vector(vcpu);
 
        vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2,
                      KVM_X86_QUIRK_FIX_HYPERCALL_INSN);
@@ -153,7 +151,7 @@ static void test_fix_hypercall_disabled(void)
 
        virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
 
-       enter_guest(vm);
+       enter_guest(vcpu);
 }
 
 int main(void)