xref: /openbmc/linux/arch/x86/hyperv/nested.c (revision d4295e12)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 /*
4  * Hyper-V nested virtualization code.
5  *
6  * Copyright (C) 2018, Microsoft, Inc.
7  *
8  * Author : Lan Tianyu <Tianyu.Lan@microsoft.com>
9  */
10 
11 
12 #include <linux/types.h>
13 #include <asm/hyperv-tlfs.h>
14 #include <asm/mshyperv.h>
15 #include <asm/tlbflush.h>
16 
17 #include <asm/trace/hyperv.h>
18 
19 int hyperv_flush_guest_mapping(u64 as)
20 {
21 	struct hv_guest_mapping_flush **flush_pcpu;
22 	struct hv_guest_mapping_flush *flush;
23 	u64 status;
24 	unsigned long flags;
25 	int ret = -ENOTSUPP;
26 
27 	if (!hv_hypercall_pg)
28 		goto fault;
29 
30 	local_irq_save(flags);
31 
32 	flush_pcpu = (struct hv_guest_mapping_flush **)
33 		this_cpu_ptr(hyperv_pcpu_input_arg);
34 
35 	flush = *flush_pcpu;
36 
37 	if (unlikely(!flush)) {
38 		local_irq_restore(flags);
39 		goto fault;
40 	}
41 
42 	flush->address_space = as;
43 	flush->flags = 0;
44 
45 	status = hv_do_hypercall(HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE,
46 				 flush, NULL);
47 	local_irq_restore(flags);
48 
49 	if (!(status & HV_HYPERCALL_RESULT_MASK))
50 		ret = 0;
51 
52 fault:
53 	trace_hyperv_nested_flush_guest_mapping(as, ret);
54 	return ret;
55 }
56 EXPORT_SYMBOL_GPL(hyperv_flush_guest_mapping);
57