From patchwork Mon Feb 6 14:57:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9558173 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 1834560413 for ; Mon, 6 Feb 2017 15:00:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07C6327FA8 for ; Mon, 6 Feb 2017 15:00:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F10C127FB1; Mon, 6 Feb 2017 15:00:21 +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 93CAD27FB0 for ; Mon, 6 Feb 2017 15:00:21 +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 1cakk1-00083z-3G; Mon, 06 Feb 2017 14:58:05 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cakjz-00082k-EC for xen-devel@lists.xen.org; Mon, 06 Feb 2017 14:58:03 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id DB/3B-04971-BFE88985; Mon, 06 Feb 2017 14:58:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrohUvdX34w Ig8MX9S2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyJ15ewFDQpVHw6+5GtgfG4VBcjJ4eEgL9E w/EOVhCbTUBPYuPsV0wgtoiArMTqrjnsXYxcHMwCRxglpq46wg6SEBawltg6fwmYzSKgInHs9 wE2EJtXwFbi7YN+JoihchKXtn1hBrE5BewkFjYsB4sLAdW8mfKTEcJWlXj9YhcLRK+gxMmZT8 BsZgEJiYMvXjBPYOSdhSQ1C0lqASPTKkaN4tSistQiXUNjvaSizPSMktzEzBxdQwMzvdzU4uL E9NScxKRiveT83E2MwPBhAIIdjF+WBRxilORgUhLlNfSYGiHEl5SfUpmRWJwRX1Sak1p8iFGG g0NJgte6d0aEkGBRanpqRVpmDjCQYdISHDxKIrwHe4DSvMUFibnFmekQqVOMilLivJtA+gRAE hmleXBtsOi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHeBJApPJl5JXDTXwEtZgJavO3KNJ DFJYkIKakGxr2lF989ltTMyNklm5I650XW36PBSfm8TucdrU7xLouqzInaWlC5gkud7/bR7e9 lPi6xUpd6lsf22f341Nk3JlpMKPr8y7X2kEXwS8FFAiYzd5gH82priwm1WC06wpYm+SwgVrX+ /5O34cHqjTNlwzMPNBRszQ+aWPHz6j3/uIXay0U75j63U2Ipzkg01GIuKk4EAFjtxhaZAgAA X-Env-Sender: prvs=203acdd53=sergey.dyasli@citrix.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1486393079!56327287!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60263 invoked from network); 6 Feb 2017 14:58:02 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 6 Feb 2017 14:58:02 -0000 X-IronPort-AV: E=Sophos;i="5.33,342,1477958400"; d="scan'208";a="404675685" From: Sergey Dyasli To: Date: Mon, 6 Feb 2017 14:57:46 +0000 Message-ID: <20170206145747.13885-4-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 3/4] x86/vvmx: correctly emulate VMWRITE 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 There is an issue with the original __vmwrite() in nested vmx mode: emulation of a guest's VMWRITE with invalid arguments leads to BUG(). Fix this by using vmwrite_safe() and reporting any kind of VMfail back to the guest. Signed-off-by: Sergey Dyasli Acked-by: Kevin Tian --- xen/arch/x86/hvm/vmx/vmcs.c | 9 +++++++-- xen/arch/x86/hvm/vmx/vvmx.c | 15 +++++++++++---- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 +- xen/include/asm-x86/hvm/vmx/vvmx.h | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 24f7570..1d83a69 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -943,11 +943,16 @@ u64 virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_encoding) return res; } -void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val) +unsigned long virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, + u64 val) { + unsigned long ret; + virtual_vmcs_enter(v); - __vmwrite(vmcs_encoding, val); + ret = vmwrite_safe(vmcs_encoding, val); virtual_vmcs_exit(v); + + return ret; } /* diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 31ac360..1a3d1d2 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -264,7 +264,7 @@ u64 get_vvmcs_real(const struct vcpu *v, u32 encoding) return virtual_vmcs_vmread(v, encoding); } -void set_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding, u64 val) +unsigned long set_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding, u64 val) { union vmcs_encoding enc; u64 *content = (u64 *) vvmcs; @@ -298,11 +298,13 @@ void set_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding, u64 val) } content[offset] = res; + + return 0; } -void set_vvmcs_real(const struct vcpu *v, u32 encoding, u64 val) +unsigned long set_vvmcs_real(const struct vcpu *v, u32 encoding, u64 val) { - virtual_vmcs_vmwrite(v, encoding, val); + return virtual_vmcs_vmwrite(v, encoding, val); } static unsigned long reg_read(struct cpu_user_regs *regs, @@ -1740,13 +1742,18 @@ int nvmx_handle_vmwrite(struct cpu_user_regs *regs) unsigned long operand; u64 vmcs_encoding; bool_t okay = 1; + unsigned long err; if ( decode_vmx_inst(regs, &decode, &operand, 0) != X86EMUL_OKAY ) return X86EMUL_EXCEPTION; vmcs_encoding = reg_read(regs, decode.reg2); - set_vvmcs(v, vmcs_encoding, operand); + if ( (err = set_vvmcs(v, vmcs_encoding, operand)) ) + { + vmfail(regs, err); + return X86EMUL_OKAY; + } switch ( vmcs_encoding & ~VMCS_HIGH(0) ) { diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index 8d43efd..72dc5fc 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -541,7 +541,7 @@ int vmx_check_msr_bitmap(unsigned long *msr_bitmap, u32 msr, int access_type); void virtual_vmcs_enter(const struct vcpu *); void virtual_vmcs_exit(const struct vcpu *); u64 virtual_vmcs_vmread(const struct vcpu *, u32 encoding); -void virtual_vmcs_vmwrite(const struct vcpu *, u32 encoding, u64 val); +unsigned long virtual_vmcs_vmwrite(const struct vcpu *, u32 encoding, u64 val); static inline int vmx_add_guest_msr(u32 msr) { diff --git a/xen/include/asm-x86/hvm/vmx/vvmx.h b/xen/include/asm-x86/hvm/vmx/vvmx.h index 242e524..d60e0bb 100644 --- a/xen/include/asm-x86/hvm/vmx/vvmx.h +++ b/xen/include/asm-x86/hvm/vmx/vvmx.h @@ -181,8 +181,8 @@ enum vvmcs_encoding_type { u64 get_vvmcs_virtual(void *vvmcs, u32 encoding); u64 get_vvmcs_real(const struct vcpu *, u32 encoding); -void set_vvmcs_virtual(void *vvmcs, u32 encoding, u64 val); -void set_vvmcs_real(const struct vcpu *, u32 encoding, u64 val); +unsigned long set_vvmcs_virtual(void *vvmcs, u32 encoding, u64 val); +unsigned long set_vvmcs_real(const struct vcpu *, u32 encoding, u64 val); #define get_vvmcs(vcpu, encoding) \ (cpu_has_vmx_vmcs_shadowing ? \