|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC PATCH v6 13/43] x86/altp2m: Add lock functions accessible from common code
From: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
This commit adds three altp2m_lock functions which wrap the corresponding
altp2m_list_lock functions present in "mm-locks.h". The "mm-locks.h" file
is only accessible in x86 code. In order to make altp2m common across
architectures, it must be possible to acquire the altp2m lock without
including an x86-specific header file.
These functions cannot be static inline like their "mm-locks.h"
counterparts, since "mm-locks.h" is only included in source files, not
header files. Therefore, these functions might introduce a slight function
call overhead over their "mm-locks.h" counterparts. However, the altp2m
lock is mostly used in init/teardown routines and HVMOP implementations.
For these cases, the altp2m_list_lock functions have been switched out for
the altp2m_lock functions so they can be later migrated to common code. The
only other function using the altp2m lock is altp2m_get_or_propagate, which
is in the hot path of the page fault handler, so the altp2m_list_lock calls
have not been replaced for that function.
This is commit 2/12 of the altp2m_init/altp2m_teardown routines phase.
Signed-off-by: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
---
v6: Introduced this patch.
This seems like the solution which makes the most sense here, but it
would be nicer if it could be static inline. I'm also not sure if the
"mm-locks.h" functions are really supposed to be exposed outside of
their translation unit like this, so feedback on this is appreciated.
---
xen/arch/x86/include/asm/altp2m.h | 4 +++
xen/arch/x86/mm/altp2m.c | 42 ++++++++++++++++++++-----------
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/xen/arch/x86/include/asm/altp2m.h
b/xen/arch/x86/include/asm/altp2m.h
index 9c58a396448d..7cff40beb7c6 100644
--- a/xen/arch/x86/include/asm/altp2m.h
+++ b/xen/arch/x86/include/asm/altp2m.h
@@ -156,6 +156,10 @@ int p2m_set_suppress_ve_multi(struct domain *d,
int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve,
unsigned int altp2m_idx);
+void altp2m_lock_init(struct domain *d);
+void altp2m_lock(struct domain *d);
+void altp2m_unlock(struct domain *d);
+
#else
static inline bool altp2m_is_eptp_valid(const struct domain *d,
diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c
index 2dc84b76b8c1..371bf3f0b8d4 100644
--- a/xen/arch/x86/mm/altp2m.c
+++ b/xen/arch/x86/mm/altp2m.c
@@ -129,7 +129,7 @@ int altp2m_init(struct domain *d)
struct p2m_domain *p2m;
struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
- mm_lock_init(&d->arch.altp2m_list_lock);
+ altp2m_lock_init(d);
d->altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
if ( !d->altp2m_p2m )
@@ -221,7 +221,7 @@ bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int
idx)
if ( idx >= d->nr_altp2m )
return rc;
- altp2m_list_lock(d);
+ altp2m_lock(d);
if ( d->arch.altp2m_eptp[idx] != mfn_x(INVALID_MFN) )
{
@@ -230,7 +230,7 @@ bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int
idx)
rc = 1;
}
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
return rc;
}
@@ -348,7 +348,7 @@ void altp2m_flush(struct domain *d)
{
unsigned int i;
- altp2m_list_lock(d);
+ altp2m_lock(d);
for ( i = 0; i < d->nr_altp2m; i++ )
{
@@ -357,7 +357,7 @@ void altp2m_flush(struct domain *d)
d->arch.altp2m_visible_eptp[i] = mfn_x(INVALID_MFN);
}
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
}
static int altp2m_activate_altp2m(struct domain *d, unsigned int idx,
@@ -409,13 +409,13 @@ int altp2m_init_by_id(struct domain *d, unsigned int idx)
if ( idx >= d->nr_altp2m )
return rc;
- altp2m_list_lock(d);
+ altp2m_lock(d);
if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] ==
mfn_x(INVALID_MFN) )
rc = altp2m_activate_altp2m(d, idx, hostp2m->default_access);
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
return rc;
}
@@ -431,7 +431,7 @@ int altp2m_init_next_available(struct domain *d, uint16_t
*idx,
!xenmem_access_to_p2m_access(hostp2m, hvmmem_default_access, &a) )
return rc;
- altp2m_list_lock(d);
+ altp2m_lock(d);
for ( i = 0; i < d->nr_altp2m; i++ )
{
@@ -446,7 +446,7 @@ int altp2m_init_next_available(struct domain *d, uint16_t
*idx,
break;
}
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
return rc;
}
@@ -463,7 +463,7 @@ int altp2m_destroy_by_id(struct domain *d, unsigned int idx)
return rc;
rc = -EBUSY;
- altp2m_list_lock(d);
+ altp2m_lock(d);
if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] !=
mfn_x(INVALID_MFN) )
@@ -481,7 +481,7 @@ int altp2m_destroy_by_id(struct domain *d, unsigned int idx)
}
}
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
domain_unpause_except_self(d);
@@ -501,7 +501,7 @@ int altp2m_switch_domain_altp2m_by_id(struct domain *d,
unsigned int idx)
return rc;
rc = -EINVAL;
- altp2m_list_lock(d);
+ altp2m_lock(d);
if ( d->arch.altp2m_visible_eptp[idx] != mfn_x(INVALID_MFN) )
{
@@ -512,7 +512,7 @@ int altp2m_switch_domain_altp2m_by_id(struct domain *d,
unsigned int idx)
rc = 0;
}
- altp2m_list_unlock(d);
+ altp2m_unlock(d);
domain_unpause_except_self(d);
@@ -773,7 +773,7 @@ int altp2m_set_view_visibility(struct domain *d, unsigned
int altp2m_idx,
{
int rc = 0;
- altp2m_list_lock(d);
+ altp2m_lock(d);
if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
rc = -EINVAL;
@@ -784,11 +784,23 @@ 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_list_unlock(d);
+ altp2m_unlock(d);
return rc;
}
+void altp2m_lock_init(struct domain *d) {
+ mm_lock_init(&d->arch.altp2m_list_lock);
+}
+
+void altp2m_lock(struct domain *d) {
+ altp2m_list_lock(d);
+}
+
+void altp2m_unlock(struct domain *d) {
+ altp2m_list_unlock(d);
+}
+
/*
* Local variables:
* mode: C
--
2.34.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |