[RFC PATCH v6 42/43] arm/altp2m: Add support for altp2m_flush

Rose Spangler posted 43 patches 3 months, 3 weeks ago
[RFC PATCH v6 42/43] arm/altp2m: Add support for altp2m_flush
Posted by Rose Spangler 3 months, 3 weeks ago
This commit makes the altp2m_flush compatible with ARM by replacing the
x86-specific set view visibility code with the architecture independent
altp2m_set_view_visibility locked.

This is commit 2/2 of the altp2m_flush phase.

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

    There is a small amount of additional overhead introduced on x86 by
    replacing these direct array sets with calls to
    altp2m_set_view_visibility_locked. That function also calls
    altp2m_is_eptp_valid, which performs additional checks, and also bounds
    the array sets with array_index_nospec, which isn't technically
    necessary here since we can be certain that the array set will be less
    than nr_altp2m. This could be resolved by introducing another
    altp2m_set_view_visibility variant (ex.
    altp2m_set_view_visibility_unchecked?) which would replace usages of
    altp2m_set_view_visibility_locked, but I'm not sure if the overhead is
    enough to matter here.
---
 xen/common/altp2m.c      | 5 +----
 xen/include/xen/altp2m.h | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/xen/common/altp2m.c b/xen/common/altp2m.c
index 0dd3ecf226fd..d980ebed08ab 100644
--- a/xen/common/altp2m.c
+++ b/xen/common/altp2m.c
@@ -123,7 +123,6 @@ int altp2m_init_by_id(struct domain *d, unsigned int idx)
     return rc;
 }
 
-#ifdef CONFIG_X86
 void altp2m_flush(struct domain *d)
 {
     unsigned int i;
@@ -133,13 +132,11 @@ void altp2m_flush(struct domain *d)
     for ( i = 0; i < d->nr_altp2m; i++ )
     {
         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);
+        altp2m_set_view_visibility_locked(d, i, 0);
     }
 
     altp2m_unlock(d);
 }
-#endif
 
 /*
  * altp2m operations are envisioned as being used in several different
diff --git a/xen/include/xen/altp2m.h b/xen/include/xen/altp2m.h
index fa2c11f5432e..5222c24ef418 100644
--- a/xen/include/xen/altp2m.h
+++ b/xen/include/xen/altp2m.h
@@ -74,10 +74,8 @@ int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg);
 /* Make a specific alternate p2m valid */
 int altp2m_init_by_id(struct domain *d, unsigned int idx);
 
-#ifdef CONFIG_X86
 /* Flush all the alternate p2m's for a domain */
 void altp2m_flush(struct domain *d);
-#endif
 
 #else /* CONFIG_ALTP2M */
 
-- 
2.34.1
Re: [RFC PATCH v6 42/43] arm/altp2m: Add support for altp2m_flush
Posted by Spangler, Rose 3 months, 3 weeks ago
>         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);
>+        altp2m_set_view_visibility_locked(d, i, 0);

While implementing altp2m_destroy_view_by_id, I realized that I set the
visibility of the views here instead of actually making them invalid. I've fixed
this in my working branch by adding a new arch-specific function,
altp2m_deactivate_altp2m, which both calls altp2m_reset_altp2m and sets the
views as invalid by setting the eptp/visible_eptp values to INVALID_MFN on x86,
and sets the altp2m_state value to ALTP2M_INVALID on ARM.

A side effect of this is that altp2m_reset_altp2m doesn't actually need to be
callable from common code anymore, so the concern I raised previously about
ARM's altp2m_reset_altp2m implementation needing a useless altp2m_reset_type
parameter is no longer an issue. altp2m_reset_altp2m is used in
altp2m_propagate_change however, so this issue might pop back up later.