From: "Kamble, Nitin A" Subject: Re: [PATCH][RFC] Emulating real mode with x86_emulate Date: Fri, 30 Mar 2007 11:53:01 -0700 Message-ID: <1175280781.32115.13.camel@lnitindesktop.sc.intel.com> References: <4607074E.1030807@us.ibm.com> <1175203075.27076.17.camel@lnitindesktop.sc.intel.com> <460C4AAE.5020707@us.ibm.com> <1175212362.27076.32.camel@lnitindesktop.sc.intel.com> <460C55BD.5050202@us.ibm.com> <1175216381.27076.39.camel@lnitindesktop.sc.intel.com> <1175221214.27076.43.camel@lnitindesktop.sc.intel.com> <460C8207.8000604@us.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1153693488==" Return-path: Content-class: urn:content-classes:message In-Reply-To: <460C8207.8000604@us.ibm.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Anthony Liguori Cc: "Yu, Wilfred" , xen-devel@lists.xensource.com, Keir Fraser , "Nakajima, Jun" List-Id: xen-devel@lists.xenproject.org --===============1153693488== Content-Type: multipart/signed; boundary="=-Z7YCJFSn2dbNyt3U0hiM"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-class: urn:content-classes:message --=-Z7YCJFSn2dbNyt3U0hiM Content-Type: multipart/alternative; boundary="=-l818IGBd2Ik8imTBSyPs" --=-l818IGBd2Ik8imTBSyPs Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 2007-03-29 at 22:20 -0500, Anthony Liguori wrote: > > ... =20 > > (XEN) hvm.c:446:d2 Triple fault on VCPU0 - invoking HVM system reset. >=20 > The Triple fault you're seeing here is terribly curious. Also the=20 > "deadbeef" output. Just to sanity check, I threw the following printk=20 > in vmcs.c >=20 Anthony, To me the tripple fault makes sense.=20 Your patch enables emulation only when "emulating" is set to 1. void arch_vmx_do_resume(struct vcpu *v) { if ( v->arch.hvm_vmx.active_cpu =3D=3D smp_processor_id() ) @@ -508,7 +644,11 @@ void arch_vmx_do_resume(struct vcpu *v) } =20 hvm_do_resume(v); - reset_stack_and_jump(vmx_asm_do_vmentry); + + if (v->arch.hvm_vmx.emulating) + vmx_do_emulate(v); + else + reset_stack_and_jump(vmx_asm_do_vmentry); } And it is turned on only when guest (hvmloader) sets up CR0. -static int vmx_set_cr0(unsigned long value) +int vmx_set_cr0(unsigned long value) { struct vcpu *v =3D current; unsigned long mfn; @@ -1982,13 +1982,29 @@ static int vmx_set_cr0(unsigned long val } } - if ( vmx_assist(v, VMX_ASSIST_INVOKE) ) + if ( v->arch.hvm_vcpu.emulate_realmode ) + { + eip =3D __vmread(GUEST_RIP); + HVM_DBG_LOG(DBG_LEVEL_1, + "Transfering control to x86_emulate %%eip 0x%lx \n", eip); + v->arch.hvm_vmx.emulating =3D 1; + return 1; + } + else if ( vmx_assist(v, VMX_ASSIST_INVOKE) ) { And I don't see any code in the hvmloader for setting cr0 before returning from the main. So the code flow is returning from main, which is causing the tripple fault. I observe the vmx_do_emulate is never getting called. I think set cr0 instruction is needed just after the emulate_realmode hypercall in the hvmloader code. Have you added more code lateron after sending the patch out? Thanks & Regards, Nitin=20 Open Source Technology Center, Intel Corporation. ------------------------------------------------------------------------- The mind is like a parachute; it works much better when it's open.=20 > while (!hypercall_preempt_check()) { > + printk("eip =3D 0x%x\n", regs->eip); > if (x86_emulate(&ctxt, &em_ops)) { >=20 > And I get the following output with a FC5 guest: >=20 > (XEN)=20 > hvmop_emulate_realmode =20 > (XEN) guest requests real mode=20 > emulation =20 > (XEN) foo=20 > 221 =20 > (XEN) eip =3D=20 > 0xd338d =20 > (XEN) eip =3D=20 > 0xd338e =20 > (XEN) eip =3D=20 > 0xffbf0000 =20 > (XEN) failed to emulate instruction at %eip =3D=20 > 0xd338d =20 > (XEN) domain_crash_sync called from=20 > vmcs.c:625 =20 > (XEN) Domain 1 (vcpu#0) crashed on=20 > cpu#0: =20 > (XEN) ----[ Xen-3.0-unstable x86_32 debug=3Dn Not tainted=20 > ]---- =20 > (XEN) CPU: =20 > 0 =20 > (XEN) EIP: =20 > 0010:[<000d338d>] =20 > (XEN) EFLAGS: 00000002 CONTEXT:=20 > hvm =20 > (XEN) eax: 00000076 ebx: 000d7324 ecx: 000d7324 edx:=20 > 000000e9 =20 > (XEN) esi: 000d4e54 edi: 000d3380 ebp: 000d72a8 esp:=20 > 000d72a8 =20 > (XEN) cr0: 00050032 cr4: 00000651 cr3: 00000000 cr2:=20 > 00000000 =20 > (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: 0018 cs: 0010 =20 >=20 > So, perhaps it's the guest you're using? Clearly, we're running in=20 > x86_emulate and hitting a 16 bit instruction we can't handle. N.B. the=20 > printk in the error path for x86_emulate is wrong. I should be looking=20 > at regs->eip, not GUEST_RIP since that wouldn't have been updated again. >=20 > Regards, >=20 > Anthony Liguori --=-l818IGBd2Ik8imTBSyPs Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, 2007-03-29 at 22:20 -0500, Anthony Liguori wrote:
> ...                                           =
    
> (XEN) hvm.c:446:d2 Triple fault on VCPU0 - inv=
oking HVM system reset.

The Triple fault you're seeing here is terribly cur=
ious.  Also the 
"deadbeef" output.  Just to sanity check,=
 I threw the following printk 
in vmcs.c


Anthony,
  To me the tripple fault makes sense.

Your patch enables emulation only when "emulating" is set to 1.

void arch_vmx_do_resume(struct vcpu *v)
{
     if ( v->arch.hvm_vmx.active_cpu =3D=3D smp_proc= essor_id() )
@@ -508,7 +644,11 @@ void arch_vmx_do_resume(struct vcpu *v)
     }

     hvm_do_resume(v);
-    reset_stack_and_jump(vmx_asm_do_vmentry);
+
+    if (v->arch.hvm_vmx.emulating)
+        vmx_do_emulate(v);
+    else
+        reset_stack_and_jump(vmx_asm_do= _vmentry);
}


And it is turned on only when guest (hvmloader) sets up CR0.

-static int vmx_set_cr0(unsigned long value)
+int vmx_set_cr0(unsigned long value)
{
     struct vcpu *v =3D current;
     unsigned long mfn;
@@ -1982,13 +1982,29 @@ static int vmx_set_cr0(unsigned long val
             }<= BR>          }

-        if ( vmx_assist(v, VMX_ASSIST_I= NVOKE) )
+        if ( v->arch.hvm_vcpu.emulat= e_realmode )
+        {
+            eip =3D= __vmread(GUEST_RIP);
+            HVM_DBG= _LOG(DBG_LEVEL_1,
+            &n= bsp;           "Tran= sfering control to x86_emulate %%eip 0x%lx\n", eip);
+            v->a= rch.hvm_vmx.emulating =3D 1;
+            return = 1;
+        }
+        else if ( vmx_assist(v, VMX_ASS= IST_INVOKE) )
         {

And I don't see any code in the hvmloader for setting cr0 before returning = from the main.

So the code flow is returning from main, which is causing the tripple fault= .

I observe the vmx_do_emulate is never getting called.

I think set cr0 instruction is needed just after the emulate_realmode hyper= call in the hvmloader code.

Have you added more code lateron after sending the patch out?

Thanks & Regards,
Nitin
Open Source Technology Center, Int= el Corporation.
----------------------------------= ---------------------------------------
The mind is like a parachute; it w= orks much better when it's open.=20


     while (!hypercall_preempt_check()) {
+        printk("eip =3D 0x%x\n", regs-&g=
t;eip);
         if (x86_emulate(&ctxt, &em_ops)) {=


And I get the following output with a FC5 guest:

(XEN) 
hvmop_emulate_realmode                             =
                      
(XEN) guest requests real mode 
emulation                                       
(XEN) foo 
221                                                =
                  
(XEN) eip =3D 
0xd338d                                            =
                
(XEN) eip =3D 
0xd338e                                            =
                
(XEN) eip =3D 
0xffbf0000                                         =
                
(XEN) failed to emulate instruction at %eip =3D 
0xd338d                          
(XEN) domain_crash_sync called from 
vmcs.c:625                                 
(XEN) Domain 1 (vcpu#0) crashed on 
cpu#0:                                      
(XEN) ----[ Xen-3.0-unstable  x86_32  debug=3Dn  No=
t tainted 
]----               
(XEN) CPU:    
0                                                  =
              
(XEN) EIP:    
0010:[<000d338d>]                            =
                    
(XEN) EFLAGS: 00000002   CONTEXT: 
hvm                                          
(XEN) eax: 00000076   ebx: 000d7324   ecx: 000d7324=
   edx: 
000000e9            
(XEN) esi: 000d4e54   edi: 000d3380   ebp: 000d72a8=
   esp: 
000d72a8            
(XEN) cr0: 00050032   cr4: 00000651   cr3: 00000000=
   cr2: 
00000000            
(XEN) ds: 0000   es: 0000   fs: 0000   gs: 0000   s=
s: 0018   cs: 0010   

So, perhaps it's the guest you're using?  Clearly, =
we're running in 
x86_emulate and hitting a 16 bit instruction we can=
't handle.  N.B. the 
printk in the error path for x86_emulate is wrong. =
 I should be looking 
at regs->eip, not GUEST_RIP since that wouldn't =
have been updated again.

Regards,

Anthony Liguori

--=-l818IGBd2Ik8imTBSyPs-- --=-Z7YCJFSn2dbNyt3U0hiM Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBGDVyNZ1sfU7kTCR8RAnVeAJ9ERSNhpgoAcMpvHW6VUfk5j4mKyACePl5g OYttSFsBJDkgIyCCRTo5YeU= =jZWR -----END PGP SIGNATURE----- --=-Z7YCJFSn2dbNyt3U0hiM-- --===============1153693488== 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 --===============1153693488==--