git: ca46f3289d96 - main - xen: use an hypercall for shutdown and reboot

From: Roger Pau Monné <royger_at_FreeBSD.org>
Date: Thu, 13 Jan 2022 15:54:56 UTC
The branch main has been updated by royger:

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

commit ca46f3289d9630a9b203379333b46f3f11363146
Author:     Roger Pau Monné <royger@FreeBSD.org>
AuthorDate: 2022-01-13 13:47:18 +0000
Commit:     Roger Pau Monné <royger@FreeBSD.org>
CommitDate: 2022-01-13 15:54:30 +0000

    xen: use an hypercall for shutdown and reboot
    
    When running as a Xen guest it's easier to use an hypercall in order
    to do power management operations (power off, power cycle). Do this
    for all supported guest types (HVM and PVH). Note that for HVM the
    power operation could also be done using ACPI, but there's no reason
    to differentiate between PVH and HVM.
    
    While there fix the shutdown handler to properly differentiate between
    power cycle and power off requests.
    
    Reported by: Freddy DISSAUX
    MFC: 1 week
    Sponsored by: Citrix Systems R&D
---
 sys/dev/xen/control/control.c | 18 ++++++------------
 sys/x86/include/xen/xen-os.h  |  7 -------
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
index 426682a8f2d9..b42b52a62411 100644
--- a/sys/dev/xen/control/control.c
+++ b/sys/dev/xen/control/control.c
@@ -347,17 +347,12 @@ xctrl_crash()
 }
 
 static void
-xen_pv_shutdown_final(void *arg, int howto)
+shutdown_final(void *arg, int howto)
 {
-	/*
-	 * Inform the hypervisor that shutdown is complete.
-	 * This is not necessary in HVM domains since Xen
-	 * emulates ACPI in that mode and FreeBSD's ACPI
-	 * support will request this transition.
-	 */
-	if (howto & (RB_HALT | RB_POWEROFF))
+	/* Inform the hypervisor that shutdown is complete. */
+	if (howto & RB_POWEROFF)
 		HYPERVISOR_shutdown(SHUTDOWN_poweroff);
-	else
+	else if (howto & RB_POWERCYCLE)
 		HYPERVISOR_shutdown(SHUTDOWN_reboot);
 }
 
@@ -453,9 +448,8 @@ xctrl_attach(device_t dev)
 	xctrl->xctrl_watch.max_pending = 1;
 	xs_register_watch(&xctrl->xctrl_watch);
 
-	if (xen_pv_shutdown_handler())
-		EVENTHANDLER_REGISTER(shutdown_final, xen_pv_shutdown_final, NULL,
-		                      SHUTDOWN_PRI_LAST);
+	EVENTHANDLER_REGISTER(shutdown_final, shutdown_final, NULL,
+	    SHUTDOWN_PRI_LAST);
 
 	return (0);
 }
diff --git a/sys/x86/include/xen/xen-os.h b/sys/x86/include/xen/xen-os.h
index 9d0964c6631d..655961da22fd 100644
--- a/sys/x86/include/xen/xen-os.h
+++ b/sys/x86/include/xen/xen-os.h
@@ -56,13 +56,6 @@ xen_has_percpu_evtchn(void)
 	return (!xen_hvm_domain() || xen_vector_callback_enabled);
 }
 
-static inline bool
-xen_pv_shutdown_handler(void)
-{
-
-	return (xen_pv_domain());
-}
-
 static inline bool
 xen_pv_disks_disabled(void)
 {