[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] xen: handle domain_shutdown() return values


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • Date: Fri, 20 Nov 2026 16:08:15 +0000
  • Accept-language: en-US, uk-UA
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+SGl0uO3IilJGbFkVZBFXh9Xw3BZJkYmMsPYboFSYtk=; b=NgrEAtppYk6Jbc2HinUSMilFmO3pNxqNaXoBuo/OMFFLtKt678xEI7n+Ygx4MLWfEq8E6j4j2DuydvARUFqf6/LY8xFCige26S4LrBdSfIQktl9e1lm7sBp2Be9C37V93k0WlNfD64lfpxvuCjnP5Fer1MBwo5H5Y/yF8kAIZWTi0LGCO+AoILXBiColwHTc1uUT+KYh8pWN0bCSvpYF9W1z5aXOPVfzbJQWeMt4IOWixJHawm88L9mjAhEOvbvY9UUOxeyX0MGiArASeXmR3YjocEVKdGDUE3thwLlDLuBTwyCgu1qM+2xy0V+OR6WuXmSfHIFlDWnqWzMJ5ogkhQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mh87b3xaANhCyI/pB7J8k11zR5BMoXGTaSHzBQ6as9j3cST3CuivcKM0UEf4MzigxNYr2F0JtQpj3zqL5drAgs+/5uOIjBSkzc5iSfLDmy4a1lL9Uj9Mwdq/7lFIVUN+QHGqszV8jGOYaRwS6FXj0jLz8spkO6qQzy/htDTarY7GFl1APTO7cATVk/eJle4wLyaoV9DCLLshM4hayAzXVxijfIGRpYZc5tpqCalqTtGZs56LNiugGEowiN6cBNKGYknLQoVxPUSNxIJmVolVKw6x3oIP+ubRTURvnarA6qwKlm8FRRJ+8tlLufr8kdJPp0W9BJdi5jo1IP6BAF6O6A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>
  • Delivery-date: Fri, 20 Nov 2026 16:08:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdeQlZ+G+2VicjqkaZFs1q+PJATg==
  • Thread-topic: [PATCH v2] xen: handle domain_shutdown() return values

Ten callers discard the value returned by domain_shutdown(). MISRA C
Rule 17.7 requires the return value of a non-void function to be used,
and Directive 4.7 requires callers to test returned error information.

Return the status to guests using the legacy SCHEDOP_shutdown hypercall.
In PV shim mode, a cancelled suspend or a checkpoint returns 1. The
legacy handler loses that result and returns 0, telling the guest it
has resumed in a new domain.

Propagate the result from both remote shutdown operations. The explicit
zero in XEN_DMOP_remote_shutdown dates from when domain_shutdown()
returned void. Also propagate a failed poweroff from VCPUOP_down when
the last vCPU goes down. On that path the shim has not taken the local
vCPU offline, so reporting success would hide a failed request.

On Arm, domain_shutdown() returns zero whenever it returns. Assert
this in the PSCI poweroff and reset handlers so that a change to this
assumption is caught in debug builds. Keep the call outside ASSERT().

The HVM poweroff and triple-fault handlers, the domain crash path and
the watchdog callback cannot return a shutdown error to a caller. Log
these errors at guest error level. The configured triple-fault action
can be suspend, so only a negative result indicates failure.

Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
---
Changes in v2:
- Explain the MISRA rationale, the legacy suspend result and why the last
  vCPU's poweroff result matters. Drop Suggested-by.
- Use assertions for PSCI SYSTEM_OFF and SYSTEM_RESET on Arm.
- Use guest-class error messages for shutdown failures. Include the target
  domain when it can differ from the current domain, and the timer ID on
  watchdog expiry.
- Log poweroff failures in HVM release builds. For triple faults, report
  only negative results, since a suspend action can return 1.
- Drop the unreachable return at the end of do_sched_op_compat().

Previous RFC:
https://lore.kernel.org/xen-devel/95dacecdce8f8417562548e16a4d3e11c41a3f27.1773923242.git.mykola_kvach@xxxxxxxx/
---
 xen/arch/arm/vpsci.c    |  8 ++++++--
 xen/arch/x86/compat.c   |  5 +----
 xen/arch/x86/hvm/dm.c   |  3 +--
 xen/arch/x86/hvm/hvm.c  | 12 ++++++++++--
 xen/common/domain.c     |  9 +++++++--
 xen/common/sched/core.c |  8 ++++++--
 6 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/xen/arch/arm/vpsci.c b/xen/arch/arm/vpsci.c
index 
8c7a70c7a907cf96252ae60cabb3927e6a972a8a..ae92a336ede70e1e519703efb6d0e8f23f7d3fbc
 100644
--- a/xen/arch/arm/vpsci.c
+++ b/xen/arch/arm/vpsci.c
@@ -210,13 +210,17 @@ static int32_t do_psci_0_2_migrate_info_type(void)
 static void do_psci_0_2_system_off( void )
 {
     struct domain *d = current->domain;
-    domain_shutdown(d,SHUTDOWN_poweroff);
+    int rc = domain_shutdown(d, SHUTDOWN_poweroff);
+
+    ASSERT(!rc);
 }
 
 static void do_psci_0_2_system_reset(void)
 {
     struct domain *d = current->domain;
-    domain_shutdown(d,SHUTDOWN_reboot);
+    int rc = domain_shutdown(d, SHUTDOWN_reboot);
+
+    ASSERT(!rc);
 }
 
 static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t cid)
diff --git a/xen/arch/x86/compat.c b/xen/arch/x86/compat.c
index 
217b5b1fcc41700cde830a8c74f4c230d0e1d58c..ec3f253a8b46834932e05b53f7fa7022774f187e
 100644
--- a/xen/arch/x86/compat.c
+++ b/xen/arch/x86/compat.c
@@ -39,14 +39,11 @@ long do_sched_op_compat(int cmd, unsigned long arg)
     case SCHEDOP_shutdown:
         TRACE_TIME(TRC_SCHED_SHUTDOWN,
                    current->domain->domain_id, current->vcpu_id, arg);
-        domain_shutdown(current->domain, (u8)arg);
-        break;
+        return domain_shutdown(current->domain, (u8)arg);
 
     default:
         return -ENOSYS;
     }
-
-    return 0;
 }
 
 /* Legacy hypercall (as of 0x00030202). */
diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 
91f6ca669b2b4304c8c25265253778538eac1109..7528bb5b2c60948c388e2739624589dc8a5b0d49
 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -551,8 +551,7 @@ int dm_op(const struct dmop_args *op_args)
         const struct xen_dm_op_remote_shutdown *data =
             &op.u.remote_shutdown;
 
-        domain_shutdown(d, data->reason);
-        rc = 0;
+        rc = domain_shutdown(d, data->reason);
         break;
     }
 
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 
4334ff678d348f1002d5b509daeef2bf4057d78e..98deb2eefc5127ec13fdd610a6c2686c39939bb4
 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1720,8 +1720,12 @@ void hvm_vcpu_down(struct vcpu *v)
     /* ... Shut down the domain if not. */
     if ( online_count == 0 )
     {
+        int rc;
+
         gdprintk(XENLOG_INFO, "All CPUs offline -- powering off.\n");
-        domain_shutdown(d, SHUTDOWN_poweroff);
+        rc = domain_shutdown(d, SHUTDOWN_poweroff);
+        if ( unlikely(rc < 0) )
+            printk(XENLOG_G_ERR "%pd: failed to power off: %d\n", d, rc);
     }
 }
 
@@ -1750,12 +1754,16 @@ void hvm_triple_fault(void)
     struct vcpu *v = current;
     struct domain *d = v->domain;
     u8 reason = d->arch.hvm.params[HVM_PARAM_TRIPLE_FAULT_REASON];
+    int rc;
 
     gprintk(XENLOG_ERR,
             "Triple fault - invoking HVM shutdown action %d\n",
             reason);
     vcpu_show_execution_state(v);
-    domain_shutdown(d, reason);
+    rc = domain_shutdown(d, reason);
+    if ( unlikely(rc < 0) )
+        gprintk(XENLOG_ERR, "Failed to shut down after triple fault: %d\n",
+                rc);
 }
 
 void hvm_inject_event(const struct x86_event *event)
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 
f3a2634d5f985e094236f81c49acbf6f9ebc8d58..9253c811b520977a691f831fa979eb0df135af95
 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1358,6 +1358,8 @@ int domain_kill(struct domain *d)
 
 void __domain_crash(struct domain *d)
 {
+    int rc;
+
     if ( domain_shutting_down(d) )
     {
         /* Print nothing: the domain is already shutting down. */
@@ -1374,7 +1376,10 @@ void __domain_crash(struct domain *d)
                d->domain_id, current->domain->domain_id, smp_processor_id());
     }
 
-    domain_shutdown(d, SHUTDOWN_crash);
+    rc = domain_shutdown(d, SHUTDOWN_crash);
+    if ( unlikely(rc) )
+        printk(XENLOG_G_ERR "Failed to shut down crashed domain %pd: %d\n",
+               d, rc);
 }
 
 
@@ -2198,7 +2203,7 @@ long common_vcpu_op(int cmd, struct vcpu *v, 
XEN_GUEST_HANDLE_PARAM(void) arg)
 
         if ( !rc ) /* Last vcpu going down? */
         {
-            domain_shutdown(d, SHUTDOWN_poweroff);
+            rc = domain_shutdown(d, SHUTDOWN_poweroff);
             break;
         }
 
diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index 
10b6eecccd3b39cfdc684e434e6eb9cdcd707417..d3aca88cc832fe76fcb914aa870eaa82aef1113b
 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -1588,6 +1588,7 @@ static void cf_check domain_watchdog_timeout(void *data)
      */
     struct domain *d = _p((unsigned long)data & PAGE_MASK);
     unsigned int id = (unsigned long)data & ~PAGE_MASK;
+    int rc;
 
     BUILD_BUG_ON(alignof(*d) < PAGE_SIZE);
 
@@ -1595,7 +1596,10 @@ static void cf_check domain_watchdog_timeout(void *data)
         return;
 
     printk("Watchdog timer %u fired for %pd\n", id, d);
-    domain_shutdown(d, SHUTDOWN_watchdog);
+    rc = domain_shutdown(d, SHUTDOWN_watchdog);
+    if ( unlikely(rc) )
+        printk(XENLOG_G_ERR "Watchdog timer %u failed to shut down %pd: %d\n",
+               id, d, rc);
 }
 
 static long domain_watchdog(struct domain *d, uint32_t id, uint32_t timeout)
@@ -2027,7 +2031,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) 
arg)
 
         ret = xsm_schedop_shutdown(XSM_DM_PRIV, currd, d);
         if ( likely(!ret) )
-            domain_shutdown(d, sched_remote_shutdown.reason);
+            ret = domain_shutdown(d, sched_remote_shutdown.reason);
 
         rcu_unlock_domain(d);
 


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.