From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 12/17] x86/PV: split out dealing with DRn from privileged instruction handling Date: Thu, 08 Sep 2016 07:17:32 -0600 Message-ID: <57D1810C020000780010D1D6@prv-mh.provo.novell.com> References: <57D17C78020000780010D127@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part7640FDFC.1__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhzCx-0001XS-PS for xen-devel@lists.xenproject.org; Thu, 08 Sep 2016 13:17:35 +0000 In-Reply-To: <57D17C78020000780010D127@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. --=__Part7640FDFC.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is in preparation for using the generic emulator here. Some care is needed temporarily to not unduly alter guest register state: The local variable "res" can only go away once this code got fully switched over to using x86_emulate(). Also switch to IS_ERR_VALUE() instead of (incorrectly) open coding it. Signed-off-by: Jan Beulich --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -2343,6 +2343,26 @@ static int priv_op_write_cr(unsigned int return X86EMUL_UNHANDLEABLE; } =20 +static int priv_op_read_dr(unsigned int reg, unsigned long *val, + struct x86_emulate_ctxt *ctxt) +{ + unsigned long res =3D do_get_debugreg(reg); + + if ( IS_ERR_VALUE(res) ) + return X86EMUL_UNHANDLEABLE; + + *val =3D res; + + return X86EMUL_OKAY; +} + +static int priv_op_write_dr(unsigned int reg, unsigned long val, + struct x86_emulate_ctxt *ctxt) +{ + return do_set_debugreg(reg, val) =3D=3D 0 + ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE; +} + static inline uint64_t guest_misc_enable(uint64_t val) { val &=3D ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL | @@ -2761,16 +2781,14 @@ static int emulate_privileged_op(struct break; =20 case 0x21: /* MOV DR?, */ { - unsigned long res; opcode =3D insn_fetch(u8, code_base, eip, code_limit); if ( opcode < 0xc0 ) goto fail; modrm_reg +=3D ((opcode >> 3) & 7) + (lock << 3); modrm_rm |=3D (opcode >> 0) & 7; - reg =3D decode_register(modrm_rm, regs, 0); - if ( (res =3D do_get_debugreg(modrm_reg)) > (unsigned long)-256 ) + if ( priv_op_read_dr(modrm_reg, decode_register(modrm_rm, regs, = 0), + NULL) !=3D X86EMUL_OKAY ) goto fail; - *reg =3D res; break; } =20 @@ -2799,7 +2817,7 @@ static int emulate_privileged_op(struct modrm_reg +=3D ((opcode >> 3) & 7) + (lock << 3); modrm_rm |=3D (opcode >> 0) & 7; reg =3D decode_register(modrm_rm, regs, 0); - if ( do_set_debugreg(modrm_reg, *reg) !=3D 0 ) + if ( priv_op_write_dr(modrm_reg, *reg, NULL) !=3D X86EMUL_OKAY ) goto fail; break; =20 --=__Part7640FDFC.1__= Content-Type: text/plain; name="x86-PV-priv-op-split-DR.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-PV-priv-op-split-DR.patch" x86/PV: split out dealing with DRn from privileged instruction handling=0A= =0AThis is in preparation for using the generic emulator here.=0A=0ASome = care is needed temporarily to not unduly alter guest register=0Astate: The = local variable "res" can only go away once this code got=0Afully switched = over to using x86_emulate().=0A=0AAlso switch to IS_ERR_VALUE() instead of = (incorrectly) open coding it.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ = -2343,6 +2343,26 @@ static int priv_op_write_cr(unsigned int=0A return = X86EMUL_UNHANDLEABLE;=0A }=0A =0A+static int priv_op_read_dr(unsigned int = reg, unsigned long *val,=0A+ struct x86_emulate_c= txt *ctxt)=0A+{=0A+ unsigned long res =3D do_get_debugreg(reg);=0A+=0A+ = if ( IS_ERR_VALUE(res) )=0A+ return X86EMUL_UNHANDLEABLE;=0A+=0A+= *val =3D res;=0A+=0A+ return X86EMUL_OKAY;=0A+}=0A+=0A+static int = priv_op_write_dr(unsigned int reg, unsigned long val,=0A+ = struct x86_emulate_ctxt *ctxt)=0A+{=0A+ return do_set_debugreg= (reg, val) =3D=3D 0=0A+ ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;=0A= +}=0A+=0A static inline uint64_t guest_misc_enable(uint64_t val)=0A {=0A = val &=3D ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL |=0A@@ -2761,16 +2781,14 @@ = static int emulate_privileged_op(struct=0A break;=0A =0A case = 0x21: /* MOV DR?, */ {=0A- unsigned long res;=0A = opcode =3D insn_fetch(u8, code_base, eip, code_limit);=0A if ( = opcode < 0xc0 )=0A goto fail;=0A modrm_reg +=3D = ((opcode >> 3) & 7) + (lock << 3);=0A modrm_rm |=3D (opcode >> 0) = & 7;=0A- reg =3D decode_register(modrm_rm, regs, 0);=0A- if = ( (res =3D do_get_debugreg(modrm_reg)) > (unsigned long)-256 )=0A+ = if ( priv_op_read_dr(modrm_reg, decode_register(modrm_rm, regs, 0),=0A+ = NULL) !=3D X86EMUL_OKAY )=0A goto = fail;=0A- *reg =3D res;=0A break;=0A }=0A =0A@@ -2799,7 = +2817,7 @@ static int emulate_privileged_op(struct=0A modrm_reg = +=3D ((opcode >> 3) & 7) + (lock << 3);=0A modrm_rm |=3D (opcode = >> 0) & 7;=0A reg =3D decode_register(modrm_rm, regs, 0);=0A- = if ( do_set_debugreg(modrm_reg, *reg) !=3D 0 )=0A+ if ( priv_op_wr= ite_dr(modrm_reg, *reg, NULL) !=3D X86EMUL_OKAY )=0A goto = fail;=0A break;=0A =0A --=__Part7640FDFC.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part7640FDFC.1__=--