]> git.itanic.dy.fi Git - linux-stable/commitdiff
KVM: selftests: Run clocksource dependent tests with hyperv_clocksource_tsc_page too
authorVitaly Kuznetsov <vkuznets@redhat.com>
Tue, 9 Jan 2024 14:11:19 +0000 (15:11 +0100)
committerSean Christopherson <seanjc@google.com>
Thu, 1 Feb 2024 16:58:14 +0000 (08:58 -0800)
KVM's 'gtod_is_based_on_tsc()' recognizes two clocksources: 'tsc' and
'hyperv_clocksource_tsc_page' and enables kvmclock in 'masterclock'
mode when either is in use. Transform 'sys_clocksource_is_tsc()' into
'sys_clocksource_is_based_on_tsc()' to support the later. This affects
two tests: kvm_clock_test and vmx_nested_tsc_scaling_test, both seem
to work well when system clocksource is 'hyperv_clocksource_tsc_page'.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20240109141121.1619463-4-vkuznets@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/lib/x86_64/processor.c
tools/testing/selftests/kvm/x86_64/kvm_clock_test.c
tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c

index 01eec72e0d3e3645216927350d99d87b77c7e927..5bca8c947c8253819dd07ed6266a03194a0c1857 100644 (file)
@@ -1271,6 +1271,6 @@ void virt_map_level(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
 #define PFERR_GUEST_PAGE_MASK  BIT_ULL(PFERR_GUEST_PAGE_BIT)
 #define PFERR_IMPLICIT_ACCESS  BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT)
 
-bool sys_clocksource_is_tsc(void);
+bool sys_clocksource_is_based_on_tsc(void);
 
 #endif /* SELFTEST_KVM_PROCESSOR_H */
index e6964ff2a37da75b11f0c098668a4d541f1d0344..f639b3e062e3a328165bfb6ed32f606cf1f48e76 100644 (file)
@@ -1300,10 +1300,11 @@ void kvm_selftest_arch_init(void)
        host_cpu_is_amd = this_cpu_is_amd();
 }
 
-bool sys_clocksource_is_tsc(void)
+bool sys_clocksource_is_based_on_tsc(void)
 {
        char *clk_name = sys_get_cur_clocksource();
-       bool ret = !strcmp(clk_name, "tsc\n");
+       bool ret = !strcmp(clk_name, "tsc\n") ||
+                  !strcmp(clk_name, "hyperv_clocksource_tsc_page\n");
 
        free(clk_name);
 
index 6fcc1a433587575ae982eb722bbd5cf4c9f8f9b9..5bc12222d87af696dc2f35e8874c4eb3f58a4f7e 100644 (file)
@@ -143,7 +143,7 @@ int main(void)
        flags = kvm_check_cap(KVM_CAP_ADJUST_CLOCK);
        TEST_REQUIRE(flags & KVM_CLOCK_REALTIME);
 
-       TEST_REQUIRE(sys_clocksource_is_tsc());
+       TEST_REQUIRE(sys_clocksource_is_based_on_tsc());
 
        vm = vm_create_with_one_vcpu(&vcpu, guest_main);
 
index 93b0a850a2400326c5b2ee40f0a0a87d109aaf5c..1759fa5cb3f29c337a09a5d15569ff028067e2db 100644 (file)
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
 
        TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL));
-       TEST_REQUIRE(sys_clocksource_is_tsc());
+       TEST_REQUIRE(sys_clocksource_is_based_on_tsc());
 
        /*
         * We set L1's scale factor to be a random number from 2 to 10.