|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH V8 4/7] x86/p2m: refactor p2m_reset_altp2m()
Refactor p2m_reset_altp2m() so that it can be used to remove
redundant codepaths, fixing the locking while we're at it.
Signed-off-by: Razvan Cojocaru <rcojocaru@xxxxxxxxxxxxxxx>
---
CC: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
---
xen/arch/x86/mm/p2m.c | 57 ++++++++++++++++++++++++++++++---------------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 955c3c7..9773495 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2282,6 +2282,36 @@ bool_t p2m_altp2m_lazy_copy(struct vcpu *v, paddr_t gpa,
return 1;
}
+enum altp2m_reset_type {
+ ALTP2M_RESET,
+ ALTP2M_DEACTIVATE
+};
+
+static void p2m_reset_altp2m(struct domain *d, unsigned int idx,
+ enum altp2m_reset_type reset_type)
+{
+ struct p2m_domain *p2m;
+
+ ASSERT(idx < MAX_ALTP2M);
+ p2m = d->arch.altp2m_p2m[idx];
+
+ p2m_lock(p2m);
+
+ p2m_flush_table_locked(p2m);
+
+ if ( reset_type == ALTP2M_DEACTIVATE )
+ p2m_free_logdirty(p2m);
+
+ /* Uninit and reinit ept to force TLB shootdown */
+ ept_p2m_uninit(p2m);
+ ept_p2m_init(p2m);
+
+ p2m->min_remapped_gfn = gfn_x(INVALID_GFN);
+ p2m->max_remapped_gfn = 0;
+
+ p2m_unlock(p2m);
+}
+
void p2m_flush_altp2m(struct domain *d)
{
unsigned int i;
@@ -2290,10 +2320,7 @@ void p2m_flush_altp2m(struct domain *d)
for ( i = 0; i < MAX_ALTP2M; i++ )
{
- p2m_flush_table(d->arch.altp2m_p2m[i]);
- /* Uninit and reinit ept to force TLB shootdown */
- ept_p2m_uninit(d->arch.altp2m_p2m[i]);
- ept_p2m_init(d->arch.altp2m_p2m[i]);
+ p2m_reset_altp2m(d, i, ALTP2M_DEACTIVATE);
d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN);
}
@@ -2392,10 +2419,7 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned
int idx)
if ( !_atomic_read(p2m->active_vcpus) )
{
- p2m_flush_table(d->arch.altp2m_p2m[idx]);
- /* Uninit and reinit ept to force TLB shootdown */
- ept_p2m_uninit(d->arch.altp2m_p2m[idx]);
- ept_p2m_init(d->arch.altp2m_p2m[idx]);
+ p2m_reset_altp2m(d, idx, ALTP2M_DEACTIVATE);
d->arch.altp2m_eptp[idx] = mfn_x(INVALID_MFN);
rc = 0;
}
@@ -2520,16 +2544,6 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int
idx,
return rc;
}
-static void p2m_reset_altp2m(struct p2m_domain *p2m)
-{
- p2m_flush_table(p2m);
- /* Uninit and reinit ept to force TLB shootdown */
- ept_p2m_uninit(p2m);
- ept_p2m_init(p2m);
- p2m->min_remapped_gfn = gfn_x(INVALID_GFN);
- p2m->max_remapped_gfn = 0;
-}
-
int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
mfn_t mfn, unsigned int page_order,
p2m_type_t p2mt, p2m_access_t p2ma)
@@ -2563,7 +2577,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t
gfn,
{
if ( !reset_count++ )
{
- p2m_reset_altp2m(p2m);
+ p2m_reset_altp2m(d, i, ALTP2M_RESET);
last_reset_idx = i;
}
else
@@ -2577,10 +2591,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t
gfn,
d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
continue;
- p2m = d->arch.altp2m_p2m[i];
- p2m_lock(p2m);
- p2m_reset_altp2m(p2m);
- p2m_unlock(p2m);
+ p2m_reset_altp2m(d, i, ALTP2M_RESET);
}
ret = 0;
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |