From: "Jan Beulich" Subject: [PATCH v2 4/4] fix XENMEM_add_to_physmap_range preemption handling Date: Fri, 20 Dec 2013 08:30:37 +0000 Message-ID: <52B40E3D020000780010F613@nat28.tlf.novell.com> References: <52B1BF76020000780010EC02@nat28.tlf.novell.com> <52B40C69020000780010F5F6@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB380583D.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VtvTl-0004Kk-5E for xen-devel@lists.xenproject.org; Fri, 20 Dec 2013 08:30:41 +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. --=__PartB380583D.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself). Signed-off-by: Jan Beulich Reviewed-by: Tim Deegan Acked-by: Keir Fraser --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct=20 } =20 static int xenmem_add_to_physmap_range(struct domain *d, - struct xen_add_to_physmap_range = *xatpr) + struct xen_add_to_physmap_range = *xatpr, + unsigned int start) { + unsigned int done =3D 0; int rc; =20 - while ( xatpr->size > 0 ) + if ( xatpr->size < start ) + return -EILSEQ; + + guest_handle_add_offset(xatpr->idxs, start); + guest_handle_add_offset(xatpr->gpfns, start); + guest_handle_add_offset(xatpr->errs, start); + xatpr->size -=3D start; + + while ( xatpr->size > done ) { xen_ulong_t idx; xen_pfn_t gpfn; @@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_range(s guest_handle_add_offset(xatpr->idxs, 1); guest_handle_add_offset(xatpr->gpfns, 1); guest_handle_add_offset(xatpr->errs, 1); - xatpr->size--; =20 /* Check for continuation if it's not the last iteration. */ - if ( xatpr->size > 0 && hypercall_preempt_check() ) + if ( xatpr->size > ++done && hypercall_preempt_check() ) { - rc =3D -EAGAIN; + rc =3D start + done; goto out; } } @@ -816,6 +825,13 @@ long do_memory_op(unsigned long cmd, XEN struct xen_add_to_physmap_range xatpr; struct domain *d; =20 + BUILD_BUG_ON((typeof(xatpr.size))-1 > + (UINT_MAX >> MEMOP_EXTENT_SHIFT)); + + /* Check for faked input. */ + if ( start_extent !=3D (typeof(xatpr.size))start_extent ) + return -EDOM; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) || @@ -837,18 +853,14 @@ long do_memory_op(unsigned long cmd, XEN return rc; } =20 - rc =3D xenmem_add_to_physmap_range(d, &xatpr); + rc =3D xenmem_add_to_physmap_range(d, &xatpr, start_extent); =20 rcu_unlock_domain(d); =20 - if ( rc =3D=3D -EAGAIN ) - { - if ( !__copy_to_guest(arg, &xatpr, 1) ) - rc =3D hypercall_create_continuation( - __HYPERVISOR_memory_op, "ih", op, arg); - else - rc =3D -EFAULT; - } + if ( rc > 0 ) + rc =3D hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", + op | (rc << MEMOP_EXTENT_SHIFT), arg); =20 return rc; } --=__PartB380583D.2__= Content-Type: text/plain; name="xatpr-preemption.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xatpr-preemption.patch" fix XENMEM_add_to_physmap_range preemption handling=0A=0AJust like for all = other hypercalls we shouldn't be modifying the input=0Astructure - all of = the fields are, even if not explicitly documented,=0Ajust inputs (the one = OUT one really refers to the memory pointed to by=0Athat handle rather = than the handle itself).=0A=0ASigned-off-by: Jan Beulich =0AReviewed-by: Tim Deegan =0AAcked-by: Keir Fraser = =0A=0A--- a/xen/common/memory.c=0A+++ b/xen/common/memory.c= =0A@@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct =0A }=0A = =0A static int xenmem_add_to_physmap_range(struct domain *d,=0A- = struct xen_add_to_physmap_range *xatpr)=0A+ = struct xen_add_to_physmap_range = *xatpr,=0A+ unsigned int start)=0A = {=0A+ unsigned int done =3D 0;=0A int rc;=0A =0A- while ( = xatpr->size > 0 )=0A+ if ( xatpr->size < start )=0A+ return = -EILSEQ;=0A+=0A+ guest_handle_add_offset(xatpr->idxs, start);=0A+ = guest_handle_add_offset(xatpr->gpfns, start);=0A+ guest_handle_add_offse= t(xatpr->errs, start);=0A+ xatpr->size -=3D start;=0A+=0A+ while ( = xatpr->size > done )=0A {=0A xen_ulong_t idx;=0A = xen_pfn_t gpfn;=0A@@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_ra= nge(s=0A guest_handle_add_offset(xatpr->idxs, 1);=0A = guest_handle_add_offset(xatpr->gpfns, 1);=0A guest_handle_add_offse= t(xatpr->errs, 1);=0A- xatpr->size--;=0A =0A /* Check for = continuation if it's not the last iteration. */=0A- if ( xatpr->size= > 0 && hypercall_preempt_check() )=0A+ if ( xatpr->size > ++done = && hypercall_preempt_check() )=0A {=0A- rc =3D = -EAGAIN;=0A+ rc =3D start + done;=0A goto out;=0A = }=0A }=0A@@ -816,6 +825,13 @@ long do_memory_op(unsigned long = cmd, XEN=0A struct xen_add_to_physmap_range xatpr;=0A = struct domain *d;=0A =0A+ BUILD_BUG_ON((typeof(xatpr.size))-1 >=0A+ = (UINT_MAX >> MEMOP_EXTENT_SHIFT));=0A+=0A+ /* = Check for faked input. */=0A+ if ( start_extent !=3D (typeof(xatpr.s= ize))start_extent )=0A+ return -EDOM;=0A+=0A if ( = copy_from_guest(&xatpr, arg, 1) ||=0A !guest_handle_okay(xatpr= .idxs, xatpr.size) ||=0A !guest_handle_okay(xatpr.gpfns, = xatpr.size) ||=0A@@ -837,18 +853,14 @@ long do_memory_op(unsigned long = cmd, XEN=0A return rc;=0A }=0A =0A- rc =3D = xenmem_add_to_physmap_range(d, &xatpr);=0A+ rc =3D xenmem_add_to_phy= smap_range(d, &xatpr, start_extent);=0A =0A rcu_unlock_domain(d);= =0A =0A- if ( rc =3D=3D -EAGAIN )=0A- {=0A- if ( = !__copy_to_guest(arg, &xatpr, 1) )=0A- rc =3D hypercall_crea= te_continuation(=0A- __HYPERVISOR_memory_op, "ih", op, = arg);=0A- else=0A- rc =3D -EFAULT;=0A- = }=0A+ if ( rc > 0 )=0A+ rc =3D hypercall_create_continuat= ion(=0A+ __HYPERVISOR_memory_op, "lh",=0A+ = op | (rc << MEMOP_EXTENT_SHIFT), arg);=0A =0A return rc;=0A = }=0A --=__PartB380583D.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 --=__PartB380583D.2__=--