From: "Kamble, Nitin A" Subject: Re: [PATCH][RFC] Emulating real mode with x86_emulate Date: Thu, 29 Mar 2007 14:17:55 -0700 Message-ID: <1175203075.27076.17.camel@lnitindesktop.sc.intel.com> References: <4607074E.1030807@us.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0859694023==" Return-path: Content-class: urn:content-classes:message In-Reply-To: <4607074E.1030807@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 --===============0859694023== Content-Type: multipart/signed; boundary="=-MlUu6QCT3GcfubhjksnE"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-class: urn:content-classes:message --=-MlUu6QCT3GcfubhjksnE Content-Type: multipart/alternative; boundary="=-xRnzlvB56UBj5KEYrtz4" --=-xRnzlvB56UBj5KEYrtz4 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi Anthony, I tried your patch at my end with snapshot of xen-unstable on 20070326. And here are my findings. - The --emulate-16bit option for qemu did not work. qemu is not accepting this as an valid command line option. - I tried hardcoding this to 1 in the qemu code, and found that the port x595 is not reflecting it correctly to hvmloader. - Then I tried forcing in the hvmloader to use the emulator instead of vmxassit, and I see the the emulator is not getting the right context. Following is the console log at this point. (XEN) HVM3: HVM Loader =20 (XEN) HVM3: Detected Xen v3.0-unstable =20 (XEN) HVM3: Writing SMBIOS tables ... =20 (XEN) HVM3: Loading ROMBIOS ... =20 (XEN) irq.c:210: Dom3 PCI link 0 changed 0 -> 5 =20 (XEN) HVM3: PCI-ISA link 0 routed to IRQ5 =20 (XEN) irq.c:210: Dom3 PCI link 1 changed 0 -> 7 =20 (XEN) HVM3: PCI-ISA link 1 routed to IRQ7 =20 (XEN) irq.c:210: Dom3 PCI link 2 changed 0 -> 10 =20 (XEN) HVM3: PCI-ISA link 2 routed to IRQ10 =20 (XEN) irq.c:210: Dom3 PCI link 3 changed 0 -> 11 =20 (XEN) HVM3: PCI-ISA link 3 routed to IRQ11 =20 (XEN) HVM3: pci dev 01:1 bar 20 size 00000010: 0000c001 =20 (XEN) HVM3: pci dev 01:2 INTA->IRQ7 =20 (XEN) HVM3: pci dev 02:0 bar 10 size 02000000: f0000008 =20 (XEN) HVM3: pci dev 02:0 bar 14 size 00001000: f2000000 =20 (XEN) HVM3: pci dev 03:0 bar 10 size 00000100: 0000c101 =20 (XEN) HVM3: pci dev 03:0 bar 14 size 01000000: f3000008 =20 (XEN) HVM3: pci dev 03:0 INTA->IRQ11 =20 (XEN) HVM3: pci dev 04:0 bar 10 size 00000100: 0000c201 =20 (XEN) HVM3: pci dev 04:0 bar 14 size 00000100: f4000000 =20 (XEN) HVM3: pci dev 04:0 INTA->IRQ5 =20 (XEN) HVM3: Creating MP tables ... =20 (XEN) HVM3: Loading Cirrus VGABIOS ... =20 (XEN) HVM3: Loading ACPI ... =20 (XEN) HVM3: Not Loading VMXAssist ... ffffffff =20 (XEN) HVM3: foo =20 (XEN) hvmop_emulate_realmode =20 (XEN) guest requests real mode emulation =20 (XEN) foo 221 =20 (XEN) HVM3: Invoking ROMBIOS ... =20 (XEN) Transfering control to x86_emulate %eip 0x0 =20 (XEN) hvm.c:446:d3 Triple fault on VCPU0 - invoking HVM system reset. =20 The log shows that emulator is not getting the right cpu context.=20 How much of testing have you done with this code? I am not able to proceed to emulation of 1 instruction with the patch. How many instruction could you emulate with the patch? 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 On Sun, 2007-03-25 at 16:35 -0700, Anthony Liguori wrote: > Howdy, >=20 > Attached is a patch that begins to lay down the infrastructure for > emulating real mode with x86_emulate(). With a little more > refactoring, > I think it could also replace the SVM emulator. >=20 > The patch introduces an HVMOP hypercall to set a flag in the hvm vcpu > struct to signal that real mode should be emulated with x86_emulate > instead of using vm86. This is to make development a little bit > easier > since x86_emulate is not quite there yet wrt 16 bit emulation. It can > be enabled by passing -emulate-16bit to qemu-dm (I use a wrapper > script > similar to qemu-dm.debug). >=20 > The VT code keeps track of the whether it's in the emulator and loops > on > the do_resume path in x86_emulate. I think this code probably should > be > refactored into the common HVM code although this would require > changing > some of the HVM ops. This would allow SVM to use the x86_emulate to > handle individual instructions. >=20 > There are some issues to work out. Namely, x86_emulate appears to > want > blocking PIO calls which isn't conducive to the wait PIO works today > in > HVM. This is only a problem for instructions at the moment. I'm also > a > bit confused about how to properly loop in the emulator. > schedule_tail > is not meant to return so perhaps we should loop on emulating =3D=3D 1 > instead of hypercall_preempt_check? I didn't think the hypervisor was > preemptable though. >=20 > The current code doesn't handle non-flat segments as I don't think > hvm_copy_from/to_guest handles it (which I assume it would need to). >=20 > However, it is enough to start running instructions in x86_emulate so > it's enough to start working on enhancing that. >=20 > Regards, >=20 > Anthony Liguori >=20 >=20 --=-xRnzlvB56UBj5KEYrtz4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable [PATCH][RFC] Emulating real mode with x86_emulate Hi Anthony,
  I tried your patch at my end with snapshot of xen-unstable on 200703= 26. And here are my findings.
   - The --emulate-16bit option for qemu did not work. qemu is no= t accepting this as an valid command line option.
   - I tried hardcoding this to 1 in the qemu code, and found tha= t the port x595 is not reflecting it correctly to hvmloader.
   - Then I tried forcing in the hvmloader to use the emulator in= stead of vmxassit, and I see the the emulator is not getting the right cont= ext. Following is the console log at this point.

(XEN) HVM3: HVM Loader         = ;            &n= bsp;            = ;            &n= bsp;          
(XEN) HVM3: Detected Xen v3.0-unstable      &= nbsp;           &nbs= p;            &= nbsp;         
(XEN) HVM3: Writing SMBIOS tables ...      &n= bsp;            = ;            &n= bsp;          
(XEN) HVM3: Loading ROMBIOS ...       &n= bsp;            = ;            &n= bsp;            = ;   
(XEN) irq.c:210: Dom3 PCI link 0 changed 0 -> 5    &= nbsp;           &nbs= p;            &= nbsp;  
(XEN) HVM3: PCI-ISA link 0 routed to IRQ5     &nbs= p;            &= nbsp;           &nbs= p;       
(XEN) irq.c:210: Dom3 PCI link 1 changed 0 -> 7    &= nbsp;           &nbs= p;            &= nbsp;  
(XEN) HVM3: PCI-ISA link 1 routed to IRQ7     &nbs= p;            &= nbsp;           &nbs= p;       
(XEN) irq.c:210: Dom3 PCI link 2 changed 0 -> 10    =             &nb= sp;            =   
(XEN) HVM3: PCI-ISA link 2 routed to IRQ10     &nb= sp;            =             &nb= sp;      
(XEN) irq.c:210: Dom3 PCI link 3 changed 0 -> 11    =             &nb= sp;            =   
(XEN) HVM3: PCI-ISA link 3 routed to IRQ11     &nb= sp;            =             &nb= sp;      
(XEN) HVM3: pci dev 01:1 bar 20 size 00000010: 0000c001   &n= bsp;            = ;        
(XEN) HVM3: pci dev 01:2 INTA->IRQ7      &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;
(XEN) HVM3: pci dev 02:0 bar 10 size 02000000: f0000008   &n= bsp;            = ;        
(XEN) HVM3: pci dev 02:0 bar 14 size 00001000: f2000000   &n= bsp;            = ;        
(XEN) HVM3: pci dev 03:0 bar 10 size 00000100: 0000c101   &n= bsp;            = ;        
(XEN) HVM3: pci dev 03:0 bar 14 size 01000000: f3000008   &n= bsp;            = ;        
(XEN) HVM3: pci dev 03:0 INTA->IRQ11      =             &nb= sp;            =              (XEN) HVM3: pci dev 04:0 bar 10 size 00000100: 0000c201   &n= bsp;            = ;        
(XEN) HVM3: pci dev 04:0 bar 14 size 00000100: f4000000   &n= bsp;            = ;        
(XEN) HVM3: pci dev 04:0 INTA->IRQ5      &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;
(XEN) HVM3: Creating MP tables ...       = ;            &n= bsp;            = ;            &n= bsp;
(XEN) HVM3: Loading Cirrus VGABIOS ...      &= nbsp;           &nbs= p;            &= nbsp;         
(XEN) HVM3: Loading ACPI ...        = ;            &n= bsp;            = ;            &n= bsp;     
(XEN) HVM3: Not Loading VMXAssist ... ffffffff     = ;            &n= bsp;            = ;   
(XEN) HVM3: foo          =             &nb= sp;            =             &nb= sp;            =     
(XEN) hvmop_emulate_realmode        = ;            &n= bsp;            = ;            &n= bsp;     
(XEN) guest requests real mode emulation      = ;            &n= bsp;            = ;        
(XEN) foo 221          &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;     
(XEN) HVM3: Invoking ROMBIOS ...       &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;  
(XEN) Transfering control to x86_emulate %eip 0x0    &n= bsp;            = ;            &n= bsp;
(XEN) hvm.c:446:d3 Triple fault on VCPU0 - invoking HVM system reset. =   

The log shows that emulator is not getting the right cpu context.
How much of testing have you done with this code? I am not able to proceed = to emulation of 1 instruction with the patch. How many instruction could yo= u emulate with the patch?

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
On Sun, 2007-03-25 at 16:35 -0700, Anthony Liguori wrote:
Howdy,

Attached is a patch that begin= s to lay down the infrastructure for
emulating real mode with x86_e= mulate().  With a little more refactoring,
I think it could also replace = the SVM emulator.

The patch introduces an HVMOP = hypercall to set a flag in the hvm vcpu
struct to signal that real mod= e should be emulated with x86_emulate
instead of using vm86.  T= his is to make development a little bit easier
since x86_emulate is not quite= there yet wrt 16 bit emulation.  It can
be enabled by passing -emulate= -16bit to qemu-dm (I use a wrapper script
similar to qemu-dm.debug).

The VT code keeps track of the= whether it's in the emulator and loops on
the do_resume path in x86_emul= ate.  I think this code probably should be
refactored into the common HVM= code although this would require changing
some of the HVM ops.  Thi= s would allow SVM to use the x86_emulate to
handle individual instructions= .

There are some issues to work = out.  Namely, x86_emulate appears to want
blocking PIO calls which isn't= conducive to the wait PIO works today in
HVM.  This is only a prob= lem for instructions at the moment.  I'm also a
bit confused about how to prop= erly loop in the emulator.  schedule_tail
is not meant to return so perh= aps we should loop on emulating =3D=3D 1
instead of hypercall_preempt_c= heck?  I didn't think the hypervisor was
preemptable though.

The current code doesn't handl= e non-flat segments as I don't think
hvm_copy_from/to_guest handles= it (which I assume it would need to).

However, it is enough to start= running instructions in x86_emulate so
it's enough to start working o= n enhancing that.

Regards,

Anthony Liguori<= BR>


--=-xRnzlvB56UBj5KEYrtz4-- --=-MlUu6QCT3GcfubhjksnE 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) iD8DBQBGDC0DZ1sfU7kTCR8RAmWLAJ0Y2ZXaJUxw4xuhweBOFBiOirw8ywCfXTFc 5fpPXdkTZEEWXTqHtxv15Ns= =bL3H -----END PGP SIGNATURE----- --=-MlUu6QCT3GcfubhjksnE-- --===============0859694023== 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 --===============0859694023==--