From patchwork Tue Jan 31 11:20:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9546941 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 2F0B9604A0 for ; Tue, 31 Jan 2017 11:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20EB727BA5 for ; Tue, 31 Jan 2017 11:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 155C028338; Tue, 31 Jan 2017 11:23: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 6A4CD27BA5 for ; Tue, 31 Jan 2017 11:23: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 1cYWUk-0003JL-Km; Tue, 31 Jan 2017 11:21:06 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYWUj-0003Hi-Dr for xen-devel@lists.xen.org; Tue, 31 Jan 2017 11:21:05 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id B1/51-25337-02370985; Tue, 31 Jan 2017 11:21:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXle+eEK Ewe7r+hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bhf6wFbQoVD3/9Y2lgPC3VxcjJISHgL3Gg 5RA7iM0moCexcfYrJhBbREBWYnXXHKA4FwezwBFGiamrjoAVCQtYSMw72sUIYrMIqErs6jzKB mLzCrhLfO2ZwwQxVE7i5rlOZhCbU8BD4t+qtywgthBQzdHf09khbFWJ1y92sUD0CkqcnPkEzG YWkJA4+OIF8wRG3llIUrOQpBYwMq1i1ChOLSpLLdI1MtVLKspMzyjJTczM0TU0MNPLTS0uTkx PzUlMKtZLzs/dxAgMHgYg2MG4akHgIUZJDiYlUd7PwhMihPiS8lMqMxKLM+KLSnNSiw8xynBw KEnwphcB5QSLUtNTK9Iyc4BhDJOW4OBREuF9WQiU5i0uSMwtzkyHSJ1iVJQS55UG6RMASWSU5 sG1wWLnEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5s0Cm8GTmlcBNfwW0mAlosfurPpDFJY kIKakGxsJD/gnKhj+eBzHeFfh/vnZGaPQ0B88veau+18czvHHyfS7RpBGesSwiJL9v14rr1Qu 9dm6fMnVxzsVg9WrxgHK7/3/qvX13+p0vDfaaYbUh6NmOd4+cF9rL3Bd0unD+R/d3VY3787an r/rp/ZRzxYXad5zcR+wezRNnNPjoxpV9++/7vNdcpUosxRmJhlrMRcWJABW1uAmYAgAA X-Env-Sender: prvs=197ca0e1a=sergey.dyasli@citrix.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1485861655!48694532!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.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18807 invoked from network); 31 Jan 2017 11:21:03 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-10.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jan 2017 11:21:03 -0000 X-IronPort-AV: E=Sophos;i="5.33,314,1477958400"; d="scan'208";a="411964581" From: Sergey Dyasli To: Date: Tue, 31 Jan 2017 11:20:34 +0000 Message-ID: <1485861635-3473-4-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 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 --- 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 641e2ef..c1f09c6 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 e0cf0fb..c427a24 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 cb02d53..b30e0f7 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 ? \