From patchwork Thu Sep 8 13:17:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9321381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8CA4607D3 for ; Thu, 8 Sep 2016 13:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99B992987F for ; Thu, 8 Sep 2016 13:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E83D29883; Thu, 8 Sep 2016 13:19:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AF4A2987F for ; Thu, 8 Sep 2016 13:19:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhzCy-0001Xp-Rx; Thu, 08 Sep 2016 13:17:36 +0000 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 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id FD/A5-21406-FE461D75; Thu, 08 Sep 2016 13:17:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRWlGSWpSXmKPExsXS6fjDS/ddysV wg5fPZSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyJc66xFDzUrFhycg5rA+N/+S5GTg4hgTyJ ux8usoPYvAJ2Ev/mdoPZEgKGEk/fX2cDsVkEVCXuXzvPCmKzCahLtD3bDmRzcIgIGEicO5oEY jIL6EtsW8cCUiEsEC/RufwJC8R0O4lnpw6C2ZwC9hJfWucwgpTzCghK/N0hDBJmBiqZ9OoR+w RGnlkImVlIMhC2lsTDX7dYIGxtiWULXzPPAtsrLbH8HweEaScxuZEHVQWI7Skx699xtgWMHKs YNYpTi8pSi3QNjfWSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQIDlQEIdjB+WRZw iFGSg0lJlNen+EK4EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQne/ckXw4UEi1LTUyvSMnOAMQOTl uDgURLhVQHGjRBvcUFibnFmOkTqFKOilDjvT5A+AZBERmkeXBssTi8xykoJ8zICHSLEU5BalJ tZgir/ilGcg1FJmHcOyBSezLwSuOmvgBYzAS0WOnUeZHFJIkJKqoHRP3vTHVf3cCsvxz1zVKM a7Hlc+YxLmITZ3RTuXLoq63EmPrY4Z5Pb0a9C99MaZ+nb6zg7xx4/3/JuipZJUqWU54essPST ddoMnx+zrtO4Hrhm911Rj71mDdPV2kuCPkgJH5nDcz87/Pzyfq3czaVTSjw/p89pE47iPp74X lxqmUj3ZBevN0osxRmJhlrMRcWJAGnAzF7OAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1473340652!47942190!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44308 invoked from network); 8 Sep 2016 13:17:34 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Sep 2016 13:17:34 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 08 Sep 2016 07:17:32 -0600 Message-Id: <57D1810C020000780010D1D6@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Thu, 08 Sep 2016 07:17:32 -0600 From: "Jan Beulich" To: "xen-devel" References: <57D17C78020000780010D127@prv-mh.provo.novell.com> In-Reply-To: <57D17C78020000780010D127@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH 12/17] x86/PV: split out dealing with DRn from privileged instruction handling X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 x86/PV: split out dealing with DRn from privileged instruction handling 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; } +static int priv_op_read_dr(unsigned int reg, unsigned long *val, + struct x86_emulate_ctxt *ctxt) +{ + unsigned long res = do_get_debugreg(reg); + + if ( IS_ERR_VALUE(res) ) + return X86EMUL_UNHANDLEABLE; + + *val = 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) == 0 + ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE; +} + static inline uint64_t guest_misc_enable(uint64_t val) { val &= ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL | @@ -2761,16 +2781,14 @@ static int emulate_privileged_op(struct break; case 0x21: /* MOV DR?, */ { - unsigned long res; opcode = insn_fetch(u8, code_base, eip, code_limit); if ( opcode < 0xc0 ) goto fail; modrm_reg += ((opcode >> 3) & 7) + (lock << 3); modrm_rm |= (opcode >> 0) & 7; - reg = decode_register(modrm_rm, regs, 0); - if ( (res = do_get_debugreg(modrm_reg)) > (unsigned long)-256 ) + if ( priv_op_read_dr(modrm_reg, decode_register(modrm_rm, regs, 0), + NULL) != X86EMUL_OKAY ) goto fail; - *reg = res; break; } @@ -2799,7 +2817,7 @@ static int emulate_privileged_op(struct modrm_reg += ((opcode >> 3) & 7) + (lock << 3); modrm_rm |= (opcode >> 0) & 7; reg = decode_register(modrm_rm, regs, 0); - if ( do_set_debugreg(modrm_reg, *reg) != 0 ) + if ( priv_op_write_dr(modrm_reg, *reg, NULL) != X86EMUL_OKAY ) goto fail; break; --- 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; } +static int priv_op_read_dr(unsigned int reg, unsigned long *val, + struct x86_emulate_ctxt *ctxt) +{ + unsigned long res = do_get_debugreg(reg); + + if ( IS_ERR_VALUE(res) ) + return X86EMUL_UNHANDLEABLE; + + *val = 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) == 0 + ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE; +} + static inline uint64_t guest_misc_enable(uint64_t val) { val &= ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL | @@ -2761,16 +2781,14 @@ static int emulate_privileged_op(struct break; case 0x21: /* MOV DR?, */ { - unsigned long res; opcode = insn_fetch(u8, code_base, eip, code_limit); if ( opcode < 0xc0 ) goto fail; modrm_reg += ((opcode >> 3) & 7) + (lock << 3); modrm_rm |= (opcode >> 0) & 7; - reg = decode_register(modrm_rm, regs, 0); - if ( (res = do_get_debugreg(modrm_reg)) > (unsigned long)-256 ) + if ( priv_op_read_dr(modrm_reg, decode_register(modrm_rm, regs, 0), + NULL) != X86EMUL_OKAY ) goto fail; - *reg = res; break; } @@ -2799,7 +2817,7 @@ static int emulate_privileged_op(struct modrm_reg += ((opcode >> 3) & 7) + (lock << 3); modrm_rm |= (opcode >> 0) & 7; reg = decode_register(modrm_rm, regs, 0); - if ( do_set_debugreg(modrm_reg, *reg) != 0 ) + if ( priv_op_write_dr(modrm_reg, *reg, NULL) != X86EMUL_OKAY ) goto fail; break;