From patchwork Mon Feb 6 14:57:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9558177 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 8090A60413 for ; Mon, 6 Feb 2017 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 708B327FC0 for ; Mon, 6 Feb 2017 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6023827FB1; Mon, 6 Feb 2017 15:00:43 +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 C995927FB0 for ; Mon, 6 Feb 2017 15:00:42 +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 1cakkd-0008BM-C2; Mon, 06 Feb 2017 14:58:43 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cakkb-0008B5-Cu for xen-devel@lists.xen.org; Mon, 06 Feb 2017 14:58:41 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 5E/40-01971-02F88985; Mon, 06 Feb 2017 14:58:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXlehf0a EQetcfoslHxezODB6HN39mymAMYo1My8pvyKBNeP82TuMBR3SFXO63rI1MPaLdDFyckgI+EtM v/ePFcRmE9CT2Dj7FROILSIgK7G6aw57FyMXB7PAEUaJqauOsIMkhAXMJCaun8LYxcjBwSKgI nHkki1ImFfAVqJtxRwmiJlyEpe2fWEGsTkF7CQWNiwHiwsB1byZ8pMRwlaVeP1iFwtEr6DEyZ lPwGxmAQmJgy9eME9g5J2FJDULSWoBI9MqRo3i1KKy1CJdIwu9pKLM9IyS3MTMHF1DA1O93NT i4sT01JzEpGK95PzcTYzA4KlnYGDcwdi3yu8QoyQHk5Ior6HH1AghvqT8lMqMxOKM+KLSnNTi Q4wyHBxKErzzemdECAkWpaanVqRl5gDDGCYtwcGjJML7BiTNW1yQmFucmQ6ROsWoKCXOuwkkI QCSyCjNg2uDxc4lRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK810Cm8GTmlcBNfwW0mAlo8b Yr00AWlyQipKQaGDPLHs0wzOns07yTyjntWtust51a1qX2T+K+Pl83QUvkjuSB/6nLlqR2GYW yu3v2ZqvVtiftdnXUan61PoTfYfesl28163o6DAyN+3teVS47vybydnxO4a+ixZYeh6QZH27T 8q+csbKt6eIKYdmOF/s3+Cb1eZwKP851YOXxw9X5d+7YsbjFKLEUZyQaajEXFScCAJ6S0xWYA gAA X-Env-Sender: prvs=203acdd53=sergey.dyasli@citrix.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1486393118!44667478!1 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 21654 invoked from network); 6 Feb 2017 14:58:39 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 6 Feb 2017 14:58:39 -0000 X-IronPort-AV: E=Sophos;i="5.33,342,1477958400"; d="scan'208";a="413566036" From: Sergey Dyasli To: Date: Mon, 6 Feb 2017 14:57:45 +0000 Message-ID: <20170206145747.13885-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170206145747.13885-1-sergey.dyasli@citrix.com> References: <20170206145747.13885-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v2 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 Acked-by: Kevin Tian --- 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 d40d6a5..24fbbd4 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 unsigned long 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 always_inline unsigned long vmwrite_safe(unsigned long field,