Skip to content

Commit 512c111

Browse files
kelleymhliuw
authored andcommitted
arm64: hyperv: Add panic handler
Add a function to inform Hyper-V about a guest panic. 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> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Acked-by: Marc Zyngier <maz@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/1628092359-61351-3-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 57d276b commit 512c111

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

arch/arm64/hyperv/hv_core.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,55 @@ u64 hv_get_vpreg(u32 msr)
127127
return output.as64.low;
128128
}
129129
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_OSID);
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_CRASH_P0, err);
171+
hv_set_vpreg(HV_REGISTER_CRASH_P1, guest_id);
172+
hv_set_vpreg(HV_REGISTER_CRASH_P2, regs->pc);
173+
hv_set_vpreg(HV_REGISTER_CRASH_P3, regs->sp);
174+
hv_set_vpreg(HV_REGISTER_CRASH_P4, 0);
175+
176+
/*
177+
* Let Hyper-V know there is crash data available
178+
*/
179+
hv_set_vpreg(HV_REGISTER_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
180+
}
181+
EXPORT_SYMBOL_GPL(hyperv_report_panic);

0 commit comments

Comments
 (0)