From patchwork Mon Sep 4 08:14: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: 9936805 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 1C2D76089F for ; Mon, 4 Sep 2017 08:17:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CC0328770 for ; Mon, 4 Sep 2017 08:17:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019372877D; Mon, 4 Sep 2017 08:17:50 +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 962DE28792 for ; Mon, 4 Sep 2017 08:17:47 +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 1domXK-0006lL-10; Mon, 04 Sep 2017 08:15:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domXI-0006k7-Tt for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:15:13 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id C8/23-03423-09B0DA95; Mon, 04 Sep 2017 08:15:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeJIrShJLcpLzFFi42JxWrohUrefe22 kQedXE4slHxezODB6HN39mymAMYo1My8pvyKBNeN7z0rWgucSFRv/CDcw/hfuYuTkkBDwl1h3 awcriM0moCexcfYrJhBbREBWYnXXHHYQm1ngE5NEwzFHEFtYIECiedYcsHoWARWJvYt+MXcxc nDwCthKzDmQADFSXmJX20WwEk4BO4mzq98wgthCQCU9iw8zQ9iqEq9f7GIBsXkFBCVOznzCAr FKQuLgixfMExh5ZyFJzUKSWsDItIpRvTi1qCy1SNdYL6koMz2jJDcxM0fX0MBMLze1uDgxPTU nMalYLzk/dxMjMGwYgGAHY8c/p0OMkhxMSqK89x+viRTiS8pPqcxILM6ILyrNSS0+xCjDwaEk wSvBtTZSSLAoNT21Ii0zBxjAMGkJDh4lEV45kDRvcUFibnFmOkTqFKOilDivG0hCACSRUZoH1 waLmkuMslLCvIxAhwjxFKQW5WaWoMq/YhTnYFQS5t0GMoUnM68EbvoroMVMQIurXq4BWVySiJ CSamC0rhYU25jLLbKJc/m2XUHWDBz7gk+of+tbvWJ70Akmwd235qxf+1SP9z6PHpfh/dfuHc9 yN9yffkSq5Jiv5feO5d+YZz2ZtWRqhdOnJqfuL9M08qZKHNryPkO0ejunl/2qe6cn2i869CDt 9M6fcvGvNuTYyegt8At0kVGU955/6YrZJLMzHwyeKbEUZyQaajEXFScCAJq42a2VAgAA X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1504512910!114067308!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.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 36620 invoked from network); 4 Sep 2017 08:15:11 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2017 08:15:11 -0000 X-IronPort-AV: E=Sophos;i="5.41,473,1498521600"; d="scan'208";a="438259575" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:45 +0100 Message-ID: <20170904081452.12960-8-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170904081452.12960-1-sergey.dyasli@citrix.com> References: <20170904081452.12960-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jun Nakajima , George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v1 07/14] x86/vvmx: restart nested vmentry in case of stale_np2m 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 If an IPI flushes vCPU's np2m object just before nested vmentry, there will be a stale shadow EPTP value in VMCS02. Allow vmentry to be restarted in such cases and add nvmx_eptp_update() to perform an update. Signed-off-by: Sergey Dyasli --- xen/arch/x86/hvm/vmx/entry.S | 6 ++++++ xen/arch/x86/hvm/vmx/vmx.c | 8 +++++++- xen/arch/x86/hvm/vmx/vvmx.c | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vmx/entry.S b/xen/arch/x86/hvm/vmx/entry.S index 53eedc6363..9fb8f89220 100644 --- a/xen/arch/x86/hvm/vmx/entry.S +++ b/xen/arch/x86/hvm/vmx/entry.S @@ -79,6 +79,8 @@ UNLIKELY_END(realmode) mov %rsp,%rdi call vmx_vmenter_helper + cmp $0,%eax + jne .Lvmx_vmentry_restart mov VCPU_hvm_guest_cr2(%rbx),%rax pop %r15 @@ -117,6 +119,10 @@ ENTRY(vmx_asm_do_vmentry) GET_CURRENT(bx) jmp .Lvmx_do_vmentry +.Lvmx_vmentry_restart: + sti + jmp .Lvmx_do_vmentry + .Lvmx_goto_emulator: sti mov %rsp,%rdi diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index f6da119c9f..06509590b7 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -4223,13 +4223,17 @@ static void lbr_fixup(void) bdw_erratum_bdf14_fixup(); } -void vmx_vmenter_helper(const struct cpu_user_regs *regs) +int vmx_vmenter_helper(const struct cpu_user_regs *regs) { struct vcpu *curr = current; u32 new_asid, old_asid; struct hvm_vcpu_asid *p_asid; bool_t need_flush; + /* Shadow EPTP can't be updated here because irqs are disabled */ + if ( nestedhvm_vcpu_in_guestmode(curr) && vcpu_nestedhvm(curr).stale_np2m ) + return 1; + if ( curr->domain->arch.hvm_domain.pi_ops.do_resume ) curr->domain->arch.hvm_domain.pi_ops.do_resume(curr); @@ -4290,6 +4294,8 @@ void vmx_vmenter_helper(const struct cpu_user_regs *regs) __vmwrite(GUEST_RIP, regs->rip); __vmwrite(GUEST_RSP, regs->rsp); __vmwrite(GUEST_RFLAGS, regs->rflags | X86_EFLAGS_MBS); + + return 0; } /* diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index ea2da14489..26ce349c76 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1405,12 +1405,26 @@ static void virtual_vmexit(struct cpu_user_regs *regs) vmsucceed(regs); } +static void nvmx_eptp_update(void) +{ + if ( !nestedhvm_vcpu_in_guestmode(current) || + vcpu_nestedhvm(current).nv_vmexit_pending || + !vcpu_nestedhvm(current).stale_np2m || + !nestedhvm_paging_mode_hap(current) ) + return; + + __vmwrite(EPT_POINTER, get_shadow_eptp(current)); + vcpu_nestedhvm(current).stale_np2m = false; +} + void nvmx_switch_guest(void) { struct vcpu *v = current; struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v); struct cpu_user_regs *regs = guest_cpu_user_regs(); + nvmx_eptp_update(); + /* * A pending IO emulation may still be not finished. In this case, no * virtual vmswitch is allowed. Or else, the following IO emulation will