Commit 8ad48552 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Sean Christopherson

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: bd827bd7 ("KVM: selftests: Test Hyper-V invariant TSC control")
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20240129085847.2674082-1-vkuznets@redhat.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 46fee9e3
...@@ -454,7 +454,7 @@ static void guest_test_msrs_access(void) ...@@ -454,7 +454,7 @@ static void guest_test_msrs_access(void)
case 44: case 44:
/* MSR is not available when CPUID feature bit is unset */ /* MSR is not available when CPUID feature bit is unset */
if (!has_invtsc) if (!has_invtsc)
continue; goto next_stage;
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL; msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
msr->write = false; msr->write = false;
msr->fault_expected = true; msr->fault_expected = true;
...@@ -462,7 +462,7 @@ static void guest_test_msrs_access(void) ...@@ -462,7 +462,7 @@ static void guest_test_msrs_access(void)
case 45: case 45:
/* MSR is vailable when CPUID feature bit is set */ /* MSR is vailable when CPUID feature bit is set */
if (!has_invtsc) if (!has_invtsc)
continue; goto next_stage;
vcpu_set_cpuid_feature(vcpu, HV_ACCESS_TSC_INVARIANT); vcpu_set_cpuid_feature(vcpu, HV_ACCESS_TSC_INVARIANT);
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL; msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
msr->write = false; msr->write = false;
...@@ -471,7 +471,7 @@ static void guest_test_msrs_access(void) ...@@ -471,7 +471,7 @@ static void guest_test_msrs_access(void)
case 46: case 46:
/* Writing bits other than 0 is forbidden */ /* Writing bits other than 0 is forbidden */
if (!has_invtsc) if (!has_invtsc)
continue; goto next_stage;
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL; msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
msr->write = true; msr->write = true;
msr->write_val = 0xdeadbeef; msr->write_val = 0xdeadbeef;
...@@ -480,7 +480,7 @@ static void guest_test_msrs_access(void) ...@@ -480,7 +480,7 @@ static void guest_test_msrs_access(void)
case 47: case 47:
/* Setting bit 0 enables the feature */ /* Setting bit 0 enables the feature */
if (!has_invtsc) if (!has_invtsc)
continue; goto next_stage;
msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL; msr->idx = HV_X64_MSR_TSC_INVARIANT_CONTROL;
msr->write = true; msr->write = true;
msr->write_val = 1; msr->write_val = 1;
...@@ -513,6 +513,7 @@ static void guest_test_msrs_access(void) ...@@ -513,6 +513,7 @@ static void guest_test_msrs_access(void)
return; return;
} }
next_stage:
stage++; stage++;
kvm_vm_free(vm); kvm_vm_free(vm);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment