xref: /openbmc/linux/arch/x86/hyperv/hv_init.c (revision 99a0f46a)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * X86 specific Hyper-V initialization code.
4  *
5  * Copyright (C) 2016, Microsoft, Inc.
6  *
7  * Author : K. Y. Srinivasan <kys@microsoft.com>
8  */
9 
10 #include <linux/acpi.h>
11 #include <linux/efi.h>
12 #include <linux/types.h>
13 #include <linux/bitfield.h>
14 #include <asm/apic.h>
15 #include <asm/desc.h>
16 #include <asm/hypervisor.h>
17 #include <asm/hyperv-tlfs.h>
18 #include <asm/mshyperv.h>
19 #include <asm/idtentry.h>
20 #include <linux/kexec.h>
21 #include <linux/version.h>
22 #include <linux/vmalloc.h>
23 #include <linux/mm.h>
24 #include <linux/hyperv.h>
25 #include <linux/slab.h>
26 #include <linux/kernel.h>
27 #include <linux/cpuhotplug.h>
28 #include <linux/syscore_ops.h>
29 #include <clocksource/hyperv_timer.h>
30 
31 int hyperv_init_cpuhp;
32 u64 hv_current_partition_id = ~0ull;
33 EXPORT_SYMBOL_GPL(hv_current_partition_id);
34 
35 void *hv_hypercall_pg;
36 EXPORT_SYMBOL_GPL(hv_hypercall_pg);
37 
38 /* Storage to save the hypercall page temporarily for hibernation */
39 static void *hv_hypercall_pg_saved;
40 
41 u32 *hv_vp_index;
42 EXPORT_SYMBOL_GPL(hv_vp_index);
43 
44 struct hv_vp_assist_page **hv_vp_assist_page;
45 EXPORT_SYMBOL_GPL(hv_vp_assist_page);
46 
47 void  __percpu **hyperv_pcpu_input_arg;
48 EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg);
49 
50 void  __percpu **hyperv_pcpu_output_arg;
51 EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg);
52 
53 u32 hv_max_vp_index;
54 EXPORT_SYMBOL_GPL(hv_max_vp_index);
55 
56 void *hv_alloc_hyperv_page(void)
57 {
58 	BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
59 
60 	return (void *)__get_free_page(GFP_KERNEL);
61 }
62 EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
63 
64 void *hv_alloc_hyperv_zeroed_page(void)
65 {
66         BUILD_BUG_ON(PAGE_SIZE != HV_HYP_PAGE_SIZE);
67 
68         return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
69 }
70 EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
71 
72 void hv_free_hyperv_page(unsigned long addr)
73 {
74 	free_page(addr);
75 }
76 EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
77 
78 static int hv_cpu_init(unsigned int cpu)
79 {
80 	u64 msr_vp_index;
81 	struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()];
82 	void **input_arg;
83 	struct page *pg;
84 
85 	/* hv_cpu_init() can be called with IRQs disabled from hv_resume() */
86 	pg = alloc_pages(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL, hv_root_partition ? 1 : 0);
87 	if (unlikely(!pg))
88 		return -ENOMEM;
89 
90 	input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
91 	*input_arg = page_address(pg);
92 	if (hv_root_partition) {
93 		void **output_arg;
94 
95 		output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
96 		*output_arg = page_address(pg + 1);
97 	}
98 
99 	hv_get_vp_index(msr_vp_index);
100 
101 	hv_vp_index[smp_processor_id()] = msr_vp_index;
102 
103 	if (msr_vp_index > hv_max_vp_index)
104 		hv_max_vp_index = msr_vp_index;
105 
106 	if (!hv_vp_assist_page)
107 		return 0;
108 
109 	/*
110 	 * The VP ASSIST PAGE is an "overlay" page (see Hyper-V TLFS's Section
111 	 * 5.2.1 "GPA Overlay Pages"). Here it must be zeroed out to make sure
112 	 * we always write the EOI MSR in hv_apic_eoi_write() *after* the
113 	 * EOI optimization is disabled in hv_cpu_die(), otherwise a CPU may
114 	 * not be stopped in the case of CPU offlining and the VM will hang.
115 	 */
116 	if (!*hvp) {
117 		*hvp = __vmalloc(PAGE_SIZE, GFP_KERNEL | __GFP_ZERO);
118 	}
119 
120 	if (*hvp) {
121 		u64 val;
122 
123 		val = vmalloc_to_pfn(*hvp);
124 		val = (val << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) |
125 			HV_X64_MSR_VP_ASSIST_PAGE_ENABLE;
126 
127 		wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val);
128 	}
129 
130 	return 0;
131 }
132 
133 static void (*hv_reenlightenment_cb)(void);
134 
135 static void hv_reenlightenment_notify(struct work_struct *dummy)
136 {
137 	struct hv_tsc_emulation_status emu_status;
138 
139 	rdmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
140 
141 	/* Don't issue the callback if TSC accesses are not emulated */
142 	if (hv_reenlightenment_cb && emu_status.inprogress)
143 		hv_reenlightenment_cb();
144 }
145 static DECLARE_DELAYED_WORK(hv_reenlightenment_work, hv_reenlightenment_notify);
146 
147 void hyperv_stop_tsc_emulation(void)
148 {
149 	u64 freq;
150 	struct hv_tsc_emulation_status emu_status;
151 
152 	rdmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
153 	emu_status.inprogress = 0;
154 	wrmsrl(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
155 
156 	rdmsrl(HV_X64_MSR_TSC_FREQUENCY, freq);
157 	tsc_khz = div64_u64(freq, 1000);
158 }
159 EXPORT_SYMBOL_GPL(hyperv_stop_tsc_emulation);
160 
161 static inline bool hv_reenlightenment_available(void)
162 {
163 	/*
164 	 * Check for required features and priviliges to make TSC frequency
165 	 * change notifications work.
166 	 */
167 	return ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
168 		ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE &&
169 		ms_hyperv.features & HV_ACCESS_REENLIGHTENMENT;
170 }
171 
172 DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_reenlightenment)
173 {
174 	ack_APIC_irq();
175 	inc_irq_stat(irq_hv_reenlightenment_count);
176 	schedule_delayed_work(&hv_reenlightenment_work, HZ/10);
177 }
178 
179 void set_hv_tscchange_cb(void (*cb)(void))
180 {
181 	struct hv_reenlightenment_control re_ctrl = {
182 		.vector = HYPERV_REENLIGHTENMENT_VECTOR,
183 		.enabled = 1,
184 		.target_vp = hv_vp_index[smp_processor_id()]
185 	};
186 	struct hv_tsc_emulation_control emu_ctrl = {.enabled = 1};
187 
188 	if (!hv_reenlightenment_available()) {
189 		pr_warn("Hyper-V: reenlightenment support is unavailable\n");
190 		return;
191 	}
192 
193 	hv_reenlightenment_cb = cb;
194 
195 	/* Make sure callback is registered before we write to MSRs */
196 	wmb();
197 
198 	wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
199 	wrmsrl(HV_X64_MSR_TSC_EMULATION_CONTROL, *((u64 *)&emu_ctrl));
200 }
201 EXPORT_SYMBOL_GPL(set_hv_tscchange_cb);
202 
203 void clear_hv_tscchange_cb(void)
204 {
205 	struct hv_reenlightenment_control re_ctrl;
206 
207 	if (!hv_reenlightenment_available())
208 		return;
209 
210 	rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *(u64 *)&re_ctrl);
211 	re_ctrl.enabled = 0;
212 	wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *(u64 *)&re_ctrl);
213 
214 	hv_reenlightenment_cb = NULL;
215 }
216 EXPORT_SYMBOL_GPL(clear_hv_tscchange_cb);
217 
218 static int hv_cpu_die(unsigned int cpu)
219 {
220 	struct hv_reenlightenment_control re_ctrl;
221 	unsigned int new_cpu;
222 	unsigned long flags;
223 	void **input_arg;
224 	void *pg;
225 
226 	local_irq_save(flags);
227 	input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg);
228 	pg = *input_arg;
229 	*input_arg = NULL;
230 
231 	if (hv_root_partition) {
232 		void **output_arg;
233 
234 		output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
235 		*output_arg = NULL;
236 	}
237 
238 	local_irq_restore(flags);
239 
240 	free_pages((unsigned long)pg, hv_root_partition ? 1 : 0);
241 
242 	if (hv_vp_assist_page && hv_vp_assist_page[cpu])
243 		wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0);
244 
245 	if (hv_reenlightenment_cb == NULL)
246 		return 0;
247 
248 	rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
249 	if (re_ctrl.target_vp == hv_vp_index[cpu]) {
250 		/*
251 		 * Reassign reenlightenment notifications to some other online
252 		 * CPU or just disable the feature if there are no online CPUs
253 		 * left (happens on hibernation).
254 		 */
255 		new_cpu = cpumask_any_but(cpu_online_mask, cpu);
256 
257 		if (new_cpu < nr_cpu_ids)
258 			re_ctrl.target_vp = hv_vp_index[new_cpu];
259 		else
260 			re_ctrl.enabled = 0;
261 
262 		wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
263 	}
264 
265 	return 0;
266 }
267 
268 static int __init hv_pci_init(void)
269 {
270 	int gen2vm = efi_enabled(EFI_BOOT);
271 
272 	/*
273 	 * For Generation-2 VM, we exit from pci_arch_init() by returning 0.
274 	 * The purpose is to suppress the harmless warning:
275 	 * "PCI: Fatal: No config space access function found"
276 	 */
277 	if (gen2vm)
278 		return 0;
279 
280 	/* For Generation-1 VM, we'll proceed in pci_arch_init().  */
281 	return 1;
282 }
283 
284 static int hv_suspend(void)
285 {
286 	union hv_x64_msr_hypercall_contents hypercall_msr;
287 	int ret;
288 
289 	/*
290 	 * Reset the hypercall page as it is going to be invalidated
291 	 * accross hibernation. Setting hv_hypercall_pg to NULL ensures
292 	 * that any subsequent hypercall operation fails safely instead of
293 	 * crashing due to an access of an invalid page. The hypercall page
294 	 * pointer is restored on resume.
295 	 */
296 	hv_hypercall_pg_saved = hv_hypercall_pg;
297 	hv_hypercall_pg = NULL;
298 
299 	/* Disable the hypercall page in the hypervisor */
300 	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
301 	hypercall_msr.enable = 0;
302 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
303 
304 	ret = hv_cpu_die(0);
305 	return ret;
306 }
307 
308 static void hv_resume(void)
309 {
310 	union hv_x64_msr_hypercall_contents hypercall_msr;
311 	int ret;
312 
313 	ret = hv_cpu_init(0);
314 	WARN_ON(ret);
315 
316 	/* Re-enable the hypercall page */
317 	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
318 	hypercall_msr.enable = 1;
319 	hypercall_msr.guest_physical_address =
320 		vmalloc_to_pfn(hv_hypercall_pg_saved);
321 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
322 
323 	hv_hypercall_pg = hv_hypercall_pg_saved;
324 	hv_hypercall_pg_saved = NULL;
325 
326 	/*
327 	 * Reenlightenment notifications are disabled by hv_cpu_die(0),
328 	 * reenable them here if hv_reenlightenment_cb was previously set.
329 	 */
330 	if (hv_reenlightenment_cb)
331 		set_hv_tscchange_cb(hv_reenlightenment_cb);
332 }
333 
334 /* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */
335 static struct syscore_ops hv_syscore_ops = {
336 	.suspend	= hv_suspend,
337 	.resume		= hv_resume,
338 };
339 
340 static void (* __initdata old_setup_percpu_clockev)(void);
341 
342 static void __init hv_stimer_setup_percpu_clockev(void)
343 {
344 	/*
345 	 * Ignore any errors in setting up stimer clockevents
346 	 * as we can run with the LAPIC timer as a fallback.
347 	 */
348 	(void)hv_stimer_alloc();
349 
350 	/*
351 	 * Still register the LAPIC timer, because the direct-mode STIMER is
352 	 * not supported by old versions of Hyper-V. This also allows users
353 	 * to switch to LAPIC timer via /sys, if they want to.
354 	 */
355 	if (old_setup_percpu_clockev)
356 		old_setup_percpu_clockev();
357 }
358 
359 static void __init hv_get_partition_id(void)
360 {
361 	struct hv_get_partition_id *output_page;
362 	u64 status;
363 	unsigned long flags;
364 
365 	local_irq_save(flags);
366 	output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
367 	status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
368 	if ((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS) {
369 		/* No point in proceeding if this failed */
370 		pr_err("Failed to get partition ID: %lld\n", status);
371 		BUG();
372 	}
373 	hv_current_partition_id = output_page->partition_id;
374 	local_irq_restore(flags);
375 }
376 
377 /*
378  * This function is to be invoked early in the boot sequence after the
379  * hypervisor has been detected.
380  *
381  * 1. Setup the hypercall page.
382  * 2. Register Hyper-V specific clocksource.
383  * 3. Setup Hyper-V specific APIC entry points.
384  */
385 void __init hyperv_init(void)
386 {
387 	u64 guest_id, required_msrs;
388 	union hv_x64_msr_hypercall_contents hypercall_msr;
389 	int cpuhp, i;
390 
391 	if (x86_hyper_type != X86_HYPER_MS_HYPERV)
392 		return;
393 
394 	/* Absolutely required MSRs */
395 	required_msrs = HV_MSR_HYPERCALL_AVAILABLE |
396 		HV_MSR_VP_INDEX_AVAILABLE;
397 
398 	if ((ms_hyperv.features & required_msrs) != required_msrs)
399 		return;
400 
401 	/*
402 	 * Allocate the per-CPU state for the hypercall input arg.
403 	 * If this allocation fails, we will not be able to setup
404 	 * (per-CPU) hypercall input page and thus this failure is
405 	 * fatal on Hyper-V.
406 	 */
407 	hyperv_pcpu_input_arg = alloc_percpu(void  *);
408 
409 	BUG_ON(hyperv_pcpu_input_arg == NULL);
410 
411 	/* Allocate the per-CPU state for output arg for root */
412 	if (hv_root_partition) {
413 		hyperv_pcpu_output_arg = alloc_percpu(void *);
414 		BUG_ON(hyperv_pcpu_output_arg == NULL);
415 	}
416 
417 	/* Allocate percpu VP index */
418 	hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
419 				    GFP_KERNEL);
420 	if (!hv_vp_index)
421 		return;
422 
423 	for (i = 0; i < num_possible_cpus(); i++)
424 		hv_vp_index[i] = VP_INVAL;
425 
426 	hv_vp_assist_page = kcalloc(num_possible_cpus(),
427 				    sizeof(*hv_vp_assist_page), GFP_KERNEL);
428 	if (!hv_vp_assist_page) {
429 		ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED;
430 		goto free_vp_index;
431 	}
432 
433 	cpuhp = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online",
434 				  hv_cpu_init, hv_cpu_die);
435 	if (cpuhp < 0)
436 		goto free_vp_assist_page;
437 
438 	/*
439 	 * Setup the hypercall page and enable hypercalls.
440 	 * 1. Register the guest ID
441 	 * 2. Enable the hypercall and register the hypercall page
442 	 */
443 	guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
444 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
445 
446 	hv_hypercall_pg = __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START,
447 			VMALLOC_END, GFP_KERNEL, PAGE_KERNEL_ROX,
448 			VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,
449 			__builtin_return_address(0));
450 	if (hv_hypercall_pg == NULL) {
451 		wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
452 		goto remove_cpuhp_state;
453 	}
454 
455 	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
456 	hypercall_msr.enable = 1;
457 	hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
458 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
459 
460 	/*
461 	 * hyperv_init() is called before LAPIC is initialized: see
462 	 * apic_intr_mode_init() -> x86_platform.apic_post_init() and
463 	 * apic_bsp_setup() -> setup_local_APIC(). The direct-mode STIMER
464 	 * depends on LAPIC, so hv_stimer_alloc() should be called from
465 	 * x86_init.timers.setup_percpu_clockev.
466 	 */
467 	old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev;
468 	x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev;
469 
470 	hv_apic_init();
471 
472 	x86_init.pci.arch_init = hv_pci_init;
473 
474 	register_syscore_ops(&hv_syscore_ops);
475 
476 	hyperv_init_cpuhp = cpuhp;
477 
478 	if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
479 		hv_get_partition_id();
480 
481 	BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
482 
483 	return;
484 
485 remove_cpuhp_state:
486 	cpuhp_remove_state(cpuhp);
487 free_vp_assist_page:
488 	kfree(hv_vp_assist_page);
489 	hv_vp_assist_page = NULL;
490 free_vp_index:
491 	kfree(hv_vp_index);
492 	hv_vp_index = NULL;
493 }
494 
495 /*
496  * This routine is called before kexec/kdump, it does the required cleanup.
497  */
498 void hyperv_cleanup(void)
499 {
500 	union hv_x64_msr_hypercall_contents hypercall_msr;
501 
502 	unregister_syscore_ops(&hv_syscore_ops);
503 
504 	/* Reset our OS id */
505 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
506 
507 	/*
508 	 * Reset hypercall page reference before reset the page,
509 	 * let hypercall operations fail safely rather than
510 	 * panic the kernel for using invalid hypercall page
511 	 */
512 	hv_hypercall_pg = NULL;
513 
514 	/* Reset the hypercall page */
515 	hypercall_msr.as_uint64 = 0;
516 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
517 
518 	/* Reset the TSC page */
519 	hypercall_msr.as_uint64 = 0;
520 	wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
521 }
522 EXPORT_SYMBOL_GPL(hyperv_cleanup);
523 
524 void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
525 {
526 	static bool panic_reported;
527 	u64 guest_id;
528 
529 	if (in_die && !panic_on_oops)
530 		return;
531 
532 	/*
533 	 * We prefer to report panic on 'die' chain as we have proper
534 	 * registers to report, but if we miss it (e.g. on BUG()) we need
535 	 * to report it on 'panic'.
536 	 */
537 	if (panic_reported)
538 		return;
539 	panic_reported = true;
540 
541 	rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
542 
543 	wrmsrl(HV_X64_MSR_CRASH_P0, err);
544 	wrmsrl(HV_X64_MSR_CRASH_P1, guest_id);
545 	wrmsrl(HV_X64_MSR_CRASH_P2, regs->ip);
546 	wrmsrl(HV_X64_MSR_CRASH_P3, regs->ax);
547 	wrmsrl(HV_X64_MSR_CRASH_P4, regs->sp);
548 
549 	/*
550 	 * Let Hyper-V know there is crash data available
551 	 */
552 	wrmsrl(HV_X64_MSR_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
553 }
554 EXPORT_SYMBOL_GPL(hyperv_report_panic);
555 
556 /**
557  * hyperv_report_panic_msg - report panic message to Hyper-V
558  * @pa: physical address of the panic page containing the message
559  * @size: size of the message in the page
560  */
561 void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
562 {
563 	/*
564 	 * P3 to contain the physical address of the panic page & P4 to
565 	 * contain the size of the panic data in that page. Rest of the
566 	 * registers are no-op when the NOTIFY_MSG flag is set.
567 	 */
568 	wrmsrl(HV_X64_MSR_CRASH_P0, 0);
569 	wrmsrl(HV_X64_MSR_CRASH_P1, 0);
570 	wrmsrl(HV_X64_MSR_CRASH_P2, 0);
571 	wrmsrl(HV_X64_MSR_CRASH_P3, pa);
572 	wrmsrl(HV_X64_MSR_CRASH_P4, size);
573 
574 	/*
575 	 * Let Hyper-V know there is crash data available along with
576 	 * the panic message.
577 	 */
578 	wrmsrl(HV_X64_MSR_CRASH_CTL,
579 	       (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
580 }
581 EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
582 
583 bool hv_is_hyperv_initialized(void)
584 {
585 	union hv_x64_msr_hypercall_contents hypercall_msr;
586 
587 	/*
588 	 * Ensure that we're really on Hyper-V, and not a KVM or Xen
589 	 * emulation of Hyper-V
590 	 */
591 	if (x86_hyper_type != X86_HYPER_MS_HYPERV)
592 		return false;
593 
594 	/*
595 	 * Verify that earlier initialization succeeded by checking
596 	 * that the hypercall page is setup
597 	 */
598 	hypercall_msr.as_uint64 = 0;
599 	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
600 
601 	return hypercall_msr.enable;
602 }
603 EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);
604 
605 bool hv_is_hibernation_supported(void)
606 {
607 	return acpi_sleep_state_supported(ACPI_STATE_S4);
608 }
609 EXPORT_SYMBOL_GPL(hv_is_hibernation_supported);
610 
611 enum hv_isolation_type hv_get_isolation_type(void)
612 {
613 	if (!(ms_hyperv.features_b & HV_ISOLATION))
614 		return HV_ISOLATION_TYPE_NONE;
615 	return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b);
616 }
617 EXPORT_SYMBOL_GPL(hv_get_isolation_type);
618 
619 bool hv_is_isolation_supported(void)
620 {
621 	return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE;
622 }
623 EXPORT_SYMBOL_GPL(hv_is_isolation_supported);
624