From patchwork Tue Jan 31 11:20:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9546945 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 62BEC604A0 for ; Tue, 31 Jan 2017 11:23:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55A7E27BA5 for ; Tue, 31 Jan 2017 11:23:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49FBE28329; Tue, 31 Jan 2017 11:23:05 +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 DE48E2833B for ; Tue, 31 Jan 2017 11:23:04 +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 1cYWUf-0003GT-L0; Tue, 31 Jan 2017 11:21:01 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYWUe-0003GD-Fm for xen-devel@lists.xen.org; Tue, 31 Jan 2017 11:21:00 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 4D/0D-29440-B1370985; Tue, 31 Jan 2017 11:20:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrohUleqeEK EwdceE4slHxezODB6HN39mymAMYo1My8pvyKBNaPvyFK2gh7Vio9PwxsYX8t1MXJySAj4Sxyc +IARxGYT0JPYOPsVE4gtIiArsbprDnsXIxcHs8ARRompq46wgySEBcwlVr9sYAOxWQRUJRbdW gkU5+DgFXCXuLTTB2KmnMTNc53MIDangIfEv1VvWUBsIaCSo7+ns0PYqhKvX+wCi/MKCEqcnP kEzGYWkJA4+OIF8wRG3llIUrOQpBYwMq1i1ChOLSpLLdI1MtFLKspMzyjJTczM0TU0MNPLTS0 uTkxPzUlMKtZLzs/dxAgMHQYg2MG4cl3gIUZJDiYlUd7PwhMihPiS8lMqMxKLM+KLSnNSiw8x ynBwKEnw/i4EygkWpaanVqRl5gCDGCYtwcGjJML7EiTNW1yQmFucmQ6ROsWoKCXOK10ElBAAS WSU5sG1wSLnEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5P4KM58nMK4Gb/gpoMRPQYvdXfS CLSxIRUlINjGvS/mbO2pkhbVbwrkHN++7+suzlm27IR9ySuN+X8cTu5us9UW/sHl937rn69eB FdebMOZqsGse5M9fe81pRYj6pkJtH6MXKVWmL2DukW00eTjZbIeyaf+RJtfeld19ii989kNpb skVBaJ32qbSIBbGf066f7pcXdGp6+0VI6O5r81/thpX75yuxFGckGmoxFxUnAgBmMjjzlwIAA A== X-Env-Sender: prvs=197ca0e1a=sergey.dyasli@citrix.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1485861655!54123596!1 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 42012 invoked from network); 31 Jan 2017 11:20:58 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jan 2017 11:20:58 -0000 X-IronPort-AV: E=Sophos;i="5.33,314,1477958400"; d="scan'208";a="403088919" From: Sergey Dyasli To: Date: Tue, 31 Jan 2017 11:20:35 +0000 Message-ID: <1485861635-3473-5-git-send-email-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485861635-3473-1-git-send-email-sergey.dyasli@citrix.com> References: <1485861635-3473-1-git-send-email-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH 4/4] x86/vvmx: correctly emulate VMREAD 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 __vmread() in nested vmx mode: emulation of a guest's VMREAD with invalid arguments leads to BUG(). Fix this by using __vmread_safe() and reporting any kind of VMfail back to the guest. A new safe versions of get_vvmcs() macro and related functions are introduced because of new function signatures and lots of existing users. Signed-off-by: Sergey Dyasli --- xen/arch/x86/hvm/vmx/vmcs.c | 9 +++++---- xen/arch/x86/hvm/vmx/vvmx.c | 26 +++++++++++++++++++++++--- xen/include/asm-x86/hvm/vmx/vmcs.h | 3 ++- xen/include/asm-x86/hvm/vmx/vvmx.h | 7 +++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index c1f09c6..8d49c89 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -932,15 +932,16 @@ void virtual_vmcs_exit(const struct vcpu *v) __vmptrld(cur); } -u64 virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_encoding) +unsigned long virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_encoding, + u64 *val) { - u64 res; + unsigned long ret; virtual_vmcs_enter(v); - __vmread(vmcs_encoding, &res); + ret = __vmread_safe(vmcs_encoding, val); virtual_vmcs_exit(v); - return res; + return ret; } unsigned long virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index c427a24..e7f5010 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -261,7 +261,23 @@ u64 get_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding) u64 get_vvmcs_real(const struct vcpu *v, u32 encoding) { - return virtual_vmcs_vmread(v, encoding); + u64 val; + + virtual_vmcs_vmread(v, encoding, &val); + + return val; +} + +unsigned long get_vvmcs_virtual_safe(void *vvmcs, u32 encoding, u64 *val) +{ + *val = get_vvmcs_virtual(vvmcs, encoding); + + return 0; +} + +unsigned long get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, u64 *val) +{ + return virtual_vmcs_vmread(v, encoding, val); } unsigned long set_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding, u64 val) @@ -1710,13 +1726,17 @@ int nvmx_handle_vmread(struct cpu_user_regs *regs) struct vmx_inst_decoded decode; pagefault_info_t pfinfo; u64 value = 0; - int rc; + unsigned long rc; rc = decode_vmx_inst(regs, &decode, NULL, 0); if ( rc != X86EMUL_OKAY ) return rc; - value = get_vvmcs(v, reg_read(regs, decode.reg2)); + if ( (rc = get_vvmcs_safe(v, reg_read(regs, decode.reg2), &value)) ) + { + vmfail(regs, rc); + return X86EMUL_OKAY; + } switch ( decode.type ) { case VMX_INST_MEMREG_TYPE_MEMORY: diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index b30e0f7..7c57c00 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -540,7 +540,8 @@ void vmx_clear_eoi_exit_bitmap(struct vcpu *v, u8 vector); 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); +unsigned long virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_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 d60e0bb..28e2503 100644 --- a/xen/include/asm-x86/hvm/vmx/vvmx.h +++ b/xen/include/asm-x86/hvm/vmx/vvmx.h @@ -181,6 +181,8 @@ enum vvmcs_encoding_type { u64 get_vvmcs_virtual(void *vvmcs, u32 encoding); u64 get_vvmcs_real(const struct vcpu *, u32 encoding); +unsigned long get_vvmcs_virtual_safe(void *vvmcs, u32 encoding, u64 *val); +unsigned long get_vvmcs_real_safe(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); @@ -194,6 +196,11 @@ unsigned long set_vvmcs_real(const struct vcpu *, u32 encoding, u64 val); set_vvmcs_real(vcpu, encoding, val) : \ set_vvmcs_virtual(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding, val)) +#define get_vvmcs_safe(vcpu, encoding, val) \ + (cpu_has_vmx_vmcs_shadowing ? \ + get_vvmcs_real_safe(vcpu, encoding, val) : \ + get_vvmcs_virtual_safe(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding, val)) + uint64_t get_shadow_eptp(struct vcpu *v); void nvmx_destroy_vmcs(struct vcpu *v);