From patchwork Wed Feb 8 10:09: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: 9562153 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 DB6F3601E5 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 CD87528391 for ; Wed, 8 Feb 2017 10:12:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1E65284A3; 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 5D4742849E for ; Wed, 8 Feb 2017 10:12:03 +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 1cbPC8-00018h-59; Wed, 08 Feb 2017 10:09:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbPC6-00018C-UE for xen-devel@lists.xen.org; Wed, 08 Feb 2017 10:09:47 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id B9/6E-21675-A6EEA985; Wed, 08 Feb 2017 10:09:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrrBXjfz3aw Igw97rC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozJu8+wF/xRrZj5YAtjA+MduS5GTg4JAX+J lw/2MIPYbAJ6Ehtnv2ICsUUEZCVWd81h72Lk4mAWOMIoMXXVEXaQhLCAlcT9vjYgm4ODRUBF4 ufOTJAwr4CtxJvVLcwQM+UkLm37wgxSwilgJ/HgnglIWAioZOqUjUwQtqrE6xe7WCBaBSVOzn wCZjMLSEgcfPGCeQIj7ywkqVlIUgsYmVYxqhenFpWlFula6CUVZaZnlOQmZuboGhqY6eWmFhc npqfmJCYV6yXn525iBAYOAxDsYJx92f8QoyQHk5Ior8/TWRFCfEn5KZUZicUZ8UWlOanFhxhl ODiUJHg/vgHKCRalpqdWpGXmAEMYJi3BwaMkwvsYJM1bXJCYW5yZDpE6xagoJc6r+RYoIQCSy CjNg2uDxc0lRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfN+AxnPk5lXAjf9FdBiJqDF10+DLS 5JREhJNTCyqzb2X6tryxKcX7zIqzjh1LJy46sHf7z8u9mnvKUipOaZygIT5wCPiFLXuGXLy+8 s6yla12c/9QKnX/+HKWJ7k497zNqv9Pi7xk3T/NJ7Kr/4ni/ZwPwn+1/GwwfrL72J7pUtv5xp K2qY02iUsth76aHNp/Q+Kc3pt7Urtw6wf/DyYPrtOHUlluKMREMt5qLiRACES9wxlgIAAA== X-Env-Sender: prvs=205b15c4b=sergey.dyasli@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1486548581!76480820!4 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 54213 invoked from network); 8 Feb 2017 10:09:45 -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:45 -0000 X-IronPort-AV: E=Sophos;i="5.33,346,1477958400"; d="scan'208";a="414224278" From: Sergey Dyasli To: Date: Wed, 8 Feb 2017 10:09:35 +0000 Message-ID: <20170208100935.30332-5-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 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 --- v2 --> v3: * virtual_vmcs_vmread_safe() is added in order to preserve the old behaviour for existing callers xen/arch/x86/hvm/vmx/vmcs.c | 12 ++++++++++++ xen/arch/x86/hvm/vmx/vvmx.c | 19 ++++++++++++++++++- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 ++ xen/include/asm-x86/hvm/vmx/vvmx.h | 8 ++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 1a429a3..2fd2d06 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -943,6 +943,18 @@ u64 virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_encoding) return res; } +enum vmx_insn_errno virtual_vmcs_vmread_safe(const struct vcpu *v, + u32 vmcs_encoding, u64 *val) +{ + enum vmx_insn_errno ret; + + virtual_vmcs_enter(v); + ret = vmread_safe(vmcs_encoding, val); + virtual_vmcs_exit(v); + + return ret; +} + void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val) { virtual_vmcs_enter(v); diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 402d5dc..a82ac50 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -264,6 +264,19 @@ u64 get_vvmcs_real(const struct vcpu *v, u32 encoding) return virtual_vmcs_vmread(v, encoding); } +enum vmx_insn_errno get_vvmcs_virtual_safe(void *vvmcs, u32 encoding, u64 *val) +{ + *val = get_vvmcs_virtual(vvmcs, encoding); + + return 0; +} + +enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, + u64 *val) +{ + return virtual_vmcs_vmread_safe(v, encoding, val); +} + void set_vvmcs_virtual(void *vvmcs, u32 vmcs_encoding, u64 val) { union vmcs_encoding enc; @@ -1727,7 +1740,11 @@ int nvmx_handle_vmread(struct cpu_user_regs *regs) 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 1e0fce5..ec4db43 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -541,6 +541,8 @@ 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); +enum vmx_insn_errno virtual_vmcs_vmread_safe(const struct vcpu *v, + u32 vmcs_encoding, u64 *val); void virtual_vmcs_vmwrite(const struct vcpu *, u32 encoding, u64 val); enum vmx_insn_errno virtual_vmcs_vmwrite_safe(const struct vcpu *v, u32 vmcs_encoding, u64 val); diff --git a/xen/include/asm-x86/hvm/vmx/vvmx.h b/xen/include/asm-x86/hvm/vmx/vvmx.h index e49a000..ca2fb25 100644 --- a/xen/include/asm-x86/hvm/vmx/vvmx.h +++ b/xen/include/asm-x86/hvm/vmx/vvmx.h @@ -183,6 +183,9 @@ 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); +enum vmx_insn_errno get_vvmcs_virtual_safe(void *vvmcs, u32 encoding, u64 *val); +enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *, u32 encoding, + u64 *val); enum vmx_insn_errno set_vvmcs_virtual_safe(void *vvmcs, u32 encoding, u64 val); enum vmx_insn_errno set_vvmcs_real_safe(const struct vcpu *, u32 encoding, u64 val); @@ -197,6 +200,11 @@ enum vmx_insn_errno set_vvmcs_real_safe(const struct vcpu *, u32 encoding, 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)) + #define set_vvmcs_safe(vcpu, encoding, val) \ (cpu_has_vmx_vmcs_shadowing ? \ set_vvmcs_real_safe(vcpu, encoding, val) : \