[RFC PATCH v6 36/43] arm/altp2m: Add support for altp2m_activate_altp2m

Rose Spangler posted 43 patches 3 months, 3 weeks ago
[RFC PATCH v6 36/43] arm/altp2m: Add support for altp2m_activate_altp2m
Posted by Rose Spangler 3 months, 3 weeks ago
This commit adds the altp2m_activate_altp2m function on ARM. This makes it
possible to activate altp2m views in common altp2m routines (namely,
altp2m_init_by_id).

This is commit 2/2 of the altp2m_activate_altp2m phase.

Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
---
v6: Introduced this patch.

    While the ARM version of this function is very similar to the x86
    version of this function, I still think it makes sense to have this
    implemented on both architectures instead of using a common
    implementation. A significant portion of the function would need to be
    #ifdef CONFIG_X86/#else CONFIG_ARM gated (like p2m->min_mapped_gfn vs.
    p2m->lowest_mapped_gfn on ARM, for example). This would become even
    more of an issue if other architectures implement altp2m in the future,
    so I think it's best to keep these architecture specific.
---
 xen/arch/arm/altp2m.c             | 26 +++++++++++++++++++++++++-
 xen/arch/arm/include/asm/altp2m.h |  4 ++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c
index aa48c17e11a3..aa56b3ca79b5 100644
--- a/xen/arch/arm/altp2m.c
+++ b/xen/arch/arm/altp2m.c
@@ -37,6 +37,31 @@ bool altp2m_view_is_visible(struct domain *d, unsigned int idx)
     return d->arch.altp2m_state[array_index_nospec(idx, d->nr_altp2m)] == ALTP2M_VISIBLE;
 }
 
+int altp2m_activate_altp2m(struct domain *d, unsigned int idx,
+                           p2m_access_t hvmmem_default_access)
+{
+    struct p2m_domain *hostp2m, *p2m;
+
+    ASSERT(idx < d->nr_altp2m);
+
+    p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+    hostp2m = p2m_get_hostp2m(d);
+
+    p2m_write_lock(p2m);
+
+    p2m->default_access = hvmmem_default_access;
+    p2m->domain = hostp2m->domain;
+
+    p2m->lowest_mapped_gfn = INVALID_GFN;
+    p2m->max_mapped_gfn = _gfn(0);
+
+    d->arch.altp2m_state[idx] = ALTP2M_VISIBLE;
+
+    p2m_write_unlock(p2m);
+
+    return 0;
+}
+
 int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
                                uint8_t visible)
 {
@@ -66,7 +91,6 @@ int altp2m_set_view_visibility_locked(struct domain *d, unsigned int altp2m_idx,
     return rc;
 }
 
-
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/arm/include/asm/altp2m.h b/xen/arch/arm/include/asm/altp2m.h
index f8d0dd799a4a..192240f48c33 100644
--- a/xen/arch/arm/include/asm/altp2m.h
+++ b/xen/arch/arm/include/asm/altp2m.h
@@ -48,6 +48,10 @@ int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
 int altp2m_set_view_visibility_locked(struct domain *d, unsigned int altp2m_idx,
                                       uint8_t visible);
 
+/* Activate an altp2m view */
+int altp2m_activate_altp2m(struct domain *d, unsigned int idx,
+                           p2m_access_t hvmmem_default_access);
+
 #else /* CONFIG_ALTP2M */
 
 static inline bool altp2m_supported(void)
-- 
2.34.1