public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Michael Kelley <mikelley@microsoft•com>
To: "will@kernel•org" <will@kernel•org>,
	"catalin.marinas@arm•com" <catalin.marinas@arm•com>,
	"mark.rutland@arm•com" <mark.rutland@arm•com>,
	"maz@kernel•org" <maz@kernel•org>,
	"linux-arm-kernel@lists•infradead.org"
	<linux-arm-kernel@lists•infradead.org>,
	"gregkh@linuxfoundation•org" <gregkh@linuxfoundation•org>,
	"linux-kernel@vger•kernel.org" <linux-kernel@vger•kernel.org>,
	"linux-hyperv@vger•kernel.org" <linux-hyperv@vger•kernel.org>,
	"devel@linuxdriverproject•org" <devel@linuxdriverproject•org>,
	"olaf@aepfle•de" <olaf@aepfle•de>,
	"apw@canonical•com" <apw@canonical•com>,
	vkuznets <vkuznets@redhat•com>,
	"jasowang@redhat•com" <jasowang@redhat•com>,
	"marcelo.cerri@canonical•com" <marcelo.cerri@canonical•com>,
	KY Srinivasan <kys@microsoft•com>
Cc: Sunil Muthuswamy <sunilmut@microsoft•com>,
	"boqun.feng" <boqun.feng@gmail•com>,
	Michael Kelley <mikelley@microsoft•com>
Subject: [PATCH v5 5/8] arm64: hyperv: Add kexec and panic handlers
Date: Thu, 3 Oct 2019 19:03:23 +0000	[thread overview]
Message-ID: <1570129355-16005-6-git-send-email-mikelley@microsoft.com> (raw)
In-Reply-To: <1570129355-16005-1-git-send-email-mikelley@microsoft.com>

Add functions to set up and remove kexec and panic
handlers, and to inform Hyper-V about a guest panic.
These functions 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>
---
 arch/arm64/hyperv/hv_init.c  | 61 ++++++++++++++++++++++++++++++++++++++++++++
 arch/arm64/hyperv/mshyperv.c | 26 +++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c
index 9c294f6..67350ec 100644
--- a/arch/arm64/hyperv/hv_init.c
+++ b/arch/arm64/hyperv/hv_init.c
@@ -199,3 +199,64 @@ void hv_get_vpreg_128(u32 msr, struct hv_get_vp_register_output *result)
 
 }
 EXPORT_SYMBOL_GPL(hv_get_vpreg_128);
+
+void hyperv_report_panic(struct pt_regs *regs, long err)
+{
+	static bool panic_reported;
+	u64 guest_id;
+
+	/*
+	 * We prefer to report panic on 'die' chain as we have proper
+	 * registers to report, but if we miss it (e.g. on BUG()) we need
+	 * to report it on 'panic'.
+	 */
+	if (panic_reported)
+		return;
+	panic_reported = true;
+
+	guest_id = hv_get_vpreg(HV_REGISTER_GUEST_OSID);
+
+	/*
+	 * Hyper-V provides the ability to store only 5 values.
+	 * Pick the passed in error value, the guest_id, and the PC.
+	 * The first two general registers are added arbitrarily.
+	 */
+	hv_set_vpreg(HV_REGISTER_CRASH_P0, err);
+	hv_set_vpreg(HV_REGISTER_CRASH_P1, guest_id);
+	hv_set_vpreg(HV_REGISTER_CRASH_P2, regs->pc);
+	hv_set_vpreg(HV_REGISTER_CRASH_P3, regs->regs[0]);
+	hv_set_vpreg(HV_REGISTER_CRASH_P4, regs->regs[1]);
+
+	/*
+	 * Let Hyper-V know there is crash data available
+	 */
+	hv_set_vpreg(HV_REGISTER_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic);
+
+/*
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ */
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+	/*
+	 * P3 to contain the physical address of the panic page & P4 to
+	 * contain the size of the panic data in that page. Rest of the
+	 * registers are no-op when the NOTIFY_MSG flag is set.
+	 */
+	hv_set_vpreg(HV_REGISTER_CRASH_P0, 0);
+	hv_set_vpreg(HV_REGISTER_CRASH_P1, 0);
+	hv_set_vpreg(HV_REGISTER_CRASH_P2, 0);
+	hv_set_vpreg(HV_REGISTER_CRASH_P3, pa);
+	hv_set_vpreg(HV_REGISTER_CRASH_P4, size);
+
+	/*
+	 * Let Hyper-V know there is crash data available along with
+	 * the panic message.
+	 */
+	hv_set_vpreg(HV_REGISTER_CRASH_CTL,
+	       (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
index ae6ece6..c58940d 100644
--- a/arch/arm64/hyperv/mshyperv.c
+++ b/arch/arm64/hyperv/mshyperv.c
@@ -23,6 +23,8 @@
 
 static void (*vmbus_handler)(void);
 static void (*hv_stimer0_handler)(void);
+static void (*hv_kexec_handler)(void);
+static void (*hv_crash_handler)(struct pt_regs *regs);
 
 static int vmbus_irq;
 static long __percpu *vmbus_evt;
@@ -137,3 +139,27 @@ void hv_remove_stimer0_irq(int irq)
 	}
 }
 EXPORT_SYMBOL_GPL(hv_remove_stimer0_irq);
+
+void hv_setup_kexec_handler(void (*handler)(void))
+{
+	hv_kexec_handler = handler;
+}
+EXPORT_SYMBOL_GPL(hv_setup_kexec_handler);
+
+void hv_remove_kexec_handler(void)
+{
+	hv_kexec_handler = NULL;
+}
+EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);
+
+void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs))
+{
+	hv_crash_handler = handler;
+}
+EXPORT_SYMBOL_GPL(hv_setup_crash_handler);
+
+void hv_remove_crash_handler(void)
+{
+	hv_crash_handler = NULL;
+}
+EXPORT_SYMBOL_GPL(hv_remove_crash_handler);
-- 
1.8.3.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-10-03 19:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 19:03 [PATCH v5 0/8] Enable Linux guests on Hyper-V on ARM64 Michael Kelley
2019-10-03 19:03 ` [PATCH v5 1/8] arm64: hyperv: Add core Hyper-V include files Michael Kelley
2019-10-03 19:03 ` [PATCH v5 2/8] arm64: hyperv: Add hypercall and register access functions Michael Kelley
2019-11-04  4:36   ` Boqun Feng
2019-11-06  0:40     ` Michael Kelley
2019-11-06 10:19   ` Marc Zyngier
2019-11-06 17:59     ` Michael Kelley
2019-11-07  9:10       ` Marc Zyngier
2019-11-11 17:16         ` Michael Kelley
2019-10-03 19:03 ` [PATCH v5 3/8] arm64: hyperv: Add memory alloc/free functions for Hyper-V size pages Michael Kelley
2019-11-07 14:19   ` Marc Zyngier
2019-11-08 19:00     ` Michael Kelley
2019-10-03 19:03 ` [PATCH v5 4/8] arm64: hyperv: Add interrupt handlers for VMbus and stimer Michael Kelley
2019-10-03 19:03 ` Michael Kelley [this message]
2019-10-03 19:03 ` [PATCH v5 6/8] arm64: hyperv: Initialize hypervisor on boot Michael Kelley
2019-10-03 19:03 ` [PATCH v5 7/8] Drivers: hv: vmbus: Add hooks for per-CPU IRQ Michael Kelley
2019-10-03 19:03 ` [PATCH v5 8/8] Drivers: hv: Enable Hyper-V code to be built on ARM64 Michael Kelley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1570129355-16005-6-git-send-email-mikelley@microsoft.com \
    --to=mikelley@microsoft$(echo .)com \
    --cc=apw@canonical$(echo .)com \
    --cc=boqun.feng@gmail$(echo .)com \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=devel@linuxdriverproject$(echo .)org \
    --cc=gregkh@linuxfoundation$(echo .)org \
    --cc=jasowang@redhat$(echo .)com \
    --cc=kys@microsoft$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-hyperv@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=marcelo.cerri@canonical$(echo .)com \
    --cc=mark.rutland@arm$(echo .)com \
    --cc=maz@kernel$(echo .)org \
    --cc=olaf@aepfle$(echo .)de \
    --cc=sunilmut@microsoft$(echo .)com \
    --cc=vkuznets@redhat$(echo .)com \
    --cc=will@kernel$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox