Skip to contentSkip to conversation

altp2m: Move altp2m routines to common code and add ARM support

RFC PATCH New Rose Spangler 1 participant 8 messages Apr 20

lore
Share & tools
lore
#0 lore raw

v6 cover altp2m: Move altp2m routines to common code and add ARM support

Hi all,

For the past few months, myself and Aqib Javid have been working to port altp2m to ARM with support from Stewart Hildebrand and Stefano Stabellini. At the recent Spring Xen Summit, Aqib and Stewart gave a presentation which discussed the motivation behind this, along with an overview of the rebasing and testing process. While this effort started as a rebase[1] of the v5 patch series[2] by Sergej Proskurin and Tamas Lengyel, I have been reworking the branch to make most of the altp2m code common between x86 and ARM. This should address the major concerns that came up during review of the original patch series. For a quick overview of altp2m functionality and scope of the patch series, here's an excerpt from Sergej's cover letter:

Quoted 10 lines

In this patch series, we provide an implementation of the altp2m subsystem for ARM. Our implementation is based on the altp2m subsystem for x86, providing additional --alternate-- views on the guest's physical memory by means of the ARM 2nd stage translation mechanism. The patches introduce new HVMOPs and extend the p2m subsystem. [...] To be more precise, altp2m allows to create and switch to additional p2m views (i.e. gfn to mfn mappings). These views can be manipulated and activated as will through the provided HVMOPs. In this way, the active guest instance in question can seamlessly proceed execution without noticing that anything has changed.

As of right now, I've reworked patch series up through the HVMOP_altp2m_set_domain_state command and plan to continue implementing the remaining altp2m features. I've continued the patch series versioning by labeling my notes as v6, and the patch notes from v1-v5 have been preserved where applicable. I am hoping for some feedback on the general approach I've taken with this patch series, and I can incorporate any changes requested into the actual patch series submission.

This is a pretty big patch series, so I've tried to make it as easy as possible to follow. I've tried to minimize the number of changes in each patch; there are quite a lot of patches so if it would be preferred to combine some patches I can do so. Here is the general approach I used throughout the patch series to turn x86 altp2m code into common altp2m code with ARM support:

- Move function(s) from arch/x86/mm/altp2m.c to common/altp2m.c, gating declarations/definitions with #ifdef CONFIG_X86
- Add any additional features to ARM code needed to implement these functions
- Make any changes necessary to functions to support ARM, and remove #ifdef CONFIG_X86

This approach makes it possible to separate out code movement patches from the actual changes needed to support ARM. Furthermore, each patch in the patch series still compiles for both x86 and ARM.

Additionally, I've split the patch series into a number of "phases" to make it easier to understand the context of each patch. Each patch description indicates which phase it's a part of.
- Preparation (8 commits)
- Common do_altp2m_op (2 commits)
- get_domain_state (1 commit)
- altp2m_{init,teardown} routines (12 commits)
- altp2m_{get,set}_altp2m (4 commits)
- Needed for altp2m_vcpu_{initialise,destroy}
- altp2m_vcpu_{initialise,destroy} (2 commits)
- Needed for HVMOP_set_domain_state
- altp2m view visibility (5 commits)
- Needed for altp2m_init_by_id, altp2m_flush
- altp2m_activate_altp2m (2 commits)
- Needed for altp2m_init_by_id
- altp2m_init_by_id (2 commits)
- Needed for HVMOP_altp2m_set_domain_state
- altp2m_reset_altp2m (2 commits)
- Needed for altp2m_flush
- altp2m_flush (2 commits)
- Needed for HVMOP_altp2m_set_domain_state
- set_domain_state (1 commit)

The code for this patch series can also be found on GitLab:
https://gitlab.com/xen-project/people/elektrobit/xen/-/tree/altp2m-arm-rework-rfc

Best,
Rose Spangler

[1] Rebase of original patch series:
https://gitlab.com/xen-project/people/elektrobit/xen/-/commits/altp2m-arm-rebase

[2] Original patch series:
v1: https://lore.kernel.org/xen-devel/[email protected]/
v2: https://lore.kernel.org/xen-devel/[email protected]/
v3: https://lore.kernel.org/xen-devel/[email protected]/
v4: https://lore.kernel.org/xen-devel/[email protected]/
v5 was never submitted to mailing list, but is available on GitHub:
https://github.com/sergej-proskurin/xen/tree/arm-altp2m-v5

(Resend due to threading issues in first send attempt)

Rose Spangler (38):
altp2m: Add template common altp2m.c/altp2m.h
altp2m: Move altp2m_active to common domain struct
altp2m: Move altp2m_p2m to common domain struct x86/altp2m: Rename hvm_altp2m_supported to altp2m_supported
altp2m: Move altp2m_supported to arch header arm/altp2m: Add template arch-specific altp2m.c/altp2m.h arm/altp2m: Introduce CONFIG_ALTP2M Kconfig option
altp2m: Rename p2m_*_altp2m functions and move declarations out of

    p2m.h

altp2m: Move do_altp2m_op to common code
altp2m: Add ARM support to do_altp2m_op
arm/altp2m: Add support for HVMOP_altp2m_get_domain_state x86/p2m: Move p2m_{init,free}_one declarations to arch header x86/altp2m: Add lock functions accessible from common code
altp2m: Move altp2m_{init,teardown} to common code arm/p2m: Allocate hostp2m with xzalloc
arm/p2m: Move hostp2m init/teardown to individual functions arm/p2m: Invalidate root page table entries and flush TLB in
p2m_flush_table
arm/altp2m: Add support for altp2m init/teardown routines
altp2m: Move altp2m_{get,set}_altp2m to common code arm/altp2m: Add altp2m index to arch_vcpu
altp2m: Add altp2m_set_vcpu_idx
arm/altp2m: Add support for altp2m_{get,set}_altp2m
altp2m: Move altp2m_vcpu_{initialise,destroy} to common code arm/altp2m: Add support for altp2m_vcpu_{initialise,destroy} arm/altp2m: Add altp2m view validity/visibility indicator
altp2m: Add altp2m_view_is_{valid,visible}
x86/altp2m: Add altp2m_set_view_visibility_locked arm/altp2m: Add altp2m_set_view_visibility{,_locked} support arm/altp2m: Add support for HVMOP_altp2m_set_visibility x86/altp2m: Add altp2m_activate_altp2m declaration to arch header arm/altp2m: Add support for altp2m_activate_altp2m
altp2m: Move altp2m_init_by_id to common code arm/altp2m: Add support for altp2m_init_by_id x86/altp2m: Add altp2m_reset_altp2m declaration to arch header arm/altp2m: Add altp2m_reset_altp2m routine
altp2m: Move altp2m_flush to common code
arm/altp2m: Add support for altp2m_flush
arm/p2m: Add support for HVMOP_altp2m_set_domain_state

Sergej Proskurin (5):
arm/p2m: Cosmetic fix - substitute _gfn(ULONG_MAX) for INVALID_GFN arm/p2m: Change function prototype of p2m_alloc_table arm/p2m: Rename parameter in p2m_alloc_vmid
arm/p2m: Change func prototype and impl of p2m_{alloc,free}_vmid arm/p2m: Introduce p2m_is_{hostp2m,altp2m}

 xen/arch/arm/Kconfig                     |  11 +
 xen/arch/arm/Makefile                    |   1 +
 xen/arch/arm/altp2m.c                    | 122 +++++
 xen/arch/arm/domain.c                    |   2 +-
 xen/arch/arm/hvm.c                       |   9 +
 xen/arch/arm/include/asm/Makefile        |   1 -
 xen/arch/arm/include/asm/altp2m.h        |  84 ++++
 xen/arch/arm/include/asm/domain.h        |  19 +-
 xen/arch/arm/include/asm/p2m.h           |  41 +-
 xen/arch/arm/mm.c                        |   2 +-
 xen/arch/arm/mmu/p2m.c                   | 162 ++++++-
 xen/arch/arm/p2m.c                       |  31 +-
 xen/arch/arm/traps.c                     |   2 +-
 xen/arch/x86/domain.c                    |   3 +-
 xen/arch/x86/hvm/emulate.c               |   1 +
 xen/arch/x86/hvm/hvm.c                   | 413 +----------------
 xen/arch/x86/hvm/monitor.c               |   3 +-
 xen/arch/x86/hvm/vmx/vmx.c               |   9 +-
 xen/arch/x86/include/asm/altp2m.h        | 115 ++++-
 xen/arch/x86/include/asm/domain.h        |   5 -
 xen/arch/x86/include/asm/hvm/hvm.h       |  11 -
 xen/arch/x86/include/asm/p2m.h           | 112 +----
 xen/arch/x86/mm/altp2m.c                 | 242 +++-------
 xen/arch/x86/mm/hap/hap.c                |  17 +-
 xen/arch/x86/mm/mem_access.c             |  22 +-
 xen/arch/x86/mm/mem_sharing.c            |   3 +-
 xen/arch/x86/mm/p2m-basic.c              |   7 +-
 xen/arch/x86/mm/p2m-ept.c                |  13 +-
 xen/arch/x86/mm/p2m-pt.c                 |   1 +
 xen/arch/x86/mm/p2m.c                    |   9 +-
 xen/arch/x86/mm/p2m.h                    |   6 -
 xen/common/Makefile                      |   1 +
 xen/common/altp2m.c                      | 551 +++++++++++++++++++++++
 xen/common/monitor.c                     |   1 +
 xen/common/vm_event.c                    |   2 +-
 xen/drivers/passthrough/arm/ipmmu-vmsa.c |   2 +-
 xen/drivers/passthrough/arm/smmu-v3.c    |   2 +-
 xen/drivers/passthrough/arm/smmu.c       |   2 +-
 xen/include/asm-generic/altp2m.h         |   5 +-
 xen/include/xen/altp2m.h                 |  98 ++++
 xen/include/xen/p2m-common.h             |   2 +-
 xen/include/xen/sched.h                  |   3 +
 42 files changed, 1330 insertions(+), 818 deletions(-)
 create mode 100644 xen/arch/arm/altp2m.c
 create mode 100644 xen/arch/arm/include/asm/altp2m.h
 create mode 100644 xen/common/altp2m.c
 create mode 100644 xen/include/xen/altp2m.h
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH v6 1/43 altp2m: Add template common altp2m.c/altp2m.h

This commit adds an empty common altp2m.c and altp2m.h file to be added to in later commits. Creating a commit with just the empty file additions makes it easier to reorder later commits which add to these files.

This commit can be squashed into the first commit which actually adds something to altp2m.c/altp2m.h for the actual submission if that would be preferred.

This is commit 1/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/common/Makefile      |  1 +
 xen/common/altp2m.c      | 12 ++++++++++++
 xen/include/xen/altp2m.h |  5 +++++
 3 files changed, 18 insertions(+)
 create mode 100644 xen/common/altp2m.c
 create mode 100644 xen/include/xen/altp2m.h
xen/common/Makefile +1 -0
index 6018e256147f..dbe0094006df 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_ALTP2M) += altp2m.o
 obj-$(CONFIG_ARGO) += argo.o
 obj-y += bitmap.o
 obj-bin-$(CONFIG_SELF_TESTS) += bitops.init.o
xen/common/altp2m.c new file +12 -0
new file mode 100644
index 000000000000..1a4e102324d4
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <xen/altp2m.h>
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/xen/altp2m.h new file +5 -0
new file mode 100644
index 000000000000..520328fd3fa8
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __XEN_ALTP2M_H__
+#define __XEN_ALTP2M_H__
+
+#endif /* __XEN_ALTP2M_H__ */
Signature · 1 line
2.34.1
#2 lore raw

RFC PATCH v6 2/43 altp2m: Move altp2m_active to common domain struct

In reply to Rose Spangler

This commit moves altp2m_active from arch_domain on x86 to the common domain struct. Similarly to nr_altp2m, this is not an arch-specific value. Moving it to common code allows the common altp2m routines introduced later in this patch series to operate on altp2m_active without needing an altp2m_active member on arch_domain for each architecture supporting altp2m.

This is commit 2/8 of the preparation phase.

This commit is a refactor, and no change in functionality is intended.

---
v6: Introduced this patch.

---
 xen/arch/x86/hvm/emulate.c        |  1 +
 xen/arch/x86/hvm/hvm.c            | 11 ++++++-----
 xen/arch/x86/hvm/monitor.c        |  1 +
 xen/arch/x86/hvm/vmx/vmx.c        |  1 +
 xen/arch/x86/include/asm/altp2m.h | 11 -----------
 xen/arch/x86/include/asm/domain.h |  2 --
 xen/arch/x86/mm/altp2m.c          |  1 +
 xen/arch/x86/mm/hap/hap.c         |  5 +++--
 xen/arch/x86/mm/mem_access.c      |  1 +
 xen/arch/x86/mm/mem_sharing.c     |  1 +
 xen/arch/x86/mm/p2m-ept.c         |  1 +
 xen/arch/x86/mm/p2m-pt.c          |  1 +
 xen/arch/x86/mm/p2m.c             |  1 +
 xen/common/monitor.c              |  1 +
 xen/include/asm-generic/altp2m.h  |  8 --------
 xen/include/xen/altp2m.h          | 19 +++++++++++++++++++
 xen/include/xen/sched.h           |  2 ++
 17 files changed, 40 insertions(+), 28 deletions(-)
xen/arch/x86/hvm/emulate.c +1 -0
index f3aae158e9f8..9a9b89a232e6 100644
@@ -9,6 +9,7 @@
  *    Keir Fraser <[email protected]>
  */
 
+#include <xen/altp2m.h>
 #include <xen/init.h>
 #include <xen/iocap.h>
 #include <xen/ioreq.h>
xen/arch/x86/hvm/hvm.c +6 -5
index 4a81afce02e7..86c12c0d1ef4 100644
@@ -7,6 +7,7 @@
  * Copyright (c) 2008, Citrix Systems, Inc.
  */
 
+#include <xen/altp2m.h>
 #include <xen/console.h>
 #include <xen/cpu.h>
 #include <xen/domain.h>
@@ -4612,7 +4613,7 @@ static int do_altp2m_op(
 
     if ( (a.cmd != HVMOP_altp2m_get_domain_state) &&
          (a.cmd != HVMOP_altp2m_set_domain_state) &&
-         !d->arch.altp2m_active )
+         !d->altp2m_active )
     {
         rc = -EOPNOTSUPP;
         goto out;
@@ -4657,11 +4658,11 @@ static int do_altp2m_op(
         if ( rc )
             break;
 
-        ostate = d->arch.altp2m_active;
-        d->arch.altp2m_active = !!a.u.domain_state.state;
+        ostate = d->altp2m_active;
+        d->altp2m_active = !!a.u.domain_state.state;
 
         /* If the alternate p2m state has changed, handle appropriately */
-        if ( d->arch.altp2m_active != ostate &&
+        if ( d->altp2m_active != ostate &&
              (ostate || !(rc = p2m_init_altp2m_by_id(d, 0))) )
         {
             for_each_vcpu( d, v )
@@ -4676,7 +4677,7 @@ static int do_altp2m_op(
                 p2m_flush_altp2m(d);
         }
         else if ( rc )
-            d->arch.altp2m_active = false;
+            d->altp2m_active = false;
 
         domain_unpause_except_self(d);
         break;
xen/arch/x86/hvm/monitor.c +1 -0
index d22a2e464460..84c1c2234ca9 100644
@@ -22,6 +22,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/altp2m.h>
 #include <xen/vm_event.h>
 #include <xen/mem_access.h>
 #include <xen/monitor.h>
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index 269ca5643346..ff895f7f9437 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2004, Intel Corporation.
  */
 
+#include <xen/altp2m.h>
 #include <xen/domain_page.h>
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
xen/arch/x86/include/asm/altp2m.h +0 -11
index 9c1ac3cc2676..ad5ded833a75 100644
@@ -28,12 +28,6 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
         mfn_x(INVALID_MFN);
 }
 
-/* Alternate p2m HVM on/off per domain */
-static inline bool altp2m_active(const struct domain *d)
-{
-    return d->arch.altp2m_active;
-}
-
 static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
 {
     return vcpu_altp2m(v).p2midx;
@@ -64,11 +58,6 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
     return false;
 }
 
-static inline bool altp2m_active(const struct domain *d)
-{
-    return false;
-}
-
 /* Only declaration is needed. DCE will optimise it out when linking. */
 uint16_t altp2m_vcpu_idx(const struct vcpu *v);
 void altp2m_vcpu_initialise(struct vcpu *v);
xen/arch/x86/include/asm/domain.h +0 -2
index 385a6666dafa..0cf0c0d92087 100644
@@ -368,8 +368,6 @@ struct arch_domain
     mm_lock_t nested_p2m_lock;
 
 #ifdef CONFIG_ALTP2M
-    /* altp2m: allow multiple copies of host p2m */
-    bool altp2m_active;
     struct p2m_domain **altp2m_p2m;
     mm_lock_t altp2m_list_lock;
     uint64_t *altp2m_eptp;
xen/arch/x86/mm/altp2m.c +1 -0
index 0bc9b9ad2f52..08db8f37c1b1 100644
@@ -8,6 +8,7 @@
 #include <asm/p2m.h>
 #include <asm/altp2m.h>
 #include <public/hvm/hvm_op.h>
+#include <xen/altp2m.h>
 #include <xen/event.h>
 #include <xen/xvmalloc.h>
 #include "mm-locks.h"
xen/arch/x86/mm/hap/hap.c +3 -2
index 5ccb80bda5d3..3d563b3bc2d1 100644
@@ -7,6 +7,7 @@
  * Parts of this code are Copyright (c) 2007 by XenSource Inc.
  */
 
+#include <xen/altp2m.h>
 #include <xen/types.h>
 #include <xen/mm.h>
 #include <xen/trace.h>
@@ -528,7 +529,7 @@ int hap_enable(struct domain *d, u32 mode)
                goto out;
         }
 
-        d->arch.altp2m_active = false;
+        d->altp2m_active = false;
     }
 #endif /* CONFIG_ALTP2M */
 
@@ -595,7 +596,7 @@ void hap_teardown(struct domain *d, bool *preempted)
             for_each_vcpu ( d, v )
                 altp2m_vcpu_disable_ve(v);
 
-        d->arch.altp2m_active = false;
+        d->altp2m_active = false;
 
         FREE_XENHEAP_PAGE(d->arch.altp2m_eptp);
         FREE_XENHEAP_PAGE(d->arch.altp2m_visible_eptp);
xen/arch/x86/mm/mem_access.c +1 -0
index e55e53f44c78..a9d6b081a523 100644
@@ -9,6 +9,7 @@
  * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
  */
 
+#include <xen/altp2m.h>
 #include <xen/guest_access.h> /* copy_from_guest() */
 #include <xen/mem_access.h>
 #include <xen/nospec.h>
xen/arch/x86/mm/mem_sharing.c +1 -0
index 5c7a0ff30e8b..8319733b1bb6 100644
@@ -8,6 +8,7 @@
  * Copyright (c) 2009 Citrix Systems, Inc. (Grzegorz Milos)
  */
 
+#include <xen/altp2m.h>
 #include <xen/types.h>
 #include <xen/domain_page.h>
 #include <xen/event.h>
xen/arch/x86/mm/p2m-ept.c +1 -0
index dfdbfa0afec8..ed850723f5fd 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2007, Intel Corporation.
  */
 
+#include <xen/altp2m.h>
 #include <xen/domain_page.h>
 #include <xen/sched.h>
 #include <public/hvm/dm_op.h>
xen/arch/x86/mm/p2m-pt.c +1 -0
index 5a6ce2f8bc2e..17f38aac14d5 100644
@@ -12,6 +12,7 @@
  * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
  */
 
+#include <xen/altp2m.h>
 #include <xen/vm_event.h>
 #include <xen/event.h>
 #include <xen/trace.h>
xen/arch/x86/mm/p2m.c +1 -0
index fddecdf978ec..41517765c5ec 100644
@@ -11,6 +11,7 @@
  * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
  */
 
+#include <xen/altp2m.h>
 #include <xen/iommu.h>
 #include <xen/mem_access.h>
 #include <xen/vm_event.h>
xen/common/monitor.c +1 -0
index d5c9ff1cbf8c..e758a3fea9f1 100644
@@ -19,6 +19,7 @@
  * License along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/altp2m.h>
 #include <xen/event.h>
 #include <xen/monitor.h>
 #include <xen/sched.h>
xen/include/asm-generic/altp2m.h +0 -8
index 39865a842ab3..ecee6942f4e8 100644
@@ -4,16 +4,8 @@
 
 #include <xen/bug.h>
 
-struct domain;
 struct vcpu;
 
-/* Alternate p2m on/off per domain */
-static inline bool altp2m_active(const struct domain *d)
-{
-    /* Not implemented on GENERIC. */
-    return false;
-}
-
 /* Alternate p2m VCPU */
 static inline unsigned int altp2m_vcpu_idx(const struct vcpu *v)
 {
xen/include/xen/altp2m.h +19 -0
index 520328fd3fa8..b3b21124dd7e 100644
@@ -2,4 +2,23 @@
 #ifndef __XEN_ALTP2M_H__
 #define __XEN_ALTP2M_H__
 
+#include <xen/sched.h>
+
+#ifdef CONFIG_ALTP2M
+
+/* Alternate p2m HVM on/off per domain */
+static inline bool altp2m_active(const struct domain *d)
+{
+    return d->altp2m_active;
+}
+
+#else /* CONFIG_ALTP2M */
+
+static inline bool altp2m_active(const struct domain *d)
+{
+    return false;
+}
+
+#endif /* CONFIG_ALTP2M */
+
 #endif /* __XEN_ALTP2M_H__ */
xen/include/xen/sched.h +2 -0
index 212c7d765c3e..458f2f260dd7 100644
@@ -623,6 +623,8 @@ struct domain
     } monitor;
 
 #ifdef CONFIG_ALTP2M
+    /* altp2m: allow multiple copies of host p2m */
+    bool altp2m_active;
     unsigned int nr_altp2m;    /* Number of altp2m tables. */
 #endif
 
Signature · 1 line
2.34.1
#3 lore raw

RFC PATCH v6 3/43 altp2m: Move altp2m_p2m to common domain struct

In reply to Rose Spangler

Similarly to the previous commit, this commit moves altp2m_p2m to the common domain struct. The representation of altp2m views as an array of p2m_domain pointers is the same on x86 and ARM, and it seems that this would be the case for other architectures as well.

This commit is a refactor, and no change in functionality is intended.

This is commit 3/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/arch/x86/hvm/vmx/vmx.c        |  2 +-
 xen/arch/x86/include/asm/domain.h |  1 -
 xen/arch/x86/include/asm/p2m.h    |  4 ++--
 xen/arch/x86/mm/altp2m.c          | 28 ++++++++++++++--------------
 xen/arch/x86/mm/hap/hap.c         |  6 +++---
 xen/arch/x86/mm/mem_access.c      |  8 ++++----
 xen/arch/x86/mm/mem_sharing.c     |  2 +-
 xen/arch/x86/mm/p2m-ept.c         |  6 +++---
 xen/arch/x86/mm/p2m.c             |  8 ++++----
 xen/include/xen/sched.h           |  1 +
 10 files changed, 33 insertions(+), 33 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index ff895f7f9437..0909929c00e0 100644
@@ -5004,7 +5004,7 @@ bool asmlinkage vmx_vmenter_helper(const struct cpu_user_regs *regs)
                 if ( currd->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
                     continue;
 
-                ept = &currd->arch.altp2m_p2m[i]->ept;
+                ept = &currd->altp2m_p2m[i]->ept;
                 if ( cpumask_test_cpu(cpu, ept->invalidate) )
                 {
                     cpumask_clear_cpu(cpu, ept->invalidate);
xen/arch/x86/include/asm/domain.h +0 -1
index 0cf0c0d92087..f8038087e612 100644
@@ -368,7 +368,6 @@ struct arch_domain
     mm_lock_t nested_p2m_lock;
 
 #ifdef CONFIG_ALTP2M
-    struct p2m_domain **altp2m_p2m;
     mm_lock_t altp2m_list_lock;
     uint64_t *altp2m_eptp;
     uint64_t *altp2m_visible_eptp;
xen/arch/x86/include/asm/p2m.h +2 -2
index 3a5a5fd43c2a..ec871717a9e4 100644
@@ -901,7 +901,7 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v)
 
     BUG_ON(index >= v->domain->nr_altp2m);
 
-    return v->domain->arch.altp2m_p2m[index];
+    return v->domain->altp2m_p2m[index];
 }
 
 /* set current alternate p2m table */
@@ -919,7 +919,7 @@ static inline bool p2m_set_altp2m(struct vcpu *v, unsigned int idx)
     atomic_dec(&orig->active_vcpus);
 
     vcpu_altp2m(v).p2midx = idx;
-    atomic_inc(&v->domain->arch.altp2m_p2m[idx]->active_vcpus);
+    atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus);
 
     return true;
 }
xen/arch/x86/mm/altp2m.c +14 -14
index 08db8f37c1b1..8dd3c0f96be0 100644
@@ -130,14 +130,14 @@ int p2m_init_altp2m(struct domain *d)
     struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
 
     mm_lock_init(&d->arch.altp2m_list_lock);
-    d->arch.altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
+    d->altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
 
-    if ( !d->arch.altp2m_p2m )
+    if ( !d->altp2m_p2m )
         return -ENOMEM;
 
     for ( i = 0; i < d->nr_altp2m; i++ )
     {
-        d->arch.altp2m_p2m[i] = p2m = p2m_init_one(d);
+        d->altp2m_p2m[i] = p2m = p2m_init_one(d);
         if ( p2m == NULL )
         {
             p2m_teardown_altp2m(d);
@@ -158,14 +158,14 @@ void p2m_teardown_altp2m(struct domain *d)
 
     for ( i = 0; i < d->nr_altp2m; i++ )
     {
-        if ( !d->arch.altp2m_p2m[i] )
+        if ( !d->altp2m_p2m[i] )
             continue;
-        p2m = d->arch.altp2m_p2m[i];
-        d->arch.altp2m_p2m[i] = NULL;
+        p2m = d->altp2m_p2m[i];
+        d->altp2m_p2m[i] = NULL;
         p2m_free_one(p2m);
     }
 
-    XVFREE(d->arch.altp2m_p2m);
+    XVFREE(d->altp2m_p2m);
 }
 
 int altp2m_get_effective_entry(struct p2m_domain *ap2m, gfn_t gfn, mfn_t *mfn,
@@ -325,7 +325,7 @@ static void p2m_reset_altp2m(struct domain *d, unsigned int idx,
     struct p2m_domain *p2m;
 
     ASSERT(idx < d->nr_altp2m);
-    p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+    p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
 
     p2m_lock(p2m);
 
@@ -368,7 +368,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx,
 
     ASSERT(idx < d->nr_altp2m);
 
-    p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+    p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
     hostp2m = p2m_get_hostp2m(d);
 
     p2m_lock(p2m);
@@ -468,7 +468,7 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx)
     if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] !=
          mfn_x(INVALID_MFN) )
     {
-        p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+        p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
 
         if ( !_atomic_read(p2m->active_vcpus) )
         {
@@ -532,7 +532,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
         return rc;
 
     hp2m = p2m_get_hostp2m(d);
-    ap2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+    ap2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
 
     p2m_lock(hp2m);
     p2m_lock(ap2m);
@@ -596,7 +596,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
         if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
             continue;
 
-        p2m = d->arch.altp2m_p2m[i];
+        p2m = d->altp2m_p2m[i];
 
         /* Check for a dropped page that may impact this altp2m */
         if ( mfn_eq(mfn, INVALID_MFN) &&
@@ -679,7 +679,7 @@ int p2m_set_suppress_ve_multi(struct domain *d,
             return -EINVAL;
 
         p2m = ap2m =
-            d->arch.altp2m_p2m[array_index_nospec(sve->view, d->nr_altp2m)];
+            d->altp2m_p2m[array_index_nospec(sve->view, d->nr_altp2m)];
     }
 
     p2m_lock(host_p2m);
@@ -746,7 +746,7 @@ int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve,
             return -EINVAL;
 
         p2m = ap2m =
-            d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+            d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
     }
     else
         p2m = host_p2m;
xen/arch/x86/mm/hap/hap.c +3 -3
index 3d563b3bc2d1..6918a00a2a25 100644
@@ -524,7 +524,7 @@ int hap_enable(struct domain *d, u32 mode)
 
         for ( i = 0; i < d->nr_altp2m; i++ )
         {
-            rv = p2m_alloc_table(d->arch.altp2m_p2m[i]);
+            rv = p2m_alloc_table(d->altp2m_p2m[i]);
             if ( rv != 0 )
                goto out;
         }
@@ -548,7 +548,7 @@ void hap_final_teardown(struct domain *d)
 #ifdef CONFIG_ALTP2M
     if ( hvm_altp2m_supported() )
         for ( i = 0; i < d->nr_altp2m; i++ )
-            p2m_teardown(d->arch.altp2m_p2m[i], true, NULL);
+            p2m_teardown(d->altp2m_p2m[i], true, NULL);
 #endif
 
     /* Destroy nestedp2m's first */
@@ -603,7 +603,7 @@ void hap_teardown(struct domain *d, bool *preempted)
 
         for ( i = 0; i < d->nr_altp2m; i++ )
         {
-            p2m_teardown(d->arch.altp2m_p2m[i], false, preempted);
+            p2m_teardown(d->altp2m_p2m[i], false, preempted);
             if ( preempted && *preempted )
                 return;
         }
xen/arch/x86/mm/mem_access.c +4 -4
index a9d6b081a523..e5548e64d8d0 100644
@@ -319,7 +319,7 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
         if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
             return -EINVAL;
 
-        ap2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+        ap2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
     }
 #endif
 
@@ -375,7 +375,7 @@ long p2m_set_mem_access_multi(struct domain *d,
         if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
             return -EINVAL;
 
-        ap2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+        ap2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
     }
 #endif
 
@@ -438,7 +438,7 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access,
         if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
             return -EINVAL;
 
-        p2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+        p2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
     }
 #endif
 
@@ -457,7 +457,7 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required)
         unsigned int i;
         for ( i = 0; i < d->nr_altp2m; i++ )
         {
-            struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
+            struct p2m_domain *p2m = d->altp2m_p2m[i];
 
             if ( p2m )
                 p2m->access_required = access_required;
xen/arch/x86/mm/mem_sharing.c +1 -1
index 8319733b1bb6..b7d8fb9ad1aa 100644
@@ -919,7 +919,7 @@ static int nominate_page(struct domain *d, gfn_t gfn,
 
         for ( i = 0; i < d->nr_altp2m; i++ )
         {
-            ap2m = d->arch.altp2m_p2m[i];
+            ap2m = d->altp2m_p2m[i];
             if ( !ap2m )
                 continue;
 
xen/arch/x86/mm/p2m-ept.c +3 -3
index ed850723f5fd..ddb4c7606be1 100644
@@ -1311,7 +1311,7 @@ static void ept_set_ad_sync(struct domain *d, bool value)
             if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
                 continue;
 
-            p2m = d->arch.altp2m_p2m[i];
+            p2m = d->altp2m_p2m[i];
 
             p2m_lock(p2m);
             p2m->ept.ad = value;
@@ -1579,7 +1579,7 @@ void __init setup_ept_dump(void)
 void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
 {
     struct p2m_domain *p2m =
-        d->arch.altp2m_p2m[array_index_nospec(i, d->nr_altp2m)];
+        d->altp2m_p2m[array_index_nospec(i, d->nr_altp2m)];
     struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
     struct ept_data *ept;
 
@@ -1603,7 +1603,7 @@ unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
         if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
             continue;
 
-        p2m = d->arch.altp2m_p2m[i];
+        p2m = d->altp2m_p2m[i];
         ept = &p2m->ept;
 
         if ( eptp == ept->eptp )
xen/arch/x86/mm/p2m.c +4 -4
index 41517765c5ec..5bd426296f20 100644
@@ -111,7 +111,7 @@ void p2m_change_entry_type_global(struct domain *d,
         {
             if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             {
-                struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+                struct p2m_domain *altp2m = d->altp2m_p2m[i];
 
                 p2m_lock(altp2m);
                 change_entry_type_global(altp2m, ot, nt);
@@ -157,7 +157,7 @@ bool p2m_memory_type_changed(struct domain *d)
         {
             if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             {
-                struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+                struct p2m_domain *altp2m = d->altp2m_p2m[i];
 
                 p2m_lock(altp2m);
                 _memory_type_changed(altp2m);
@@ -955,7 +955,7 @@ void p2m_change_type_range(struct domain *d,
         {
             if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             {
-                struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+                struct p2m_domain *altp2m = d->altp2m_p2m[i];
 
                 p2m_lock(altp2m);
                 change_type_range(altp2m, start, end, ot, nt);
@@ -1031,7 +1031,7 @@ int p2m_finish_type_change(struct domain *d,
         {
             if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
             {
-                struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+                struct p2m_domain *altp2m = d->altp2m_p2m[i];
 
                 p2m_lock(altp2m);
                 rc = finish_type_change(altp2m, first_gfn, max_nr);
xen/include/xen/sched.h +1 -0
index 458f2f260dd7..5d8ba2d2ab19 100644
@@ -626,6 +626,7 @@ struct domain
     /* altp2m: allow multiple copies of host p2m */
     bool altp2m_active;
     unsigned int nr_altp2m;    /* Number of altp2m tables. */
+    struct p2m_domain **altp2m_p2m;
 #endif
 
 #ifdef CONFIG_VMTRACE
Signature · 1 line
2.34.1
#4 lore raw

RFC PATCH v6 4/43 x86/altp2m: Rename hvm_altp2m_supported to altp2m_supported

Using a generic name for altp2m_supported makes it possible to indicate whether altp2m is supported on other architectures as well. Even if other architectures always support altp2m at a hardware level (like ARM), altp2m might not be supported due to CONFIG_ALTP2M being disabled. Therefore, the altp2m_supported function can be implemented on all architectures to indicate if the hardware supports altp2m *and* if CONFIG_ALTP2M is enabled.

This is commit 4/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/arch/x86/domain.c              | 2 +-
 xen/arch/x86/hvm/hvm.c             | 6 +++---
 xen/arch/x86/include/asm/hvm/hvm.h | 4 ++--
 xen/arch/x86/mm/hap/hap.c          | 6 +++---
 xen/arch/x86/mm/p2m-basic.c        | 4 ++--
 xen/arch/x86/mm/p2m-ept.c          | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/domain.c +1 -1
index 1d458f1372e5..512b18d4010f 100644
@@ -698,7 +698,7 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
 
     if ( altp2m_mode )
     {
-        if ( !hvm_altp2m_supported() )
+        if ( !altp2m_supported() )
         {
             dprintk(XENLOG_INFO, "altp2m is not supported\n");
             return -EINVAL;
xen/arch/x86/hvm/hvm.c +3 -3
index 86c12c0d1ef4..bc35efdf2c02 100644
@@ -1692,7 +1692,7 @@ void hvm_vcpu_destroy(struct vcpu *v)
 
     ioreq_server_remove_vcpu_all(v->domain, v);
 
-    if ( hvm_altp2m_supported() )
+    if ( altp2m_supported() )
         altp2m_vcpu_destroy(v);
 
     nestedhvm_vcpu_destroy(v);
@@ -4566,7 +4566,7 @@ static int do_altp2m_op(
     int rc = 0;
     uint64_t mode;
 
-    if ( !hvm_altp2m_supported() )
+    if ( !altp2m_supported() )
         return -EOPNOTSUPP;
 
     if ( copy_from_guest(&a, arg, 1) )
@@ -4965,7 +4965,7 @@ static int compat_altp2m_op(
         struct xen_hvm_altp2m_op *altp2m_op;
     } nat;
 
-    if ( !hvm_altp2m_supported() )
+    if ( !altp2m_supported() )
         return -EOPNOTSUPP;
 
     if ( copy_from_guest(&a, arg, 1) )
xen/arch/x86/include/asm/hvm/hvm.h +2 -2
index e7c1364802f8..6406bb687718 100644
@@ -702,7 +702,7 @@ static inline bool hvm_hap_supported(void)
 }
 
 /* returns true if hardware supports alternate p2m's */
-static inline bool hvm_altp2m_supported(void)
+static inline bool altp2m_supported(void)
 {
     return IS_ENABLED(CONFIG_ALTP2M) && hvm_funcs.caps.altp2m;
 }
@@ -876,7 +876,7 @@ static inline bool hvm_hap_supported(void)
     return false;
 }
 
-static inline bool hvm_altp2m_supported(void)
+static inline bool altp2m_supported(void)
 {
     return false;
 }
xen/arch/x86/mm/hap/hap.c +3 -3
index 6918a00a2a25..563eba3c0d36 100644
@@ -501,7 +501,7 @@ int hap_enable(struct domain *d, u32 mode)
     }
 
 #ifdef CONFIG_ALTP2M
-    if ( hvm_altp2m_supported() )
+    if ( altp2m_supported() )
     {
         /* Init alternate p2m data */
         if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL )
@@ -546,7 +546,7 @@ void hap_final_teardown(struct domain *d)
     unsigned int i;
 
 #ifdef CONFIG_ALTP2M
-    if ( hvm_altp2m_supported() )
+    if ( altp2m_supported() )
         for ( i = 0; i < d->nr_altp2m; i++ )
             p2m_teardown(d->altp2m_p2m[i], true, NULL);
 #endif
@@ -590,7 +590,7 @@ void hap_teardown(struct domain *d, bool *preempted)
 
 #ifdef CONFIG_ALTP2M
     /* Leave the root pt in case we get further attempts to modify the p2m. */
-    if ( hvm_altp2m_supported() )
+    if ( altp2m_supported() )
     {
         if ( altp2m_active(d) )
             for_each_vcpu ( d, v )
xen/arch/x86/mm/p2m-basic.c +2 -2
index e126fda26760..ce14066fedaf 100644
@@ -128,7 +128,7 @@ int p2m_init(struct domain *d)
         return rc;
     }
 
-    rc = hvm_altp2m_supported() ? p2m_init_altp2m(d) : 0;
+    rc = altp2m_supported() ? p2m_init_altp2m(d) : 0;
     if ( rc )
     {
         p2m_teardown_hostp2m(d);
@@ -197,7 +197,7 @@ void p2m_final_teardown(struct domain *d)
 {
     if ( is_hvm_domain(d) )
     {
-        if ( hvm_altp2m_supported() )
+        if ( altp2m_supported() )
             p2m_teardown_altp2m(d);
         /*
          * We must tear down nestedp2m unconditionally because
xen/arch/x86/mm/p2m-ept.c +1 -1
index ddb4c7606be1..84159198f3a0 100644
@@ -995,7 +995,7 @@ out:
     if ( is_epte_present(&old_entry) )
         ept_free_entry(p2m, &old_entry, target);
 
-    if ( hvm_altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) )
+    if ( altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) )
     {
         ret = p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
         if ( !rc )
Signature · 1 line
2.34.1
#5 lore raw

RFC PATCH v6 5/43 altp2m: Move altp2m_supported to arch header

In reply to Rose Spangler

Following from the previous commit, this commit makes altp2m_supported available through the asm/altp2m.h header.

This is commit 5/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/arch/x86/domain.c              |  1 +
 xen/arch/x86/include/asm/altp2m.h  | 11 +++++++++++
 xen/arch/x86/include/asm/hvm/hvm.h | 11 -----------
 xen/include/asm-generic/altp2m.h   |  7 +++++++
 4 files changed, 19 insertions(+), 11 deletions(-)
xen/arch/x86/domain.c +1 -0
index 512b18d4010f..e4f1cbf3b51e 100644
@@ -39,6 +39,7 @@
 #include <xen/softirq.h>
 #include <xen/wait.h>
 
+#include <asm/altp2m.h>
 #include <asm/amd.h>
 #include <asm/cpu-policy.h>
 #include <asm/cpuidle.h>
xen/arch/x86/include/asm/altp2m.h +11 -0
index ad5ded833a75..07e760f60659 100644
@@ -28,6 +28,12 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
         mfn_x(INVALID_MFN);
 }
 
+/* returns true if hardware supports alternate p2m's */
+static inline bool altp2m_supported(void)
+{
+    return hvm_funcs.caps.altp2m;
+}
+
 static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
 {
     return vcpu_altp2m(v).p2midx;
@@ -58,6 +64,11 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
     return false;
 }
 
+static inline bool altp2m_supported(void)
+{
+    return false;
+}
+
 /* Only declaration is needed. DCE will optimise it out when linking. */
 uint16_t altp2m_vcpu_idx(const struct vcpu *v);
 void altp2m_vcpu_initialise(struct vcpu *v);
xen/arch/x86/include/asm/hvm/hvm.h +0 -11
index 6406bb687718..e6d8042831dc 100644
@@ -701,12 +701,6 @@ static inline bool hvm_hap_supported(void)
     return hvm_funcs.caps.hap;
 }
 
-/* returns true if hardware supports alternate p2m's */
-static inline bool altp2m_supported(void)
-{
-    return IS_ENABLED(CONFIG_ALTP2M) && hvm_funcs.caps.altp2m;
-}
-
 /* Returns true if we have the minimum hardware requirements for nested virt */
 static inline bool hvm_nested_virt_supported(void)
 {
@@ -876,11 +870,6 @@ static inline bool hvm_hap_supported(void)
     return false;
 }
 
-static inline bool altp2m_supported(void)
-{
-    return false;
-}
-
 static inline bool hvm_nested_virt_supported(void)
 {
     return false;
xen/include/asm-generic/altp2m.h +7 -0
index ecee6942f4e8..a3cdbdae9953 100644
@@ -6,6 +6,13 @@
 
 struct vcpu;
 
+/* returns true if hardware supports alternate p2m's */
+static inline bool altp2m_supported(void)
+{
+    /* Not implemented on GENERIC. */
+    return false;
+}
+
 /* Alternate p2m VCPU */
 static inline unsigned int altp2m_vcpu_idx(const struct vcpu *v)
 {
Signature · 1 line
2.34.1
#6 lore raw

RFC PATCH v6 6/43 arm/altp2m: Add template arch-specific altp2m.c/altp2m.h

In reply to Rose Spangler

Similarly to the earlier common altp2m.c/altp2m.h commit, this commit adds a template altp2m.c and altp2m.h file for ARM to be added to in later commits. Creating a commit with just the template file additions makes it easier to reorder later commits which add to these files.

This commit can be squashed into the first commit which actually adds something to altp2m.c/altp2m.h for the actual submission if that would be preferred.

This is commit 6/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/arch/arm/Makefile             |  1 +
 xen/arch/arm/altp2m.c             | 16 +++++++++++++
 xen/arch/arm/include/asm/Makefile |  1 -
 xen/arch/arm/include/asm/altp2m.h | 37 +++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/altp2m.c
 create mode 100644 xen/arch/arm/include/asm/altp2m.h
xen/arch/arm/Makefile +1 -0
index 69200b27280d..d995d4ff7aa1 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_TEE) += tee/
 obj-$(CONFIG_HAS_VPCI) += vpci.o
 
 obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
+obj-$(CONFIG_ALTP2M) += altp2m.o
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
xen/arch/arm/altp2m.c new file +16 -0
new file mode 100644
index 000000000000..2bd1ff4df223
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * altp2m.c: Alternate p2m
+ *
+ * Copyright (c) 2016 Sergej Proskurin <[email protected]>
+ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/include/asm/Makefile +0 -1
index 4565baca6a4d..fef4dd42b6cb 100644
@@ -1,5 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-generic-y += altp2m.h
 generic-y += device.h
 generic-y += hardirq.h
 generic-y += iocap.h
xen/arch/arm/include/asm/altp2m.h new file +37 -0
new file mode 100644
index 000000000000..ca836bae7330
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * altp2m.h: Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2016, Sergej Proskurin <[email protected]>.
+ */
+
+#ifndef __ASM_ARM_ALTP2M_H
+#define __ASM_ARM_ALTP2M_H
+
+#include <xen/sched.h>
+
+static inline bool altp2m_supported(void)
+{
+    /* Not implemented yet */
+    return false;
+}
+
+/* Alternate p2m VCPU */
+static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
+{
+    /* Not implemented yet */
+    BUG();
+    return 0;
+}
+
+#endif /* __ASM_ARM_ALTP2M_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.34.1
#7 lore raw

RFC PATCH v6 7/43 arm/altp2m: Introduce CONFIG_ALTP2M Kconfig option

In reply to Rose Spangler

Following the x86 implementation in commit e96831ece819, this commit adds the CONFIG_ALTP2M Kconfig option for ARM. This makes it possible to build Xen without building altp2m code.

This commit also implements a stub for p2m_altp2m_check, as some implementation is needed when CONFIG_ALTP2M is enabled. This is due to a call to p2m_altp2m_check in vm_event.c which is gated by CONFIG_ALTP2M.

This is commit 7/8 of the preparation phase.

---
v6: Introduced this patch.

---
 xen/arch/arm/Kconfig              | 11 +++++++++++
 xen/arch/arm/altp2m.c             |  9 +++++++++
 xen/arch/arm/include/asm/altp2m.h | 18 ++++++++++++++++--
 3 files changed, 36 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +11 -0
index 2f2b501fdac4..fdf0721c3c03 100644
@@ -98,6 +98,17 @@ config MPU
 	  systems supporting EL2. (UNSUPPORTED)
 endchoice
 
+config ALTP2M
+	bool "Alternate P2M support" if EXPERT
+	depends on MMU
+	default y
+	help
+	  Alternate-p2m allows a guest to manage multiple p2m guest physical
+	  "memory views" (as opposed to a single p2m).
+	  Useful for memory introspection.
+
+	  If unsure, stay with defaults.
+
 source "arch/Kconfig"
 
 config ACPI
xen/arch/arm/altp2m.c +9 -0
index 2bd1ff4df223..8bd174ea8f37 100644
@@ -5,6 +5,15 @@
  * Copyright (c) 2016 Sergej Proskurin <[email protected]>
  */
 
+#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)
+{
+    /* Not yet implemented */
+    BUG();
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/include/asm/altp2m.h +16 -2
index ca836bae7330..698c35427e75 100644
@@ -11,10 +11,12 @@
 
 #include <xen/sched.h>
 
+#ifdef CONFIG_ALTP2M
+
+/* Hardware always supports altp2m on ARM */
 static inline bool altp2m_supported(void)
 {
-    /* Not implemented yet */
-    return false;
+    return true;
 }
 
 /* Alternate p2m VCPU */
@@ -25,6 +27,18 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
     return 0;
 }
 
+#else /* CONFIG_ALTP2M */
+
+static inline bool altp2m_supported(void)
+{
+    return false;
+}
+
+/* Only declaration is needed. DCE will optimise it out when linking. */
+uint16_t altp2m_vcpu_idx(const struct vcpu *v);
+
+#endif /* CONFIG_ALTP2M */
+
 #endif /* __ASM_ARM_ALTP2M_H */
 
 /*
Signature · 1 line
2.34.1