~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm64/hyperv/hv_core.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 /*
  4  * Low level utility routines for interacting with Hyper-V.
  5  *
  6  * Copyright (C) 2021, Microsoft, Inc.
  7  *
  8  * Author : Michael Kelley <mikelley@microsoft.com>
  9  */
 10 
 11 #include <linux/types.h>
 12 #include <linux/export.h>
 13 #include <linux/mm.h>
 14 #include <linux/hyperv.h>
 15 #include <linux/arm-smccc.h>
 16 #include <linux/module.h>
 17 #include <asm-generic/bug.h>
 18 #include <asm/hyperv-tlfs.h>
 19 #include <asm/mshyperv.h>
 20 
 21 /*
 22  * hv_do_hypercall- Invoke the specified hypercall
 23  */
 24 u64 hv_do_hypercall(u64 control, void *input, void *output)
 25 {
 26         struct arm_smccc_res    res;
 27         u64                     input_address;
 28         u64                     output_address;
 29 
 30         input_address = input ? virt_to_phys(input) : 0;
 31         output_address = output ? virt_to_phys(output) : 0;
 32 
 33         arm_smccc_1_1_hvc(HV_FUNC_ID, control,
 34                           input_address, output_address, &res);
 35         return res.a0;
 36 }
 37 EXPORT_SYMBOL_GPL(hv_do_hypercall);
 38 
 39 /*
 40  * hv_do_fast_hypercall8 -- Invoke the specified hypercall
 41  * with arguments in registers instead of physical memory.
 42  * Avoids the overhead of virt_to_phys for simple hypercalls.
 43  */
 44 
 45 u64 hv_do_fast_hypercall8(u16 code, u64 input)
 46 {
 47         struct arm_smccc_res    res;
 48         u64                     control;
 49 
 50         control = (u64)code | HV_HYPERCALL_FAST_BIT;
 51 
 52         arm_smccc_1_1_hvc(HV_FUNC_ID, control, input, &res);
 53         return res.a0;
 54 }
 55 EXPORT_SYMBOL_GPL(hv_do_fast_hypercall8);
 56 
 57 /*
 58  * Set a single VP register to a 64-bit value.
 59  */
 60 void hv_set_vpreg(u32 msr, u64 value)
 61 {
 62         struct arm_smccc_res res;
 63 
 64         arm_smccc_1_1_hvc(HV_FUNC_ID,
 65                 HVCALL_SET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
 66                         HV_HYPERCALL_REP_COMP_1,
 67                 HV_PARTITION_ID_SELF,
 68                 HV_VP_INDEX_SELF,
 69                 msr,
 70                 0,
 71                 value,
 72                 0,
 73                 &res);
 74 
 75         /*
 76          * Something is fundamentally broken in the hypervisor if
 77          * setting a VP register fails. There's really no way to
 78          * continue as a guest VM, so panic.
 79          */
 80         BUG_ON(!hv_result_success(res.a0));
 81 }
 82 EXPORT_SYMBOL_GPL(hv_set_vpreg);
 83 
 84 /*
 85  * Get the value of a single VP register.  One version
 86  * returns just 64 bits and another returns the full 128 bits.
 87  * The two versions are separate to avoid complicating the
 88  * calling sequence for the more frequently used 64 bit version.
 89  */
 90 
 91 void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *result)
 92 {
 93         struct arm_smccc_1_2_regs args;
 94         struct arm_smccc_1_2_regs res;
 95 
 96         args.a0 = HV_FUNC_ID;
 97         args.a1 = HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
 98                         HV_HYPERCALL_REP_COMP_1;
 99         args.a2 = HV_PARTITION_ID_SELF;
100         args.a3 = HV_VP_INDEX_SELF;
101         args.a4 = msr;
102 
103         /*
104          * Use the SMCCC 1.2 interface because the results are in registers
105          * beyond X0-X3.
106          */
107         arm_smccc_1_2_hvc(&args, &res);
108 
109         /*
110          * Something is fundamentally broken in the hypervisor if
111          * getting a VP register fails. There's really no way to
112          * continue as a guest VM, so panic.
113          */
114         BUG_ON(!hv_result_success(res.a0));
115 
116         result->as64.low = res.a6;
117         result->as64.high = res.a7;
118 }
119 EXPORT_SYMBOL_GPL(hv_get_vpreg_128);
120 
121 u64 hv_get_vpreg(u32 msr)
122 {
123         struct hv_get_vp_registers_output output;
124 
125         hv_get_vpreg_128(msr, &output);
126 
127         return output.as64.low;
128 }
129 EXPORT_SYMBOL_GPL(hv_get_vpreg);
130 
131 /*
132  * hyperv_report_panic - report a panic to Hyper-V.  This function uses
133  * the older version of the Hyper-V interface that admittedly doesn't
134  * pass enough information to be useful beyond just recording the
135  * occurrence of a panic. The parallel hv_kmsg_dump() uses the
136  * new interface that allows reporting 4 Kbytes of data, which is much
137  * more useful. Hyper-V on ARM64 always supports the newer interface, but
138  * we retain support for the older version because the sysadmin is allowed
139  * to disable the newer version via sysctl in case of information security
140  * concerns about the more verbose version.
141  */
142 void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
143 {
144         static bool     panic_reported;
145         u64             guest_id;
146 
147         /* Don't report a panic to Hyper-V if we're not going to panic */
148         if (in_die && !panic_on_oops)
149                 return;
150 
151         /*
152          * We prefer to report panic on 'die' chain as we have proper
153          * registers to report, but if we miss it (e.g. on BUG()) we need
154          * to report it on 'panic'.
155          *
156          * Calling code in the 'die' and 'panic' paths ensures that only
157          * one CPU is running this code, so no atomicity is needed.
158          */
159         if (panic_reported)
160                 return;
161         panic_reported = true;
162 
163         guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OS_ID);
164 
165         /*
166          * Hyper-V provides the ability to store only 5 values.
167          * Pick the passed in error value, the guest_id, the PC,
168          * and the SP.
169          */
170         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P0, err);
171         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P1, guest_id);
172         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P2, regs->pc);
173         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P3, regs->sp);
174         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_P4, 0);
175 
176         /*
177          * Let Hyper-V know there is crash data available
178          */
179         hv_set_vpreg(HV_REGISTER_GUEST_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
180 }
181 EXPORT_SYMBOL_GPL(hyperv_report_panic);
182 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php