From: Jean Guyader Subject: Re: [PATCH 5/7] mm: New XENMEM space, XENMAPSPACE_gmfn_range Date: Thu, 10 Nov 2011 15:44:10 +0000 Message-ID: <20111110154410.GN22224@spongy.cam.xci-test.com> References: <4EBBD5F602000078000602EE@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="raC6veAxrt5nqIoY" Return-path: Content-Disposition: inline In-Reply-To: <4EBBD5F602000078000602EE@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jan Beulich Cc: "xen-devel@lists.xensource.com" , "Keir (Xen.org)" , George Dunlap , "Tim (Xen.org)" , "allen.m.kay@intel.com" , Jean Guyader List-Id: xen-devel@lists.xenproject.org --raC6veAxrt5nqIoY Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline 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(void) arg) > > } > > > > rc = xenmem_add_to_physmap(d, &xatp); > >+ if ( rc == -EAGAIN ) > > if ( rc ) > > >+ { > >+ if ( copy_to_guest(arg, &xatp, 1) ) > >+ { > >+ rcu_unlock_domain(d); > >+ return -EFAULT; > >+ } > > } > if ( rc == -EAGAIN ) > > (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. > > >+ > >+ rc = hypercall_create_continuation( > >+ __HYPERVISOR_memory_op, "ih", op, arg); > >+ } > > > > rcu_unlock_domain(d); > > 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). > > > > >--- 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(void) arg) > > > > XLAT_add_to_physmap(nat, &cmp); > > rc = arch_memory_op(op, guest_handle_from_ptr(nat, void)); > >+ if ( rc < 0 ) > >+ break; > >+ > > 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. > > >+ if ( rc == __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; > > 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. > > 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? > Jan, did you have something like the attached patch in mind? We will return EFAULT to the hypercall without touching the guest memory because the copy_to_guest failed. For the example I ignored the multicalls. Jean --raC6veAxrt5nqIoY Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="hypercall-cancel-continuation.patch" diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 52c7f37..6b3620b 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1723,6 +1723,16 @@ void sync_vcpu_execstate(struct vcpu *v) __arg; \ }) +void hypercall_cancel_continuation(void) +{ + struct cpu_user_regs *regs = guest_cpu_user_regs(); + + if ( !is_hvm_vcpu(current) ) + regs->eip += 2; /* skip re-execute 'syscall' / 'int $xx' */ + else + current->arch.hvm_vcpu.hcall_preempted = 0; +} + unsigned long hypercall_create_continuation( unsigned int op, const char *format, ...) { diff --git a/xen/arch/x86/x86_64/compat/mm.c b/xen/arch/x86/x86_64/compat/mm.c index 2c05099..577da6a 100644 --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -133,7 +133,10 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) XLAT_pod_target(&cmp, nat); if ( copy_to_guest(arg, &cmp, 1) ) + { + hypercall_cancel_continuation(); rc = -EFAULT; + } break; } diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3ba5495..80d5c4b 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -554,6 +554,7 @@ extern void (*dead_idle) (void); */ unsigned long hypercall_create_continuation( unsigned int op, const char *format, ...); +void hypercall_cancel_continuation(void); #define hypercall_preempt_check() (unlikely( \ softirq_pending(smp_processor_id()) | \ --raC6veAxrt5nqIoY 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.xensource.com http://lists.xensource.com/xen-devel --raC6veAxrt5nqIoY--