KVM: selftests: Convert platform_info_test away from VCPU_ID
authorSean Christopherson <seanjc@google.com>
Wed, 16 Feb 2022 00:11:59 +0000 (16:11 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:46:45 +0000 (11:46 -0400)
Convert platform_info_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/platform_info_test.c

index e79c045..eb5e1f9 100644 (file)
@@ -21,7 +21,6 @@
 #include "kvm_util.h"
 #include "processor.h"
 
-#define VCPU_ID 0
 #define MSR_PLATFORM_INFO_MAX_TURBO_RATIO 0xff00
 
 static void guest_code(void)
@@ -35,18 +34,18 @@ static void guest_code(void)
        }
 }
 
-static void test_msr_platform_info_enabled(struct kvm_vm *vm)
+static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
 {
-       struct kvm_run *run = vcpu_state(vm, VCPU_ID);
+       struct kvm_run *run = vcpu->run;
        struct ucall uc;
 
-       vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, true);
-       vcpu_run(vm, VCPU_ID);
+       vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
+       vcpu_run(vcpu->vm, vcpu->id);
        TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
                        "Exit_reason other than KVM_EXIT_IO: %u (%s),\n",
                        run->exit_reason,
                        exit_reason_str(run->exit_reason));
-       get_ucall(vm, VCPU_ID, &uc);
+       get_ucall(vcpu->vm, vcpu->id, &uc);
        TEST_ASSERT(uc.cmd == UCALL_SYNC,
                        "Received ucall other than UCALL_SYNC: %lu\n", uc.cmd);
        TEST_ASSERT((uc.args[1] & MSR_PLATFORM_INFO_MAX_TURBO_RATIO) ==
@@ -55,12 +54,12 @@ static void test_msr_platform_info_enabled(struct kvm_vm *vm)
                MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
 }
 
-static void test_msr_platform_info_disabled(struct kvm_vm *vm)
+static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu)
 {
-       struct kvm_run *run = vcpu_state(vm, VCPU_ID);
+       struct kvm_run *run = vcpu->run;
 
-       vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, false);
-       vcpu_run(vm, VCPU_ID);
+       vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false);
+       vcpu_run(vcpu->vm, vcpu->id);
        TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN,
                        "Exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
                        run->exit_reason,
@@ -69,6 +68,7 @@ static void test_msr_platform_info_disabled(struct kvm_vm *vm)
 
 int main(int argc, char *argv[])
 {
+       struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
        int rv;
        uint64_t msr_platform_info;
@@ -82,14 +82,14 @@ int main(int argc, char *argv[])
                exit(KSFT_SKIP);
        }
 
-       vm = vm_create_default(VCPU_ID, 0, guest_code);
+       vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 
-       msr_platform_info = vcpu_get_msr(vm, VCPU_ID, MSR_PLATFORM_INFO);
-       vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO,
+       msr_platform_info = vcpu_get_msr(vm, vcpu->id, MSR_PLATFORM_INFO);
+       vcpu_set_msr(vm, vcpu->id, MSR_PLATFORM_INFO,
                msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
-       test_msr_platform_info_enabled(vm);
-       test_msr_platform_info_disabled(vm);
-       vcpu_set_msr(vm, VCPU_ID, MSR_PLATFORM_INFO, msr_platform_info);
+       test_msr_platform_info_enabled(vcpu);
+       test_msr_platform_info_disabled(vcpu);
+       vcpu_set_msr(vm, vcpu->id, MSR_PLATFORM_INFO, msr_platform_info);
 
        kvm_vm_free(vm);