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

[RFC PATCH] xen/domctl: require a completed shutdown before resuming a domain


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • Date: Fri, 20 Nov 2026 14:36:38 +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=d7V4kDl716LYw87g82pX2bW9hC8fnGQW5s/e2GlvkXI=; b=V80tFKFztXRSNBkNyR0bKu/Hc9rcRrZ2hhINm2RQymd1/eWdljmIK+omxkbOqyfWZ2E8777FE2cvuLpFlEZ8uD0XVWTu+IqPHmOB+TyVOp5Lalan5yr3CQftTPicJeD88eFA6W118yebRN5ag620YxWISOfdOXNCJ8qa/Ee10+KfTQRX4gptoP2MrpkDQhelFJ3Hr1EMSiAGgi3Qf7AbP/09t5PP8Y3UaAZJhCbH/TF6peez6iTNMkn3VutyKT84+NPr3+kavLkd/HghUpbKhOfadyY+aCTagUamRvCL9neA8qYbmbknrTx/HuFBAs/dr5IPJp9BKEIxvAqSn3NSYA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EUosSt+fO9JVJ9/bnIsldH/XgskO0m+Xd/Oj/20qMXwmq2JDJ9xPRh40luLuIU1EcvKLToihfzkS/pp+47XwkEBZoQS6j3fHbf67ebHfxL5miCgVMvj1QJjh24tfKUt9Fk8MeR4i3VrjdrD6938zsh7CTDM/vAL7TLEl5fiWKp5x6BZQTwxedUAiQP3CHO3mO8RoEQ+ofgX6uWTsjtfxs6YkLCfCJCYizTU5/CoZflH+kF/uiKV0gTxbkSbWF3sndDTL+CoZ7ABgaqz6xvqcmZ0CEkhsMUELmRw3immMpIubtg3jRbanyQAt2B6x/HtN7ezD1LvVmlmUXu2GLdG5jA==
  • 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: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 20 Nov 2026 14:37:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdePyNb0G+EmfpWk25fQ9bzS2vuQ==
  • Thread-topic: [RFC PATCH] xen/domctl: require a completed shutdown before resuming a domain

XEN_DOMCTL_resumedomain can clear a reason set with SCHEDOP_shutdown_code
before shutdown starts. It can also undo a shutdown while a vCPU is
still deferring it.

Check for completed shutdown under shutdown_lock before changing the
domain state. Return -EINVAL if shutdown has not started or is still in
progress. A repeated resume therefore also returns -EINVAL.

Soft reset already checks the vCPUs before resetting domain resources.
After a successful reset, clear the old shutdown state and release the
shutdown pauses without calling arch_domain_resume(). This also works
with on_reboot="soft-reset", where the shutdown reason is reboot.

Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
---
Follow-up to the v2 discussion of "xen/domain: make shutdown state explicit":
https://lore.kernel.org/xen-devel/a0de8496-66cb-4e7f-854e-fcc0053bd666@xxxxxxxx/
---
 xen/common/domain.c         | 22 +++++++++++++++++++---
 xen/common/domctl.c         |  2 +-
 xen/include/public/domctl.h |  1 +
 xen/include/xen/sched.h     |  2 +-
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 
f3a2634d5f985e094236f81c49acbf6f9ebc8d58..470406af22725b150a308923e63a60cf26822168
 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1425,9 +1425,10 @@ int domain_shutdown(struct domain *d, u8 reason)
     return 0;
 }
 
-void domain_resume(struct domain *d)
+static int domain_leave_shutdown_state(struct domain *d, bool resume)
 {
     struct vcpu *v;
+    int rc = 0;
 
     /*
      * Some code paths assume that shutdown status does not get reset under
@@ -1437,9 +1438,16 @@ void domain_resume(struct domain *d)
 
     spin_lock(&d->shutdown_lock);
 
+    if ( resume && !domain_shutdown_completed(d) )
+    {
+        rc = -EINVAL;
+        goto out_unlock;
+    }
+
     d->shutdown_state = DOMSHUTDOWN_none;
 
-    arch_domain_resume(d);
+    if ( resume )
+        arch_domain_resume(d);
 
     d->shutdown_code = SHUTDOWN_CODE_INVALID;
 
@@ -1450,9 +1458,17 @@ void domain_resume(struct domain *d)
         v->paused_for_shutdown = 0;
     }
 
+ out_unlock:
     spin_unlock(&d->shutdown_lock);
 
     domain_unpause(d);
+
+    return rc;
+}
+
+int domain_resume(struct domain *d)
+{
+    return domain_leave_shutdown_state(d, true);
 }
 
 int vcpu_start_shutdown_deferral(struct vcpu *v)
@@ -1804,7 +1820,7 @@ int domain_soft_reset(struct domain *d, bool resuming)
 
     rc = arch_domain_soft_reset(d);
     if ( !rc )
-        domain_resume(d);
+        rc = domain_leave_shutdown_state(d, false);
     else
         domain_crash(d);
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 
83405a766a54cc45d34cd1f5797778d7e20c3528..2420ad17213ce05e2a78f99b9e386e944661e1cd
 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -672,7 +672,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 
u_domctl)
         if ( d == current->domain ) /* no domain_pause() */
             ret = -EINVAL;
         else
-            domain_resume(d);
+            ret = domain_resume(d);
         break;
 
     case XEN_DOMCTL_createdomain:
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 
4ca8a2d7ca65e21c3c1020d9428d6f180f7fe783..974c9327e74d2288e582708e2eb6b62d9cc3cbac
 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1311,6 +1311,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
+/* Return -EINVAL unless the domain has completed shutdown. */
 #define XEN_DOMCTL_resumedomain                  27
 #define XEN_DOMCTL_sendtrigger                   28
 #define XEN_DOMCTL_subscribe                     29
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 
ce1fa636db368d0e5c65fac1b13f9f6d908216d9..fd19bd075eb3af6e0ed67b9e76f9f28d5cb3ec69
 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -849,7 +849,7 @@ static inline void put_pg_owner(struct domain *pg_owner)
 void domain_destroy(struct domain *d);
 int domain_kill(struct domain *d);
 int domain_shutdown(struct domain *d, u8 reason);
-void domain_resume(struct domain *d);
+int domain_resume(struct domain *d);
 
 int domain_soft_reset(struct domain *d, bool resuming);
 


 


Rackspace

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