From patchwork Thu Oct 26 17:03:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Harris X-Patchwork-Id: 10028657 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 CA6CA601E8 for ; Thu, 26 Oct 2017 17:06:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6EB228E75 for ; Thu, 26 Oct 2017 17:06:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABCAF28E7F; Thu, 26 Oct 2017 17:06:34 +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 571B928E75 for ; Thu, 26 Oct 2017 17:06:34 +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 1e7lZT-0002dR-4l; Thu, 26 Oct 2017 17:03:55 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e7lZS-0002d9-Bi for xen-devel@lists.xenproject.org; Thu, 26 Oct 2017 17:03:54 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id DC/EF-01785-97512F95; Thu, 26 Oct 2017 17:03:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOIsWRWlGSWpSXmKPExsXitHSDvW6F6Kd Ig+mnLCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyrvzayFTRIVaxcNoWpgXGSUBcjJ4eEgL9E 4/lPzCA2m4CWxO4PC9m7GDk4RARUJG7vNehi5OJgFuhllFj6/gITSI2wQIDEmwsf2UBsFgFVi a17DzKC2LwCbhIT7x5khpipIDHl4Xswm1PAXeLQwk1g9UJANRe//WKFsJUlPlxZww7RKyhxcu YTFhCbWUBC4uCLF8wTGHlnIUnNQpJawMi0ilGjOLWoLLVI18hIL6koMz2jJDcxM0fX0MBULze 1uDgxPTUnMalYLzk/dxMjMHjqGRgYdzDuafc7xCjJwaQkysuw50OkEF9SfkplRmJxRnxRaU5q 8SFGGQ4OJQnehcKfIoUEi1LTUyvSMnOAYQyTluDgURLhvQSS5i0uSMwtzkyHSJ1iNObouHn3D xPHs5mvG5iFWPLy81KlxHlNRYBKBUBKM0rz4AbB4usSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ 5GJWGIhTyZeSVw+14BncIEdEqT6geQU0oSEVJSDYytBioFi0WXpC3PX950Zb/GibB7Sm96IvO 2pGsod7enKFZXp6gw9B2UW36vJ9Hs7/SX78veNXAwSM399YShdtfltz8Xfax3XHvrvGO9TNJW bte7fle//pev/5B/73aK4ov5gWGqeXc1/B3qwv3MRC7qGMxXM42I/7zvzj3ridbLXpucMnuW+ UWJpTgj0VCLuag4EQD8gq3nqgIAAA== X-Env-Sender: prvs=465eced58=euan.harris@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1509037429!105948291!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41047 invoked from network); 26 Oct 2017 17:03:52 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 26 Oct 2017 17:03:52 -0000 X-IronPort-AV: E=Sophos;i="5.44,301,1505779200"; d="scan'208";a="456259607" From: Euan Harris To: Date: Thu, 26 Oct 2017 18:03:13 +0100 Message-ID: <1509037399-48926-4-git-send-email-euan.harris@citrix.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1509037399-48926-1-git-send-email-euan.harris@citrix.com> References: <1509037399-48926-1-git-send-email-euan.harris@citrix.com> MIME-Version: 1.0 Cc: andrew.cooper3@citrix.com, kevin.tian@intel.com, Euan Harris , jun.nakajima@intel.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH 3/9] x86/vvmx: Extract operand reading logic into operand_read() 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 Extract the logic for reading operands from decode_vmx_inst() into operand_read(). Future patches will replace operand reading logic in elsewhere with calls to operand_read(). operand_read() must explicitly handle different operand sizes to avoid corrupting the caller's stack. This patch should not change the overall behaviour of the code. Signed-off-by: Euan Harris --- xen/arch/x86/hvm/vmx/vvmx.c | 59 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 20e5e29031..df84592490 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -361,6 +361,40 @@ static void reg_write(struct cpu_user_regs *regs, *pval = value; } +static int operand_read(void *buf, struct vmx_inst_op *op, + struct cpu_user_regs *regs, unsigned int bytes) +{ + if ( op->type == VMX_INST_MEMREG_TYPE_REG ) + { + switch ( bytes ) + { + case 4: + *(uint32_t *)buf = reg_read(regs, op->reg_idx); + + case 8: + *(uint64_t *)buf = reg_read(regs, op->reg_idx); + + default: + ASSERT_UNREACHABLE(); + return X86EMUL_UNHANDLEABLE; + } + + return X86EMUL_OKAY; + } + else + { + pagefault_info_t pfinfo; + int rc = hvm_copy_from_guest_linear(buf, op->mem, bytes, 0, &pfinfo); + + if ( rc == HVMTRANS_bad_linear_to_gfn ) + hvm_inject_page_fault(pfinfo.ec, pfinfo.linear); + if ( rc != HVMTRANS_okay ) + return X86EMUL_EXCEPTION; + + return X86EMUL_OKAY; + } +} + static inline u32 __n2_pin_exec_control(struct vcpu *v) { return get_vvmcs(v, PIN_BASED_VM_EXEC_CONTROL); @@ -440,7 +474,12 @@ static int decode_vmx_inst(struct cpu_user_regs *regs, decode->op[0].type = VMX_INST_MEMREG_TYPE_REG; decode->op[0].reg_idx = info.fields.reg1; if ( poperandS != NULL ) - *poperandS = reg_read(regs, decode->op[0].reg_idx); + { + int rc = operand_read(poperandS, &decode->op[0], regs, + decode->op[0].len); + if ( rc != X86EMUL_OKAY ) + return rc; + } } else { @@ -475,20 +514,16 @@ static int decode_vmx_inst(struct cpu_user_regs *regs, offset + size - 1 > seg.limit) ) goto gp_fault; + decode->op[0].mem = base; + decode->op[0].len = size; + if ( poperandS != NULL ) { - pagefault_info_t pfinfo; - int rc = hvm_copy_from_guest_linear(poperandS, base, size, - 0, &pfinfo); - - if ( rc == HVMTRANS_bad_linear_to_gfn ) - hvm_inject_page_fault(pfinfo.ec, pfinfo.linear); - if ( rc != HVMTRANS_okay ) - return X86EMUL_EXCEPTION; + int rc = operand_read(poperandS, &decode->op[0], regs, + decode->op[0].len); + if ( rc != X86EMUL_OKAY ) + return rc; } - - decode->op[0].mem = base; - decode->op[0].len = size; } decode->op[1].type = VMX_INST_MEMREG_TYPE_REG;