From patchwork Thu Oct 26 17:03:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Harris X-Patchwork-Id: 10028649 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 9F05B60567 for ; Thu, 26 Oct 2017 17:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B2428E77 for ; Thu, 26 Oct 2017 17:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D84C28E80; Thu, 26 Oct 2017 17:06:29 +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 DDBC028E77 for ; Thu, 26 Oct 2017 17:06:28 +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 1e7lZU-0002eM-MH; Thu, 26 Oct 2017 17:03:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e7lZT-0002dQ-C9 for xen-devel@lists.xenproject.org; Thu, 26 Oct 2017 17:03:55 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 82/BF-21967-A7512F95; Thu, 26 Oct 2017 17:03:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOIsWRWlGSWpSXmKPExsXitHSDvW6V6Kd Ig6XXhCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyls14xF5zTqtgzdT1jA+N1+S5GTg4JAX+J o40v2UBsNgEtid0fFrJ3MXJwiAioSNzea9DFyMXBLNDLKLH0/QUmkBphAQ+JX5+7WUFsFgFVi RXnp4P18gq4SSxdupgdYqaCxJSH75lBbE4Bd4lDCzeB1QgB1Vz89osVwlaW+HBlDTtEr6DEyZ lPWEBsZgEJiYMvXjBPYOSdhSQ1C0lqASPTKkaN4tSistQiXSMjvaSizPSMktzEzBxdQwNTvdz U4uLE9NScxKRiveT83E2MwOCpZ2Bg3MG4p93vEKMkB5OSKC/Dng+RQnxJ+SmVGYnFGfFFpTmp xYcYZTg4lCR4Fwp/ihQSLEpNT61Iy8wBhjFMWoKDR0mE9xJImre4IDG3ODMdInWK0Zij4+bdP 0wcz2a+bmAWYsnLz0uVEuc1FQEqFQApzSjNgxsEi69LjLJSwryMDAwMQjwFqUW5mSWo8q8YxT kYlYQhFvJk5pXA7XsFdAoT0ClNqh9ATilJREhJNTAe1pr+fVXg2nOMhiw/psRn7ixYtjdffrX aY/aFFz+3vNHiO/e66VtR/sweg9MrHq1IOOVbaJ/P4iV9UYNJ6cEu/RaRNX7cTaeKJ/d8qdwr aOYfe3OL/jV5p9QJx2aUhl21jO2TWj5vyScDt/jvM80e3nvL+oG/jcf4veHUoOdKcxf927ox7 fpfJZbijERDLeai4kQAo/9zjKoCAAA= X-Env-Sender: prvs=465eced58=euan.harris@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1509037429!105948291!3 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 41186 invoked from network); 26 Oct 2017 17:03:53 -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:53 -0000 X-IronPort-AV: E=Sophos;i="5.44,301,1505779200"; d="scan'208";a="456259608" From: Euan Harris To: Date: Thu, 26 Oct 2017 18:03:12 +0100 Message-ID: <1509037399-48926-3-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 2/9] x86/vvmx: Unify operands in struct vmx_inst_decoded 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 change prepares the way for abstracting the code which reads memory and register operands into a generic operand_read() function in a future patch. Operand 1 may either be a memory location or a register, depending on the instruction being handled. Operand 2 may only be a register, but it is now represented in the same way as operand 1 and so has a type field. This will always equal VMX_INST_MEMREG_TYPE_REG. References to the old structure map to the new one as follows: mem -> op[0].mem len -> op[0].len reg1 -> op[0].reg reg2 -> op[1].reg References to type always map to op[0].type in this patch because previously operand 2 could only be a register and so type was never checked when accessing it. Signed-off-by: Euan Harris --- xen/arch/x86/hvm/vmx/vvmx.c | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 9d87786894..20e5e29031 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -195,16 +195,16 @@ bool_t nvmx_ept_enabled(struct vcpu *v) struct vmx_inst_decoded { #define VMX_INST_MEMREG_TYPE_MEMORY 0 #define VMX_INST_MEMREG_TYPE_REG 1 - int type; - union { - struct { - unsigned long mem; - unsigned int len; + struct vmx_inst_op { + int type; + union { + struct { + unsigned long mem; + unsigned int len; + }; + unsigned int reg_idx; }; - unsigned int reg1; - }; - - unsigned int reg2; + } op[2]; }; enum vmx_ops_result { @@ -437,16 +437,16 @@ static int decode_vmx_inst(struct cpu_user_regs *regs, info.word = offset; if ( info.fields.memreg ) { - decode->type = VMX_INST_MEMREG_TYPE_REG; - decode->reg1 = info.fields.reg1; + 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->reg1); + *poperandS = reg_read(regs, decode->op[0].reg_idx); } else { bool mode_64bit = (vmx_guest_x86_mode(v) == 8); - decode->type = VMX_INST_MEMREG_TYPE_MEMORY; + decode->op[0].type = VMX_INST_MEMREG_TYPE_MEMORY; if ( info.fields.segment > x86_seg_gs ) goto gp_fault; @@ -486,11 +486,13 @@ static int decode_vmx_inst(struct cpu_user_regs *regs, if ( rc != HVMTRANS_okay ) return X86EMUL_EXCEPTION; } - decode->mem = base; - decode->len = size; + + decode->op[0].mem = base; + decode->op[0].len = size; } - decode->reg2 = info.fields.reg2; + decode->op[1].type = VMX_INST_MEMREG_TYPE_REG; + decode->op[1].reg_idx = info.fields.reg2; return X86EMUL_OKAY; @@ -1770,7 +1772,8 @@ int nvmx_handle_vmptrst(struct cpu_user_regs *regs) gpa = nvcpu->nv_vvmcxaddr; - rc = hvm_copy_to_guest_linear(decode.mem, &gpa, decode.len, 0, &pfinfo); + rc = hvm_copy_to_guest_linear(decode.op[0].mem, &gpa, + decode.op[0].len, 0, &pfinfo); if ( rc == HVMTRANS_bad_linear_to_gfn ) hvm_inject_page_fault(pfinfo.ec, pfinfo.linear); if ( rc != HVMTRANS_okay ) @@ -1850,23 +1853,24 @@ int nvmx_handle_vmread(struct cpu_user_regs *regs) return X86EMUL_OKAY; } - rc = get_vvmcs_safe(v, reg_read(regs, decode.reg2), &value); + rc = get_vvmcs_safe(v, reg_read(regs, decode.op[1].reg_idx), &value); if ( rc != VMX_INSN_SUCCEED ) { vmfail(regs, rc); return X86EMUL_OKAY; } - switch ( decode.type ) { + switch ( decode.op[0].type ) { case VMX_INST_MEMREG_TYPE_MEMORY: - rc = hvm_copy_to_guest_linear(decode.mem, &value, decode.len, 0, &pfinfo); + rc = hvm_copy_to_guest_linear(decode.op[0].mem, &value, + decode.op[0].len, 0, &pfinfo); if ( rc == HVMTRANS_bad_linear_to_gfn ) hvm_inject_page_fault(pfinfo.ec, pfinfo.linear); if ( rc != HVMTRANS_okay ) return X86EMUL_EXCEPTION; break; case VMX_INST_MEMREG_TYPE_REG: - reg_write(regs, decode.reg1, value); + reg_write(regs, decode.op[0].reg_idx, value); break; } @@ -1893,7 +1897,7 @@ int nvmx_handle_vmwrite(struct cpu_user_regs *regs) return X86EMUL_OKAY; } - vmcs_encoding = reg_read(regs, decode.reg2); + vmcs_encoding = reg_read(regs, decode.op[1].reg_idx); err = set_vvmcs_safe(v, vmcs_encoding, operand); if ( err != VMX_INSN_SUCCEED ) { @@ -1931,7 +1935,7 @@ int nvmx_handle_invept(struct cpu_user_regs *regs) if ( (ret = decode_vmx_inst(regs, &decode, &eptp, 0)) != X86EMUL_OKAY ) return ret; - switch ( reg_read(regs, decode.reg2) ) + switch ( reg_read(regs, decode.op[1].reg_idx) ) { case INVEPT_SINGLE_CONTEXT: { @@ -1959,7 +1963,7 @@ int nvmx_handle_invvpid(struct cpu_user_regs *regs) if ( (ret = decode_vmx_inst(regs, &decode, &vpid, 0)) != X86EMUL_OKAY ) return ret; - switch ( reg_read(regs, decode.reg2) ) + switch ( reg_read(regs, decode.op[1].reg_idx) ) { /* Just invalidate all tlb entries for all types! */ case INVVPID_INDIVIDUAL_ADDR: