From: "Jan Beulich" Subject: [PATCH v2 13/16] x86emul: support XSETBV Date: Wed, 28 Sep 2016 02:17:16 -0600 Message-ID: <57EB98AC0200007800113207@prv-mh.provo.novell.com> References: <57EB94940200007800113179@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3402859C.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpA3Q-0001IO-BV for xen-devel@lists.xenproject.org; Wed, 28 Sep 2016 08:17:24 +0000 In-Reply-To: <57EB94940200007800113179@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper 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. --=__Part3402859C.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is a prereq for switching PV privileged op emulation to the generic instruction emulator. Since handle_xsetbv() is already capable of dealing with all guest kinds, avoid introducing another hook here. Signed-off-by: Jan Beulich --- v2: Explicitly generate #UD when vex.pfx is non-zero. --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -4178,6 +4178,23 @@ x86_emulate( =20 switch( modrm ) { +#ifdef __XEN__ + case 0xd1: /* xsetbv */ + { + unsigned long cr4; + + generate_exception_if(vex.pfx, EXC_UD, -1); + if ( !ops->read_cr || ops->read_cr(4, &cr4, ctxt) !=3D = X86EMUL_OKAY ) + cr4 =3D 0; + generate_exception_if(!(cr4 & X86_CR4_OSXSAVE), EXC_UD, -1); + generate_exception_if(!mode_ring0() || + handle_xsetbv(_regs._ecx, + _regs._eax | (_regs.rdx = << 32)), + EXC_GP, 0); + goto no_writeback; + } +#endif + case 0xdf: /* invlpga */ generate_exception_if(!in_protmode(ctxt, ops), EXC_UD, -1); generate_exception_if(!mode_ring0(), EXC_GP, 0); --=__Part3402859C.1__= Content-Type: text/plain; name="x86emul-XSETBV.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-XSETBV.patch" x86emul: support XSETBV=0A=0AThis is a prereq for switching PV privileged = op emulation to the=0Ageneric instruction emulator. Since handle_xsetbv() = is already capable=0Aof dealing with all guest kinds, avoid introducing = another hook here.=0A=0ASigned-off-by: Jan Beulich =0A--= -=0Av2: Explicitly generate #UD when vex.pfx is non-zero.=0A=0A--- = a/xen/arch/x86/x86_emulate/x86_emulate.c=0A+++ b/xen/arch/x86/x86_emulate/x= 86_emulate.c=0A@@ -4178,6 +4178,23 @@ x86_emulate(=0A =0A switch( = modrm )=0A {=0A+#ifdef __XEN__=0A+ case 0xd1: /* xsetbv = */=0A+ {=0A+ unsigned long cr4;=0A+=0A+ = generate_exception_if(vex.pfx, EXC_UD, -1);=0A+ if ( !ops->read_= cr || ops->read_cr(4, &cr4, ctxt) !=3D X86EMUL_OKAY )=0A+ = cr4 =3D 0;=0A+ generate_exception_if(!(cr4 & X86_CR4_OSXSAVE), = EXC_UD, -1);=0A+ generate_exception_if(!mode_ring0() ||=0A+ = handle_xsetbv(_regs._ecx,=0A+ = _regs._eax | (_regs.rdx << 32)),=0A+ = EXC_GP, 0);=0A+ goto no_writeback;=0A+= }=0A+#endif=0A+=0A case 0xdf: /* invlpga */=0A = generate_exception_if(!in_protmode(ctxt, ops), EXC_UD, -1);=0A = generate_exception_if(!mode_ring0(), EXC_GP, 0);=0A --=__Part3402859C.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part3402859C.1__=--