Skip to contentSkip to conversation

x86/altp2m: Add altp2m_set_view_visibility_locked

RFC PATCH New [email protected] 1 participant 2 messages Apr 20

lore
Share & tools
lore
#0 lore raw

RFC PATCH v6 32/43 x86/altp2m: Add altp2m_set_view_visibility_locked

From: Rose Spangler <[email protected]>

This commit splits the altp2m_set_view_visibility into two functions, where the altp2m_set_view_visibility_locked variant has the preconditions that the altp2m lock is held. This makes it possible to change a view's visibility in an architecture independent way in code that already holds the altp2m lock (namely, altp2m_flush).

This is commit 3/5 of the altp2m view validity/visibility phase.

---
v6: Introduced this patch.

---
 xen/arch/x86/include/asm/altp2m.h |  4 ++++
 xen/arch/x86/mm/altp2m.c          | 14 +++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/altp2m.h +4 -0
index 56ae19b24b42..99c4cfa5a68b 100644
@@ -106,6 +106,10 @@ int altp2m_change_gfn(struct domain *d, unsigned int idx, gfn_t old_gfn,
 int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
                                uint8_t visible);
 
+/* Set a specific p2m view visibility (with lock already held) */
+int altp2m_set_view_visibility_locked(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.
xen/arch/x86/mm/altp2m.c +11 -3
index 0542e3ef9196..8672b8c061d3 100644
@@ -685,9 +685,19 @@ int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve,
 int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
                                uint8_t visible)
 {
-    int rc = 0;
+    int rc;
 
     altp2m_lock(d);
+    rc = altp2m_set_view_visibility_locked(d, altp2m_idx, visible);
+    altp2m_unlock(d);
+
+    return rc;
+}
+
+int altp2m_set_view_visibility_locked(struct domain *d, unsigned int altp2m_idx,
+                                      uint8_t visible)
+{
+    int rc = 0;
 
     if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
         rc = -EINVAL;
@@ -698,8 +708,6 @@ int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
         d->arch.altp2m_visible_eptp[array_index_nospec(altp2m_idx, MAX_EPTP)] =
             mfn_x(INVALID_MFN);
 
-    altp2m_unlock(d);
-
     return rc;
 }
 
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH v6 33/43 arm/altp2m: Add altp2m_set_view_visibility{,_locked} support

From: Rose Spangler <[email protected]>

This commit adds the altp2m_set_view_visibility and altp2m_set_view_visibility_locked functions on ARM. This makes it possible to set the altp2m view visibility in common altp2m routines (namely, altp2m_flush).

This is commit 4/5 of the altp2m view validity/visibility phase.

---
v6: Introduced this patch.

---
 xen/arch/arm/altp2m.c             | 30 ++++++++++++++++++++++++++++++
 xen/arch/arm/include/asm/altp2m.h |  8 ++++++++
 2 files changed, 38 insertions(+)
xen/arch/arm/altp2m.c +30 -0
index 0e19e197e826..aa48c17e11a3 100644
@@ -37,6 +37,36 @@ 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_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
+                               uint8_t visible)
+{
+    int rc;
+
+    altp2m_lock(d);
+    rc = altp2m_set_view_visibility_locked(d, altp2m_idx, visible);
+    altp2m_unlock(d);
+
+    return rc;
+}
+
+int altp2m_set_view_visibility_locked(struct domain *d, unsigned int altp2m_idx,
+                                      uint8_t visible)
+{
+    int rc = 0;
+
+    if ( altp2m_idx >= d->nr_altp2m || !altp2m_view_is_valid(d, altp2m_idx) )
+        rc = -EINVAL;
+    else if ( visible )
+        d->arch.altp2m_state[array_index_nospec(altp2m_idx, d->nr_altp2m)] =
+            ALTP2M_VISIBLE;
+    else
+        d->arch.altp2m_state[array_index_nospec(altp2m_idx, d->nr_altp2m)] =
+            ALTP2M_INVISIBLE;
+
+    return rc;
+}
+
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/include/asm/altp2m.h +8 -0
index fbe66ad5536d..f8d0dd799a4a 100644
@@ -40,6 +40,14 @@ enum altp2m_view_state {
     ALTP2M_INVISIBLE,
 };
 
+/* Set a specific p2m view visibility */
+int altp2m_set_view_visibility(struct domain *d, unsigned int altp2m_idx,
+                               uint8_t visible);
+
+/* Set a specific p2m view visibility (with lock already held) */
+int altp2m_set_view_visibility_locked(struct domain *d, unsigned int altp2m_idx,
+                                      uint8_t visible);
+
 #else /* CONFIG_ALTP2M */
 
 static inline bool altp2m_supported(void)
Signature · 1 line
2.34.1