From: "Jan Beulich" Subject: Re: Possible problem emulating movntq, movss Date: Wed, 06 Aug 2014 13:50:50 +0100 Message-ID: <53E240CA0200007800029BE3@mail.emea.novell.com> References: <53E1EDE1.5040207@bitdefender.com> <53E2176A0200007800029B53@mail.emea.novell.com> <53E207A5.9030604@bitdefender.com> <53E238AC0200007800029BC2@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4775FBBA.2__=" Return-path: In-Reply-To: <53E238AC0200007800029BC2@mail.emea.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: Razvan Cojocaru , Andrei LUTAS Cc: Andrew Cooper , keir@xen.org, "xen-devel@lists.xen.org" 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. --=__Part4775FBBA.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 06.08.14 at 14:16, wrote: >>>> On 06.08.14 at 12:47, wrote: >> On 8/6/2014 12:54 PM, Jan Beulich wrote: >>>>>> On 06.08.14 at 10:57, wrote: >>>> We found that our HVM guests froze when trying to emulate movntq >>>> instructions. The solution seems to be to replace "goto done;" with >>>> "break;" at line 4191 (when handling "case 0x7f:") in >>>> xen/arch/x86/x86_emulate/x86_emulate.c. Otherwise the writeback part >>>> doesn't happen. >>>> >>>> If you're happy with the fix I can prepare a patch, otherwise please = let >>>> me know if we're missing something. >>> No, that doesn't look right: There's nothing left to be written back = at >>> that point (registers get updated with the instruction executed via = the >>> on-stack stub, and memory gets written with immediately preceding >>> ops->write(). So without you being more specific about _what_ you >>> see going wrong I don't think I can give further advice. >> Except for maybe the instruction pointer? That doesn't seem to be = updated >> anywhereexcept during the write-back phase (or maybe I'm missing the = spot). >> The problem is that the guest gets stuck with the instruction pointer >> pointing to the sameinstruction (in our particular case it is >> "MOVDQU xmm0, xmmword ptr [rdx + rcx - 0x10]"),entering in an infinite >> loop (EPT violation - emulate), since the IP doesn't seem to be = updated. >=20 > Now that is indeed a problem, but not solved by simply replacing > the "goto done" with "break". I'll look into getting you a proper fix. Mind giving this one (lightly tested only) a try? Jan --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -720,29 +720,26 @@ do{ uint8_t stub[] =3D { _bytes, 0xc3 }; =20 put_fpu(&fic); \ } while (0) =20 -static unsigned long __get_rep_prefix( - struct cpu_user_regs *int_regs, - struct cpu_user_regs *ext_regs, +static unsigned long _get_rep_prefix( + const struct cpu_user_regs *int_regs, int ad_bytes) { - unsigned long ecx =3D ((ad_bytes =3D=3D 2) ? (uint16_t)int_regs->ecx = : - (ad_bytes =3D=3D 4) ? (uint32_t)int_regs->ecx : - int_regs->ecx); - - /* Skip the instruction if no repetitions are required. */ - if ( ecx =3D=3D 0 ) - ext_regs->eip =3D int_regs->eip; - - return ecx; + return (ad_bytes =3D=3D 2) ? (uint16_t)int_regs->ecx : + (ad_bytes =3D=3D 4) ? (uint32_t)int_regs->ecx : + int_regs->ecx; } =20 #define get_rep_prefix() ({ \ unsigned long max_reps =3D 1; = \ if ( rep_prefix() ) \ - max_reps =3D __get_rep_prefix(&_regs, ctxt->regs, ad_bytes); = \ + max_reps =3D _get_rep_prefix(&_regs, ad_bytes); = \ if ( max_reps =3D=3D 0 ) = \ - goto done; \ - max_reps; \ + { \ + /* Skip the instruction if no repetitions are required. */ \ + dst.type =3D OP_NONE; = \ + goto writeback; \ + } \ + max_reps; \ }) =20 static void __put_rep_prefix( @@ -3921,7 +3918,8 @@ x86_emulate( if ( !rc && (b & 1) && (ea.type =3D=3D OP_MEM) ) rc =3D ops->write(ea.mem.seg, ea.mem.off, mmvalp, ea.bytes, ctxt); - goto done; + dst.type =3D OP_NONE; + break; } =20 case 0x20: /* mov cr,reg */ @@ -4188,7 +4186,8 @@ x86_emulate( if ( !rc && (b !=3D 0x6f) && (ea.type =3D=3D OP_MEM) ) rc =3D ops->write(ea.mem.seg, ea.mem.off, mmvalp, ea.bytes, ctxt); - goto done; + dst.type =3D OP_NONE; + break; } =20 case 0x80 ... 0x8f: /* jcc (near) */ { --=__Part4775FBBA.2__= Content-Type: text/plain; name="x86emul-IP-updates.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-IP-updates.patch" --- a/xen/arch/x86/x86_emulate/x86_emulate.c=0A+++ b/xen/arch/x86/x86_emula= te/x86_emulate.c=0A@@ -720,29 +720,26 @@ do{ uint8_t stub[] =3D { _bytes, = 0xc3 }; =0A put_fpu(&fic); = \=0A } while (0)=0A =0A-static unsigned long __get_rep_prefix(=0A= - struct cpu_user_regs *int_regs,=0A- struct cpu_user_regs *ext_regs,= =0A+static unsigned long _get_rep_prefix(=0A+ const struct cpu_user_regs= *int_regs,=0A int ad_bytes)=0A {=0A- unsigned long ecx =3D = ((ad_bytes =3D=3D 2) ? (uint16_t)int_regs->ecx :=0A- = (ad_bytes =3D=3D 4) ? (uint32_t)int_regs->ecx :=0A- = int_regs->ecx);=0A-=0A- /* Skip the instruction if no repetitions = are required. */=0A- if ( ecx =3D=3D 0 )=0A- ext_regs->eip =3D = int_regs->eip;=0A-=0A- return ecx;=0A+ return (ad_bytes =3D=3D 2) ? = (uint16_t)int_regs->ecx :=0A+ (ad_bytes =3D=3D 4) ? (uint32_t)int= _regs->ecx :=0A+ int_regs->ecx;=0A }=0A =0A #define get_rep_prefi= x() ({ \=0A unsigned long = max_reps =3D 1; \=0A if ( = rep_prefix() ) \=0A- = max_reps =3D __get_rep_prefix(&_regs, ctxt->regs, ad_bytes); \=0A+ = max_reps =3D _get_rep_prefix(&_regs, ad_bytes); = \=0A if ( max_reps =3D=3D 0 ) = \=0A- goto done; = \=0A- max_reps; = \=0A+ { = \=0A+ /* Skip the instruction if no repetitions are = required. */ \=0A+ dst.type =3D OP_NONE; = \=0A+ goto writeback; = \=0A+ } = \=0A+ max_reps; = \=0A })=0A =0A static void __put_rep_prefix(=0A= @@ -3921,7 +3918,8 @@ x86_emulate(=0A if ( !rc && (b & 1) && = (ea.type =3D=3D OP_MEM) )=0A rc =3D ops->write(ea.mem.seg, = ea.mem.off, mmvalp,=0A ea.bytes, ctxt);=0A- = goto done;=0A+ dst.type =3D OP_NONE;=0A+ break;=0A = }=0A =0A case 0x20: /* mov cr,reg */=0A@@ -4188,7 +4186,8 @@ x86_emulat= e(=0A if ( !rc && (b !=3D 0x6f) && (ea.type =3D=3D OP_MEM) )=0A = rc =3D ops->write(ea.mem.seg, ea.mem.off, mmvalp,=0A = ea.bytes, ctxt);=0A- goto done;=0A+ dst.type = =3D OP_NONE;=0A+ break;=0A }=0A =0A case 0x80 ... 0x8f: /* = jcc (near) */ {=0A --=__Part4775FBBA.2__= 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 --=__Part4775FBBA.2__=--