Skip to content

Commit 6a7797b

Browse files
kelleymhtyhicks
authored andcommitted
arm64: hyperv: Add kexec and panic handlers
Add function to inform Hyper-V about a guest panic. Also add functions to set up and remove kexec and panic handlers, which are currently unused on ARM64 but are called from architecture independent code in the VMbus driver. This code is built only when CONFIG_HYPERV is enabled. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Reviewed-by: Sunil Muthuswamy <sunilmut@microsoft.com>
1 parent 198e24a commit 6a7797b

3 files changed

Lines changed: 107 additions & 1 deletion

File tree

arch/arm64/hyperv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-y := hv_core.o
2+
obj-y := hv_core.o mshyperv.o

arch/arm64/hyperv/hv_core.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,55 @@ u64 hv_get_vpreg(u32 msr)
124124
return output.as64.low;
125125
}
126126
EXPORT_SYMBOL_GPL(hv_get_vpreg);
127+
128+
/*
129+
* hyperv_report_panic - report a panic to Hyper-V. This function uses
130+
* the older version of the Hyper-V interface that admittedly doesn't
131+
* pass enough information to be useful beyond just recording the
132+
* occurrence of a panic. The parallel hv_kmsg_dump() uses the
133+
* new interface that allows reporting 4 Kbytes of data, which is much
134+
* more useful. Hyper-V on ARM64 always supports the newer interface, but
135+
* we retain support for the older version because the sysadmin is allowed
136+
* to disable the newer version via sysctl in case of information security
137+
* concerns about the more verbose version.
138+
*/
139+
void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die)
140+
{
141+
static bool panic_reported;
142+
u64 guest_id;
143+
144+
/* Don't report a panic to Hyper-V if we're not going to panic */
145+
if (in_die && !panic_on_oops)
146+
return;
147+
148+
/*
149+
* We prefer to report panic on 'die' chain as we have proper
150+
* registers to report, but if we miss it (e.g. on BUG()) we need
151+
* to report it on 'panic'.
152+
*
153+
* Calling code in the 'die' and 'panic' paths ensures that only
154+
* one CPU is running this code, so no atomicity is needed.
155+
*/
156+
if (panic_reported)
157+
return;
158+
panic_reported = true;
159+
160+
guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OSID);
161+
162+
/*
163+
* Hyper-V provides the ability to store only 5 values.
164+
* Pick the passed in error value, the guest_id, and the PC.
165+
* The first two general registers are added arbitrarily.
166+
*/
167+
hv_set_vpreg(HV_REGISTER_CRASH_P0, err);
168+
hv_set_vpreg(HV_REGISTER_CRASH_P1, guest_id);
169+
hv_set_vpreg(HV_REGISTER_CRASH_P2, regs->pc);
170+
hv_set_vpreg(HV_REGISTER_CRASH_P3, regs->regs[0]);
171+
hv_set_vpreg(HV_REGISTER_CRASH_P4, regs->regs[1]);
172+
173+
/*
174+
* Let Hyper-V know there is crash data available
175+
*/
176+
hv_set_vpreg(HV_REGISTER_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
177+
}
178+
EXPORT_SYMBOL_GPL(hyperv_report_panic);

arch/arm64/hyperv/mshyperv.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/*
4+
* Core routines for interacting with Microsoft's Hyper-V hypervisor.
5+
* Includes hypervisor initialization, and handling of crashes and
6+
* kexecs through a set of static "handler" variables set by the
7+
* architecture independent VMbus driver.
8+
*
9+
* Copyright (C) 2021, Microsoft, Inc.
10+
*
11+
* Author : Michael Kelley <mikelley@microsoft.com>
12+
*/
13+
14+
#include <linux/types.h>
15+
#include <linux/export.h>
16+
#include <linux/ptrace.h>
17+
18+
/*
19+
* The VMbus handler functions are no-ops on ARM64 because
20+
* VMbus interrupts are handled as percpu IRQs.
21+
*/
22+
void hv_setup_vmbus_handler(void (*handler)(void))
23+
{
24+
}
25+
EXPORT_SYMBOL_GPL(hv_setup_vmbus_handler);
26+
27+
void hv_remove_vmbus_handler(void)
28+
{
29+
}
30+
EXPORT_SYMBOL_GPL(hv_remove_vmbus_handler);
31+
32+
/*
33+
* The kexec and crash handler functions are
34+
* currently no-ops on ARM64.
35+
*/
36+
void hv_setup_kexec_handler(void (*handler)(void))
37+
{
38+
}
39+
EXPORT_SYMBOL_GPL(hv_setup_kexec_handler);
40+
41+
void hv_remove_kexec_handler(void)
42+
{
43+
}
44+
EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);
45+
46+
void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs))
47+
{
48+
}
49+
EXPORT_SYMBOL_GPL(hv_setup_crash_handler);
50+
51+
void hv_remove_crash_handler(void)
52+
{
53+
}
54+
EXPORT_SYMBOL_GPL(hv_remove_crash_handler);

0 commit comments

Comments
 (0)