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

[RFC PATCH v6 08/43] altp2m: Rename p2m_*_altp2m functions and move declarations out of p2m.h


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
  • Date: Mon, 20 Apr 2026 17:31:31 -0400
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 40.93.14.103) 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=2Xr6LLXjzqnGjZ+q/CL1Op56Lgquh9rAvy51mivO1rA=; b=HXw4XFvnQA3/7yanLk0roDwMWU8a76QaiblqQCEnw5OP+vRvCe1HGAQv9sFDsWeowUAzkTgDxNxFLR49zjBCIELe64GIzdLUidzvG9Ulo1FTX4a0yTuPdRtcAd/9rP+mmvZ2atVt4BSynqpynLoByV0czsxqfijlFUtkaDB9l1kAIUqr8XLQF0rjoSsqYeK2dlJlNnNNF9c3n7Wmnu30jvKAtsbG+Fzx5E/mUIdmzJ7IfxpjHAW/gGm4GVD5qeYsE0zrR3C4+x4PAmWH/TaRWZTpBvr/K+O+0ehuYX4hIRpkNuRmNBKSiwSA+ZuReK7JygOl3jRUGX097CKA+bP+5Q==
  • 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=2Xr6LLXjzqnGjZ+q/CL1Op56Lgquh9rAvy51mivO1rA=; b=Lm+FvvBi1KkUsChrTLrtvq08TlzmUBhR0mcZ2u5GeQTnn7SIBnRB+8NWqWgzvB1qv8tnjaK3e8fdzJQHbwDBDKQJWhNBrJ7mzjrATpplMcZD0Fby25TvE3eMw8ZMwzqaKF5ragtmY0hStT5hTega3r3oFeC/+dJv4t9h5XOf1oW3nA7u1STVF4/B2RUu0CR5TUOxn+IoW6wwQSO2nGVgQHdTE6f/+te4aEWIPr5dIYBYHtHg6y5AOvygf8jluOSOh1brg3PM2X8yQ7kItEMqGbpa9XkQMnuGB6vdxXqJcZN5KoVBU61rOeqimNZri7uxLykZQWcEkO8cJi2dIPlrXA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=GN8IGpfUZKXiGY7c9btOQDr+GoZ9NhAHKxKGZApqy4Z+6Tthj8fq3U7jDU8dakJgTPnIhdW3KBoQ0zcxnhEatHbKICUQDBxdDlswf/kM1kaVvn/sOA/CJphfCq3ggtmM0qBxBNdp2HIHrsr4s0kNhRwE4O7rVk+ZNQA5N3oPRyQ4bR1wJqF/p5/qimckHPnceR0zymOSEsYmxeKHVNNBe1f38rH226E/Iayef8/+FE2JMVfXJzaNDzGvrmDfg5B1uSHHquRBkYQchbR5+GhiVALBaT9MInLtVbQ8P2523VP+clCXrQ3WWkEEl2s5qqqwLyTph74YC9ujVmi44DJEtQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y6THxcZhbHOnZTXDmfiYtmfXKPFOUElAYwWhBP/7UPTV5n+FjHHwzHqlgPQeojAoUCYXcUQIUxtf2E5K+T/TvIuHJdXM8QEJxQd8q080ZSI6qtkwlHT/86PvEVcrz6UGh4jHxs6djzbYaamcygHGs6dap4CrYED4Bd2AV1TIX+Og/VaPgAXlmwLJK69tHyglL1xme0PEMSW2u/n9nFMsCXTr4jBTQI1GNmBi0SujJ14w05AtGc8MjIgB0NXtwvB1f5GU0/9dsBDQZXEfPRbE0t1BCg8W0MgRKX5RGSSIrBYJ/bh1MgAHmZfKw0ji2d/l9tnW5aMzHN5P16KZiQ8Lig==
  • 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>, 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.pau@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
  • Delivery-date: Mon, 20 Apr 2026 21:33:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This commit renames altp2m functions with a p2m prefix. These functions
were originally defined in p2m.c, hence the p2m prefix. When they were
moved to altp2m.c in commit ae7584f63678, the function names were kept and
the declarations remained in p2m.h. This commit finishes that move by
renaming these functions to have an altp2m prefix and moving the
declarations to altp2m.h.

Since these functions will either be moved to the common altp2m.c, or
implemented separately for ARM, it doesn't seem to make sense to continue
with this naming convention. Therefore, this commit preemptively renames
the x86 implementations of these functions so they can later be implemented
with altp2m function name prefixes in common code or for ARM.

For convenience, here is the full list of renames:
- p2m_init_altp2m -> altp2m_init
- p2m_teardown_altp2m -> altp2m_teardown
- p2m_flush_altp2m -> altp2m_flush
- p2m_altp2m_get_or_propagate -> altp2m_get_or_propagate
- p2m_altp2m_propagate_change -> altp2m_propagate_change
- p2m_get_altp2m -> altp2m_get_altp2m
- p2m_set_altp2m -> altp2m_set_altp2m
- p2m_reset_altp2m -> altp2m_reset_altp2m
- p2m_activate_altp2m -> altp2m_activate_altp2m
- p2m_init_altp2m_by_id -> altp2m_init_by_id
- p2m_init_next_altp2m -> altp2m_init_next_available
- p2m_destroy_altp2m_by_id -> altp2m_destroy_by_id
- p2m_switch_domain_altp2m_by_id -> altp2m_switch_domain_altp2m_by_id
- p2m_change_altp2m_gfn -> altp2m_change_gfn
- p2m_set_altp2m_view_visibility -> altp2m_set_view_visibility

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

This is commit 8/8 of the preparation phase.

Signed-off-by: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
---
v6: Introduced this patch.
---
 xen/arch/arm/altp2m.c             |   2 +-
 xen/arch/x86/hvm/hvm.c            |  30 ++++----
 xen/arch/x86/hvm/monitor.c        |   2 +-
 xen/arch/x86/hvm/vmx/vmx.c        |   6 +-
 xen/arch/x86/include/asm/altp2m.h | 116 +++++++++++++++++++++++++++++-
 xen/arch/x86/include/asm/p2m.h    | 109 ----------------------------
 xen/arch/x86/mm/altp2m.c          |  76 ++++++++++----------
 xen/arch/x86/mm/mem_access.c      |  13 ++--
 xen/arch/x86/mm/p2m-basic.c       |   4 +-
 xen/arch/x86/mm/p2m-ept.c         |   4 +-
 xen/arch/x86/mm/p2m.h             |   3 -
 xen/common/vm_event.c             |   2 +-
 xen/include/xen/p2m-common.h      |   2 +-
 13 files changed, 186 insertions(+), 183 deletions(-)

diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c
index 8bd174ea8f37..339f82835caf 100644
--- a/xen/arch/arm/altp2m.c
+++ b/xen/arch/arm/altp2m.c
@@ -8,7 +8,7 @@
 #include <asm/p2m.h>
 
 /* Check to see if vcpu should be switched to a different p2m. */
-void p2m_altp2m_check(struct vcpu *v, uint16_t idx)
+void altp2m_check(struct vcpu *v, uint16_t idx)
 {
     /* Not yet implemented */
     BUG();
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index bc35efdf2c02..5b6e91adce17 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1885,15 +1885,15 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned 
long gla,
 
     if ( altp2m_active(currd) )
     {
-        p2m = p2m_get_altp2m(curr);
+        p2m = altp2m_get_altp2m(curr);
 
         /*
          * Get the altp2m entry if present; or if not, propagate from
          * the host p2m.  NB that this returns with gfn locked in the
          * altp2m.
          */
-        if ( p2m_altp2m_get_or_propagate(p2m, gfn, &mfn, &p2mt,
-                                         &p2ma, &page_order) )
+        if ( altp2m_get_or_propagate(p2m, gfn, &mfn, &p2mt, &p2ma,
+                                     &page_order) )
         {
             /* Entry was copied from host -- retry fault */
             rc = 1;
@@ -2036,7 +2036,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long 
gla,
             paging_mark_pfn_dirty(currd, _pfn(gfn));
             /*
              * If p2m is really an altp2m, unlock it before changing the type,
-             * as p2m_altp2m_propagate_change() needs to acquire the
+             * as altp2m_propagate_change() needs to acquire the
              * altp2m_list lock.
              */
             if ( p2m != hostp2m )
@@ -4663,7 +4663,7 @@ static int do_altp2m_op(
 
         /* If the alternate p2m state has changed, handle appropriately */
         if ( d->altp2m_active != ostate &&
-             (ostate || !(rc = p2m_init_altp2m_by_id(d, 0))) )
+             (ostate || !(rc = altp2m_init_by_id(d, 0))) )
         {
             for_each_vcpu( d, v )
             {
@@ -4674,7 +4674,7 @@ static int do_altp2m_op(
             }
 
             if ( ostate )
-                p2m_flush_altp2m(d);
+                altp2m_flush(d);
         }
         else if ( rc )
             d->altp2m_active = false;
@@ -4729,17 +4729,18 @@ static int do_altp2m_op(
     }
 
     case HVMOP_altp2m_create_p2m:
-        if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view,
-                                         a.u.view.hvmmem_default_access)) )
+        rc = altp2m_init_next_available(d, &a.u.view.view,
+                                        a.u.view.hvmmem_default_access);
+        if ( !rc )
             rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
         break;
 
     case HVMOP_altp2m_destroy_p2m:
-        rc = p2m_destroy_altp2m_by_id(d, a.u.view.view);
+        rc = altp2m_destroy_by_id(d, a.u.view.view);
         break;
 
     case HVMOP_altp2m_switch_p2m:
-        rc = p2m_switch_domain_altp2m_by_id(d, a.u.view.view);
+        rc = altp2m_switch_domain_altp2m_by_id(d, a.u.view.view);
         break;
 
     case HVMOP_altp2m_set_suppress_ve:
@@ -4871,9 +4872,9 @@ static int do_altp2m_op(
         if ( a.u.change_gfn.pad1 || a.u.change_gfn.pad2 )
             rc = -EINVAL;
         else
-            rc = p2m_change_altp2m_gfn(d, a.u.change_gfn.view,
-                    _gfn(a.u.change_gfn.old_gfn),
-                    _gfn(a.u.change_gfn.new_gfn));
+            rc = altp2m_change_gfn(d, a.u.change_gfn.view,
+                                   _gfn(a.u.change_gfn.old_gfn),
+                                   _gfn(a.u.change_gfn.new_gfn));
         break;
 
     case HVMOP_altp2m_get_p2m_idx:
@@ -4906,8 +4907,7 @@ static int do_altp2m_op(
         else if ( !altp2m_active(d) )
             rc = -EOPNOTSUPP;
         else
-            rc = p2m_set_altp2m_view_visibility(d, idx,
-                                                a.u.set_visibility.visible);
+            rc = altp2m_set_view_visibility(d, idx, 
a.u.set_visibility.visible);
         break;
     }
 
diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c
index 84c1c2234ca9..78137220b22a 100644
--- a/xen/arch/x86/hvm/monitor.c
+++ b/xen/arch/x86/hvm/monitor.c
@@ -182,7 +182,7 @@ int hvm_monitor_debug(unsigned long rip, enum 
hvm_monitor_debug_type type,
 #ifdef CONFIG_ALTP2M
         if ( curr->arch.hvm.fast_single_step.enabled )
         {
-            p2m_altp2m_check(curr, curr->arch.hvm.fast_single_step.p2midx);
+            altp2m_check(curr, curr->arch.hvm.fast_single_step.p2midx);
             curr->arch.hvm.single_step = false;
             curr->arch.hvm.fast_single_step.enabled = false;
             curr->arch.hvm.fast_single_step.p2midx = 0;
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 0909929c00e0..f2cf95ee500e 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -2452,7 +2452,7 @@ static void cf_check vmx_vcpu_update_eptp(struct vcpu *v)
     struct ept_data *ept;
 
     if ( altp2m_active(d) )
-        p2m = p2m_get_altp2m(v);
+        p2m = altp2m_get_altp2m(v);
     if ( !p2m )
         p2m = p2m_get_hostp2m(d);
 
@@ -2521,7 +2521,7 @@ static int cf_check vmx_vcpu_emulate_vmfunc(const struct 
cpu_user_regs *regs)
 
     if ( !cpu_has_vmx_vmfunc && altp2m_active(curr->domain) &&
          regs->eax == 0 &&
-         p2m_switch_vcpu_altp2m_by_id(curr, regs->ecx) )
+         altp2m_switch_vcpu_by_id(curr, regs->ecx) )
         rc = X86EMUL_OKAY;
 
     return rc;
@@ -4277,7 +4277,7 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_regs 
*regs)
             }
         }
 
-        p2m_set_altp2m(v, idx);
+        altp2m_set_altp2m(v, idx);
     }
 
     if ( vm_event_is_enabled(v) &&
diff --git a/xen/arch/x86/include/asm/altp2m.h 
b/xen/arch/x86/include/asm/altp2m.h
index 07e760f60659..9c58a396448d 100644
--- a/xen/arch/x86/include/asm/altp2m.h
+++ b/xen/arch/x86/include/asm/altp2m.h
@@ -7,12 +7,33 @@
 #ifndef __ASM_X86_ALTP2M_H
 #define __ASM_X86_ALTP2M_H
 
-#ifdef CONFIG_ALTP2M
 
 #include <xen/types.h>
 #include <xen/sched.h>         /* for struct vcpu, struct domain */
+
+#include <asm/p2m.h>
 #include <asm/hvm/vcpu.h>      /* for vcpu_altp2m */
 
+/*
+ * Common alternate p2m declarations that need to be visible
+ * regardless of CONFIG_ALTP2M
+ */
+
+/* Alternate p2m paging */
+bool altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
+                             mfn_t *mfn, p2m_type_t *p2mt, p2m_access_t *p2ma,
+                             unsigned int *page_order);
+
+/* Propagate a host p2m change to all alternate p2m's */
+int altp2m_propagate_change(struct domain *d, gfn_t gfn, mfn_t mfn,
+                            unsigned int page_order, p2m_type_t p2mt,
+                            p2m_access_t p2ma);
+
+#ifdef CONFIG_ALTP2M
+
+#define AP2MGET_prepopulate true
+#define AP2MGET_query false
+
 static inline bool altp2m_is_eptp_valid(const struct domain *d,
                                         unsigned int idx)
 {
@@ -39,6 +60,85 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
     return vcpu_altp2m(v).p2midx;
 }
 
+/*
+ * 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;
+}
+
+/* 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);
+
+/* Flush all the alternate p2m's for a domain */
+void altp2m_flush(struct domain *d);
+
+/* Make a specific alternate p2m valid */
+int altp2m_init_by_id(struct domain *d, unsigned int idx);
+
+/* Find an available alternate p2m and make it valid */
+int altp2m_init_next_available(struct domain *d, uint16_t *idx,
+                               xenmem_access_t hvmmem_default_access);
+
+/* Make a specific alternate p2m invalid */
+int altp2m_destroy_by_id(struct domain *d, unsigned int idx);
+
+/* Switch alternate p2m for entire domain */
+int altp2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx);
+
+/* Change a gfn->mfn mapping */
+int altp2m_change_gfn(struct domain *d, unsigned int idx, gfn_t old_gfn,
+                      gfn_t new_gfn);
+
+/* Set a specific p2m view visibility */
+int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
+                               uint8_t visible);
+
+/*
+ * Looks up altp2m entry. If the entry is not found it looks up the entry in
+ * hostp2m.
+ * The prepopulate param is used to set the found entry in altp2m.
+ */
+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);
+
 /* Alternate p2m VCPU */
 void altp2m_vcpu_initialise(struct vcpu *v);
 void altp2m_vcpu_destroy(struct vcpu *v);
@@ -69,7 +169,21 @@ static inline bool altp2m_supported(void)
     return false;
 }
 
+static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m,
+                                             gfn_t gfn, mfn_t *mfn,
+                                             p2m_type_t *t, p2m_access_t *a)
+{
+    ASSERT_UNREACHABLE();
+    return -EOPNOTSUPP;
+}
+#define altp2m_get_effective_entry(ap2m, gfn, mfn, t, a, prepopulate) \
+        _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);
 void altp2m_vcpu_initialise(struct vcpu *v);
 void altp2m_vcpu_destroy(struct vcpu *v);
diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h
index ec871717a9e4..5110b3e77807 100644
--- a/xen/arch/x86/include/asm/p2m.h
+++ b/xen/arch/x86/include/asm/p2m.h
@@ -582,30 +582,6 @@ static inline gfn_t mfn_to_gfn(const struct domain *d, 
mfn_t mfn)
         return _gfn(mfn_x(mfn));
 }
 
-#ifdef CONFIG_ALTP2M
-#define AP2MGET_prepopulate true
-#define AP2MGET_query false
-
-/*
- * Looks up altp2m entry. If the entry is not found it looks up the entry in
- * hostp2m.
- * The prepopulate param is used to set the found entry in altp2m.
- */
-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);
-#else
-static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m,
-                                             gfn_t gfn, mfn_t *mfn,
-                                             p2m_type_t *t, p2m_access_t *a)
-{
-    ASSERT_UNREACHABLE();
-    return -EOPNOTSUPP;
-}
-#define altp2m_get_effective_entry(ap2m, gfn, mfn, t, a, prepopulate) \
-        _altp2m_get_effective_entry(ap2m, gfn, mfn, t, a)
-#endif
-
 /* Init the datastructures for later use by the p2m code */
 int p2m_init(struct domain *d);
 
@@ -885,91 +861,6 @@ void shadow_p2m_init(struct p2m_domain *p2m);
 void cf_check nestedp2m_write_p2m_entry_post(
     struct p2m_domain *p2m, unsigned int oflags);
 
-#ifdef CONFIG_ALTP2M
-
-/*
- * Alternate p2m: shadow p2m tables used for alternate memory views
- */
-
-/* get current alternate p2m table */
-static inline struct p2m_domain *p2m_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 p2m_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 = p2m_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 p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx);
-
-/* Flush all the alternate p2m's for a domain */
-void p2m_flush_altp2m(struct domain *d);
-
-/* Make a specific alternate p2m valid */
-int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx);
-
-/* Find an available alternate p2m and make it valid */
-int p2m_init_next_altp2m(struct domain *d, uint16_t *idx,
-                         xenmem_access_t hvmmem_default_access);
-
-/* Make a specific alternate p2m invalid */
-int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx);
-
-/* Switch alternate p2m for entire domain */
-int p2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx);
-
-/* Change a gfn->mfn mapping */
-int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
-                          gfn_t old_gfn, gfn_t new_gfn);
-
-/* Set a specific p2m view visibility */
-int p2m_set_altp2m_view_visibility(struct domain *d, unsigned int altp2m_idx,
-                                   uint8_t visible);
-
-#else /* !CONFIG_ALTP2M */
-struct p2m_domain *p2m_get_altp2m(struct vcpu *v);
-bool p2m_set_altp2m(struct vcpu *v, unsigned int idx);
-#endif /* CONFIG_ALTP2M */
-
-/*
- * Common alternate p2m declarations that need to be visible
- * regardless of CONFIG_ALTP2M
- */
-
-/* Alternate p2m paging */
-bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
-                                 mfn_t *mfn, p2m_type_t *p2mt,
-                                 p2m_access_t *p2ma, unsigned int *page_order);
-                                 
-/* Propagate a host p2m change to all alternate p2m's */
-int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
-                                mfn_t mfn, unsigned int page_order,
-                                p2m_type_t p2mt, p2m_access_t p2ma);
 #endif /* CONFIG_HVM */
 
 /* p2m access to IOMMU flags */
diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c
index 8dd3c0f96be0..2dc84b76b8c1 100644
--- a/xen/arch/x86/mm/altp2m.c
+++ b/xen/arch/x86/mm/altp2m.c
@@ -24,7 +24,7 @@ altp2m_vcpu_initialise(struct vcpu *v)
         vcpu_pause(v);
 
     vcpu_altp2m(v).p2midx = 0;
-    atomic_inc(&p2m_get_altp2m(v)->active_vcpus);
+    atomic_inc(&altp2m_get_altp2m(v)->active_vcpus);
 
     altp2m_vcpu_update_p2m(v);
 
@@ -43,7 +43,7 @@ altp2m_vcpu_destroy(struct vcpu *v)
     if ( v != current )
         vcpu_pause(v);
 
-    if ( (p2m = p2m_get_altp2m(v)) )
+    if ( (p2m = altp2m_get_altp2m(v)) )
         atomic_dec(&p2m->active_vcpus);
 
     altp2m_vcpu_disable_ve(v);
@@ -123,7 +123,7 @@ void altp2m_vcpu_disable_ve(struct vcpu *v)
     }
 }
 
-int p2m_init_altp2m(struct domain *d)
+int altp2m_init(struct domain *d)
 {
     unsigned int i;
     struct p2m_domain *p2m;
@@ -140,7 +140,7 @@ int p2m_init_altp2m(struct domain *d)
         d->altp2m_p2m[i] = p2m = p2m_init_one(d);
         if ( p2m == NULL )
         {
-            p2m_teardown_altp2m(d);
+            altp2m_teardown(d);
             return -ENOMEM;
         }
         p2m->p2m_class = p2m_alternate;
@@ -151,7 +151,7 @@ int p2m_init_altp2m(struct domain *d)
     return 0;
 }
 
-void p2m_teardown_altp2m(struct domain *d)
+void altp2m_teardown(struct domain *d)
 {
     unsigned int i;
     struct p2m_domain *p2m;
@@ -207,13 +207,13 @@ int altp2m_get_effective_entry(struct p2m_domain *ap2m, 
gfn_t gfn, mfn_t *mfn,
     return 0;
 }
 
-void p2m_altp2m_check(struct vcpu *v, uint16_t idx)
+void altp2m_check(struct vcpu *v, uint16_t idx)
 {
     if ( altp2m_active(v->domain) )
-        p2m_switch_vcpu_altp2m_by_id(v, idx);
+        altp2m_switch_vcpu_by_id(v, idx);
 }
 
-bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx)
+bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int idx)
 {
     struct domain *d = v->domain;
     bool rc = false;
@@ -225,7 +225,7 @@ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned 
int idx)
 
     if ( d->arch.altp2m_eptp[idx] != mfn_x(INVALID_MFN) )
     {
-        if ( p2m_set_altp2m(v, idx) )
+        if ( altp2m_set_altp2m(v, idx) )
             altp2m_vcpu_update_p2m(v);
         rc = 1;
     }
@@ -246,9 +246,9 @@ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned 
int idx)
  * the host's entry to the altp2m (retaining page order), and indicate
  * that the caller should re-try the faulting instruction.
  */
-bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
-                                 mfn_t *mfn, p2m_type_t *p2mt,
-                                 p2m_access_t *p2ma, unsigned int *page_order)
+bool altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
+                             mfn_t *mfn, p2m_type_t *p2mt, p2m_access_t *p2ma,
+                             unsigned int *page_order)
 {
     p2m_type_t ap2mt;
     p2m_access_t ap2ma;
@@ -319,8 +319,8 @@ enum altp2m_reset_type {
     ALTP2M_DEACTIVATE
 };
 
-static void p2m_reset_altp2m(struct domain *d, unsigned int idx,
-                             enum altp2m_reset_type reset_type)
+static void altp2m_reset_altp2m(struct domain *d, unsigned int idx,
+                                enum altp2m_reset_type reset_type)
 {
     struct p2m_domain *p2m;
 
@@ -344,7 +344,7 @@ static void p2m_reset_altp2m(struct domain *d, unsigned int 
idx,
     p2m_unlock(p2m);
 }
 
-void p2m_flush_altp2m(struct domain *d)
+void altp2m_flush(struct domain *d)
 {
     unsigned int i;
 
@@ -352,7 +352,7 @@ void p2m_flush_altp2m(struct domain *d)
 
     for ( i = 0; i < d->nr_altp2m; i++ )
     {
-        p2m_reset_altp2m(d, i, ALTP2M_DEACTIVATE);
+        altp2m_reset_altp2m(d, i, ALTP2M_DEACTIVATE);
         d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN);
         d->arch.altp2m_visible_eptp[i] = mfn_x(INVALID_MFN);
     }
@@ -360,8 +360,8 @@ void p2m_flush_altp2m(struct domain *d)
     altp2m_list_unlock(d);
 }
 
-static int p2m_activate_altp2m(struct domain *d, unsigned int idx,
-                               p2m_access_t hvmmem_default_access)
+static int altp2m_activate_altp2m(struct domain *d, unsigned int idx,
+                                  p2m_access_t hvmmem_default_access)
 {
     struct p2m_domain *hostp2m, *p2m;
     int rc;
@@ -399,9 +399,9 @@ static int p2m_activate_altp2m(struct domain *d, unsigned 
int idx,
     p2m_unlock(p2m);
 
     return rc;
-}
+ }
 
-int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx)
+int altp2m_init_by_id(struct domain *d, unsigned int idx)
 {
     int rc = -EINVAL;
     struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
@@ -413,14 +413,14 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int 
idx)
 
     if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] ==
          mfn_x(INVALID_MFN) )
-        rc = p2m_activate_altp2m(d, idx, hostp2m->default_access);
+        rc = altp2m_activate_altp2m(d, idx, hostp2m->default_access);
 
     altp2m_list_unlock(d);
     return rc;
 }
 
-int p2m_init_next_altp2m(struct domain *d, uint16_t *idx,
-                         xenmem_access_t hvmmem_default_access)
+int altp2m_init_next_available(struct domain *d, uint16_t *idx,
+                               xenmem_access_t hvmmem_default_access)
 {
     int rc = -EINVAL;
     unsigned int i;
@@ -438,7 +438,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx,
         if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             continue;
 
-        rc = p2m_activate_altp2m(d, i, a);
+        rc = altp2m_activate_altp2m(d, i, a);
 
         if ( !rc )
             *idx = i;
@@ -450,7 +450,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx,
     return rc;
 }
 
-int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx)
+int altp2m_destroy_by_id(struct domain *d, unsigned int idx)
 {
     struct p2m_domain *p2m;
     int rc = -EBUSY;
@@ -472,7 +472,7 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int 
idx)
 
         if ( !_atomic_read(p2m->active_vcpus) )
         {
-            p2m_reset_altp2m(d, idx, ALTP2M_DEACTIVATE);
+            altp2m_reset_altp2m(d, idx, ALTP2M_DEACTIVATE);
             d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] =
                 mfn_x(INVALID_MFN);
             d->arch.altp2m_visible_eptp[array_index_nospec(idx, MAX_EPTP)] =
@@ -488,7 +488,7 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int 
idx)
     return rc;
 }
 
-int p2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx)
+int altp2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx)
 {
     struct vcpu *v;
     int rc = -EINVAL;
@@ -506,7 +506,7 @@ int p2m_switch_domain_altp2m_by_id(struct domain *d, 
unsigned int idx)
     if ( d->arch.altp2m_visible_eptp[idx] != mfn_x(INVALID_MFN) )
     {
         for_each_vcpu( d, v )
-            if ( p2m_set_altp2m(v, idx) )
+            if ( altp2m_set_altp2m(v, idx) )
                 altp2m_vcpu_update_p2m(v);
 
         rc = 0;
@@ -519,8 +519,8 @@ int p2m_switch_domain_altp2m_by_id(struct domain *d, 
unsigned int idx)
     return rc;
 }
 
-int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
-                          gfn_t old_gfn, gfn_t new_gfn)
+int altp2m_change_gfn(struct domain *d, unsigned int idx, gfn_t old_gfn,
+                      gfn_t new_gfn)
 {
     struct p2m_domain *hp2m, *ap2m;
     p2m_access_t a;
@@ -571,11 +571,11 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int 
idx,
     p2m_unlock(ap2m);
     p2m_unlock(hp2m);
     return rc;
-}
+ }
 
-int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
-                                mfn_t mfn, unsigned int page_order,
-                                p2m_type_t p2mt, p2m_access_t p2ma)
+int altp2m_propagate_change(struct domain *d, gfn_t gfn, mfn_t mfn,
+                            unsigned int page_order, p2m_type_t p2mt,
+                            p2m_access_t p2ma)
 {
     struct p2m_domain *p2m;
     unsigned int i;
@@ -605,7 +605,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
         {
             if ( !reset_count++ )
             {
-                p2m_reset_altp2m(d, i, ALTP2M_RESET);
+                altp2m_reset_altp2m(d, i, ALTP2M_RESET);
                 last_reset_idx = i;
             }
             else
@@ -617,7 +617,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
                          d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
                         continue;
 
-                    p2m_reset_altp2m(d, i, ALTP2M_RESET);
+                    altp2m_reset_altp2m(d, i, ALTP2M_RESET);
                 }
 
                 ret = 0;
@@ -768,8 +768,8 @@ int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool 
*suppress_ve,
     return rc;
 }
 
-int p2m_set_altp2m_view_visibility(struct domain *d, unsigned int altp2m_idx,
-                                   uint8_t visible)
+int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
+                               uint8_t visible)
 {
     int rc = 0;
 
diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c
index e5548e64d8d0..0492356d99ad 100644
--- a/xen/arch/x86/mm/mem_access.c
+++ b/xen/arch/x86/mm/mem_access.c
@@ -81,7 +81,7 @@ bool p2m_mem_access_emulate_check(struct vcpu *v,
     struct p2m_domain *p2m = NULL;
 
     if ( altp2m_active(d) )
-        p2m = p2m_get_altp2m(v);
+        p2m = altp2m_get_altp2m(v);
     if ( !p2m )
         p2m = p2m_get_hostp2m(d);
 
@@ -145,7 +145,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
     int rc;
 
     if ( altp2m_active(d) )
-        p2m = p2m_get_altp2m(v);
+        p2m = altp2m_get_altp2m(v);
     if ( !p2m )
         p2m = p2m_get_hostp2m(d);
 
@@ -252,9 +252,10 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
     return (p2ma != p2m_access_n2rwx);
 }
 
-static int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
-                                     struct p2m_domain *ap2m, p2m_access_t a,
-                                     gfn_t gfn)
+static int altp2m_set_altp2m_mem_access(struct domain *d,
+                                        struct p2m_domain *hp2m,
+                                        struct p2m_domain *ap2m, p2m_access_t 
a,
+                                        gfn_t gfn)
 {
     mfn_t mfn;
     p2m_type_t t;
@@ -281,7 +282,7 @@ static int set_mem_access(struct domain *d, struct 
p2m_domain *p2m,
 
     if ( ap2m )
     {
-        rc = p2m_set_altp2m_mem_access(d, p2m, ap2m, a, gfn);
+        rc = altp2m_set_altp2m_mem_access(d, p2m, ap2m, a, gfn);
         /* If the corresponding mfn is invalid we will want to just skip it */
         if ( rc == -ESRCH )
             rc = 0;
diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c
index ce14066fedaf..433e7d08b78f 100644
--- a/xen/arch/x86/mm/p2m-basic.c
+++ b/xen/arch/x86/mm/p2m-basic.c
@@ -128,7 +128,7 @@ int p2m_init(struct domain *d)
         return rc;
     }
 
-    rc = altp2m_supported() ? p2m_init_altp2m(d) : 0;
+    rc = altp2m_supported() ? altp2m_init(d) : 0;
     if ( rc )
     {
         p2m_teardown_hostp2m(d);
@@ -198,7 +198,7 @@ void p2m_final_teardown(struct domain *d)
     if ( is_hvm_domain(d) )
     {
         if ( altp2m_supported() )
-            p2m_teardown_altp2m(d);
+            altp2m_teardown(d);
         /*
          * We must tear down nestedp2m unconditionally because
          * we initialise it unconditionally.
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index 84159198f3a0..a6f61a9dd3d7 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -773,7 +773,7 @@ bool ept_handle_misconfig(uint64_t gpa)
     int rc;
 
     if ( altp2m_active(curr->domain) )
-        p2m = p2m_get_altp2m(curr);
+        p2m = altp2m_get_altp2m(curr);
 
     p2m_lock(p2m);
 
@@ -997,7 +997,7 @@ out:
 
     if ( altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) )
     {
-        ret = p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, 
p2ma);
+        ret = altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
         if ( !rc )
             rc = ret;
     }
diff --git a/xen/arch/x86/mm/p2m.h b/xen/arch/x86/mm/p2m.h
index 635f5a7f45cd..64218878067e 100644
--- a/xen/arch/x86/mm/p2m.h
+++ b/xen/arch/x86/mm/p2m.h
@@ -19,9 +19,6 @@ static inline int p2m_init_logdirty(struct p2m_domain *p2m) { 
return 0; }
 static inline void p2m_free_logdirty(struct p2m_domain *p2m) {}
 #endif
 
-int p2m_init_altp2m(struct domain *d);
-void p2m_teardown_altp2m(struct domain *d);
-
 void p2m_flush_table_locked(struct p2m_domain *p2m);
 int __must_check p2m_remove_entry(struct p2m_domain *p2m, gfn_t gfn, mfn_t mfn,
                                   unsigned int page_order);
diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
index cf0258223f50..77e0c8a0b240 100644
--- a/xen/common/vm_event.c
+++ b/xen/common/vm_event.c
@@ -433,7 +433,7 @@ static int vm_event_resume(struct domain *d, struct 
vm_event_domain *ved)
             /* Check for altp2m switch */
             if ( IS_ENABLED(CONFIG_ALTP2M) &&
                  rsp.flags & VM_EVENT_FLAG_ALTERNATE_P2M )
-                p2m_altp2m_check(v, rsp.altp2m_idx);
+                altp2m_check(v, rsp.altp2m_idx);
 
             if ( rsp.flags & VM_EVENT_FLAG_SET_REGISTERS )
                 vm_event_set_registers(v, &rsp);
diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h
index f0bd9a6b9896..6da330acca1f 100644
--- a/xen/include/xen/p2m-common.h
+++ b/xen/include/xen/p2m-common.h
@@ -25,7 +25,7 @@ int unmap_mmio_regions(struct domain *d,
                        mfn_t mfn);
 
 /* Check to see if vcpu should be switched to a different p2m. */
-void p2m_altp2m_check(struct vcpu *v, uint16_t idx);
+void altp2m_check(struct vcpu *v, uint16_t idx);
 
 /*
  * Populate-on-Demand
-- 
2.34.1




 


Rackspace

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