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

[RFC PATCH v6 24/43] altp2m: Move altp2m_{get,set}_altp2m to common code


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
  • Date: Mon, 20 Apr 2026 17:31:47 -0400
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 40.93.10.101) smtp.rcpttodomain=amd.com smtp.mailfrom=elektrobit.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=elektrobit.com; dkim=pass (signature was verified) header.d=elektrobit.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=elektrobit.com] dmarc=[1,1,header.from=elektrobit.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 213.95.148.172) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=elektrobit.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=elektrobit.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=2; 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=/xFPvcddJmAh/7k7Gzv3o+d1z1DGyz3l1lzwxv3F8MY=; b=FtO5hosF4UFmybFgkE5MNXObp9CcuUkGfkAsyOaO6x5jr91YWzqiEYm8TI8/kCMG/ucXudBzu0XQMjLiNGlHPpRrFzKgOrRg159uUzJHABRA9ki54/aevmq4WVwOgTWa7xcZXT51XUMOAsqGbL1BXm9FsFn+983PGBkrSfHDDais0vD4oYnQyhCCjje02ogzUe7304PWaLJzY4CIroFJlbi4waWg/sxPawI+5VoL5YbpAwGZTBaESi5UXCnUk2IdDGHNU/5GUOQpw/RcmoSQnBjRIHJzVuvfrLXhlNm90/WhA6Q03Xx9/HkBY4FzfmEREBWXnMJY6Gy6PnQE5681iA==
  • 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=/xFPvcddJmAh/7k7Gzv3o+d1z1DGyz3l1lzwxv3F8MY=; b=ToZBUZNWZo6MlM2dD8W1B4+Q9cgbz/akBeKRXuWhVEnaG3Xki+ozy5dk2DOvIUJy7ot6If9Zyq9W/5B1m3M+/ILe0m1dE2dMKDc9HQiQ2pASmnz6pjd91JHxCGP1OS1y98izFgSPmWTmzfvxWMbQ3/KeZlIfKQowco23K5BZNiiM3+hxaeF3iZxoxBXDuGzI81uRz04o331FXfrw/vEd0kAsbLKJnu4Y3PPZfe3RhvXNC9W7o+IOifKdk5HJGmHxYHFR4FbwDwl3Zjrx9dJCSWAMpwoPTfCpB01VmMsevQG9Oq577gHB3Wzq7em0llBJa+vzDaHfJjIQnB2nWxwEfg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=FMSJb+aycSBeSNUd2T2odW6B6bxjmQ6Rm8gpTxZ6fSBUSxTFtwJokiIXh1/TkgEdTefxjrFQIP87cd5OsUEm2lhCL7NpwMReJAUWh/8ADSWHiXpsrsArTygBKwxLJ8ZOA8S7YymLOwK5JqPy69ZD1z1r1BdmQ8ykm2GhEiauuQbQWJZaWhOpC74qhKogZrtWK4NIWhJ9HqMCfTjhb+vBfeCx+XifgOBgIEA++3oA1VlwxH/E3sbALtKxDOKXqmPkJJyKll06m7Ix1Y0GbstFX67X7RlgpnkJAwcslZHq1Im9MwMDjGdRNrtirU6KbSLkYI82JGHTug0ZKWBA6GsfZA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GBCsg2ercueuEKeF0TYR6sv3g/OnwKJI/KoHsck0DQNbLFjG5pIepqMPcVHXAzBObIn3zIKw/2/pl7exPVM5nRBwds3pu7y714zCSxcVPPNkQUy0chpCq6GaMXqc+6Skss3/IJJulxmhPQr0fOXnbSFEaYomnI9JjSMB1so5CEO2QmXppDp4U39c7Wf/Wu97ZFRsjt5nsYsZwNvQqosO+GI24VpE4oYhnSwK7zPSEM6XVKt4RWkE5Ew9e/6buI5Uq+EW8+h+RiRsRNfYSiIbbwepCnzg2IvMBrI1BY8/fuuKdwAgovvFXmooD+FhHhKJuSKHcK4LNpuyUqnxfB0eDA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=elektrobit.com header.i="@elektrobit.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=elektrobit.com header.i="@elektrobit.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, "Michal Orzel" <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 20 Apr 2026 21:34:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This commit moves the altp2m_get_altp2m and altp2m_set_altp2m functions to
the common code. This make sit possible to use them in other common
routines (namely, altp2m_vcpu_{initialise,destroy}).

This commit contains only code movement, and no change in functionality is
intended.

This is commit 1/4 of the altp2m_{get,set}_altp2m phase.

Signed-off-by: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
---
v6: Introduced this patch.
---
 xen/arch/x86/include/asm/altp2m.h | 35 -------------------------
 xen/arch/x86/include/asm/domain.h |  2 --
 xen/common/altp2m.c               |  1 -
 xen/include/xen/altp2m.h          | 43 +++++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/xen/arch/x86/include/asm/altp2m.h 
b/xen/arch/x86/include/asm/altp2m.h
index 13017525a62f..a1b078783b3e 100644
--- a/xen/arch/x86/include/asm/altp2m.h
+++ b/xen/arch/x86/include/asm/altp2m.h
@@ -64,39 +64,6 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
  * Alternate p2m: shadow p2m tables used for alternate memory views
  */
 
-/* get current alternate p2m table */
-static inline struct p2m_domain *altp2m_get_altp2m(struct vcpu *v)
-{
-    unsigned int index = vcpu_altp2m(v).p2midx;
-
-    if ( index == INVALID_ALTP2M )
-        return NULL;
-
-    BUG_ON(index >= v->domain->nr_altp2m);
-
-    return v->domain->altp2m_p2m[index];
-}
-
-/* set current alternate p2m table */
-static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx)
-{
-    struct p2m_domain *orig;
-
-    BUG_ON(idx >= v->domain->nr_altp2m);
-
-    if ( idx == vcpu_altp2m(v).p2midx )
-        return false;
-
-    orig = altp2m_get_altp2m(v);
-    BUG_ON(!orig);
-    atomic_dec(&orig->active_vcpus);
-
-    vcpu_altp2m(v).p2midx = idx;
-    atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus);
-
-    return true;
-}
-
 /* Switch alternate p2m for a single vcpu */
 bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int idx);
 
@@ -178,8 +145,6 @@ static inline int _altp2m_get_effective_entry(struct 
p2m_domain *ap2m,
         _altp2m_get_effective_entry(ap2m, gfn, mfn, t, a)
 
 /* Only declaration is needed. DCE will optimise it out when linking. */
-struct p2m_domain *altp2m_get_altp2m(struct vcpu *v);
-bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx);
 uint16_t altp2m_vcpu_idx(const struct vcpu *v);
 void altp2m_vcpu_initialise(struct vcpu *v);
 void altp2m_vcpu_destroy(struct vcpu *v);
diff --git a/xen/arch/x86/include/asm/domain.h 
b/xen/arch/x86/include/asm/domain.h
index f8038087e612..72460e38f581 100644
--- a/xen/arch/x86/include/asm/domain.h
+++ b/xen/arch/x86/include/asm/domain.h
@@ -277,8 +277,6 @@ struct paging_vcpu {
 #define MAX_NR_ALTP2M   MAX_EPTP
 #define MAX_NESTEDP2M   10
 
-#define INVALID_ALTP2M  0xffff
-
 struct p2m_domain;
 struct time_scale {
     int shift;
diff --git a/xen/common/altp2m.c b/xen/common/altp2m.c
index 989d8bdcb923..a731ad7cdab8 100644
--- a/xen/common/altp2m.c
+++ b/xen/common/altp2m.c
@@ -5,7 +5,6 @@
 #include <xen/xvmalloc.h>
 
 #include <asm/altp2m.h>
-#include <asm/p2m.h>
 
 #include <public/hvm/params.h>
 
diff --git a/xen/include/xen/altp2m.h b/xen/include/xen/altp2m.h
index 238c7a935586..58e74be6deb0 100644
--- a/xen/include/xen/altp2m.h
+++ b/xen/include/xen/altp2m.h
@@ -8,6 +8,10 @@
 
 #include <public/hvm/hvm_op.h>
 
+#include <asm/p2m.h>
+
+#define INVALID_ALTP2M  0xffff
+
 /*
  * Common alternate p2m declarations that need to be visible
  * regardless of CONFIG_ALTP2M
@@ -27,6 +31,41 @@ static inline bool altp2m_active(const struct domain *d)
     return d->altp2m_active;
 }
 
+#ifdef CONFIG_X86
+/* get current alternate p2m table */
+static inline struct p2m_domain *altp2m_get_altp2m(struct vcpu *v)
+{
+    unsigned int index = vcpu_altp2m(v).p2midx;
+
+    if ( index == INVALID_ALTP2M )
+        return NULL;
+
+    BUG_ON(index >= v->domain->nr_altp2m);
+
+    return v->domain->altp2m_p2m[index];
+}
+
+/* set current alternate p2m table */
+static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx)
+{
+    struct p2m_domain *orig;
+
+    BUG_ON(idx >= v->domain->nr_altp2m);
+
+    if ( idx == vcpu_altp2m(v).p2midx )
+        return false;
+
+    orig = altp2m_get_altp2m(v);
+    BUG_ON(!orig);
+    atomic_dec(&orig->active_vcpus);
+
+    vcpu_altp2m(v).p2midx = idx;
+    atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus);
+
+    return true;
+}
+#endif
+
 int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg);
 
 #else /* CONFIG_ALTP2M */
@@ -41,6 +80,10 @@ static inline int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) 
arg)
     return -EOPNOTSUPP;
 }
 
+/* Only declaration is needed. DCE will optimise it out when linking. */
+struct p2m_domain *altp2m_get_altp2m(struct vcpu *v);
+bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx);
+
 #endif /* CONFIG_ALTP2M */
 
 #endif /* __XEN_ALTP2M_H__ */
-- 
2.34.1




 


Rackspace

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