x86/altp2m: Add altp2m_set_view_visibility_locked
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
@@ -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
@@ -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
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
@@ -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
@@ -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