From: "Jan Beulich" Subject: Re: [PATCH 5/7] mm: New XENMEM space, XENMAPSPACE_gmfn_range Date: Thu, 10 Nov 2011 16:26:39 +0000 Message-ID: <4EBC094F020000780006042E@nat28.tlf.novell.com> References: <4EBBD5F602000078000602EE@nat28.tlf.novell.com> <20111110154410.GN22224@spongy.cam.xci-test.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20111110154410.GN22224@spongy.cam.xci-test.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jean.Guyader@citrix.com, Jean Guyader Cc: George Dunlap , "Keir (Xen.org)" , "xen-devel@lists.xensource.com" , "allen.m.kay@intel.com" , "Tim(Xen.org)" List-Id: xen-devel@lists.xenproject.org >>> On 10.11.11 at 16:44, Jean Guyader wrote: > On 10/11 12:47, Jan Beulich wrote: >> >>> On 10.11.11 at 12:35, Jean Guyader = wrote: >> >@@ -4716,6 +4748,17 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(voi= d)=20 > arg) >> > } >> >=20 >> > rc =3D xenmem_add_to_physmap(d, &xatp); >> >+ if ( rc =3D=3D -EAGAIN ) >>=20 >> if ( rc ) >>=20 >> >+ { >> >+ if ( copy_to_guest(arg, &xatp, 1) ) >> >+ { >> >+ rcu_unlock_domain(d); >> >+ return -EFAULT; >> >+ } >>=20 >> } >> if ( rc =3D=3D -EAGAIN ) >>=20 >> (with some room for further simplification). Without that (or the = minimal >> alternative of copying back just .size or yet some other mechanism), as >> pointed out before, the caller won't have a way to know how far into >> the batch things succeeded. >>=20 >> >+ >> >+ rc =3D hypercall_create_continuation( >> >+ __HYPERVISOR_memory_op, "ih", op, arg); >> >+ } >> >=20 >> > rcu_unlock_domain(d); >>=20 >> Also, the whole block above can be move past this rcu_unlock_domain(), >> eliminating the need to do it separately in the above error path(s). >>=20 >> >=20 >> >--- a/xen/arch/x86/x86_64/compat/mm.c >> >+++ b/xen/arch/x86/x86_64/compat/mm.c >> >@@ -63,6 +63,18 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE(v= oid)=20 > arg) >> >=20 >> > XLAT_add_to_physmap(nat, &cmp); >> > rc =3D arch_memory_op(op, guest_handle_from_ptr(nat, void)); >> >+ if ( rc < 0 ) >> >+ break; >> >+ >>=20 >> With the way the code below is currently this is superfluous. But just >> as above you will need to provide some indication to the caller >> *where* the failure occurred. >>=20 >> >+ if ( rc =3D=3D __HYPERVISOR_memory_op ) >> >+ { >> >+ hypercall_xlat_continuation(NULL, 0x2, nat, arg); >> >+ >> >+ XLAT_add_to_physmap(&cmp, nat); >> >+ >> >+ if ( copy_to_guest(arg, &cmp, 1) ) >> >+ return -EFAULT; >>=20 >> I realize that this is the same way in the code handling >> XENMEM_[gs]et_pod_target, but unfortunately that's wrong (that's >> why I'm copying you, George): Once a continuation was set up, you >> mustn't change the return value anymore, since the continuation was >> established by adjusting the guest's rIP. >>=20 >> As for other memory ops, the continuation can be encoded in "op" (see >> xen/common/memory.c and xen/common/compat/memory.c). However, >> while suitable here I don't think that's usable for the PoD variant. = The >> alternative is to cancel the continuation (would require quite a bit of >> new code I think) or to adjust the low level hypercall handler code (at >> least the compat mode one) to special case rAX values in the negative >> errno range, leaving rAX unchanged instead of returning -ENOSYS. >> Keir? >>=20 >=20 > Jan, did you have something like the attached patch in mind? Indeed, and it's fortunately much simpler than I would have thought. > We will return EFAULT to the hypercall without touching the guest memory > because the copy_to_guest failed. >=20 > For the example I ignored the multicalls. Adding the support for that would seem to be strait forward too. Jan