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

[PATCH v1] xen/domctl: make domctl_lock generic


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Wed, 23 Jul 2025 14:53:25 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=PyMEOiDAC6cTdjm1z7YemfcJPrj4nzyhzLEJWpy3Ks8=; b=ff6VLQmBAqaUH7SFrLqrdWMoicZLYdbqby0bEM6xyBK3cNH5juIiHtJW7FQBMBK8ulnbZbTWJZto57la935LMCouul2ORTu4y7rN/y6XHbqeI4W4mupoQeZXjezt0mMNis1oFLXvkmRMdl/0yNSL9sZlrfWXM+v2az13U6HKj5b3aJygGhamhmxhk46X0VvBrER0MNrzLutcZz+1WxMhMmXRsNf07JOwT0Ime32mcg/Q8LD87+9093yHeV32DaHYCCJLUTwKalG7EdzyFezwPhdgb+I6Zo5E5iRksN6AoZZVHTId3vfQKXtLI/7EQoW47G2J8yMTTuNUKV5UVG27Yw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BKZhfkW6szCBbKr/BW2zjuYLqwWYWZoUplaNv4I3mgfDNs/cKCKUrix1IZ5mRGPr3KjsI/Pr2oaPiDnOdv0r/TGNGMeRAWQ7DirSxHbaqTMnLs6SwLVTpdQJQILI5jEobqGegAA6pDTDkxbQpvDHFYXQ//cJkrVCOpCsoiJ3BS+gRbcwq2G6Gio3+Z2w4qg1kVGKyIPVmi0Mh12PXBeY1PK61gCY4lof4PUjUqg4zYJmVnB9oWKLMH1dqW1rvBP1wfdb5hY9S/Boo4gF3Fn0ZtB+Z2Q0Hddxtyj6OSY5ipE5LEbtz77XrNlzeqYQAK73Ah++wG9anwPPp6NH7s7FcQ==
  • Cc: <ray.huang@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, 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.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 23 Jul 2025 06:54:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Not only domctl-op could do foreign updates to guest state, some hypercall,
like HVMOP_set_param, could also do, and they all need domctl_lock for
syncronization.
Later, we will introduce CONFIG_DOMCTL to wrap domctl.c. In order to
continue using domctl_lock when CONFIG_DOMCTL not defined, we'd like to move
domctl_lock_acquire/release() out of domctl.c, and into more common space,
domain.c
The movement could also fix CI error of a randconfig picking both
PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but
domctl.c not being built, which leaves domctl_lock_acquire/release()
undefined, causing linking to fail.

Fixes: 568f806cba4c ("xen/x86: remove "depends on !PV_SHIM_EXCLUSIVE"")
Reported-by: Jan Beulich <jbeulich@xxxxxxxx>
Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
---
 xen/common/domain.c | 29 +++++++++++++++++++++++++++++
 xen/common/domctl.c | 29 -----------------------------
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index b74d4c7549..6145071e55 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -66,6 +66,35 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);
 static struct domain *domain_hash[DOMAIN_HASH_SIZE];
 struct domain *domain_list;
 
+static DEFINE_SPINLOCK(domctl_lock);
+
+bool domctl_lock_acquire(void)
+{
+    /*
+     * Caller may try to pause its own VCPUs. We must prevent deadlock
+     * against other non-domctl routines which try to do the same.
+     */
+    if ( !spin_trylock(&current->domain->hypercall_deadlock_mutex) )
+        return 0;
+
+    /*
+     * Trylock here is paranoia if we have multiple privileged domains. Then
+     * we could have one domain trying to pause another which is spinning
+     * on domctl_lock -- results in deadlock.
+     */
+    if ( spin_trylock(&domctl_lock) )
+        return 1;
+
+    spin_unlock(&current->domain->hypercall_deadlock_mutex);
+    return 0;
+}
+
+void domctl_lock_release(void)
+{
+    spin_unlock(&domctl_lock);
+    spin_unlock(&current->domain->hypercall_deadlock_mutex);
+}
+
 /*
  * Insert a domain into the domlist/hash.  This allows the domain to be looked
  * up by domid, and therefore to be the subject of hypercalls/etc.
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 99de77380f..455fbc5160 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -35,8 +35,6 @@
 #include <public/domctl.h>
 #include <xsm/xsm.h>
 
-static DEFINE_SPINLOCK(domctl_lock);
-
 static int nodemask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_nodemap,
                                      const nodemask_t *nodemask)
 {
@@ -65,33 +63,6 @@ static inline int is_free_domid(domid_t dom)
     return 0;
 }
 
-bool domctl_lock_acquire(void)
-{
-    /*
-     * Caller may try to pause its own VCPUs. We must prevent deadlock
-     * against other non-domctl routines which try to do the same.
-     */
-    if ( !spin_trylock(&current->domain->hypercall_deadlock_mutex) )
-        return 0;
-
-    /*
-     * Trylock here is paranoia if we have multiple privileged domains. Then
-     * we could have one domain trying to pause another which is spinning
-     * on domctl_lock -- results in deadlock.
-     */
-    if ( spin_trylock(&domctl_lock) )
-        return 1;
-
-    spin_unlock(&current->domain->hypercall_deadlock_mutex);
-    return 0;
-}
-
-void domctl_lock_release(void)
-{
-    spin_unlock(&domctl_lock);
-    spin_unlock(&current->domain->hypercall_deadlock_mutex);
-}
-
 void vnuma_destroy(struct vnuma_info *vnuma)
 {
     if ( vnuma )
-- 
2.34.1




 


Rackspace

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