Skip to content

Commit 8ad4855

Browse files
vittyvksean-jc
authored andcommitted
KVM: selftests: Avoid infinite loop in hyperv_features when invtsc is missing
When X86_FEATURE_INVTSC is missing, guest_test_msrs_access() was supposed to skip testing dependent Hyper-V invariant TSC feature. Unfortunately, 'continue' does not lead to that as stage is not incremented. Moreover, 'vm' allocated with vm_create_with_one_vcpu() is not freed and the test runs out of available file descriptors very quickly. Fixes: bd827bd ("KVM: selftests: Test Hyper-V invariant TSC control") Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Link: https://lore.kernel.org/r/20240129085847.2674082-1-vkuznets@redhat.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 46fee9e commit 8ad4855

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/testing/selftests/kvm/x86_64/hyperv_features.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,15 @@ static void guest_test_msrs_access(void)
454454
case 44:
455455
/* MSR is not available when CPUID feature bit is unset */
456456
if (!has_invtsc)
457-
continue;
457+
goto next_stage;
458458
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
459459
msr->write = false;
460460
msr->fault_expected = true;
461461
break;
462462
case 45:
463463
/* MSR is vailable when CPUID feature bit is set */
464464
if (!has_invtsc)
465-
continue;
465+
goto next_stage;
466466
vcpu_set_cpuid_feature(vcpu, HV_ACCESS_TSC_INVARIANT);
467467
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
468468
msr->write = false;
@@ -471,7 +471,7 @@ static void guest_test_msrs_access(void)
471471
case 46:
472472
/* Writing bits other than 0 is forbidden */
473473
if (!has_invtsc)
474-
continue;
474+
goto next_stage;
475475
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
476476
msr->write = true;
477477
msr->write_val = 0xdeadbeef;
@@ -480,7 +480,7 @@ static void guest_test_msrs_access(void)
480480
case 47:
481481
/* Setting bit 0 enables the feature */
482482
if (!has_invtsc)
483-
continue;
483+
goto next_stage;
484484
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
485485
msr->write = true;
486486
msr->write_val = 1;
@@ -513,6 +513,7 @@ static void guest_test_msrs_access(void)
513513
return;
514514
}
515515

516+
next_stage:
516517
stage++;
517518
kvm_vm_free(vm);
518519
}

0 commit comments

Comments
 (0)