From patchwork Wed Feb 8 10:09:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9562149 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 220B8601E5 for ; Wed, 8 Feb 2017 10:12:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1301928391 for ; Wed, 8 Feb 2017 10:12:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06280284BC; Wed, 8 Feb 2017 10:12:03 +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 70BA828391 for ; Wed, 8 Feb 2017 10:12:02 +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 1cbPC9-00019K-Bp; Wed, 08 Feb 2017 10:09:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbPC8-00018Y-A0 for xen-devel@lists.xen.org; Wed, 08 Feb 2017 10:09:48 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 48/48-29440-B6EEA985; Wed, 08 Feb 2017 10:09:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrrBXjfj3aw Ig0NtzBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bOGxPYCx5IV1xd3sncwHhVpIuRk0NCwF9i ytl2RhCbTUBPYuPsV0wgtoiArMTqrjnsXYxcHMwCRxglpq46wg6SEBYwkzjV/omti5GDg0VAR eL6Xm6QMK+ArcSclXcYIWbKSVza9oUZpIRTwE7iwT0TkLAQUMnUKRuZIGxVidcvdrFAtApKnJ z5BMxmFpCQOPjiBfMERt5ZSFKzkKQWMDKtYlQvTi0qSy3StdBLKspMzyjJTczM0TU0MNPLTS0 uTkxPzUlMKtZLzs/dxAgMHAYg2ME4+7L/IUZJDiYlUV6fp7MihPiS8lMqMxKLM+KLSnNSiw8x ynBwKEnwfnwDlBMsSk1PrUjLzAGGMExagoNHSYT3MUiat7ggMbc4Mx0idYpRUUqcV/MtUEIAJ JFRmgfXBoubS4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLm/QYyniczrwRu+iugxUxAi6+fBl tckoiQkmpgtJ476dsUkVsPu4/sFzTcILRGq+jSRNMEjYiL3KHTc5nLXi/dwx2yolz1h/SeUI1 I293nzskn3sn1XKVTFJ/9cFv24fnbtb/esblbs6hy6zPrpmTT+hO5+7ujNn1T/vDKquQn/zX/ r0ZzZPUWp8q/f+7kmCmX73NG9UrDh/f/LAt5qxUesFUcUmIpzkg01GIuKk4EALvKT3mWAgAA X-Env-Sender: prvs=205b15c4b=sergey.dyasli@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1486548581!76480820!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.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53883 invoked from network); 8 Feb 2017 10:09:43 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 8 Feb 2017 10:09:43 -0000 X-IronPort-AV: E=Sophos;i="5.33,346,1477958400"; d="scan'208";a="414224274" From: Sergey Dyasli To: Date: Wed, 8 Feb 2017 10:09:33 +0000 Message-ID: <20170208100935.30332-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170208100935.30332-1-sergey.dyasli@citrix.com> References: <20170208100935.30332-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v3 2/4] x86/vmx: improve vmread_safe() 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 The original function doesn't distinguish between Valid and Invalid VMfails. Improved function returns error code depending on the outcome: VMsucceed: 0 VMfailValid: VM Instruction Error Number VMfailInvalid: VMX_INSN_FAIL_INVALID (~0) Existing users of __vmread_safe() are updated and double underscore prefix is removed from the function's name because such prefixes are reserved to a compiler. Signed-off-by: Sergey Dyasli Reviewed-by: Jan Beulich Acked-by: Kevin Tian --- v2 --> v3: * vmread_safe() now returns "enum vmx_insn_errno" (32-bit value) xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 2 +- xen/include/asm-x86/hvm/vmx/vmx.h | 41 +++++++++++++++++---------------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 59ef199..24f7570 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1711,7 +1711,7 @@ static inline unsigned long vmr(unsigned long field) { unsigned long val; - return __vmread_safe(field, &val) ? val : 0; + return vmread_safe(field, &val) ? 0 : val; } #define vmr16(fld) ({ \ diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 105a3c0..31ac360 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -932,7 +932,7 @@ static inline void shadow_to_vvmcs(const struct vcpu *v, unsigned int field) { unsigned long value; - if ( __vmread_safe(field, &value) ) + if ( vmread_safe(field, &value) == 0 ) set_vvmcs(v, field, value); } diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 9bfe71a..3e809d4 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -401,32 +401,27 @@ static always_inline void __vmwrite(unsigned long field, unsigned long value) ); } -static inline bool_t __vmread_safe(unsigned long field, unsigned long *value) +static inline enum vmx_insn_errno vmread_safe(unsigned long field, + unsigned long *value) { - bool_t okay; + unsigned long ret = 0; + bool fail_invalid, fail_valid; - asm volatile ( -#ifdef HAVE_GAS_VMX - "vmread %2, %1\n\t" -#else - VMREAD_OPCODE MODRM_EAX_ECX -#endif - /* CF==1 or ZF==1 --> rc = 0 */ -#ifdef __GCC_ASM_FLAG_OUTPUTS__ - : "=@ccnbe" (okay), -#else - "setnbe %0" - : "=qm" (okay), -#endif -#ifdef HAVE_GAS_VMX - "=rm" (*value) - : "r" (field)); -#else - "=c" (*value) - : "a" (field)); -#endif + asm volatile ( GAS_VMX_OP("vmread %[field], %[value]\n\t", + VMREAD_OPCODE MODRM_EAX_ECX) + ASM_FLAG_OUT(, "setc %[invalid]\n\t") + ASM_FLAG_OUT(, "setz %[valid]\n\t") + : ASM_FLAG_OUT("=@ccc", [invalid] "=rm") (fail_invalid), + ASM_FLAG_OUT("=@ccz", [valid] "=rm") (fail_valid), + [value] GAS_VMX_OP("=rm", "=c") (*value) + : [field] GAS_VMX_OP("r", "a") (field)); + + if ( unlikely(fail_invalid) ) + ret = VMX_INSN_FAIL_INVALID; + else if ( unlikely(fail_valid) ) + __vmread(VM_INSTRUCTION_ERROR, &ret); - return okay; + return ret; } static inline enum vmx_insn_errno vmwrite_safe(unsigned long field,