]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: selftests: Re-enable hyperv_evmcs/hyperv_svm_test on bare metal
authorVitaly Kuznetsov <vkuznets@redhat.com>
Fri, 16 Aug 2024 13:01:39 +0000 (15:01 +0200)
committerSean Christopherson <seanjc@google.com>
Thu, 22 Aug 2024 19:14:42 +0000 (12:14 -0700)
KVM_CAP_HYPERV_DIRECT_TLBFLUSH is only reported when KVM runs on top of
Hyper-V and hyperv_evmcs/hyperv_svm_test don't need that, these tests check
that the feature is properly emulated for Hyper-V on KVM guests. There's no
corresponding CAP for that, the feature is reported in
KVM_GET_SUPPORTED_HV_CPUID.

Hyper-V specific CPUIDs are not reported by KVM_GET_SUPPORTED_CPUID,
implement dedicated kvm_hv_cpu_has() helper to do the job.

Fixes: 6dac1195181c ("KVM: selftests: Make Hyper-V tests explicitly require KVM Hyper-V support")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20240816130139.286246-3-vkuznets@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86_64/hyperv.h
tools/testing/selftests/kvm/lib/x86_64/hyperv.c
tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c
tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c

index a2e7cf7ee0ad1ab1d2dce76168ebb177434e2fef..6849e2552f1bfd4994c44e7ce84aa820390a35ef 100644 (file)
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED            \
        KVM_X86_CPU_FEATURE(HYPERV_CPUID_ENLIGHTMENT_INFO, 0, EAX, 14)
 
+/* HYPERV_CPUID_NESTED_FEATURES.EAX */
+#define HV_X64_NESTED_DIRECT_FLUSH                     \
+       KVM_X86_CPU_FEATURE(HYPERV_CPUID_NESTED_FEATURES, 0, EAX, 17)
+#define HV_X64_NESTED_GUEST_MAPPING_FLUSH              \
+       KVM_X86_CPU_FEATURE(HYPERV_CPUID_NESTED_FEATURES, 0, EAX, 18)
+#define HV_X64_NESTED_MSR_BITMAP                       \
+       KVM_X86_CPU_FEATURE(HYPERV_CPUID_NESTED_FEATURES, 0, EAX, 19)
+
+/* HYPERV_CPUID_NESTED_FEATURES.EBX */
+#define HV_X64_NESTED_EVMCS1_PERF_GLOBAL_CTRL          \
+       KVM_X86_CPU_FEATURE(HYPERV_CPUID_NESTED_FEATURES, 0, EBX, 0)
+
 /* HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX */
 #define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING       \
        KVM_X86_CPU_FEATURE(HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES, 0, EAX, 1)
@@ -347,4 +359,6 @@ const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void);
 const struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu);
 void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu);
 
+bool kvm_hv_cpu_has(struct kvm_x86_cpu_feature feature);
+
 #endif /* !SELFTEST_KVM_HYPERV_H */
index b4a5e4ad710545c54cf0b4dae21fef22fcf0b45d..15bc8cd583aa42dac136006f2914ad2cc3587428 100644 (file)
@@ -67,6 +67,14 @@ const struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu)
        return cpuid;
 }
 
+bool kvm_hv_cpu_has(struct kvm_x86_cpu_feature feature)
+{
+       if (!kvm_has_cap(KVM_CAP_SYS_HYPERV_CPUID))
+               return false;
+
+       return kvm_cpuid_has(kvm_get_supported_hv_cpuid(), feature);
+}
+
 struct hyperv_test_pages *vcpu_alloc_hyperv_test_pages(struct kvm_vm *vm,
                                                       vm_vaddr_t *p_hv_pages_gva)
 {
index e192720bfe14b4a1af8d55fabb90eea9cd6be92f..74cf196613090819fda37704c704bc28ed9e665b 100644 (file)
@@ -242,7 +242,7 @@ int main(int argc, char *argv[])
        TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS));
-       TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_DIRECT_TLBFLUSH));
+       TEST_REQUIRE(kvm_hv_cpu_has(HV_X64_NESTED_DIRECT_FLUSH));
 
        vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 
index b987a3d7971537bd4e3763839e153d12b038ea5f..0ddb63229bcbb8b57170c6c7b638f69829a1a79f 100644 (file)
@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
        int stage;
 
        TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM));
-       TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_DIRECT_TLBFLUSH));
+       TEST_REQUIRE(kvm_hv_cpu_has(HV_X64_NESTED_DIRECT_FLUSH));
 
        /* Create VM */
        vm = vm_create_with_one_vcpu(&vcpu, guest_code);