]> xenbits.xensource.com Git - xen.git/commitdiff
x86/hyperv: detect absolutely necessary MSRs
authorWei Liu <liuwe@microsoft.com>
Fri, 27 Dec 2019 17:14:58 +0000 (17:14 +0000)
committerWei Liu <liuwe@microsoft.com>
Fri, 3 Jan 2020 17:45:47 +0000 (17:45 +0000)
If they are not available, disable Hyper-V related features.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/guest/hyperv/hyperv.c

index 2e70b4aa828e04312f3d862f52381a85a54961b4..8d38313d7aae765b3d5153182bd675161080c537 100644 (file)
@@ -32,6 +32,8 @@ static const struct hypervisor_ops ops = {
 const struct hypervisor_ops *__init hyperv_probe(void)
 {
     uint32_t eax, ebx, ecx, edx;
+    uint64_t required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE |
+        HV_X64_MSR_VP_INDEX_AVAILABLE;
 
     cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
     if ( !((ebx == 0x7263694d) &&  /* "Micr" */
@@ -57,6 +59,16 @@ const struct hypervisor_ops *__init hyperv_probe(void)
     ms_hyperv.max_vp_index = eax;
     ms_hyperv.max_lp_index = ebx;
 
+    if ( (ms_hyperv.features & required_msrs) != required_msrs )
+    {
+        /*
+         * Oops, required MSRs are not available. Treat this as
+         * "Hyper-V is not available".
+         */
+        memset(&ms_hyperv, 0, sizeof(ms_hyperv));
+        return NULL;
+    }
+
     return &ops;
 }