From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keir Fraser Subject: Re: Foreign VCPU register change? Date: Thu, 23 Aug 2012 18:54:54 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8018410164680552582==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Cutter 409 , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --===============8018410164680552582== Content-type: multipart/alternative; boundary="B_3428592896_124067349" > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3428592896_124067349 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable So, for example, one possibly-valid scheme would be: - vcpu_pause_nosync() from the vmexit handler - vcpu_sleep_sync() at the start of the domctl - vcpu_unpause() at the end of the domctl HTH, Keir On 23/08/2012 18:49, "Keir Fraser" wrote: > FWIW I would expect your approach to basically work. >=20 > Except... Does your domctl do a vcpu_pause()/vcpu_unpause() on the vcpu? = This > will ensure that the vcpu is both fully de-scheduled, and all of its regi= ster > state is synced back into its vcpu structure. >=20 > Otherwise you race the vcpu_sleep_nosync() -- and that=B9s assuming you als= o > have a reason for that vcpu to sleep (e.g., non-zero pause counter), else > vcpu_sleep_*() operations do nothing! >=20 > In short, your problems are almost certainly something to do with the > subtleties of actually putting a vcpu properly to sleep. >=20 > -- Keir >=20 >=20 > On 23/08/2012 18:37, "Cutter 409" wrote: >=20 >> I'm making the register change directly from the hypervisor, inside of t= he >> domctl code.=20 >>=20 >> It's a custom domctl that I've added. I'll look into what setcontext doe= s >> after it modifies the register values, though. >>=20 >> Thank you! >>=20 >> On Thu, Aug 23, 2012 at 1:34 PM, Keir Fraser wrote: >>> On 23/08/2012 18:25, "Cutter 409" wrote: >>>=20 >>>> > With Xen-4.1.2: >>>> > >>>> > I'm trying to change a register value in a paused vmx vcpu. The gene= ral >>>> > process looks like this: >>>> > >>>> > 1. Some vmexit calls vcpu_sleep_nosync(v) on the vcpu >>>> > 2. From dom0, I issue a domctl to change a register via >>>> > v->arch.guest_context.user_reg, then vcpu_wake(v) >>>=20 >>> Which domctl? From dom0 userspace you can use the libxc functions >>> xc_vcpu_getcontext() and xc_vcpu_setcontext() to read/modify register s= tate. >>>=20 >>> You can read the libxc sources to see what hypercall these map to, if y= ou >>> don't want to use libxc for any reason. >>>=20 >>> =A0-- Keir >>>=20 >>>> > However, the guest register does not seem to be changed when I do it= this >>>> way. >>>> > Is there something I need to do to mark the registers as "dirty" ? I= s >>>> there a >>>> > way to force the foreign vcpu to update the changed registers? Or ma= ybe I >>>> just >>>> > have to change the registers somewhere else? >>>> > >>>> > I've tried directly using vmcs_enter(v), __vmwrite(), vmcs_exit(v) a= lso, >>>> but >>>> > that doesn't seem to make a change either. >>>> > >>>> > Thanks! >>>> > >>>> > >>>> > >>>> > _______________________________________________ >>>> > Xen-devel mailing list >>>> > Xen-devel@lists.xen.org >>>> > http://lists.xen.org/xen-devel >>>=20 >>>=20 >>=20 >>=20 >>=20 >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@lists.xen.org >> http://lists.xen.org/xen-devel >=20 --B_3428592896_124067349 Content-type: text/html; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable Re: [Xen-devel] Foreign VCPU register change? So, for example, one possibly-valid scheme would be:

 - vcpu_pause_nosync() from the vmexit handler

 - vcpu_sleep_sync() at the start of the domctl
 - vcpu_unpause() at the end of the domctl

HTH,
 Keir


On 23/08/2012 18:49, "Keir Fraser" <keir.xen@gmail.com> wrote:

<= SPAN STYLE=3D'font-size:11pt'>FWIW I would expect your approach to basically w= ork.

Except... Does your domctl do a vcpu_pause()/vcpu_unpause() on the vcpu? Th= is will ensure that the vcpu is both fully de-scheduled, and all of its regi= ster state is synced back into its vcpu structure.

Otherwise you race the vcpu_sleep_nosync() -- and that’s assuming you= also have a reason for that vcpu to sleep (e.g., non-zero pause counter), e= lse vcpu_sleep_*() operations do nothing!

In short, your problems are almost certainly something to do with the subtl= eties of actually putting a vcpu properly to sleep.

 -- Keir


On 23/08/2012 18:37, "Cutter 409" <cutter409@gmail.com> wrote:

<= SPAN STYLE=3D'font-size:11pt'>I'm making the register change directly from the= hypervisor, inside of the domctl code.

It's a custom domctl that I've added. I'll look into what setcontext does a= fter it modifies the register values, though.

Thank you!

On Thu, Aug 23, 2012 at 1:34 PM, Keir Fraser <keir.xen@gmail.com> wrote:
<= SPAN STYLE=3D'font-size:11pt'>On 23/08/2012 18:25, "Cutter 409" <= cutter409@gmail.com> wrote:

> With Xen-4.1.2:
>
> I'm trying to change a register value in a paused vmx vcpu. The genera= l
> process looks like this:
>
> 1. Some vmexit calls vcpu_sleep_nosync(v) on the vcpu
> 2. From dom0, I issue a domctl to change a register via
> v->arch.guest_context.user_reg, then vcpu_wake(v)

Which domctl? From dom0 userspace you can use the libxc functions
xc_vcpu_getcontext() and xc_vcpu_setcontext() to read/modify register state= .

You can read the libxc sources to see what hypercall these map to, if you don't want to use libxc for any reason.

=A0-- Keir

> However, the guest register does not seem to be changed when I do it t= his way.
> Is there something I need to do to mark the registers as "dirty&q= uot; ? Is there a
> way to force the foreign vcpu to update the changed registers? Or mayb= e I just
> have to change the registers somewhere else?
>
> I've tried directly using vmcs_enter(v), __vmwrite(), vmcs_exit(v) als= o, but
> that doesn't seem to make a change either.
>
> Thanks!
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-deve= l


=


___________= ____________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel=

--B_3428592896_124067349-- --===============8018410164680552582== 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 --===============8018410164680552582==--