[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] xen/x86: factor out map and unmap from the memory_mapping DOMCTL
commit 276a9b6ea17644ebe6bf111ed365d8c3b765f10a Author: Arianna Avanzini <avanzini.arianna@xxxxxxxxx> AuthorDate: Sat Aug 30 18:29:41 2014 +0200 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Wed Sep 3 12:49:37 2014 +0100 xen/x86: factor out map and unmap from the memory_mapping DOMCTL This commit factors out from the XEN_DOMCTL_memory_mapping hypercall implementation, currently available only for x86, the operations related to memory ranges map and unmap. The code is factored out into two {map|unmap}_mmio_regions() functions for x86, that will match the corresponding pair of ARM functions when the DOMCTL will be moved to common code in the following commit. This commit also adds an unmap_mmio_regions() function for ARM so that the following transition to common code is cleaner. Signed-off-by: Arianna Avanzini <avanzini.arianna@xxxxxxxxx> Acked-by: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx> Acked-by: Jan Beulich <JBeulich@xxxxxxxx> Acked-by: Julien Grall <julien.grall@xxxxxxxxxx> Cc: Dario Faggioli <dario.faggioli@xxxxxxxxxx> Cc: Paolo Valente <paolo.valente@xxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Keir Fraser <keir@xxxxxxx> Cc: Tim Deegan <tim@xxxxxxx> Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Cc: Eric Trudeau <etrudeau@xxxxxxxxxxxx> Cc: Viktor Kleinik <viktor.kleinik@xxxxxxxxxxxxxxx> Cc: Andrii Tseglytskyi <andrii.tseglytskyi@xxxxxxxxxxxxxxx> --- xen/arch/arm/p2m.c | 12 ++++++++++++ xen/arch/x86/domctl.c | 19 +++++-------------- xen/arch/x86/mm/p2m.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/p2m.h | 4 ++++ xen/include/asm-x86/p2m.h | 12 ++++++++++++ 5 files changed, 78 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 05d83b1..c016450 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -893,6 +893,18 @@ int map_mmio_regions(struct domain *d, MATTR_DEV, p2m_mmio_direct); } +int unmap_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr_mfns, + unsigned long mfn) +{ + return apply_p2m_changes(d, REMOVE, + pfn_to_paddr(start_gfn), + pfn_to_paddr(start_gfn + nr_mfns), + pfn_to_paddr(mfn), + MATTR_DEV, p2m_invalid); +} + int guest_physmap_add_entry(struct domain *d, unsigned long gpfn, unsigned long mfn, diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 9cdbc3d..caa3be6 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -670,17 +670,14 @@ long arch_do_domctl( d->domain_id, gfn, mfn, nr_mfns); ret = iomem_permit_access(d, mfn, mfn_end); - if ( !ret && paging_mode_translate(d) ) + if ( !ret ) { - for ( i = 0; !ret && i < nr_mfns; i++ ) - ret = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i)); + ret = map_mmio_regions(d, gfn, nr_mfns, mfn); if ( ret ) { printk(XENLOG_G_WARNING - "memory_map:fail: dom%d gfn=%lx mfn=%lx ret:%ld\n", - d->domain_id, gfn + i, mfn + i, ret); - while ( i-- ) - clear_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i)); + "memory_map:fail: dom%d gfn=%lx mfn=%lx nr=%lx ret:%ld\n", + d->domain_id, gfn, mfn, nr_mfns, ret); if ( iomem_deny_access(d, mfn, mfn_end) && is_hardware_domain(current->domain) ) printk(XENLOG_ERR @@ -697,13 +694,7 @@ long arch_do_domctl( "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n", d->domain_id, gfn, mfn, nr_mfns); - if ( paging_mode_translate(d) ) - for ( i = 0; i < nr_mfns; i++ ) - { - ret = clear_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i)); - if ( ret ) - rc = ret; - } + rc = unmap_mmio_regions(d, gfn, nr_mfns, mfn); ret = iomem_deny_access(d, mfn, mfn_end); if ( !ret ) ret = rc; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 2586a3c..32776c3 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1725,6 +1725,51 @@ unsigned long paging_gva_to_gfn(struct vcpu *v, return hostmode->gva_to_gfn(v, hostp2m, va, pfec); } +int map_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn) +{ + int ret = 0; + unsigned long i; + + if ( !paging_mode_translate(d) ) + return 0; + + for ( i = 0; !ret && i < nr; i++ ) + { + ret = set_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i)); + if ( ret ) + { + unmap_mmio_regions(d, start_gfn, i, mfn); + break; + } + } + + return ret; +} + +int unmap_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn) +{ + int err = 0; + unsigned long i; + + if ( !paging_mode_translate(d) ) + return 0; + + for ( i = 0; i < nr; i++ ) + { + int ret = clear_mmio_p2m_entry(d, start_gfn + i, _mfn(mfn + i)); + if ( ret ) + err = ret; + } + + return err; +} + /*** Audit ***/ #if P2M_AUDIT diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 13fea36..648144f 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -108,6 +108,10 @@ int map_mmio_regions(struct domain *d, unsigned long start_gfn, unsigned long nr_mfns, unsigned long mfn); +int unmap_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr_mfns, + unsigned long mfn); int guest_physmap_add_entry(struct domain *d, unsigned long gfn, diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index d19f50c..2a128ed 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -32,6 +32,18 @@ #include <asm/mem_sharing.h> #include <asm/page.h> /* for pagetable_t */ +/* Map MMIO regions in the p2m: start_gfn and nr describe the range in + * the guest physical address space to map, starting from the machine + * frame number mfn. */ +int map_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn); +int unmap_mmio_regions(struct domain *d, + unsigned long start_gfn, + unsigned long nr, + unsigned long mfn); + extern bool_t opt_hap_1gb, opt_hap_2mb; /* -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |