From: "Jan Beulich" Subject: [PATCH] x86/HVM: refuse doing string operations in certain situations Date: Fri, 20 Sep 2013 14:08:45 +0100 Message-ID: <523C64FD02000078000F4EF1@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part83B0E0CD.0__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VN0Re-0003z9-Ih for xen-devel@lists.xenproject.org; Fri, 20 Sep 2013 13:08:26 +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: Tim Deegan , 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. --=__Part83B0E0CD.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline We shouldn't do any acceleration for - "rep movs" when either side is passed through MMIO or when both sides are handled by qemu - "rep ins" and "rep outs" when the memory operand is any kind of MMIO Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -686,6 +686,7 @@ static int hvmemul_rep_ins( unsigned long addr; uint32_t pfec =3D PFEC_page_present | PFEC_write_access; paddr_t gpa; + p2m_type_t p2mt; int rc; =20 rc =3D hvmemul_virtual_to_linear( @@ -702,6 +703,10 @@ static int hvmemul_rep_ins( if ( rc !=3D X86EMUL_OKAY ) return rc; =20 + (void) get_gfn_query_unlocked(current->domain, gpa >> PAGE_SHIFT, = &p2mt); + if ( p2mt =3D=3D p2m_mmio_direct || p2mt =3D=3D p2m_mmio_dm ) + return X86EMUL_UNHANDLEABLE; + return hvmemul_do_pio(src_port, reps, bytes_per_rep, gpa, IOREQ_READ, !!(ctxt->regs->eflags & X86_EFLAGS_DF), NULL); } @@ -719,6 +724,7 @@ static int hvmemul_rep_outs( unsigned long addr; uint32_t pfec =3D PFEC_page_present; paddr_t gpa; + p2m_type_t p2mt; int rc; =20 rc =3D hvmemul_virtual_to_linear( @@ -735,6 +741,10 @@ static int hvmemul_rep_outs( if ( rc !=3D X86EMUL_OKAY ) return rc; =20 + (void) get_gfn_query_unlocked(current->domain, gpa >> PAGE_SHIFT, = &p2mt); + if ( p2mt =3D=3D p2m_mmio_direct || p2mt =3D=3D p2m_mmio_dm ) + return X86EMUL_UNHANDLEABLE; + return hvmemul_do_pio(dst_port, reps, bytes_per_rep, gpa, IOREQ_WRITE,= !!(ctxt->regs->eflags & X86_EFLAGS_DF), NULL); } @@ -787,6 +797,10 @@ static int hvmemul_rep_movs( (void) get_gfn_query_unlocked(current->domain, sgpa >> PAGE_SHIFT, = &sp2mt); (void) get_gfn_query_unlocked(current->domain, dgpa >> PAGE_SHIFT, = &dp2mt); =20 + if ( sp2mt =3D=3D p2m_mmio_direct || dp2mt =3D=3D p2m_mmio_direct || + (sp2mt =3D=3D p2m_mmio_dm && dp2mt =3D=3D p2m_mmio_dm) ) + return X86EMUL_UNHANDLEABLE; + if ( sp2mt =3D=3D p2m_mmio_dm ) return hvmemul_do_mmio( sgpa, reps, bytes_per_rep, dgpa, IOREQ_READ, df, NULL); --=__Part83B0E0CD.0__= Content-Type: text/plain; name="x86-HVM-rep-movs-MMIO.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HVM-rep-movs-MMIO.patch" x86/HVM: refuse doing string operations in certain situations=0A=0AWe = shouldn't do any acceleration for=0A- "rep movs" when either side is = passed through MMIO or when both sides=0A are handled by qemu=0A- "rep = ins" and "rep outs" when the memory operand is any kind of MMIO=0A=0ASigned= -off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/emulat= e.c=0A+++ b/xen/arch/x86/hvm/emulate.c=0A@@ -686,6 +686,7 @@ static int = hvmemul_rep_ins(=0A unsigned long addr;=0A uint32_t pfec =3D = PFEC_page_present | PFEC_write_access;=0A paddr_t gpa;=0A+ = p2m_type_t p2mt;=0A int rc;=0A =0A rc =3D hvmemul_virtual_to_linear= (=0A@@ -702,6 +703,10 @@ static int hvmemul_rep_ins(=0A if ( rc !=3D = X86EMUL_OKAY )=0A return rc;=0A =0A+ (void) get_gfn_query_unlock= ed(current->domain, gpa >> PAGE_SHIFT, &p2mt);=0A+ if ( p2mt =3D=3D = p2m_mmio_direct || p2mt =3D=3D p2m_mmio_dm )=0A+ return X86EMUL_UNHA= NDLEABLE;=0A+=0A return hvmemul_do_pio(src_port, reps, bytes_per_rep, = gpa, IOREQ_READ,=0A !!(ctxt->regs->eflags & = X86_EFLAGS_DF), NULL);=0A }=0A@@ -719,6 +724,7 @@ static int hvmemul_rep_ou= ts(=0A unsigned long addr;=0A uint32_t pfec =3D PFEC_page_present;= =0A paddr_t gpa;=0A+ p2m_type_t p2mt;=0A int rc;=0A =0A rc = =3D hvmemul_virtual_to_linear(=0A@@ -735,6 +741,10 @@ static int hvmemul_re= p_outs(=0A if ( rc !=3D X86EMUL_OKAY )=0A return rc;=0A =0A+ = (void) get_gfn_query_unlocked(current->domain, gpa >> PAGE_SHIFT, = &p2mt);=0A+ if ( p2mt =3D=3D p2m_mmio_direct || p2mt =3D=3D p2m_mmio_dm = )=0A+ return X86EMUL_UNHANDLEABLE;=0A+=0A return hvmemul_do_pio(= dst_port, reps, bytes_per_rep, gpa, IOREQ_WRITE,=0A = !!(ctxt->regs->eflags & X86_EFLAGS_DF), NULL);=0A }=0A@@ -787,6 +797,10 = @@ static int hvmemul_rep_movs(=0A (void) get_gfn_query_unlocked(curren= t->domain, sgpa >> PAGE_SHIFT, &sp2mt);=0A (void) get_gfn_query_unlocke= d(current->domain, dgpa >> PAGE_SHIFT, &dp2mt);=0A =0A+ if ( sp2mt = =3D=3D p2m_mmio_direct || dp2mt =3D=3D p2m_mmio_direct ||=0A+ = (sp2mt =3D=3D p2m_mmio_dm && dp2mt =3D=3D p2m_mmio_dm) )=0A+ return = X86EMUL_UNHANDLEABLE;=0A+=0A if ( sp2mt =3D=3D p2m_mmio_dm )=0A = return hvmemul_do_mmio(=0A sgpa, reps, bytes_per_rep, dgpa, = IOREQ_READ, df, NULL);=0A --=__Part83B0E0CD.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 --=__Part83B0E0CD.0__=--