From: "Jan Beulich" Subject: [PATCH] x86_emulate: properly do IP updates and other side effects on success Date: Thu, 07 Aug 2014 09:30:27 +0100 Message-ID: <53E35543020000780002A09C@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartD2E06F33.0__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XFJ5i-0000BV-1z for xen-devel@lists.xenproject.org; Thu, 07 Aug 2014 08:30:30 +0000 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: 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. --=__PartD2E06F33.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The two MMX/SSE/AVX code blocks failed to update IP properly, and these as well as get_reg_refix(), which "manually" updated IP so far, failed to do the TF and RF processing needed at the end of successfully emulated instructions. Reported-by: Andrei LUTAS Signed-off-by: Jan Beulich Tested-by: Razvan Cojocaru --- 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) */ { --=__PartD2E06F33.0__= Content-Type: text/plain; name="x86emul-IP-updates.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-IP-updates.patch" x86_emulate: properly do IP updates and other side effects on success=0A=0A= The two MMX/SSE/AVX code blocks failed to update IP properly, and = these=0Aas well as get_reg_refix(), which "manually" updated IP so far, = failed=0Ato do the TF and RF processing needed at the end of successfully= =0Aemulated instructions.=0A=0AReported-by: Andrei LUTAS =0ASigned-off-by: Jan Beulich =0ATested-by: = Razvan Cojocaru =0A=0A--- a/xen/arch/x86/x86_emu= late/x86_emulate.c=0A+++ b/xen/arch/x86/x86_emulate/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 --=__PartD2E06F33.0__= 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 --=__PartD2E06F33.0__=--