git: c13f564f9176 - stable/14 - xen: improve shutdown hook

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 08 Dec 2023 22:03:04 UTC
The branch stable/14 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=c13f564f9176c3d946e61519ddbfa0c1e23114ab

commit c13f564f9176c3d946e61519ddbfa0c1e23114ab
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-11-23 15:27:20 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-12-08 22:02:44 +0000

    xen: improve shutdown hook
    
    Make better use of the shutdown flags. In particular this now handles
    standard reboot where RB_POWERCYCLE is not set, and indicates a crash
    when the system has panicked.
    
    While here, give the function a prefix.
    
    Reviewed by:    royger, markj
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D42343
    
    (cherry picked from commit 9e0b0f5de67fd46bddf0e12ef7b71d76a7ec1667)
---
 sys/dev/xen/control/control.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
index 9ea0222809a0..37b4bff709c7 100644
--- a/sys/dev/xen/control/control.c
+++ b/sys/dev/xen/control/control.c
@@ -345,12 +345,18 @@ xctrl_crash(void)
 }
 
 static void
-shutdown_final(void *arg, int howto)
+xctrl_shutdown_final(void *arg, int howto)
 {
-	/* Inform the hypervisor that shutdown is complete. */
-	if (howto & RB_POWEROFF)
+	/*
+	 * Inform the hypervisor that shutdown is complete, and specify the
+	 * nature of the shutdown. RB_HALT is not handled by this function.
+	 */
+	if (KERNEL_PANICKED())
+		HYPERVISOR_shutdown(SHUTDOWN_crash);
+	else if ((howto & RB_POWEROFF) != 0)
 		HYPERVISOR_shutdown(SHUTDOWN_poweroff);
-	else if (howto & RB_POWERCYCLE)
+	else if ((howto & RB_HALT) == 0)
+		/* RB_POWERCYCLE or regular reset. */
 		HYPERVISOR_shutdown(SHUTDOWN_reboot);
 }
 
@@ -446,7 +452,7 @@ xctrl_attach(device_t dev)
 	xctrl->xctrl_watch.max_pending = 1;
 	xs_register_watch(&xctrl->xctrl_watch);
 
-	EVENTHANDLER_REGISTER(shutdown_final, shutdown_final, NULL,
+	EVENTHANDLER_REGISTER(shutdown_final, xctrl_shutdown_final, NULL,
 	    SHUTDOWN_PRI_LAST);
 
 	return (0);