diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 14b5939..4530689 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -652,17 +653,38 @@ static int resolve_misconfig(struct p2m_domain *p2m, unsigned long gfn) bool_t ept_handle_misconfig(uint64_t gpa) { struct vcpu *curr = current; - struct p2m_domain *p2m = p2m_get_hostp2m(curr->domain); + struct domain *d = curr->domain; + struct p2m_domain *p2m = p2m_get_hostp2m(d); bool_t spurious; - int rc; - - p2m_lock(p2m); + int rc = 0; + unsigned int i; spurious = curr->arch.hvm_vmx.ept_spurious_misconfig; - rc = resolve_misconfig(p2m, PFN_DOWN(gpa)); - curr->arch.hvm_vmx.ept_spurious_misconfig = 0; - p2m_unlock(p2m); + if ( altp2m_active(d) ) + { + for ( i = 0; i < MAX_ALTP2M; i++ ) + if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) ) + { + p2m = d->arch.altp2m_p2m[i]; + + p2m_lock(p2m); + + rc = resolve_misconfig(p2m, PFN_DOWN(gpa)); + curr->arch.hvm_vmx.ept_spurious_misconfig = 0; + + p2m_unlock(p2m); + } + } + else + { + p2m_lock(p2m); + + rc = resolve_misconfig(p2m, PFN_DOWN(gpa)); + curr->arch.hvm_vmx.ept_spurious_misconfig = 0; + + p2m_unlock(p2m); + } return spurious ? (rc >= 0) : (rc > 0); } @@ -1375,8 +1397,15 @@ void setup_ept_dump(void) void p2m_init_altp2m_ept(struct domain *d, unsigned int i) { struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + struct p2m_domain *hostp2m = p2m_get_hostp2m(d); struct ept_data *ept; + p2m->max_mapped_pfn = hostp2m->max_mapped_pfn; + p2m->default_access = hostp2m->default_access; + p2m->domain = hostp2m->domain; + p2m->logdirty_ranges = hostp2m->logdirty_ranges; + p2m->global_logdirty = hostp2m->global_logdirty; + p2m->min_remapped_gfn = gfn_x(INVALID_GFN); p2m->max_remapped_gfn = 0; ept = &p2m->ept; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index c53cab4..00f85e1 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -248,7 +249,6 @@ int p2m_init(struct domain *d) int p2m_is_logdirty_range(struct p2m_domain *p2m, unsigned long start, unsigned long end) { - ASSERT(p2m_is_hostp2m(p2m)); if ( p2m->global_logdirty || rangeset_contains_range(p2m->logdirty_ranges, start, end) ) return 1; @@ -964,12 +964,12 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn_l, } /* Modify the p2m type of a range of gfns from ot to nt. */ -void p2m_change_type_range(struct domain *d, - unsigned long start, unsigned long end, - p2m_type_t ot, p2m_type_t nt) +static void _p2m_change_type_range(struct p2m_domain *p2m, + unsigned long start, unsigned long end, + p2m_type_t ot, p2m_type_t nt) { + struct domain *d = p2m->domain; unsigned long gfn = start; - struct p2m_domain *p2m = p2m_get_hostp2m(d); int rc = 0; ASSERT(ot != nt); @@ -1022,6 +1022,23 @@ void p2m_change_type_range(struct domain *d, p2m_unlock(p2m); } +void p2m_change_type_range(struct domain *d, + unsigned long start, unsigned long end, + p2m_type_t ot, p2m_type_t nt) +{ + unsigned int i; + + if ( !altp2m_active(d) ) + { + _p2m_change_type_range(p2m_get_hostp2m(d), start, end, ot, nt); + return; + } + + for ( i = 0; i < MAX_ALTP2M; i++ ) + if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) ) + _p2m_change_type_range(d->arch.altp2m_p2m[i], start, end, ot, nt); +} + /* * Finish p2m type change for gfns which are marked as need_recalc in a range. * Returns: 0/1 for success, negative for failure