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

Opportunistically use vcpu_run() instead of _vcpu_run() with an open
coded assert that KVM_RUN succeeded.

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

index 3330fb183c6800e346a4278555bc764f40292939..4f8f3999de2d2edcac03e5a187f2aa588feb62c8 100644 (file)
@@ -173,23 +173,21 @@ static void guest_main(struct ms_hyperv_tsc_page *tsc_page, vm_paddr_t tsc_page_
        GUEST_DONE();
 }
 
-#define VCPU_ID 0
-
-static void host_check_tsc_msr_rdtsc(struct kvm_vm *vm)
+static void host_check_tsc_msr_rdtsc(struct kvm_vcpu *vcpu)
 {
        u64 tsc_freq, r1, r2, t1, t2;
        s64 delta_ns;
 
-       tsc_freq = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TSC_FREQUENCY);
+       tsc_freq = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TSC_FREQUENCY);
        TEST_ASSERT(tsc_freq > 0, "TSC frequency must be nonzero");
 
        /* For increased accuracy, take mean rdtsc() before and afrer ioctl */
        r1 = rdtsc();
-       t1 = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TIME_REF_COUNT);
+       t1 = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TIME_REF_COUNT);
        r1 = (r1 + rdtsc()) / 2;
        nop_loop();
        r2 = rdtsc();
-       t2 = vcpu_get_msr(vm, VCPU_ID, HV_X64_MSR_TIME_REF_COUNT);
+       t2 = vcpu_get_msr(vcpu->vm, vcpu->id, HV_X64_MSR_TIME_REF_COUNT);
        r2 = (r2 + rdtsc()) / 2;
 
        TEST_ASSERT(t2 > t1, "Time reference MSR is not monotonic (%ld <= %ld)", t1, t2);
@@ -207,33 +205,34 @@ static void host_check_tsc_msr_rdtsc(struct kvm_vm *vm)
 
 int main(void)
 {
+       struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
        struct kvm_run *run;
        struct ucall uc;
        vm_vaddr_t tsc_page_gva;
        int stage;
 
-       vm = vm_create_default(VCPU_ID, 0, guest_main);
-       run = vcpu_state(vm, VCPU_ID);
+       vm = vm_create_with_one_vcpu(&vcpu, guest_main);
+       run = vcpu->run;
 
-       vcpu_set_hv_cpuid(vm, VCPU_ID);
+       vcpu_set_hv_cpuid(vm, vcpu->id);
 
        tsc_page_gva = vm_vaddr_alloc_page(vm);
        memset(addr_gva2hva(vm, tsc_page_gva), 0x0, getpagesize());
        TEST_ASSERT((addr_gva2gpa(vm, tsc_page_gva) & (getpagesize() - 1)) == 0,
                "TSC page has to be page aligned\n");
-       vcpu_args_set(vm, VCPU_ID, 2, tsc_page_gva, addr_gva2gpa(vm, tsc_page_gva));
+       vcpu_args_set(vm, vcpu->id, 2, tsc_page_gva, addr_gva2gpa(vm, tsc_page_gva));
 
-       host_check_tsc_msr_rdtsc(vm);
+       host_check_tsc_msr_rdtsc(vcpu);
 
        for (stage = 1;; stage++) {
-               _vcpu_run(vm, VCPU_ID);
+               vcpu_run(vm, vcpu->id);
                TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
                            "Stage %d: unexpected exit reason: %u (%s),\n",
                            stage, 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]);