From: "Jan Beulich" Subject: [PATCH v2 1/4] move XENMEM_add_to_physmap handling framework to common code Date: Fri, 20 Dec 2013 08:28:26 +0000 Message-ID: <52B40DBA020000780010F607@nat28.tlf.novell.com> References: <52B1BF76020000780010EC02@nat28.tlf.novell.com> <52B40C69020000780010F5F6@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCCFF20BA.2__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VtvRe-0003X2-KG for xen-devel@lists.xenproject.org; Fri, 20 Dec 2013 08:28:31 +0000 In-Reply-To: <52B40C69020000780010F5F6@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Tim Deegan , Keir Fraser , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartCCFF20BA.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one(). Note that ARM's restriction of XENMAPSPACE_gmfn_foreign only being supported through XENMEM_add_to_physmap_range is being dropped as being pointless. Signed-off-by: Jan Beulich Reviewed-by: Tim Deegan Acked-by: Keir Fraser --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -968,7 +968,7 @@ void share_xen_page_with_privileged_gues share_xen_page_with_guest(page, dom_xen, readonly); } =20 -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid, @@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HA =20 switch ( op ) { - case XENMEM_add_to_physmap: - { - struct xen_add_to_physmap xatp; - struct domain *d; - - if ( copy_from_guest(&xatp, arg, 1) ) - return -EFAULT; - - /* Foreign mapping is only supported by add_to_physmap_range */ - if ( xatp.space =3D=3D XENMAPSPACE_gmfn_foreign ) - return -EINVAL; - - d =3D rcu_lock_domain_by_any_id(xatp.domid); - if ( d =3D=3D NULL ) - return -ESRCH; - - rc =3D xsm_add_to_physmap(XSM_TARGET, current->domain, d); - if ( rc ) - { - rcu_unlock_domain(d); - return rc; - } - - rc =3D xenmem_add_to_physmap_one(d, xatp.space, DOMID_INVALID, - xatp.idx, xatp.gpfn); - - rcu_unlock_domain(d); - - return rc; - } - case XENMEM_add_to_physmap_range: { struct xen_add_to_physmap_range xatpr; --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4520,20 +4520,23 @@ static int handle_iomem_range(unsigned l return 0; } =20 -static int xenmem_add_to_physmap_once( +int xenmem_add_to_physmap_one( struct domain *d, - const struct xen_add_to_physmap *xatp) + uint16_t space, + domid_t foreign_domid, + unsigned long idx, + xen_pfn_t gpfn) { struct page_info *page =3D NULL; unsigned long gfn =3D 0; /* gcc ... */ - unsigned long prev_mfn, mfn =3D 0, gpfn, idx; + unsigned long prev_mfn, mfn =3D 0, old_gpfn; int rc; p2m_type_t p2mt; =20 - switch ( xatp->space ) + switch ( space ) { case XENMAPSPACE_shared_info: - if ( xatp->idx =3D=3D 0 ) + if ( idx =3D=3D 0 ) mfn =3D virt_to_mfn(d->shared_info); break; case XENMAPSPACE_grant_table: @@ -4542,9 +4545,8 @@ static int xenmem_add_to_physmap_once( if ( d->grant_table->gt_version =3D=3D 0 ) d->grant_table->gt_version =3D 1; =20 - idx =3D xatp->idx; if ( d->grant_table->gt_version =3D=3D 2 && - (xatp->idx & XENMAPIDX_grant_table_status) ) + (idx & XENMAPIDX_grant_table_status) ) { idx &=3D ~XENMAPIDX_grant_table_status; if ( idx < nr_status_frames(d->grant_table) ) @@ -4566,9 +4568,9 @@ static int xenmem_add_to_physmap_once( case XENMAPSPACE_gmfn: { p2m_type_t p2mt; - gfn =3D xatp->idx; =20 - idx =3D mfn_x(get_gfn_unshare(d, xatp->idx, &p2mt)); + gfn =3D idx; + idx =3D mfn_x(get_gfn_unshare(d, idx, &p2mt)); /* If the page is still shared, exit early */ if ( p2m_is_shared(p2mt) ) { @@ -4589,41 +4591,38 @@ static int xenmem_add_to_physmap_once( { if ( page ) put_page(page); - if ( xatp->space =3D=3D XENMAPSPACE_gmfn || - xatp->space =3D=3D XENMAPSPACE_gmfn_range ) + if ( space =3D=3D XENMAPSPACE_gmfn || space =3D=3D XENMAPSPACE_gmf= n_range ) put_gfn(d, gfn); return -EINVAL; } =20 /* Remove previously mapped page if it was present. */ - prev_mfn =3D mfn_x(get_gfn(d, xatp->gpfn, &p2mt)); + prev_mfn =3D mfn_x(get_gfn(d, gpfn, &p2mt)); if ( mfn_valid(prev_mfn) ) { if ( is_xen_heap_mfn(prev_mfn) ) /* Xen heap frames are simply unhooked from this phys slot. = */ - guest_physmap_remove_page(d, xatp->gpfn, prev_mfn, PAGE_ORDER_= 4K); + guest_physmap_remove_page(d, gpfn, prev_mfn, PAGE_ORDER_4K); else /* Normal domain memory is freed, to avoid leaking memory. */ - guest_remove_page(d, xatp->gpfn); + guest_remove_page(d, gpfn); } /* In the XENMAPSPACE_gmfn case we still hold a ref on the old page. = */ - put_gfn(d, xatp->gpfn); + put_gfn(d, gpfn); =20 /* Unmap from old location, if any. */ - gpfn =3D get_gpfn_from_mfn(mfn); - ASSERT( gpfn !=3D SHARED_M2P_ENTRY ); - if ( xatp->space =3D=3D XENMAPSPACE_gmfn || - xatp->space =3D=3D XENMAPSPACE_gmfn_range ) - ASSERT( gpfn =3D=3D gfn ); - if ( gpfn !=3D INVALID_M2P_ENTRY ) - guest_physmap_remove_page(d, gpfn, mfn, PAGE_ORDER_4K); + old_gpfn =3D get_gpfn_from_mfn(mfn); + ASSERT( old_gpfn !=3D SHARED_M2P_ENTRY ); + if ( space =3D=3D XENMAPSPACE_gmfn || space =3D=3D XENMAPSPACE_gmfn_ra= nge ) + ASSERT( old_gpfn =3D=3D gfn ); + if ( old_gpfn !=3D INVALID_M2P_ENTRY ) + guest_physmap_remove_page(d, old_gpfn, mfn, PAGE_ORDER_4K); =20 /* Map at new location. */ - rc =3D guest_physmap_add_page(d, xatp->gpfn, mfn, PAGE_ORDER_4K); + rc =3D guest_physmap_add_page(d, gpfn, mfn, PAGE_ORDER_4K); =20 /* In the XENMAPSPACE_gmfn, we took a ref of the gfn at the top */ - if ( xatp->space =3D=3D XENMAPSPACE_gmfn || - xatp->space =3D=3D XENMAPSPACE_gmfn_range ) + if ( space =3D=3D XENMAPSPACE_gmfn || space =3D=3D XENMAPSPACE_gmfn_ra= nge ) put_gfn(d, gfn); =20 if ( page ) @@ -4632,90 +4631,12 @@ static int xenmem_add_to_physmap_once( return rc; } =20 -static int xenmem_add_to_physmap(struct domain *d, - struct xen_add_to_physmap *xatp) -{ - struct xen_add_to_physmap start_xatp; - int rc =3D 0; - - if ( xatp->space =3D=3D XENMAPSPACE_gmfn_range ) - { - if ( need_iommu(d) ) - this_cpu(iommu_dont_flush_iotlb) =3D 1; - - start_xatp =3D *xatp; - while ( xatp->size > 0 ) - { - rc =3D xenmem_add_to_physmap_once(d, xatp); - if ( rc < 0 ) - break; - - xatp->idx++; - xatp->gpfn++; - xatp->size--; - - /* Check for continuation if it's not the last interation */ - if ( xatp->size > 0 && hypercall_preempt_check() ) - { - rc =3D -EAGAIN; - break; - } - } - - if ( need_iommu(d) ) - { - this_cpu(iommu_dont_flush_iotlb) =3D 0; - iommu_iotlb_flush(d, start_xatp.idx, start_xatp.size - = xatp->size); - iommu_iotlb_flush(d, start_xatp.gpfn, start_xatp.size - = xatp->size); - } - - return rc; - } - - return xenmem_add_to_physmap_once(d, xatp); -} - long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg) { int rc; =20 switch ( op ) { - case XENMEM_add_to_physmap: - { - struct xen_add_to_physmap xatp; - struct domain *d; - - if ( copy_from_guest(&xatp, arg, 1) ) - return -EFAULT; - - d =3D rcu_lock_domain_by_any_id(xatp.domid); - if ( d =3D=3D NULL ) - return -ESRCH; - - if ( xsm_add_to_physmap(XSM_TARGET, current->domain, d) ) - { - rcu_unlock_domain(d); - return -EPERM; - } - - rc =3D xenmem_add_to_physmap(d, &xatp); - - rcu_unlock_domain(d); - - if ( xatp.space =3D=3D XENMAPSPACE_gmfn_range ) - { - if ( rc && __copy_to_guest(arg, &xatp, 1) ) - rc =3D -EFAULT; - - if ( rc =3D=3D -EAGAIN ) - rc =3D hypercall_create_continuation( - __HYPERVISOR_memory_op, "ih", op, arg); - } - - return rc; - } - case XENMEM_set_memory_map: { struct xen_foreign_memory_map fmap; --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GU =20 switch ( op ) { - case XENMEM_add_to_physmap: - { - struct compat_add_to_physmap cmp; - struct xen_add_to_physmap *nat =3D COMPAT_ARG_XLAT_VIRT_BASE; - - if ( copy_from_guest(&cmp, arg, 1) ) - return -EFAULT; - - XLAT_add_to_physmap(nat, &cmp); - rc =3D arch_memory_op(op, guest_handle_from_ptr(nat, void)); - - if ( !rc || cmp.space !=3D XENMAPSPACE_gmfn_range ) - break; - - XLAT_add_to_physmap(&cmp, nat); - if ( __copy_to_guest(arg, &cmp, 1) ) - { - if ( rc =3D=3D __HYPERVISOR_memory_op ) - hypercall_cancel_continuation(); - return -EFAULT; - } - - if ( rc =3D=3D __HYPERVISOR_memory_op ) - hypercall_xlat_continuation(NULL, 0x2, nat, arg); - - break; - } - case XENMEM_set_memory_map: { struct compat_foreign_memory_map cmp; --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, X XEN_GUEST_HANDLE_PARAM(void) hnd; struct xen_memory_reservation *rsrv; struct xen_memory_exchange *xchg; + struct xen_add_to_physmap *atp; struct xen_remove_from_physmap *xrfp; } nat; union { struct compat_memory_reservation rsrv; struct compat_memory_exchange xchg; + struct compat_add_to_physmap atp; } cmp; =20 set_xen_guest_handle(nat.hnd, COMPAT_ARG_XLAT_VIRT_BASE); @@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd =3D compat; break; =20 + case XENMEM_add_to_physmap: + if ( copy_from_guest(&cmp.atp, compat, 1) ) + return -EFAULT; + + XLAT_add_to_physmap(nat.atp, &cmp.atp); + + break; + case XENMEM_remove_from_physmap: { struct compat_remove_from_physmap cmp; @@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, X case XENMEM_remove_from_physmap: break; =20 + case XENMEM_add_to_physmap: + if ( !rc || cmp.atp.space !=3D XENMAPSPACE_gmfn_range ) + break; + + XLAT_add_to_physmap(&cmp.atp, nat.atp); + if ( __copy_to_guest(compat, &cmp.atp, 1) ) + rc =3D -EFAULT; + + break; + default: domain_crash(current->domain); split =3D 0; --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -542,6 +542,53 @@ static long memory_exchange(XEN_GUEST_HA return rc; } =20 +static int xenmem_add_to_physmap(struct domain *d, + struct xen_add_to_physmap *xatp) +{ + struct xen_add_to_physmap start_xatp; + int rc =3D 0; + + if ( xatp->space !=3D XENMAPSPACE_gmfn_range ) + return xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID, + xatp->idx, xatp->gpfn); + +#ifdef HAS_PASSTHROUGH + if ( need_iommu(d) ) + this_cpu(iommu_dont_flush_iotlb) =3D 1; +#endif + + start_xatp =3D *xatp; + while ( xatp->size > 0 ) + { + rc =3D xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID, + xatp->idx, xatp->gpfn); + if ( rc < 0 ) + break; + + xatp->idx++; + xatp->gpfn++; + xatp->size--; + + /* Check for continuation if it's not the last iteration. */ + if ( xatp->size > 0 && hypercall_preempt_check() ) + { + rc =3D -EAGAIN; + break; + } + } + +#ifdef HAS_PASSTHROUGH + if ( need_iommu(d) ) + { + this_cpu(iommu_dont_flush_iotlb) =3D 0; + iommu_iotlb_flush(d, start_xatp.idx, start_xatp.size - xatp->size)= ; + iommu_iotlb_flush(d, start_xatp.gpfn, start_xatp.size - xatp->size= ); + } +#endif + + return rc; +} + long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { struct domain *d; @@ -673,6 +720,40 @@ long do_memory_op(unsigned long cmd, XEN =20 break; =20 + case XENMEM_add_to_physmap: + { + struct xen_add_to_physmap xatp; + + if ( copy_from_guest(&xatp, arg, 1) ) + return -EFAULT; + + d =3D rcu_lock_domain_by_any_id(xatp.domid); + if ( d =3D=3D NULL ) + return -ESRCH; + + rc =3D xsm_add_to_physmap(XSM_TARGET, current->domain, d); + if ( rc ) + { + rcu_unlock_domain(d); + return rc; + } + + rc =3D xenmem_add_to_physmap(d, &xatp); + + rcu_unlock_domain(d); + + if ( xatp.space =3D=3D XENMAPSPACE_gmfn_range && rc =3D=3D = -EAGAIN ) + { + if ( !__copy_to_guest(arg, &xatp, 1) ) + rc =3D hypercall_create_continuation( + __HYPERVISOR_memory_op, "ih", op, arg); + else + rc =3D -EFAULT; + } + + return rc; + } + case XENMEM_remove_from_physmap: { struct xen_remove_from_physmap xrfp; --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -356,6 +356,10 @@ static inline unsigned int get_order_fro =20 void scrub_one_page(struct page_info *); =20 +int xenmem_add_to_physmap_one(struct domain *d, uint16_t space, + domid_t foreign_domid, + unsigned long idx, xen_pfn_t gpfn); + /* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page(struct domain *d, unsigned long gmfn); --=__PartCCFF20BA.2__= Content-Type: text/plain; name="xatp-common.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xatp-common.patch" move XENMEM_add_to_physmap handling framework to common code=0A=0AThere's = really nothing really architecture specific here; the=0Aarchitecture = specific handling is limited to=0Axenmem_add_to_physmap_one().=0A=0ANote = that ARM's restriction of XENMAPSPACE_gmfn_foreign only being=0Asupported = through XENMEM_add_to_physmap_range is being dropped as being=0Apointless.= =0A=0ASigned-off-by: Jan Beulich =0AReviewed-by: Tim = Deegan =0AAcked-by: Keir Fraser =0A=0A--- = a/xen/arch/arm/mm.c=0A+++ b/xen/arch/arm/mm.c=0A@@ -968,7 +968,7 @@ void = share_xen_page_with_privileged_gues=0A share_xen_page_with_guest(page, = dom_xen, readonly);=0A }=0A =0A-static int xenmem_add_to_physmap_one(=0A+in= t xenmem_add_to_physmap_one(=0A struct domain *d,=0A uint16_t = space,=0A domid_t foreign_domid,=0A@@ -1118,37 +1118,6 @@ long = arch_memory_op(int op, XEN_GUEST_HA=0A =0A switch ( op )=0A {=0A- = case XENMEM_add_to_physmap:=0A- {=0A- struct xen_add_to_physmap= xatp;=0A- struct domain *d;=0A-=0A- if ( copy_from_guest(&xa= tp, arg, 1) )=0A- return -EFAULT;=0A-=0A- /* Foreign = mapping is only supported by add_to_physmap_range */=0A- if ( = xatp.space =3D=3D XENMAPSPACE_gmfn_foreign )=0A- return = -EINVAL;=0A-=0A- d =3D rcu_lock_domain_by_any_id(xatp.domid);=0A- = if ( d =3D=3D NULL )=0A- return -ESRCH;=0A-=0A- rc = =3D xsm_add_to_physmap(XSM_TARGET, current->domain, d);=0A- if ( rc = )=0A- {=0A- rcu_unlock_domain(d);=0A- return = rc;=0A- }=0A-=0A- rc =3D xenmem_add_to_physmap_one(d, = xatp.space, DOMID_INVALID,=0A- = xatp.idx, xatp.gpfn);=0A-=0A- rcu_unlock_domain(d);=0A-=0A- = return rc;=0A- }=0A-=0A case XENMEM_add_to_physmap_range:=0A = {=0A struct xen_add_to_physmap_range xatpr;=0A--- a/xen/arch/x86/mm= .c=0A+++ b/xen/arch/x86/mm.c=0A@@ -4520,20 +4520,23 @@ static int = handle_iomem_range(unsigned l=0A return 0;=0A }=0A =0A-static int = xenmem_add_to_physmap_once(=0A+int xenmem_add_to_physmap_one(=0A = struct domain *d,=0A- const struct xen_add_to_physmap *xatp)=0A+ = uint16_t space,=0A+ domid_t foreign_domid,=0A+ unsigned long = idx,=0A+ xen_pfn_t gpfn)=0A {=0A struct page_info *page =3D = NULL;=0A unsigned long gfn =3D 0; /* gcc ... */=0A- unsigned long = prev_mfn, mfn =3D 0, gpfn, idx;=0A+ unsigned long prev_mfn, mfn =3D 0, = old_gpfn;=0A int rc;=0A p2m_type_t p2mt;=0A =0A- switch ( = xatp->space )=0A+ switch ( space )=0A {=0A case XENMAPSPACE_= shared_info:=0A- if ( xatp->idx =3D=3D 0 )=0A+ if ( = idx =3D=3D 0 )=0A mfn =3D virt_to_mfn(d->shared_info);=0A = break;=0A case XENMAPSPACE_grant_table:=0A@@ -4542,9 = +4545,8 @@ static int xenmem_add_to_physmap_once(=0A if ( = d->grant_table->gt_version =3D=3D 0 )=0A d->grant_table->gt= _version =3D 1;=0A =0A- idx =3D xatp->idx;=0A if ( = d->grant_table->gt_version =3D=3D 2 &&=0A- (xatp->idx & = XENMAPIDX_grant_table_status) )=0A+ (idx & XENMAPIDX_grant_= table_status) )=0A {=0A idx &=3D ~XENMAPIDX_gra= nt_table_status;=0A if ( idx < nr_status_frames(d->grant_ta= ble) )=0A@@ -4566,9 +4568,9 @@ static int xenmem_add_to_physmap_once(=0A = case XENMAPSPACE_gmfn:=0A {=0A p2m_type_t = p2mt;=0A- gfn =3D xatp->idx;=0A =0A- idx =3D = mfn_x(get_gfn_unshare(d, xatp->idx, &p2mt));=0A+ gfn =3D = idx;=0A+ idx =3D mfn_x(get_gfn_unshare(d, idx, &p2mt));=0A = /* If the page is still shared, exit early */=0A if ( = p2m_is_shared(p2mt) )=0A {=0A@@ -4589,41 +4591,38 @@ static = int xenmem_add_to_physmap_once(=0A {=0A if ( page )=0A = put_page(page);=0A- if ( xatp->space =3D=3D XENMAPSPACE_gmfn = ||=0A- xatp->space =3D=3D XENMAPSPACE_gmfn_range )=0A+ = if ( space =3D=3D XENMAPSPACE_gmfn || space =3D=3D XENMAPSPACE_gmfn_range = )=0A put_gfn(d, gfn);=0A return -EINVAL;=0A }=0A = =0A /* Remove previously mapped page if it was present. */=0A- = prev_mfn =3D mfn_x(get_gfn(d, xatp->gpfn, &p2mt));=0A+ prev_mfn =3D = mfn_x(get_gfn(d, gpfn, &p2mt));=0A if ( mfn_valid(prev_mfn) )=0A = {=0A if ( is_xen_heap_mfn(prev_mfn) )=0A /* Xen heap = frames are simply unhooked from this phys slot. */=0A- = guest_physmap_remove_page(d, xatp->gpfn, prev_mfn, PAGE_ORDER_4K);=0A+ = guest_physmap_remove_page(d, gpfn, prev_mfn, PAGE_ORDER_4K);=0A = else=0A /* Normal domain memory is freed, to avoid leaking = memory. */=0A- guest_remove_page(d, xatp->gpfn);=0A+ = guest_remove_page(d, gpfn);=0A }=0A /* In the XENMAPSPACE_gmfn = case we still hold a ref on the old page. */=0A- put_gfn(d, xatp->gpfn);= =0A+ put_gfn(d, gpfn);=0A =0A /* Unmap from old location, if any. = */=0A- gpfn =3D get_gpfn_from_mfn(mfn);=0A- ASSERT( gpfn !=3D = SHARED_M2P_ENTRY );=0A- if ( xatp->space =3D=3D XENMAPSPACE_gmfn ||=0A- = xatp->space =3D=3D XENMAPSPACE_gmfn_range )=0A- ASSERT( = gpfn =3D=3D gfn );=0A- if ( gpfn !=3D INVALID_M2P_ENTRY )=0A- = guest_physmap_remove_page(d, gpfn, mfn, PAGE_ORDER_4K);=0A+ old_gpfn = =3D get_gpfn_from_mfn(mfn);=0A+ ASSERT( old_gpfn !=3D SHARED_M2P_ENTRY = );=0A+ if ( space =3D=3D XENMAPSPACE_gmfn || space =3D=3D XENMAPSPACE_gm= fn_range )=0A+ ASSERT( old_gpfn =3D=3D gfn );=0A+ if ( old_gpfn = !=3D INVALID_M2P_ENTRY )=0A+ guest_physmap_remove_page(d, old_gpfn, = mfn, PAGE_ORDER_4K);=0A =0A /* Map at new location. */=0A- rc =3D = guest_physmap_add_page(d, xatp->gpfn, mfn, PAGE_ORDER_4K);=0A+ rc =3D = guest_physmap_add_page(d, gpfn, mfn, PAGE_ORDER_4K);=0A =0A /* In the = XENMAPSPACE_gmfn, we took a ref of the gfn at the top */=0A- if ( = xatp->space =3D=3D XENMAPSPACE_gmfn ||=0A- xatp->space =3D=3D = XENMAPSPACE_gmfn_range )=0A+ if ( space =3D=3D XENMAPSPACE_gmfn || = space =3D=3D XENMAPSPACE_gmfn_range )=0A put_gfn(d, gfn);=0A =0A = if ( page )=0A@@ -4632,90 +4631,12 @@ static int xenmem_add_to_physmap_on= ce(=0A return rc;=0A }=0A =0A-static int xenmem_add_to_physmap(struct = domain *d,=0A- struct xen_add_to_physmap = *xatp)=0A-{=0A- struct xen_add_to_physmap start_xatp;=0A- int rc =3D = 0;=0A-=0A- if ( xatp->space =3D=3D XENMAPSPACE_gmfn_range )=0A- = {=0A- if ( need_iommu(d) )=0A- this_cpu(iommu_dont_flush_= iotlb) =3D 1;=0A-=0A- start_xatp =3D *xatp;=0A- while ( = xatp->size > 0 )=0A- {=0A- rc =3D xenmem_add_to_physmap_o= nce(d, xatp);=0A- if ( rc < 0 )=0A- break;=0A-=0A= - xatp->idx++;=0A- xatp->gpfn++;=0A- = xatp->size--;=0A-=0A- /* Check for continuation if it's not the = last interation */=0A- if ( xatp->size > 0 && hypercall_preempt_= check() )=0A- {=0A- rc =3D -EAGAIN;=0A- = break;=0A- }=0A- }=0A-=0A- if ( need_iommu(d= ) )=0A- {=0A- this_cpu(iommu_dont_flush_iotlb) =3D = 0;=0A- iommu_iotlb_flush(d, start_xatp.idx, start_xatp.size - = xatp->size);=0A- iommu_iotlb_flush(d, start_xatp.gpfn, = start_xatp.size - xatp->size);=0A- }=0A-=0A- return rc;=0A- = }=0A-=0A- return xenmem_add_to_physmap_once(d, xatp);=0A-}=0A-=0A = long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)=0A {=0A = int rc;=0A =0A switch ( op )=0A {=0A- case XENMEM_add_to_physmap= :=0A- {=0A- struct xen_add_to_physmap xatp;=0A- struct = domain *d;=0A-=0A- if ( copy_from_guest(&xatp, arg, 1) )=0A- = return -EFAULT;=0A-=0A- d =3D rcu_lock_domain_by_any_id(xatp.dom= id);=0A- if ( d =3D=3D NULL )=0A- return -ESRCH;=0A-=0A- = if ( xsm_add_to_physmap(XSM_TARGET, current->domain, d) )=0A- = {=0A- rcu_unlock_domain(d);=0A- return -EPERM;=0A- = }=0A-=0A- rc =3D xenmem_add_to_physmap(d, &xatp);=0A-=0A- = rcu_unlock_domain(d);=0A-=0A- if ( xatp.space =3D=3D XENMAPSPACE_= gmfn_range )=0A- {=0A- if ( rc && __copy_to_guest(arg, = &xatp, 1) )=0A- rc =3D -EFAULT;=0A-=0A- if ( rc = =3D=3D -EAGAIN )=0A- rc =3D hypercall_create_continuation(= =0A- __HYPERVISOR_memory_op, "ih", op, arg);=0A- = }=0A-=0A- return rc;=0A- }=0A-=0A case XENMEM_set_memory_= map:=0A {=0A struct xen_foreign_memory_map fmap;=0A--- = a/xen/arch/x86/x86_64/compat/mm.c=0A+++ b/xen/arch/x86/x86_64/compat/mm.c= =0A@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GU=0A =0A = switch ( op )=0A {=0A- case XENMEM_add_to_physmap:=0A- {=0A- = struct compat_add_to_physmap cmp;=0A- struct xen_add_to_physmap = *nat =3D COMPAT_ARG_XLAT_VIRT_BASE;=0A-=0A- if ( copy_from_guest(&cm= p, arg, 1) )=0A- return -EFAULT;=0A-=0A- XLAT_add_to_phys= map(nat, &cmp);=0A- rc =3D arch_memory_op(op, guest_handle_from_ptr(= nat, void));=0A-=0A- if ( !rc || cmp.space !=3D XENMAPSPACE_gmfn_ran= ge )=0A- break;=0A-=0A- XLAT_add_to_physmap(&cmp, = nat);=0A- if ( __copy_to_guest(arg, &cmp, 1) )=0A- {=0A- = if ( rc =3D=3D __HYPERVISOR_memory_op )=0A- = hypercall_cancel_continuation();=0A- return -EFAULT;=0A- = }=0A-=0A- if ( rc =3D=3D __HYPERVISOR_memory_op )=0A- = hypercall_xlat_continuation(NULL, 0x2, nat, arg);=0A-=0A- break;=0A-= }=0A-=0A case XENMEM_set_memory_map:=0A {=0A struct = compat_foreign_memory_map cmp;=0A--- a/xen/common/compat/memory.c=0A+++ = b/xen/common/compat/memory.c=0A@@ -26,11 +26,13 @@ int compat_memory_op(uns= igned int cmd, X=0A XEN_GUEST_HANDLE_PARAM(void) hnd;=0A = struct xen_memory_reservation *rsrv;=0A struct xen_memory= _exchange *xchg;=0A+ struct xen_add_to_physmap *atp;=0A = struct xen_remove_from_physmap *xrfp;=0A } nat;=0A = union {=0A struct compat_memory_reservation rsrv;=0A = struct compat_memory_exchange xchg;=0A+ struct compat_add_to_p= hysmap atp;=0A } cmp;=0A =0A set_xen_guest_handle(nat.hnd, = COMPAT_ARG_XLAT_VIRT_BASE);=0A@@ -187,6 +189,14 @@ int compat_memory_op(uns= igned int cmd, X=0A nat.hnd =3D compat;=0A = break;=0A =0A+ case XENMEM_add_to_physmap:=0A+ if ( = copy_from_guest(&cmp.atp, compat, 1) )=0A+ return = -EFAULT;=0A+=0A+ XLAT_add_to_physmap(nat.atp, &cmp.atp);=0A+=0A+= break;=0A+=0A case XENMEM_remove_from_physmap:=0A = {=0A struct compat_remove_from_physmap cmp;=0A@@ -315,6 = +325,16 @@ int compat_memory_op(unsigned int cmd, X=0A case = XENMEM_remove_from_physmap:=0A break;=0A =0A+ case = XENMEM_add_to_physmap:=0A+ if ( !rc || cmp.atp.space !=3D = XENMAPSPACE_gmfn_range )=0A+ break;=0A+=0A+ = XLAT_add_to_physmap(&cmp.atp, nat.atp);=0A+ if ( __copy_to_guest= (compat, &cmp.atp, 1) )=0A+ rc =3D -EFAULT;=0A+=0A+ = break;=0A+=0A default:=0A domain_crash(current->doma= in);=0A split =3D 0;=0A--- a/xen/common/memory.c=0A+++ = b/xen/common/memory.c=0A@@ -542,6 +542,53 @@ static long memory_exchange(XE= N_GUEST_HA=0A return rc;=0A }=0A =0A+static int xenmem_add_to_physmap(s= truct domain *d,=0A+ struct xen_add_to_phys= map *xatp)=0A+{=0A+ struct xen_add_to_physmap start_xatp;=0A+ int rc = =3D 0;=0A+=0A+ if ( xatp->space !=3D XENMAPSPACE_gmfn_range )=0A+ = return xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID,=0A+ = xatp->idx, xatp->gpfn);=0A+=0A+#ifdef = HAS_PASSTHROUGH=0A+ if ( need_iommu(d) )=0A+ this_cpu(iommu_dont_= flush_iotlb) =3D 1;=0A+#endif=0A+=0A+ start_xatp =3D *xatp;=0A+ = while ( xatp->size > 0 )=0A+ {=0A+ rc =3D xenmem_add_to_physmap_o= ne(d, xatp->space, DOMID_INVALID,=0A+ = xatp->idx, xatp->gpfn);=0A+ if ( rc < 0 )=0A+ break;=0A+= =0A+ xatp->idx++;=0A+ xatp->gpfn++;=0A+ xatp->size--;= =0A+=0A+ /* Check for continuation if it's not the last iteration. = */=0A+ if ( xatp->size > 0 && hypercall_preempt_check() )=0A+ = {=0A+ rc =3D -EAGAIN;=0A+ break;=0A+ }=0A+ = }=0A+=0A+#ifdef HAS_PASSTHROUGH=0A+ if ( need_iommu(d) )=0A+ {=0A+ = this_cpu(iommu_dont_flush_iotlb) =3D 0;=0A+ iommu_iotlb_flush(= d, start_xatp.idx, start_xatp.size - xatp->size);=0A+ iommu_iotlb_fl= ush(d, start_xatp.gpfn, start_xatp.size - xatp->size);=0A+ }=0A+#endif= =0A+=0A+ return rc;=0A+}=0A+=0A long do_memory_op(unsigned long cmd, = XEN_GUEST_HANDLE_PARAM(void) arg)=0A {=0A struct domain *d;=0A@@ = -673,6 +720,40 @@ long do_memory_op(unsigned long cmd, XEN=0A =0A = break;=0A =0A+ case XENMEM_add_to_physmap:=0A+ {=0A+ struct = xen_add_to_physmap xatp;=0A+=0A+ if ( copy_from_guest(&xatp, arg, = 1) )=0A+ return -EFAULT;=0A+=0A+ d =3D rcu_lock_domain_by= _any_id(xatp.domid);=0A+ if ( d =3D=3D NULL )=0A+ return = -ESRCH;=0A+=0A+ rc =3D xsm_add_to_physmap(XSM_TARGET, current->domai= n, d);=0A+ if ( rc )=0A+ {=0A+ rcu_unlock_domain(d= );=0A+ return rc;=0A+ }=0A+=0A+ rc =3D xenmem_add_= to_physmap(d, &xatp);=0A+=0A+ rcu_unlock_domain(d);=0A+=0A+ = if ( xatp.space =3D=3D XENMAPSPACE_gmfn_range && rc =3D=3D -EAGAIN )=0A+ = {=0A+ if ( !__copy_to_guest(arg, &xatp, 1) )=0A+ = rc =3D hypercall_create_continuation(=0A+ = __HYPERVISOR_memory_op, "ih", op, arg);=0A+ else=0A+ = rc =3D -EFAULT;=0A+ }=0A+=0A+ return rc;=0A+ }=0A+=0A = case XENMEM_remove_from_physmap:=0A {=0A struct xen_remove_= from_physmap xrfp;=0A--- a/xen/include/xen/mm.h=0A+++ b/xen/include/xen/mm.= h=0A@@ -356,6 +356,10 @@ static inline unsigned int get_order_fro=0A =0A = void scrub_one_page(struct page_info *);=0A =0A+int xenmem_add_to_physmap_o= ne(struct domain *d, uint16_t space,=0A+ = domid_t foreign_domid,=0A+ unsigned long idx, = xen_pfn_t gpfn);=0A+=0A /* Returns 1 on success, 0 on error, negative if = the ring=0A * for event propagation is full in the presence of paging = */=0A int guest_remove_page(struct domain *d, unsigned long gmfn);=0A --=__PartCCFF20BA.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartCCFF20BA.2__=--