Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * X86 specific Hyper-V initialization code.
0004  *
0005  * Copyright (C) 2016, Microsoft, Inc.
0006  *
0007  * Author : K. Y. Srinivasan <kys@microsoft.com>
0008  */
0009 
0010 #include <linux/efi.h>
0011 #include <linux/types.h>
0012 #include <linux/bitfield.h>
0013 #include <linux/io.h>
0014 #include <asm/apic.h>
0015 #include <asm/desc.h>
0016 #include <asm/sev.h>
0017 #include <asm/hypervisor.h>
0018 #include <asm/hyperv-tlfs.h>
0019 #include <asm/mshyperv.h>
0020 #include <asm/idtentry.h>
0021 #include <linux/kexec.h>
0022 #include <linux/version.h>
0023 #include <linux/vmalloc.h>
0024 #include <linux/mm.h>
0025 #include <linux/hyperv.h>
0026 #include <linux/slab.h>
0027 #include <linux/kernel.h>
0028 #include <linux/cpuhotplug.h>
0029 #include <linux/syscore_ops.h>
0030 #include <clocksource/hyperv_timer.h>
0031 #include <linux/highmem.h>
0032 #include <linux/swiotlb.h>
0033 
0034 int hyperv_init_cpuhp;
0035 u64 hv_current_partition_id = ~0ull;
0036 EXPORT_SYMBOL_GPL(hv_current_partition_id);
0037 
0038 void *hv_hypercall_pg;
0039 EXPORT_SYMBOL_GPL(hv_hypercall_pg);
0040 
0041 union hv_ghcb * __percpu *hv_ghcb_pg;
0042 
0043 /* Storage to save the hypercall page temporarily for hibernation */
0044 static void *hv_hypercall_pg_saved;
0045 
0046 struct hv_vp_assist_page **hv_vp_assist_page;
0047 EXPORT_SYMBOL_GPL(hv_vp_assist_page);
0048 
0049 static int hyperv_init_ghcb(void)
0050 {
0051     u64 ghcb_gpa;
0052     void *ghcb_va;
0053     void **ghcb_base;
0054 
0055     if (!hv_isolation_type_snp())
0056         return 0;
0057 
0058     if (!hv_ghcb_pg)
0059         return -EINVAL;
0060 
0061     /*
0062      * GHCB page is allocated by paravisor. The address
0063      * returned by MSR_AMD64_SEV_ES_GHCB is above shared
0064      * memory boundary and map it here.
0065      */
0066     rdmsrl(MSR_AMD64_SEV_ES_GHCB, ghcb_gpa);
0067     ghcb_va = memremap(ghcb_gpa, HV_HYP_PAGE_SIZE, MEMREMAP_WB);
0068     if (!ghcb_va)
0069         return -ENOMEM;
0070 
0071     ghcb_base = (void **)this_cpu_ptr(hv_ghcb_pg);
0072     *ghcb_base = ghcb_va;
0073 
0074     return 0;
0075 }
0076 
0077 static int hv_cpu_init(unsigned int cpu)
0078 {
0079     union hv_vp_assist_msr_contents msr = { 0 };
0080     struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
0081     int ret;
0082 
0083     ret = hv_common_cpu_init(cpu);
0084     if (ret)
0085         return ret;
0086 
0087     if (!hv_vp_assist_page)
0088         return 0;
0089 
0090     if (!*hvp) {
0091         if (hv_root_partition) {
0092             /*
0093              * For root partition we get the hypervisor provided VP assist
0094              * page, instead of allocating a new page.
0095              */
0096             rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64);
0097             *hvp = memremap(msr.pfn <<
0098                     HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT,
0099                     PAGE_SIZE, MEMREMAP_WB);
0100         } else {
0101             /*
0102              * The VP assist page is an "overlay" page (see Hyper-V TLFS's
0103              * Section 5.2.1 "GPA Overlay Pages"). Here it must be zeroed
0104              * out to make sure we always write the EOI MSR in
0105              * hv_apic_eoi_write() *after* the EOI optimization is disabled
0106              * in hv_cpu_die(), otherwise a CPU may not be stopped in the
0107              * case of CPU offlining and the VM will hang.
0108              */
0109             *hvp = __vmalloc(PAGE_SIZE, GFP_KERNEL | __GFP_ZERO);
0110             if (*hvp)
0111                 msr.pfn = vmalloc_to_pfn(*hvp);
0112         }
0113         WARN_ON(!(*hvp));
0114         if (*hvp) {
0115             msr.enable = 1;
0116             wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64);
0117         }
0118     }
0119 
0120     return hyperv_init_ghcb();
0121 }
0122 
0123 static void (*hv_reenlightenment_cb)(void);
0124 
0125 static void hv_reenlightenment_notify(struct work_struct *dummy)
0126 {
0127     struct hv_tsc_emulation_status emu_status;
0128 
0129     rdmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
0130 
0131     /* Don't issue the callback if TSC accesses are not emulated */
0132     if (hv_reenlightenment_cb && emu_status.inprogress)
0133         hv_reenlightenment_cb();
0134 }
0135 static DECLARE_DELAYED_WORK(hv_reenlightenment_work, hv_reenlightenment_notify);
0136 
0137 void hyperv_stop_tsc_emulation(void)
0138 {
0139     u64 freq;
0140     struct hv_tsc_emulation_status emu_status;
0141 
0142     rdmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
0143     emu_status.inprogress = 0;
0144     wrmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
0145 
0146     rdmsrl(HV_X64_MSR_TSC_FREQUENCY, freq);
0147     tsc_khz = div64_u64(freq, 1000);
0148 }
0149 EXPORT_SYMBOL_GPL(hyperv_stop_tsc_emulation);
0150 
0151 static inline bool hv_reenlightenment_available(void)
0152 {
0153     /*
0154      * Check for required features and privileges to make TSC frequency
0155      * change notifications work.
0156      */
0157     return ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
0158         ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE &&
0159         ms_hyperv.features & HV_ACCESS_REENLIGHTENMENT;
0160 }
0161 
0162 DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_reenlightenment)
0163 {
0164     ack_APIC_irq();
0165     inc_irq_stat(irq_hv_reenlightenment_count);
0166     schedule_delayed_work(&hv_reenlightenment_work, HZ/10);
0167 }
0168 
0169 void set_hv_tscchange_cb(void (*cb)(void))
0170 {
0171     struct hv_reenlightenment_control re_ctrl = {
0172         .vector = HYPERV_REENLIGHTENMENT_VECTOR,
0173         .enabled = 1,
0174     };
0175     struct hv_tsc_emulation_control emu_ctrl = {.enabled = 1};
0176 
0177     if (!hv_reenlightenment_available()) {
0178         pr_warn("Hyper-V: reenlightenment support is unavailable\n");
0179         return;
0180     }
0181 
0182     if (!hv_vp_index)
0183         return;
0184 
0185     hv_reenlightenment_cb = cb;
0186 
0187     /* Make sure callback is registered before we write to MSRs */
0188     wmb();
0189 
0190     re_ctrl.target_vp = hv_vp_index[get_cpu()];
0191 
0192     wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
0193     wrmsrl(HV_X64_MSR_TSC_EMULATION_CONTROL, *((u64 *)&emu_ctrl));
0194 
0195     put_cpu();
0196 }
0197 EXPORT_SYMBOL_GPL(set_hv_tscchange_cb);
0198 
0199 void clear_hv_tscchange_cb(void)
0200 {
0201     struct hv_reenlightenment_control re_ctrl;
0202 
0203     if (!hv_reenlightenment_available())
0204         return;
0205 
0206     rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *(u64 *)&re_ctrl);
0207     re_ctrl.enabled = 0;
0208     wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *(u64 *)&re_ctrl);
0209 
0210     hv_reenlightenment_cb = NULL;
0211 }
0212 EXPORT_SYMBOL_GPL(clear_hv_tscchange_cb);
0213 
0214 static int hv_cpu_die(unsigned int cpu)
0215 {
0216     struct hv_reenlightenment_control re_ctrl;
0217     unsigned int new_cpu;
0218     void **ghcb_va;
0219 
0220     if (hv_ghcb_pg) {
0221         ghcb_va = (void **)this_cpu_ptr(hv_ghcb_pg);
0222         if (*ghcb_va)
0223             memunmap(*ghcb_va);
0224         *ghcb_va = NULL;
0225     }
0226 
0227     hv_common_cpu_die(cpu);
0228 
0229     if (hv_vp_assist_page && hv_vp_assist_page[cpu]) {
0230         union hv_vp_assist_msr_contents msr = { 0 };
0231         if (hv_root_partition) {
0232             /*
0233              * For root partition the VP assist page is mapped to
0234              * hypervisor provided page, and thus we unmap the
0235              * page here and nullify it, so that in future we have
0236              * correct page address mapped in hv_cpu_init.
0237              */
0238             memunmap(hv_vp_assist_page[cpu]);
0239             hv_vp_assist_page[cpu] = NULL;
0240             rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64);
0241             msr.enable = 0;
0242         }
0243         wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64);
0244     }
0245 
0246     if (hv_reenlightenment_cb == NULL)
0247         return 0;
0248 
0249     rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
0250     if (re_ctrl.target_vp == hv_vp_index[cpu]) {
0251         /*
0252          * Reassign reenlightenment notifications to some other online
0253          * CPU or just disable the feature if there are no online CPUs
0254          * left (happens on hibernation).
0255          */
0256         new_cpu = cpumask_any_but(cpu_online_mask, cpu);
0257 
0258         if (new_cpu < nr_cpu_ids)
0259             re_ctrl.target_vp = hv_vp_index[new_cpu];
0260         else
0261             re_ctrl.enabled = 0;
0262 
0263         wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
0264     }
0265 
0266     return 0;
0267 }
0268 
0269 static int __init hv_pci_init(void)
0270 {
0271     int gen2vm = efi_enabled(EFI_BOOT);
0272 
0273     /*
0274      * For Generation-2 VM, we exit from pci_arch_init() by returning 0.
0275      * The purpose is to suppress the harmless warning:
0276      * "PCI: Fatal: No config space access function found"
0277      */
0278     if (gen2vm)
0279         return 0;
0280 
0281     /* For Generation-1 VM, we'll proceed in pci_arch_init().  */
0282     return 1;
0283 }
0284 
0285 static int hv_suspend(void)
0286 {
0287     union hv_x64_msr_hypercall_contents hypercall_msr;
0288     int ret;
0289 
0290     if (hv_root_partition)
0291         return -EPERM;
0292 
0293     /*
0294      * Reset the hypercall page as it is going to be invalidated
0295      * across hibernation. Setting hv_hypercall_pg to NULL ensures
0296      * that any subsequent hypercall operation fails safely instead of
0297      * crashing due to an access of an invalid page. The hypercall page
0298      * pointer is restored on resume.
0299      */
0300     hv_hypercall_pg_saved = hv_hypercall_pg;
0301     hv_hypercall_pg = NULL;
0302 
0303     /* Disable the hypercall page in the hypervisor */
0304     rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0305     hypercall_msr.enable = 0;
0306     wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0307 
0308     ret = hv_cpu_die(0);
0309     return ret;
0310 }
0311 
0312 static void hv_resume(void)
0313 {
0314     union hv_x64_msr_hypercall_contents hypercall_msr;
0315     int ret;
0316 
0317     ret = hv_cpu_init(0);
0318     WARN_ON(ret);
0319 
0320     /* Re-enable the hypercall page */
0321     rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0322     hypercall_msr.enable = 1;
0323     hypercall_msr.guest_physical_address =
0324         vmalloc_to_pfn(hv_hypercall_pg_saved);
0325     wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0326 
0327     hv_hypercall_pg = hv_hypercall_pg_saved;
0328     hv_hypercall_pg_saved = NULL;
0329 
0330     /*
0331      * Reenlightenment notifications are disabled by hv_cpu_die(0),
0332      * reenable them here if hv_reenlightenment_cb was previously set.
0333      */
0334     if (hv_reenlightenment_cb)
0335         set_hv_tscchange_cb(hv_reenlightenment_cb);
0336 }
0337 
0338 /* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */
0339 static struct syscore_ops hv_syscore_ops = {
0340     .suspend    = hv_suspend,
0341     .resume     = hv_resume,
0342 };
0343 
0344 static void (* __initdata old_setup_percpu_clockev)(void);
0345 
0346 static void __init hv_stimer_setup_percpu_clockev(void)
0347 {
0348     /*
0349      * Ignore any errors in setting up stimer clockevents
0350      * as we can run with the LAPIC timer as a fallback.
0351      */
0352     (void)hv_stimer_alloc(false);
0353 
0354     /*
0355      * Still register the LAPIC timer, because the direct-mode STIMER is
0356      * not supported by old versions of Hyper-V. This also allows users
0357      * to switch to LAPIC timer via /sys, if they want to.
0358      */
0359     if (old_setup_percpu_clockev)
0360         old_setup_percpu_clockev();
0361 }
0362 
0363 static void __init hv_get_partition_id(void)
0364 {
0365     struct hv_get_partition_id *output_page;
0366     u64 status;
0367     unsigned long flags;
0368 
0369     local_irq_save(flags);
0370     output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
0371     status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
0372     if (!hv_result_success(status)) {
0373         /* No point in proceeding if this failed */
0374         pr_err("Failed to get partition ID: %lld\n", status);
0375         BUG();
0376     }
0377     hv_current_partition_id = output_page->partition_id;
0378     local_irq_restore(flags);
0379 }
0380 
0381 /*
0382  * This function is to be invoked early in the boot sequence after the
0383  * hypervisor has been detected.
0384  *
0385  * 1. Setup the hypercall page.
0386  * 2. Register Hyper-V specific clocksource.
0387  * 3. Setup Hyper-V specific APIC entry points.
0388  */
0389 void __init hyperv_init(void)
0390 {
0391     u64 guest_id;
0392     union hv_x64_msr_hypercall_contents hypercall_msr;
0393     int cpuhp;
0394 
0395     if (x86_hyper_type != X86_HYPER_MS_HYPERV)
0396         return;
0397 
0398     if (hv_common_init())
0399         return;
0400 
0401     hv_vp_assist_page = kcalloc(num_possible_cpus(),
0402                     sizeof(*hv_vp_assist_page), GFP_KERNEL);
0403     if (!hv_vp_assist_page) {
0404         ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED;
0405         goto common_free;
0406     }
0407 
0408     if (hv_isolation_type_snp()) {
0409         /* Negotiate GHCB Version. */
0410         if (!hv_ghcb_negotiate_protocol())
0411             hv_ghcb_terminate(SEV_TERM_SET_GEN,
0412                       GHCB_SEV_ES_PROT_UNSUPPORTED);
0413 
0414         hv_ghcb_pg = alloc_percpu(union hv_ghcb *);
0415         if (!hv_ghcb_pg)
0416             goto free_vp_assist_page;
0417     }
0418 
0419     cpuhp = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online",
0420                   hv_cpu_init, hv_cpu_die);
0421     if (cpuhp < 0)
0422         goto free_ghcb_page;
0423 
0424     /*
0425      * Setup the hypercall page and enable hypercalls.
0426      * 1. Register the guest ID
0427      * 2. Enable the hypercall and register the hypercall page
0428      */
0429     guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
0430     wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
0431 
0432     /* Hyper-V requires to write guest os id via ghcb in SNP IVM. */
0433     hv_ghcb_msr_write(HV_X64_MSR_GUEST_OS_ID, guest_id);
0434 
0435     hv_hypercall_pg = __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START,
0436             VMALLOC_END, GFP_KERNEL, PAGE_KERNEL_ROX,
0437             VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,
0438             __builtin_return_address(0));
0439     if (hv_hypercall_pg == NULL)
0440         goto clean_guest_os_id;
0441 
0442     rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0443     hypercall_msr.enable = 1;
0444 
0445     if (hv_root_partition) {
0446         struct page *pg;
0447         void *src, *dst;
0448 
0449         /*
0450          * For the root partition, the hypervisor will set up its
0451          * hypercall page. The hypervisor guarantees it will not show
0452          * up in the root's address space. The root can't change the
0453          * location of the hypercall page.
0454          *
0455          * Order is important here. We must enable the hypercall page
0456          * so it is populated with code, then copy the code to an
0457          * executable page.
0458          */
0459         wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0460 
0461         pg = vmalloc_to_page(hv_hypercall_pg);
0462         dst = kmap(pg);
0463         src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE,
0464                 MEMREMAP_WB);
0465         BUG_ON(!(src && dst));
0466         memcpy(dst, src, HV_HYP_PAGE_SIZE);
0467         memunmap(src);
0468         kunmap(pg);
0469     } else {
0470         hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
0471         wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0472     }
0473 
0474     /*
0475      * hyperv_init() is called before LAPIC is initialized: see
0476      * apic_intr_mode_init() -> x86_platform.apic_post_init() and
0477      * apic_bsp_setup() -> setup_local_APIC(). The direct-mode STIMER
0478      * depends on LAPIC, so hv_stimer_alloc() should be called from
0479      * x86_init.timers.setup_percpu_clockev.
0480      */
0481     old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev;
0482     x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev;
0483 
0484     hv_apic_init();
0485 
0486     x86_init.pci.arch_init = hv_pci_init;
0487 
0488     register_syscore_ops(&hv_syscore_ops);
0489 
0490     hyperv_init_cpuhp = cpuhp;
0491 
0492     if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
0493         hv_get_partition_id();
0494 
0495     BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
0496 
0497 #ifdef CONFIG_PCI_MSI
0498     /*
0499      * If we're running as root, we want to create our own PCI MSI domain.
0500      * We can't set this in hv_pci_init because that would be too late.
0501      */
0502     if (hv_root_partition)
0503         x86_init.irqs.create_pci_msi_domain = hv_create_pci_msi_domain;
0504 #endif
0505 
0506     /* Query the VMs extended capability once, so that it can be cached. */
0507     hv_query_ext_cap(0);
0508 
0509 #ifdef CONFIG_SWIOTLB
0510     /*
0511      * Swiotlb bounce buffer needs to be mapped in extra address
0512      * space. Map function doesn't work in the early place and so
0513      * call swiotlb_update_mem_attributes() here.
0514      */
0515     if (hv_is_isolation_supported())
0516         swiotlb_update_mem_attributes();
0517 #endif
0518 
0519     return;
0520 
0521 clean_guest_os_id:
0522     wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
0523     hv_ghcb_msr_write(HV_X64_MSR_GUEST_OS_ID, 0);
0524     cpuhp_remove_state(cpuhp);
0525 free_ghcb_page:
0526     free_percpu(hv_ghcb_pg);
0527 free_vp_assist_page:
0528     kfree(hv_vp_assist_page);
0529     hv_vp_assist_page = NULL;
0530 common_free:
0531     hv_common_free();
0532 }
0533 
0534 /*
0535  * This routine is called before kexec/kdump, it does the required cleanup.
0536  */
0537 void hyperv_cleanup(void)
0538 {
0539     union hv_x64_msr_hypercall_contents hypercall_msr;
0540 
0541     unregister_syscore_ops(&hv_syscore_ops);
0542 
0543     /* Reset our OS id */
0544     wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
0545     hv_ghcb_msr_write(HV_X64_MSR_GUEST_OS_ID, 0);
0546 
0547     /*
0548      * Reset hypercall page reference before reset the page,
0549      * let hypercall operations fail safely rather than
0550      * panic the kernel for using invalid hypercall page
0551      */
0552     hv_hypercall_pg = NULL;
0553 
0554     /* Reset the hypercall page */
0555     hypercall_msr.as_uint64 = 0;
0556     wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0557 
0558     /* Reset the TSC page */
0559     hypercall_msr.as_uint64 = 0;
0560     wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
0561 }
0562 
0563 void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
0564 {
0565     static bool panic_reported;
0566     u64 guest_id;
0567 
0568     if (in_die && !panic_on_oops)
0569         return;
0570 
0571     /*
0572      * We prefer to report panic on 'die' chain as we have proper
0573      * registers to report, but if we miss it (e.g. on BUG()) we need
0574      * to report it on 'panic'.
0575      */
0576     if (panic_reported)
0577         return;
0578     panic_reported = true;
0579 
0580     rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
0581 
0582     wrmsrl(HV_X64_MSR_CRASH_P0, err);
0583     wrmsrl(HV_X64_MSR_CRASH_P1, guest_id);
0584     wrmsrl(HV_X64_MSR_CRASH_P2, regs->ip);
0585     wrmsrl(HV_X64_MSR_CRASH_P3, regs->ax);
0586     wrmsrl(HV_X64_MSR_CRASH_P4, regs->sp);
0587 
0588     /*
0589      * Let Hyper-V know there is crash data available
0590      */
0591     wrmsrl(HV_X64_MSR_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
0592 }
0593 EXPORT_SYMBOL_GPL(hyperv_report_panic);
0594 
0595 bool hv_is_hyperv_initialized(void)
0596 {
0597     union hv_x64_msr_hypercall_contents hypercall_msr;
0598 
0599     /*
0600      * Ensure that we're really on Hyper-V, and not a KVM or Xen
0601      * emulation of Hyper-V
0602      */
0603     if (x86_hyper_type != X86_HYPER_MS_HYPERV)
0604         return false;
0605 
0606     /*
0607      * Verify that earlier initialization succeeded by checking
0608      * that the hypercall page is setup
0609      */
0610     hypercall_msr.as_uint64 = 0;
0611     rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
0612 
0613     return hypercall_msr.enable;
0614 }
0615 EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);