x86/p2m: use large pages for MMIO mappings
PATCH v6 1/1 x86/p2m: use large pages for MMIO mappings
When mapping large BARs (e.g. the frame buffer of a graphics card) the overhead of establishing such mappings using only 4k pages has, particularly after the XSA-125 fix, become unacceptable. Alter the XEN_DOMCTL_memory_mapping semantics once again, so that there's no longer a fixed amount of guest frames that represents the upper limit of what a single invocation can map. Instead bound execution time by limiting the number of iterations (regardless of page size).
---
Open issues (perhaps for subsequent changes):
- ARM side unimplemented (and hence libxc for now made cope with both models), the main issue (besides my inability to test any change there) being the many internal uses of map_mmio_regions())
- iommu_{,un}map_page() interfaces don't support "order" (hence mmio_order() for now returns zero when !iommu_hap_pt_share, which in particular means the AMD side isn't being taken care of just yet, but note that this also has the intended effect of suppressing non-zero order mappings in the shadow mode case)
---
v6: Move an mfn_valid() assertion to cover the full MFN range. Use
PAGE_ORDER_4K in mmio_order(). Improve the return value description of set_typed_p2m_entry().
v5: Refine comment in domctl.h.
v4: Move cleanup duty entirely to the caller of the hypercall. Move
return value description to from commit message to domctl.h.
v3: Re-base on top of "x86/hvm: fold opt_hap_{2mb,1gb} into
hap_capabilities". Extend description to spell out new return value meaning. Add a couple of code comments. Use PAGE_ORDER_4K instead of literal 0. Take into consideration r/o MMIO pages.
v2: Produce valid entries for large p2m_mmio_direct mappings in
p2m_pt_set_entry(). Don't open code iommu_use_hap_pt() in mmio_order(). Update function comment of set_typed_p2m_entry() and clear_mmio_p2m_entry(). Use PRI_mfn. Add ASSERT()s to {,un}map_mmio_regions() to detect otherwise endless loops.
tools/libxc/xc_domain.c +10 -5
@@ -2229,7 +2229,7 @@ int xc_domain_memory_mapping( {DECLARE_DOMCTL ;xc_dominfo_t info; -int ret =0 , err; +int ret =0 , rc;unsigned long done =0 , nr, max_batch_sz; if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
@@ -2254,19 +2254,24 @@ int xc_domain_memory_mapping( domctl.u.memory_mapping.nr_mfns = nr; domctl.u.memory_mapping.first_gfn = first_gfn + done; domctl.u.memory_mapping.first_mfn = first_mfn + done; - err =do_domctl (xch, &domctl); -if ( err && errno ==E2BIG ) + rc =do_domctl (xch, &domctl); +if ( rc <0 && errno ==E2BIG ) {if ( max_batch_sz <=1 )break ; max_batch_sz >>=1 ;continue ; } +if ( rc >0 ) + { + done += rc; +continue ; + }/* Save the first error... */ if ( !ret ) - ret = err; + ret = rc;/* .. and ignore the rest of them when removing. */ -if ( err && add_mapping !=DPCI_REMOVE_MAPPING ) +if ( rc && add_mapping !=DPCI_REMOVE_MAPPING )break ; done += nr;
xen/arch/x86/domain_build.c +2 -1
@@ -436,7 +436,8 @@ static __init void pvh_add_mem_mapping(selse a = p2m_access_rw; -if ( (rc =set_mmio_p2m_entry (d, gfn + i,_mfn (mfn + i), a)) ) +if ( (rc =set_mmio_p2m_entry (d, gfn + i,_mfn (mfn + i), +PAGE_ORDER_4K , a)) )panic ("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n" , gfn, mfn, i, rc);if ( !(i &0xfffff ) )
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -2491,7 +2491,7 @@ static int vmx_alloc_vlapic_mapping(strushare_xen_page_with_guest (pg, d, XENSHARE_writable); d->arch.hvm_domain.vmx.apic_access_mfn = mfn;set_mmio_p2m_entry (d,paddr_to_pfn (APIC_DEFAULT_PHYS_BASE ),_mfn (mfn), -p2m_get_hostp2m (d)->default_access); +PAGE_ORDER_4K ,p2m_get_hostp2m (d)->default_access);return 0 ; }
xen/arch/x86/mm/p2m.c +108 -36
249 lines not on this page · raw message
xen/arch/x86/mm/p2m-ept.c +1 -0
@@ -136,6 +136,7 @@ static void ept_p2m_type_to_flags(struct entry->r = entry->x =1 ; entry->w = !rangeset_contains_singleton (mmio_ro_ranges, entry->mfn); +ASSERT (entry->w || !is_epte_superpage (entry)); entry->a = !!cpu_has_vmx_ept_ad; entry->d = entry->w && cpu_has_vmx_ept_ad;break ;
xen/arch/x86/mm/p2m-pt.c +8 -5
@@ -72,7 +72,8 @@ static const unsigned long pgt[] = { PGT_l3_page_table }; -static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn, +unsigned int level) {unsigned long flags;/*
@@ -107,6 +108,8 @@ static unsigned long p2m_type_to_flags(pcase p2m_mmio_direct:if ( !rangeset_contains_singleton (mmio_ro_ranges,mfn_x (mfn)) ) flags |= _PAGE_RW; +else +ASSERT (!level);return flags |P2M_BASE_FLAGS | _PAGE_PCD; } }
@@ -436,7 +439,7 @@ static int do_recalc(struct p2m_domain *p2m_type_t p2mt =p2m_is_logdirty_range (p2m, gfn & mask, gfn | ~mask) ? p2m_ram_logdirty : p2m_ram_rw;unsigned long mfn =l1e_get_pfn (e); -unsigned long flags =p2m_type_to_flags (p2mt,_mfn (mfn)); +unsigned long flags =p2m_type_to_flags (p2mt,_mfn (mfn), level);if ( level ) {
@@ -573,7 +576,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,ASSERT (!mfn_valid (mfn) || p2mt != p2m_mmio_direct); l3e_content =mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ?l3e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn) | _PAGE_PSE) +p2m_type_to_flags (p2mt, mfn,2 ) | _PAGE_PSE) :l3e_empty (); entry_content.l1 = l3e_content.l3;
@@ -609,7 +612,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,if (mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ) entry_content =p2m_l1e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn)); +p2m_type_to_flags (p2mt, mfn,0 ));else entry_content =l1e_empty ();
@@ -645,7 +648,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,ASSERT (!mfn_valid (mfn) || p2mt != p2m_mmio_direct);if (mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ) l2e_content =l2e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn) | +p2m_type_to_flags (p2mt, mfn,1 ) | _PAGE_PSE);else l2e_content =l2e_empty ();
xen/common/domctl.c +4 -2
@@ -1046,10 +1046,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe (gfn + nr_mfns - 1) < gfn ) /* wrap? */break ; +#ifndef CONFIG_X86 /* XXX ARM!? */ ret = -E2BIG ;/* Must break hypercall up as this could take a while. */ if ( nr_mfns >64 )break ; +#endif ret = -EPERM ; if ( !iomem_access_permitted(current->domain, mfn, mfn_end) ||
@@ -1067,7 +1069,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe d->domain_id, gfn, mfn, nr_mfns); ret =map_mmio_regions (d, gfn, nr_mfns, mfn); -if ( ret ) +if ( ret <0 )printk (XENLOG_G_WARNING "memory_map:fail: dom%d gfn=%lx mfn=%lx nr=%lx ret:%ld\n" , d->domain_id, gfn, mfn, nr_mfns, ret);
@@ -1079,7 +1081,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe d->domain_id, gfn, mfn, nr_mfns); ret =unmap_mmio_regions (d, gfn, nr_mfns, mfn); -if ( ret &&is_hardware_domain (current->domain) ) +if ( ret <0 &&is_hardware_domain (current->domain) )printk (XENLOG_ERR "memory_map: error %ld removing dom%d access to [%lx,%lx]\n" , ret, d->domain_id, mfn, mfn_end);
xen/common/memory.c +1 -1
@@ -259,7 +259,7 @@ int guest_remove_page(struct domain *d, }if ( p2mt == p2m_mmio_direct ) { -clear_mmio_p2m_entry (d, gmfn,_mfn (mfn)); +clear_mmio_p2m_entry (d, gmfn,_mfn (mfn),0 );put_gfn (d, gmfn);return 1 ; }
xen/include/asm-x86/p2m.h +3 -2
@@ -574,8 +574,9 @@ int p2m_is_logdirty_range(struct p2m_dom/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn, -p2m_access_t access); -int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +unsigned int order,p2m_access_t access); +int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn, +unsigned int order);/* Set identity addresses in the p2m table (for pass-through) */ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
xen/include/public/domctl.h +8 -1
@@ -542,8 +542,15 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_bind_/* Bind machine I/O address range -> HVM address range. */ -/* If this returns -E2BIG lower nr_mfns value. */ /* XEN_DOMCTL_memory_mapping */ +/* Returns +- zero success, everything done +- -E2BIG passed in nr_mfns value too large for the implementation +- positive partial success for the first <result> page frames (with +<result> less than nr_mfns), requiring re-invocation by the +caller after updating inputs +- negative error; other than -E2BIG +*/ #define DPCI_ADD_MAPPING 1#define DPCI_REMOVE_MAPPING 0struct xen_domctl_memory_mapping {
x86/p2m: use large pages for MMIO mappings
When mapping large BARs (e.g. the frame buffer of a graphics card) the overhead of establishing such mappings using only 4k pages has, particularly after the XSA-125 fix, become unacceptable. Alter the XEN_DOMCTL_memory_mapping semantics once again, so that there's no longer a fixed amount of guest frames that represents the upper limit of what a single invocation can map. Instead bound execution time by limiting the number of iterations (regardless of page size).
---
Open issues (perhaps for subsequent changes):
- ARM side unimplemented (and hence libxc for now made cope with both models), the main issue (besides my inability to test any change there) being the many internal uses of map_mmio_regions())
- iommu_{,un}map_page() interfaces don't support "order" (hence mmio_order() for now returns zero when !iommu_hap_pt_share, which in particular means the AMD side isn't being taken care of just yet, but note that this also has the intended effect of suppressing non-zero order mappings in the shadow mode case)
---
v6: Move an mfn_valid() assertion to cover the full MFN range. Use
PAGE_ORDER_4K in mmio_order(). Improve the return value description of set_typed_p2m_entry().
v5: Refine comment in domctl.h.
v4: Move cleanup duty entirely to the caller of the hypercall. Move
return value description to from commit message to domctl.h.
v3: Re-base on top of "x86/hvm: fold opt_hap_{2mb,1gb} into
hap_capabilities". Extend description to spell out new return value meaning. Add a couple of code comments. Use PAGE_ORDER_4K instead of literal 0. Take into consideration r/o MMIO pages.
v2: Produce valid entries for large p2m_mmio_direct mappings in
p2m_pt_set_entry(). Don't open code iommu_use_hap_pt() in mmio_order(). Update function comment of set_typed_p2m_entry() and clear_mmio_p2m_entry(). Use PRI_mfn. Add ASSERT()s to {,un}map_mmio_regions() to detect otherwise endless loops.
tools/libxc/xc_domain.c +10 -5
@@ -2229,7 +2229,7 @@ int xc_domain_memory_mapping( {DECLARE_DOMCTL ;xc_dominfo_t info; -int ret =0 , err; +int ret =0 , rc;unsigned long done =0 , nr, max_batch_sz; if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
@@ -2254,19 +2254,24 @@ int xc_domain_memory_mapping( domctl.u.memory_mapping.nr_mfns = nr; domctl.u.memory_mapping.first_gfn = first_gfn + done; domctl.u.memory_mapping.first_mfn = first_mfn + done; - err =do_domctl (xch, &domctl); -if ( err && errno ==E2BIG ) + rc =do_domctl (xch, &domctl); +if ( rc <0 && errno ==E2BIG ) {if ( max_batch_sz <=1 )break ; max_batch_sz >>=1 ;continue ; } +if ( rc >0 ) + { + done += rc; +continue ; + }/* Save the first error... */ if ( !ret ) - ret = err; + ret = rc;/* .. and ignore the rest of them when removing. */ -if ( err && add_mapping !=DPCI_REMOVE_MAPPING ) +if ( rc && add_mapping !=DPCI_REMOVE_MAPPING )break ; done += nr;
xen/arch/x86/domain_build.c +2 -1
@@ -436,7 +436,8 @@ static __init void pvh_add_mem_mapping(selse a = p2m_access_rw; -if ( (rc =set_mmio_p2m_entry (d, gfn + i,_mfn (mfn + i), a)) ) +if ( (rc =set_mmio_p2m_entry (d, gfn + i,_mfn (mfn + i), +PAGE_ORDER_4K , a)) )panic ("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n" , gfn, mfn, i, rc);if ( !(i &0xfffff ) )
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -2491,7 +2491,7 @@ static int vmx_alloc_vlapic_mapping(strushare_xen_page_with_guest (pg, d, XENSHARE_writable); d->arch.hvm_domain.vmx.apic_access_mfn = mfn;set_mmio_p2m_entry (d,paddr_to_pfn (APIC_DEFAULT_PHYS_BASE ),_mfn (mfn), -p2m_get_hostp2m (d)->default_access); +PAGE_ORDER_4K ,p2m_get_hostp2m (d)->default_access);return 0 ; }
xen/arch/x86/mm/p2m.c +108 -36
249 lines not on this page · raw message
xen/arch/x86/mm/p2m-ept.c +1 -0
@@ -136,6 +136,7 @@ static void ept_p2m_type_to_flags(struct entry->r = entry->x =1 ; entry->w = !rangeset_contains_singleton (mmio_ro_ranges, entry->mfn); +ASSERT (entry->w || !is_epte_superpage (entry)); entry->a = !!cpu_has_vmx_ept_ad; entry->d = entry->w && cpu_has_vmx_ept_ad;break ;
xen/arch/x86/mm/p2m-pt.c +8 -5
@@ -72,7 +72,8 @@ static const unsigned long pgt[] = { PGT_l3_page_table }; -static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn, +unsigned int level) {unsigned long flags;/*
@@ -107,6 +108,8 @@ static unsigned long p2m_type_to_flags(pcase p2m_mmio_direct:if ( !rangeset_contains_singleton (mmio_ro_ranges,mfn_x (mfn)) ) flags |= _PAGE_RW; +else +ASSERT (!level);return flags |P2M_BASE_FLAGS | _PAGE_PCD; } }
@@ -436,7 +439,7 @@ static int do_recalc(struct p2m_domain *p2m_type_t p2mt =p2m_is_logdirty_range (p2m, gfn & mask, gfn | ~mask) ? p2m_ram_logdirty : p2m_ram_rw;unsigned long mfn =l1e_get_pfn (e); -unsigned long flags =p2m_type_to_flags (p2mt,_mfn (mfn)); +unsigned long flags =p2m_type_to_flags (p2mt,_mfn (mfn), level);if ( level ) {
@@ -573,7 +576,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,ASSERT (!mfn_valid (mfn) || p2mt != p2m_mmio_direct); l3e_content =mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ?l3e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn) | _PAGE_PSE) +p2m_type_to_flags (p2mt, mfn,2 ) | _PAGE_PSE) :l3e_empty (); entry_content.l1 = l3e_content.l3;
@@ -609,7 +612,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,if (mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ) entry_content =p2m_l1e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn)); +p2m_type_to_flags (p2mt, mfn,0 ));else entry_content =l1e_empty ();
@@ -645,7 +648,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,ASSERT (!mfn_valid (mfn) || p2mt != p2m_mmio_direct);if (mfn_valid (mfn) ||p2m_allows_invalid_mfn (p2mt) ) l2e_content =l2e_from_pfn (mfn_x (mfn), -p2m_type_to_flags (p2mt, mfn) | +p2m_type_to_flags (p2mt, mfn,1 ) | _PAGE_PSE);else l2e_content =l2e_empty ();
xen/common/domctl.c +4 -2
@@ -1046,10 +1046,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe (gfn + nr_mfns - 1) < gfn ) /* wrap? */break ; +#ifndef CONFIG_X86 /* XXX ARM!? */ ret = -E2BIG ;/* Must break hypercall up as this could take a while. */ if ( nr_mfns >64 )break ; +#endif ret = -EPERM ; if ( !iomem_access_permitted(current->domain, mfn, mfn_end) ||
@@ -1067,7 +1069,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe d->domain_id, gfn, mfn, nr_mfns); ret =map_mmio_regions (d, gfn, nr_mfns, mfn); -if ( ret ) +if ( ret <0 )printk (XENLOG_G_WARNING "memory_map:fail: dom%d gfn=%lx mfn=%lx nr=%lx ret:%ld\n" , d->domain_id, gfn, mfn, nr_mfns, ret);
@@ -1079,7 +1081,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe d->domain_id, gfn, mfn, nr_mfns); ret =unmap_mmio_regions (d, gfn, nr_mfns, mfn); -if ( ret &&is_hardware_domain (current->domain) ) +if ( ret <0 &&is_hardware_domain (current->domain) )printk (XENLOG_ERR "memory_map: error %ld removing dom%d access to [%lx,%lx]\n" , ret, d->domain_id, mfn, mfn_end);
xen/common/memory.c +1 -1
@@ -259,7 +259,7 @@ int guest_remove_page(struct domain *d, }if ( p2mt == p2m_mmio_direct ) { -clear_mmio_p2m_entry (d, gmfn,_mfn (mfn)); +clear_mmio_p2m_entry (d, gmfn,_mfn (mfn),0 );put_gfn (d, gmfn);return 1 ; }
xen/include/asm-x86/p2m.h +3 -2
@@ -574,8 +574,9 @@ int p2m_is_logdirty_range(struct p2m_dom/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn, -p2m_access_t access); -int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +unsigned int order,p2m_access_t access); +int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn, +unsigned int order);/* Set identity addresses in the p2m table (for pass-through) */ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
xen/include/public/domctl.h +8 -1
@@ -542,8 +542,15 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_bind_/* Bind machine I/O address range -> HVM address range. */ -/* If this returns -E2BIG lower nr_mfns value. */ /* XEN_DOMCTL_memory_mapping */ +/* Returns +- zero success, everything done +- -E2BIG passed in nr_mfns value too large for the implementation +- positive partial success for the first <result> page frames (with +<result> less than nr_mfns), requiring re-invocation by the +caller after updating inputs +- negative error; other than -E2BIG +*/ #define DPCI_ADD_MAPPING 1#define DPCI_REMOVE_MAPPING 0struct xen_domctl_memory_mapping {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 45 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +18
-5@@ -899,48 +899,64 @@ void p2m_change_type_range(struct domainp2m_unlock (p2m); } -/* Returns: 0 for success, -errno for failure */ +/* +* Returns: +* 0 for success +* -errno for failure +* 1 + new order for caller to retry with smaller order (guaranteed +* to be smaller than order passed in) +*/ static int set_typed_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn, -p2m_type_t gfn_p2mt,p2m_access_t access) +unsigned int order,p2m_type_t gfn_p2mt, +p2m_access_t access) {int rc =0 ;p2m_access_t a;p2m_type_t ot;mfn_t omfn; +unsigned int cur_order =0 ;struct p2m_domain *p2m =p2m_get_hostp2m (d);if ( !paging_mode_translate (d) )return -EIO ; -gfn_lock (p2m, gfn,0 ); - omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 ,NULL ,NULL ); +gfn_lock (p2m, gfn, order); + omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 , &cur_order,NULL ); +if ( cur_order < order ) + { +gfn_unlock (p2m, gfn, order); +return cur_order +1 ; + }if (p2m_is_grant (ot) ||p2m_is_foreign (ot) ) { -gfn_unlock (p2m, gfn,0 ); +gfn_unlock (p2m, gfn, order);domain_crash (d);return -ENOENT ; }
xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 943
Quoted 10 lines
xen/arch/x86/mm/p2m.c +6
-2else if (p2m_is_ram (ot) ) { -ASSERT (mfn_valid (omfn)); -set_gpfn_from_mfn (mfn_x (omfn),INVALID_M2P_ENTRY ); +unsigned long i; + +for ( i =0 ; i < (1UL << order); ++i ) + { +ASSERT (mfn_valid (_mfn (mfn_x (omfn) + i))); +set_gpfn_from_mfn (mfn_x (omfn) + i,INVALID_M2P_ENTRY );
On further consideration, shouldn't we have a preemption check here? Removing a 1GB superpage's worth of RAM mappings is going to execute for an unreasonably long time.
~Andrew
Quoted 59 lines
Quoted 1 line
Quoted 1 line · On 01.02.16 at 16:00, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-0@@ -899,48 +899,64 @@ void p2m_change_type_range(struct domainp2m_unlock (p2m); }xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 909
Quoted 10 lines
xen/arch/x86/mm/p2m.c +7
-1-/* Returns: 0 for success, -errno for failure */ +/* +* Returns: +* 0 for success +* -errno for failure +* 1 + new order for caller to retry with smaller order (guaranteed +* to be smaller than order passed in) +*/ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_tmfn,
Quoted 30 lines
xen/arch/x86/mm/p2m.c +11
-4- p2m_type_t gfn_p2mt, p2m_access_t access) + unsigned int order, p2m_type_t gfn_p2mt, + p2m_access_t access) { int rc = 0;p2m_access_t a;p2m_type_t ot;mfn_t omfn; +unsigned int cur_order =0 ;struct p2m_domain *p2m =p2m_get_hostp2m (d);if ( !paging_mode_translate (d) )return -EIO ; -gfn_lock (p2m, gfn,0 ); - omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 ,NULL ,NULL ); +gfn_lock (p2m, gfn, order); + omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 , &cur_order,NULL ); +if ( cur_order < order ) + { +gfn_unlock (p2m, gfn, order); +return cur_order +1 ; + }if (p2m_is_grant (ot) ||p2m_is_foreign (ot) ) { -gfn_unlock (p2m, gfn,0 ); +gfn_unlock (p2m, gfn, order);domain_crash (d);return -ENOENT ; }xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 943
Quoted 10 lines
xen/arch/x86/mm/p2m.c +6
-2else if (p2m_is_ram (ot) ) { -ASSERT (mfn_valid (omfn)); -set_gpfn_from_mfn (mfn_x (omfn),INVALID_M2P_ENTRY ); +unsigned long i; + +for ( i =0 ; i < (1UL << order); ++i ) + { +ASSERT (mfn_valid (_mfn (mfn_x (omfn) + i))); +set_gpfn_from_mfn (mfn_x (omfn) + i,INVALID_M2P_ENTRY );
Quoted 3 lines
On further consideration, shouldn't we have a preemption check here? Removing a 1GB superpage's worth of RAM mappings is going to execute for an unreasonably long time.
Maybe. We have 256k iteration loops elsewhere, so I'm not that concerned. The thing probably needing adjustment would then be map_mmio_regions(), to avoid multiplying the 256k here by the up to 64 iterations done there. Preempting here is not really possible, as we're holding the p2m lock.
The only other alternative I see would be to disallow 1G mappings and only support 2M ones.
Thoughts?
Jan
Quoted 58 lines · Jan Beulich
Quoted 58 lines
Quoted 1 line
Quoted 1 line · On 01.02.16 at 16:00, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-0@@ -899,48 +899,64 @@ void p2m_change_type_range(struct domainp2m_unlock (p2m); }xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 909
Quoted 10 lines
xen/arch/x86/mm/p2m.c +7
-1-/* Returns: 0 for success, -errno for failure */ +/* +* Returns: +* 0 for success +* -errno for failure +* 1 + new order for caller to retry with smaller order (guaranteed +* to be smaller than order passed in) +*/ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_tmfn,
Quoted 40 lines
xen/arch/x86/mm/p2m.c +17
-6- p2m_type_t gfn_p2mt, p2m_access_t access) + unsigned int order, p2m_type_t gfn_p2mt, + p2m_access_t access) { int rc = 0;p2m_access_t a;p2m_type_t ot;mfn_t omfn; +unsigned int cur_order =0 ;struct p2m_domain *p2m =p2m_get_hostp2m (d);if ( !paging_mode_translate (d) )return -EIO ; -gfn_lock (p2m, gfn,0 ); - omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 ,NULL ,NULL ); +gfn_lock (p2m, gfn, order); + omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 , &cur_order,NULL ); +if ( cur_order < order ) + { +gfn_unlock (p2m, gfn, order); +return cur_order +1 ; + }if (p2m_is_grant (ot) ||p2m_is_foreign (ot) ) { -gfn_unlock (p2m, gfn,0 ); +gfn_unlock (p2m, gfn, order);domain_crash (d);return -ENOENT ; }else if (p2m_is_ram (ot) ) { -ASSERT (mfn_valid (omfn)); -set_gpfn_from_mfn (mfn_x (omfn),INVALID_M2P_ENTRY ); +unsigned long i; + +for ( i =0 ; i < (1UL << order); ++i ) + { +ASSERT (mfn_valid (_mfn (mfn_x (omfn) + i))); +set_gpfn_from_mfn (mfn_x (omfn) + i,INVALID_M2P_ENTRY );
Quoted 8 lines
Quoted 3 lines
On further consideration, shouldn't we have a preemption check here? Removing a 1GB superpage's worth of RAM mappings is going to execute for an unreasonably long time.
Maybe. We have 256k iteration loops elsewhere, so I'm not that concerned. The thing probably needing adjustment would then be
map_mmio_regions(), to avoid multiplying the 256k here by the up to 64 iterations done there. Preempting here is not really possible, as we're holding the p2m lock.
Why is this problematic? All that needs to happen is to -ERESTART out to a point where the p2m lock is dropped.
Quoted 5 lines
The only other alternative I see would be to disallow 1G mappings and only support 2M ones.
Thoughts?
For now, restricting to 2M mappings at least limits the potential damage while gaining some benefits of large MMIO mappings.
~Andrew
Quoted 63 lines
Quoted 1 line
Quoted 1 line · On 02.02.16 at 15:33, <[email protected]> wrote:
Quoted 61 lines · Jan Beulich
Quoted 61 lines
Quoted 1 line
Quoted 1 line · On 01.02.16 at 16:00, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-0@@ -899,48 +899,64 @@ void p2m_change_type_range(struct domainp2m_unlock (p2m); }xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 909
Quoted 10 lines
xen/arch/x86/mm/p2m.c +7
-1-/* Returns: 0 for success, -errno for failure */ +/* +* Returns: +* 0 for success +* -errno for failure +* 1 + new order for caller to retry with smaller order (guaranteed +* to be smaller than order passed in) +*/ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_tmfn,
Quoted 30 lines
xen/arch/x86/mm/p2m.c +11
-4- p2m_type_t gfn_p2mt, p2m_access_t access) + unsigned int order, p2m_type_t gfn_p2mt, + p2m_access_t access) { int rc = 0;p2m_access_t a;p2m_type_t ot;mfn_t omfn; +unsigned int cur_order =0 ;struct p2m_domain *p2m =p2m_get_hostp2m (d);if ( !paging_mode_translate (d) )return -EIO ; -gfn_lock (p2m, gfn,0 ); - omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 ,NULL ,NULL ); +gfn_lock (p2m, gfn, order); + omfn = p2m->get_entry (p2m, gfn, &ot, &a,0 , &cur_order,NULL ); +if ( cur_order < order ) + { +gfn_unlock (p2m, gfn, order); +return cur_order +1 ; + }if (p2m_is_grant (ot) ||p2m_is_foreign (ot) ) { -gfn_unlock (p2m, gfn,0 ); +gfn_unlock (p2m, gfn, order);domain_crash (d);return -ENOENT ; }xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain · line 943
Quoted 10 lines
xen/arch/x86/mm/p2m.c +6
-2else if (p2m_is_ram (ot) ) { -ASSERT (mfn_valid (omfn)); -set_gpfn_from_mfn (mfn_x (omfn),INVALID_M2P_ENTRY ); +unsigned long i; + +for ( i =0 ; i < (1UL << order); ++i ) + { +ASSERT (mfn_valid (_mfn (mfn_x (omfn) + i))); +set_gpfn_from_mfn (mfn_x (omfn) + i,INVALID_M2P_ENTRY );On further consideration, shouldn't we have a preemption check here? Removing a 1GB superpage's worth of RAM mappings is going to execute for an unreasonably long time.
Quoted 8 lines
Quoted 5 lines
Maybe. We have 256k iteration loops elsewhere, so I'm not that concerned. The thing probably needing adjustment would then be
map_mmio_regions(), to avoid multiplying the 256k here by the up to 64 iterations done there. Preempting here is not really possible, as we're holding the p2m lock.Why is this problematic? All that needs to happen is to
-ERESTARTout to a point where the p2m lock is dropped.
Because with the p2m lock dropped the region we're just trying to populate may get changed another way? And because we'd need to track where we left off?
Quoted 7 lines
Quoted 4 lines
The only other alternative I see would be to disallow 1G mappings and only support 2M ones.
Thoughts?
For now, restricting to 2M mappings at least limits the potential damage while gaining some benefits of large MMIO mappings.
Okay, will do it that way then.
Jan