Linux-HyperV List
 help / color / mirror / Atom feed
From: Shradha Gupta <shradhagupta@linux.microsoft.com>
To: "K . Y . Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Long Li <longli@microsoft.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>
Cc: Shradha Gupta <shradhagupta@linux.microsoft.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Michael Kelley <mikelley@microsoft.com>,
	linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, namjain@linux.microsoft.com
Subject: [PATCH v2] arm64: hyperv: run VMBus kexec handler via syscore shutdown
Date: Mon,  7 Sep 2026 02:25:42 -0700	[thread overview]
Message-ID: <20260907092544.230338-1-shradhagupta@linux.microsoft.com> (raw)

On ARM64, machine_shutdown() does not provide a platform hook between
device_shutdown() and smp_shutdown_nonboot_cpus(), unlike x86's
machine_ops.shutdown. This prevents the Hyper-V VMBus kexec handler
from running at the correct point during kexec shutdown, causing
kexec reboot to fail on ARM64 Hyper-V guests.

Use syscore_ops.shutdown instead: syscore_shutdown() runs in the same
window (after device_shutdown(), before CPUs are taken offline) where
VMBus UNLOAD and cpuhp_remove_state() must execute.

Provide ARM64-specific overrides of hv_setup_kexec_handler() and
hv_remove_kexec_handler() that register/unregister a syscore_ops
shutdown callback, replacing the __weak no-op stubs in hv_common.c.
On x86, the existing machine_ops.shutdown mechanism is unchanged.

Fixes: 9d7cf2c96758 ("Drivers: hv: Add arch independent default functions for some Hyper-V handlers")
Link: https://lore.kernel.org/all/20260814093133.3191250-1-shradhagupta@linux.microsoft.com/
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
Reviewed-by: Naman Jain <namjain@linux.microsoft.com>
---
 Changes in V2
 * Use syscore_ops.shutdown instead of a bare function pointer hook in
   machine_shutdown(), per Catalin's suggestion.
---
 arch/arm64/hyperv/mshyperv.c | 40 ++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c
index 4fdc26ade1d7..e608e546a395 100644
--- a/arch/arm64/hyperv/mshyperv.c
+++ b/arch/arm64/hyperv/mshyperv.c
@@ -15,10 +15,50 @@
 #include <linux/errno.h>
 #include <linux/version.h>
 #include <linux/cpuhotplug.h>
+#include <linux/kexec.h>
+#include <linux/syscore_ops.h>
 #include <asm/mshyperv.h>
 
 static bool hyperv_initialized;
 
+/*
+ * Kexec handler registered by VMBus.
+ *
+ * On ARM64, machine_shutdown() does not provide a platform hook between
+ * device_shutdown() and smp_shutdown_nonboot_cpus(), unlike the
+ * machine_ops.shutdown mechanism used on x86.  Use a syscore_ops shutdown
+ * callback instead: syscore_shutdown() runs after device_shutdown() and
+ * before CPUs are taken offline, which is the same window VMBus needs to
+ * run its UNLOAD message and cpuhp_remove_state() during kexec.
+ */
+static void (*hv_kexec_handler_fn)(void);
+
+static void hv_kexec_syscore_shutdown(void *data)
+{
+	if (kexec_in_progress && hv_kexec_handler_fn)
+		hv_kexec_handler_fn();
+}
+
+static const struct syscore_ops hv_kexec_syscore_ops = {
+	.shutdown	= hv_kexec_syscore_shutdown,
+};
+
+static struct syscore hv_kexec_syscore = {
+	.ops		= &hv_kexec_syscore_ops,
+};
+
+void hv_setup_kexec_handler(void (*handler)(void))
+{
+	hv_kexec_handler_fn = handler;
+	register_syscore(&hv_kexec_syscore);
+}
+
+void hv_remove_kexec_handler(void)
+{
+	unregister_syscore(&hv_kexec_syscore);
+	hv_kexec_handler_fn = NULL;
+}
+
 int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
 {
 	hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION,
-- 
2.43.0


                 reply	other threads:[~2026-09-07  9:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260907092544.230338-1-shradhagupta@linux.microsoft.com \
    --to=shradhagupta@linux.microsoft.com \
    --cc=catalin.marinas@arm.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=mark.rutland@arm.com \
    --cc=mikelley@microsoft.com \
    --cc=namjain@linux.microsoft.com \
    --cc=wei.liu@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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