From: "Jan Beulich" Subject: [PATCH 3/3] domctl: pause vCPU for context reads Date: Wed, 05 Feb 2014 14:54:31 +0000 Message-ID: <52F25EB702000078001196EC@nat28.tlf.novell.com> References: <52F25D4202000078001196AB@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2F1C82B7.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WB3s2-0006uw-Ld for xen-devel@lists.xenproject.org; Wed, 05 Feb 2014 14:54:34 +0000 In-Reply-To: <52F25D4202000078001196AB@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: George Dunlap , Keir Fraser 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. --=__Part2F1C82B7.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline "Base" context reads already paused the subject vCPU when being the current one, but that special case isn't being properly dealt with anyway (at the very least when x86's fsgsbase feature is in use), so just disallow it. "Extended" context reads so far didn't do any pausing. While we can't avoid the reported data being stale by the time it arrives at the caller, this way we at least guarantee that it is consistent. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -819,7 +819,13 @@ long arch_do_domctl( =20 if ( domctl->cmd =3D=3D XEN_DOMCTL_get_ext_vcpucontext ) { + if ( v =3D=3D current ) /* no vcpu_pause() */ + break; + evc->size =3D sizeof(*evc); + + vcpu_pause(v); + if ( is_pv_domain(d) ) { evc->sysenter_callback_cs =3D @@ -849,6 +855,7 @@ long arch_do_domctl( evc->vmce.mci_ctl2_bank1 =3D v->arch.vmce.bank[1].mci_ctl2; =20 ret =3D 0; + vcpu_unpause(v); copyback =3D 1; } else --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -675,11 +675,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe struct vcpu *v; =20 ret =3D -EINVAL; - if ( op->u.vcpucontext.vcpu >=3D d->max_vcpus ) - goto getvcpucontext_out; - - ret =3D -ESRCH; - if ( (v =3D d->vcpu[op->u.vcpucontext.vcpu]) =3D=3D NULL ) + if ( op->u.vcpucontext.vcpu >=3D d->max_vcpus || + (v =3D d->vcpu[op->u.vcpucontext.vcpu]) =3D=3D NULL || + v =3D=3D current ) /* no vcpu_pause() */ goto getvcpucontext_out; =20 ret =3D -ENODATA; @@ -694,14 +692,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe if ( (c.nat =3D xmalloc(struct vcpu_guest_context)) =3D=3D NULL ) goto getvcpucontext_out; =20 - if ( v !=3D current ) - vcpu_pause(v); + vcpu_pause(v); =20 arch_get_info_guest(v, c); ret =3D 0; =20 - if ( v !=3D current ) - vcpu_unpause(v); + vcpu_unpause(v); =20 #ifdef CONFIG_COMPAT if ( !is_pv_32on64_vcpu(v) ) --=__Part2F1C82B7.1__= Content-Type: text/plain; name="vcpu-get-context-pause.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vcpu-get-context-pause.patch" domctl: pause vCPU for context reads=0A=0A"Base" context reads already = paused the subject vCPU when being the=0Acurrent one, but that special = case isn't being properly dealt with=0Aanyway (at the very least when = x86's fsgsbase feature is in use), so=0Ajust disallow it.=0A=0A"Extended" = context reads so far didn't do any pausing.=0A=0AWhile we can't avoid the = reported data being stale by the time it=0Aarrives at the caller, this way = we at least guarantee that it is=0Aconsistent.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/arch/x86/domctl.c=0A+++ = b/xen/arch/x86/domctl.c=0A@@ -819,7 +819,13 @@ long arch_do_domctl(=0A =0A = if ( domctl->cmd =3D=3D XEN_DOMCTL_get_ext_vcpucontext )=0A = {=0A+ if ( v =3D=3D current ) /* no vcpu_pause() */=0A+ = break;=0A+=0A evc->size =3D sizeof(*evc);=0A+=0A+ = vcpu_pause(v);=0A+=0A if ( is_pv_domain(d) )=0A = {=0A evc->sysenter_callback_cs =3D=0A@@ -849,6 = +855,7 @@ long arch_do_domctl(=0A evc->vmce.mci_ctl2_bank1 =3D = v->arch.vmce.bank[1].mci_ctl2;=0A =0A ret =3D 0;=0A+ = vcpu_unpause(v);=0A copyback =3D 1;=0A }=0A = else=0A--- a/xen/common/domctl.c=0A+++ b/xen/common/domctl.c=0A@@ -675,11 = +675,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe=0A struct vcpu = *v;=0A =0A ret =3D -EINVAL;=0A- if ( op->u.vcpucontex= t.vcpu >=3D d->max_vcpus )=0A- goto getvcpucontext_out;=0A-=0A- = ret =3D -ESRCH;=0A- if ( (v =3D d->vcpu[op->u.vcpucontext.vcp= u]) =3D=3D NULL )=0A+ if ( op->u.vcpucontext.vcpu >=3D d->max_vcpus = ||=0A+ (v =3D d->vcpu[op->u.vcpucontext.vcpu]) =3D=3D NULL = ||=0A+ v =3D=3D current ) /* no vcpu_pause() */=0A = goto getvcpucontext_out;=0A =0A ret =3D -ENODATA;=0A@@ -694,14 = +692,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe=0A if ( (c.nat = =3D xmalloc(struct vcpu_guest_context)) =3D=3D NULL )=0A goto = getvcpucontext_out;=0A =0A- if ( v !=3D current )=0A- = vcpu_pause(v);=0A+ vcpu_pause(v);=0A =0A arch_get_info_guest= (v, c);=0A ret =3D 0;=0A =0A- if ( v !=3D current )=0A- = vcpu_unpause(v);=0A+ vcpu_unpause(v);=0A =0A #ifdef = CONFIG_COMPAT=0A if ( !is_pv_32on64_vcpu(v) )=0A --=__Part2F1C82B7.1__= 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 --=__Part2F1C82B7.1__=--