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

[RFC PATCH v6 14/43] altp2m: Move altp2m_{init,teardown} to common code


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
  • Date: Mon, 20 Apr 2026 17:31:37 -0400
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 40.93.13.65) 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=P99iOPiPAd4fedD5w4a0EUrWRqEzpWZn2WgFGdQXXEw=; b=R91QUje5IKiODbKhudRV+ZX1CR/kyIQedQTnqt2grFOp80M+S083GBdH5MtpO6HSEGeIrEe+FTh+/vI1aKhWZL8NhAR5PGRzWpfLk9fCQMcmx2YH3SOc7CerWxTXEKrUvCRX2FK7pwiPJSgwzsDoIT7kXVdyoBsGpZke/FtjIZusLQMmDMb/Jtfy5enKcrLwGp7Tro3zrJihx3hePmDCSdWV7ZgcRnfIzFS4Y5Gb+owlRJoocRpY/2PrPgCgJ7obob9MA31ZVz28WjPfpFxaPYf4SSuwHhUJmLBXwmwMjolFBMW3fRfb3CRXBUguBoNDDwXVGsZAZu+K6j47DH2HCA==
  • 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=P99iOPiPAd4fedD5w4a0EUrWRqEzpWZn2WgFGdQXXEw=; b=WjTVpnS5dWhWWOG/f+sk1AySX0LpfpPHQ/Whfi0GxnimYbs+SoLWAzLCxoViUlJ4bDzyMF6ri3/uWBZJxZLZ8ivG/zGi/HFVz2JAsogHu/uPpSK9xftc6rvnPBukfubHHMOtVIgWfQ8bFeeSbtTHhdLUV0uI/qOTbgfYajVocIEkl2kHvL45zL1GNcO0vKrqSLLvjJDJ3iZhHvuLkfT6IQ2wKszWVcvR5KQl+yC4IA8H7PaBun89CoX6y1+X15sX/mgkVsSbx94pHIJAnejhAnUi+FOKCc4VfwI/CuRd3yWcIzBl0yMiN1FKvCRNDVcYqMv6LCHOCrZ9blMSCztPKQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=DXi8w8JtA1/UjAPCKOBHjxBPSOfMEav/Sm6pbCT6Uz3kqhMD8VwwNLG44r26W2+pVVdsRIhu/hLGDjTNG3DHDRxPKqBTY+yzQUnRgGOKaEkvHqNc5fz3wNdDX/DLtWgKlAzLS0k6L6VYW/oHsQoaRguX2PJ0pZVJz1Mq3EUFy2Po9lDswNUJPDvYhZ/niJfLI2oSWqxsWZjfOgmFY0DEPERxK3v1QWGueCug63lgH8wmvucejzPxTKjfARUd56CKfbsR5sUjRNXEX2U+6ixrFw3wVD+FpNW4zNPJqLqyJoS2DME2hGY4pjWigxxXLlh0Wpi9PqRpWGa5Gw57JjwoUg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DSiXJcOpfDw1FzpLTz4sHnIW4qpIUKkoZaNqLTEFrO5hKfqfQ/wF6cqPpyZcmyy3EFthPYhu0zirfliPOrw8Bt2ckEui/A0S3B/MWg58Pibi6co04jLOV/SnVYXCD811nQRkvuzPyCZmzojzP+zynNM5AeRi4zYF/ySVA+cOZOl9tp2sQLP92OL6wPOqfuROymrNRiOBZIi0ELOPAlBpeFHH5jZOW0J3cIrNhHVf5YOEFBe3ygrurAG8xIbrRDXyvuRWWvNyIgrcNca89aitXk36DqC30DelsYunYiTO4Hk6FoJ1ngxq+3jGEUvd18s3jCDUAd1gKw5L2w6VX9Uttw==
  • 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:33:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This commit moves the init and teardown routines into common code. The
functions are gated by CONFIG_X86, so there is effectively no difference
despite common code normally being compiled for ARM.

This commit contains only renames/code movement, and no functional change is 
intended.

This is commit 3/12 of the altp2m_init/altp2m_teardown routines phase.

Signed-off-by: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
---
v6: Introduced this patch.
---
 xen/arch/x86/include/asm/altp2m.h |  8 -----
 xen/arch/x86/mm/altp2m.c          | 45 ----------------------------
 xen/arch/x86/mm/p2m-basic.c       |  1 +
 xen/common/altp2m.c               | 49 +++++++++++++++++++++++++++++++
 xen/include/xen/altp2m.h          | 13 ++++++++
 5 files changed, 63 insertions(+), 53 deletions(-)

diff --git a/xen/arch/x86/include/asm/altp2m.h 
b/xen/arch/x86/include/asm/altp2m.h
index 7cff40beb7c6..13017525a62f 100644
--- a/xen/arch/x86/include/asm/altp2m.h
+++ b/xen/arch/x86/include/asm/altp2m.h
@@ -97,12 +97,6 @@ static inline bool altp2m_set_altp2m(struct vcpu *v, 
unsigned int idx)
     return true;
 }
 
-/* Initialize altp2m views */
-int altp2m_init(struct domain *d);
-
-/* Free altp2m views */
-void altp2m_teardown(struct domain *d);
-
 /* Switch alternate p2m for a single vcpu */
 bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int idx);
 
@@ -184,8 +178,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. */
-int altp2m_init(struct domain *d);
-void altp2m_teardown(struct domain *d);
 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);
diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c
index 371bf3f0b8d4..46374373848d 100644
--- a/xen/arch/x86/mm/altp2m.c
+++ b/xen/arch/x86/mm/altp2m.c
@@ -123,51 +123,6 @@ void altp2m_vcpu_disable_ve(struct vcpu *v)
     }
 }
 
-int altp2m_init(struct domain *d)
-{
-    unsigned int i;
-    struct p2m_domain *p2m;
-    struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
-
-    altp2m_lock_init(d);
-    d->altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
-
-    if ( !d->altp2m_p2m )
-        return -ENOMEM;
-
-    for ( i = 0; i < d->nr_altp2m; i++ )
-    {
-        d->altp2m_p2m[i] = p2m = p2m_init_one(d);
-        if ( p2m == NULL )
-        {
-            altp2m_teardown(d);
-            return -ENOMEM;
-        }
-        p2m->p2m_class = p2m_alternate;
-        p2m->access_required = hostp2m->access_required;
-        _atomic_set(&p2m->active_vcpus, 0);
-    }
-
-    return 0;
-}
-
-void altp2m_teardown(struct domain *d)
-{
-    unsigned int i;
-    struct p2m_domain *p2m;
-
-    for ( i = 0; i < d->nr_altp2m; i++ )
-    {
-        if ( !d->altp2m_p2m[i] )
-            continue;
-        p2m = d->altp2m_p2m[i];
-        d->altp2m_p2m[i] = NULL;
-        p2m_free_one(p2m);
-    }
-
-    XVFREE(d->altp2m_p2m);
-}
-
 int altp2m_get_effective_entry(struct p2m_domain *ap2m, gfn_t gfn, mfn_t *mfn,
                                p2m_type_t *t, p2m_access_t *a,
                                bool prepopulate)
diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c
index 433e7d08b78f..67cef5d2b6ef 100644
--- a/xen/arch/x86/mm/p2m-basic.c
+++ b/xen/arch/x86/mm/p2m-basic.c
@@ -11,6 +11,7 @@
  * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
  */
 
+#include <xen/altp2m.h>
 #include <xen/event.h>
 #include <xen/types.h>
 #include <asm/altp2m.h>
diff --git a/xen/common/altp2m.c b/xen/common/altp2m.c
index 3a3283f0860a..cda653b713f0 100644
--- a/xen/common/altp2m.c
+++ b/xen/common/altp2m.c
@@ -2,8 +2,10 @@
 #include <xen/altp2m.h>
 #include <xen/guest_access.h>
 #include <xen/vm_event.h>
+#include <xen/xvmalloc.h>
 
 #include <asm/altp2m.h>
+#include <asm/p2m.h>
 
 #include <public/hvm/params.h>
 
@@ -13,6 +15,53 @@
 #include <asm/hvm/nestedhvm.h>
 #endif
 
+#if CONFIG_X86
+int altp2m_init(struct domain *d)
+{
+    unsigned int i;
+    struct p2m_domain *p2m;
+    struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
+
+    altp2m_lock_init(d);
+    d->altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
+
+    if ( !d->altp2m_p2m )
+        return -ENOMEM;
+
+    for ( i = 0; i < d->nr_altp2m; i++ )
+    {
+        d->altp2m_p2m[i] = p2m = p2m_init_one(d);
+        if ( p2m == NULL )
+        {
+            altp2m_teardown(d);
+            return -ENOMEM;
+        }
+        p2m->p2m_class = p2m_alternate;
+        p2m->access_required = hostp2m->access_required;
+        _atomic_set(&p2m->active_vcpus, 0);
+    }
+
+    return 0;
+}
+
+void altp2m_teardown(struct domain *d)
+{
+    unsigned int i;
+    struct p2m_domain *p2m;
+
+    for ( i = 0; i < d->nr_altp2m; i++ )
+    {
+        if ( !d->altp2m_p2m[i] )
+            continue;
+        p2m = d->altp2m_p2m[i];
+        d->altp2m_p2m[i] = NULL;
+        p2m_free_one(p2m);
+    }
+
+    XVFREE(d->altp2m_p2m);
+}
+#endif /* CONFIG_X86 */
+
 /*
  * altp2m operations are envisioned as being used in several different
  * modes:
diff --git a/xen/include/xen/altp2m.h b/xen/include/xen/altp2m.h
index be627152668a..85ef22c2b29e 100644
--- a/xen/include/xen/altp2m.h
+++ b/xen/include/xen/altp2m.h
@@ -8,6 +8,19 @@
 
 #include <public/hvm/hvm_op.h>
 
+/*
+ * Common alternate p2m declarations that need to be visible
+ * regardless of CONFIG_ALTP2M
+ */
+
+#ifdef CONFIG_X86
+/* Initialize altp2m views */
+int altp2m_init(struct domain *d);
+
+/* Free altp2m views */
+void altp2m_teardown(struct domain *d);
+#endif
+
 #ifdef CONFIG_ALTP2M
 
 /* Alternate p2m HVM on/off per domain */
-- 
2.34.1




 


Rackspace

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