From patchwork Mon Sep 4 08:14:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9936799 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 C61CC603F9 for ; Mon, 4 Sep 2017 08:17:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6BAF2879B for ; Mon, 4 Sep 2017 08:17:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B488D287B5; Mon, 4 Sep 2017 08:17:49 +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 28D51287E5 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-0006li-Eu; Mon, 04 Sep 2017 08:15:14 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domXI-0006jz-Ui for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:15:13 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id F4/67-01911-F8B0DA95; Mon, 04 Sep 2017 08:15:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUrePe22 kwZWVRhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bpbTeYCl4pVSy4MZ29gfGpTBcjJ4eEgL/E pjUNzCA2m4CexMbZr5hAbBEBWYnVXXPYQWxmgU9MEg3HHEFsYQFfie6zm8DiLAIqEuceXWcBs XkFbCX+bLzKAjFTXmJX20VWEJtTwE7i7Oo3jCC2EFBNz+LDzBC2qsTrF7ugegUlTs58wgKxS0 Li4IsXzBMYeWchSc1CklrAyLSKUaM4tagstUjXyEIvqSgzPaMkNzEzR9fQwFgvN7W4ODE9NSc xqVgvOT93EyMweOoZGBh3MLaf8DvEKMnBpCTKe//xmkghvqT8lMqMxOKM+KLSnNTiQ4wyHBxK ErwSXGsjhQSLUtNTK9Iyc4BhDJOW4OBREuGVA0nzFhck5hZnpkOkTjEqSonzuoEkBEASGaV5c G2w2LnEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZh3G8gUnsy8Erjpr4AWMwEtrnq5BmRxSS JCSqqB0XzqleKKafoioe/9fkyoOPDxzFXvbZd41xd4la5WsW+fcVissvLejmO8DlP+ii6xNP9 10jPj5yX7I7MKe+fMnPtYTPxMbMdED+92x89zCrZV79Y65J23JeX6Cd7WtYHnHZeqhskavK/n 316jcK45afvZa/t6IhcuXDLJfkd3yxeR6Zn/N2efPK3EUpyRaKjFXFScCACg53LGmAIAAA== X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1504512908!113034703!2 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 60952 invoked from network); 4 Sep 2017 08:15:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2017 08:15:10 -0000 X-IronPort-AV: E=Sophos;i="5.41,473,1498521600"; d="scan'208";a="438259573" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:42 +0100 Message-ID: <20170904081452.12960-5-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 04/14] x86/np2m: remove np2m_base from p2m_get_nestedp2m() 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 Remove np2m_base parameter as it should always match the value of np2m_base in VMCX12. Signed-off-by: Sergey Dyasli Reviewed-by: George Dunlap --- RFC --> v1: - Nested SVM: added early update of ns_vmcb_hostcr3 xen/arch/x86/hvm/svm/nestedsvm.c | 6 +++++- xen/arch/x86/hvm/vmx/vvmx.c | 3 +-- xen/arch/x86/mm/hap/nested_hap.c | 2 +- xen/arch/x86/mm/p2m.c | 8 ++++---- xen/include/asm-x86/p2m.h | 5 ++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c index 8fd9c23a02..629d5ea497 100644 --- a/xen/arch/x86/hvm/svm/nestedsvm.c +++ b/xen/arch/x86/hvm/svm/nestedsvm.c @@ -411,7 +411,11 @@ static void nestedsvm_vmcb_set_nestedp2m(struct vcpu *v, ASSERT(v != NULL); ASSERT(vvmcb != NULL); ASSERT(n2vmcb != NULL); - p2m = p2m_get_nestedp2m(v, vvmcb->_h_cr3); + + /* This will allow nsvm_vcpu_hostcr3() to return correct np2m_base */ + vcpu_nestedsvm(v).ns_vmcb_hostcr3 = vvmcb->_h_cr3; + + p2m = p2m_get_nestedp2m(v); n2vmcb->_h_cr3 = pagetable_get_paddr(p2m_get_pagetable(p2m)); } diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 3c5f560aec..ea2da14489 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1109,8 +1109,7 @@ static void load_shadow_guest_state(struct vcpu *v) uint64_t get_shadow_eptp(struct vcpu *v) { - uint64_t np2m_base = nvmx_vcpu_eptp_base(v); - struct p2m_domain *p2m = p2m_get_nestedp2m(v, np2m_base); + struct p2m_domain *p2m = p2m_get_nestedp2m(v); struct ept_data *ept = &p2m->ept; ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index 162afed46b..ed137fa784 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -212,7 +212,7 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, uint8_t p2ma_21 = p2m_access_rwx; p2m = p2m_get_hostp2m(d); /* L0 p2m */ - nested_p2m = p2m_get_nestedp2m(v, nhvm_vcpu_p2m_base(v)); + nested_p2m = p2m_get_nestedp2m(v); /* walk the L1 P2M table */ rv = nestedhap_walk_L1_p2m(v, *L2_gpa, &L1_gpa, &page_order_21, &p2ma_21, diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 94a42400ad..b735950349 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1810,11 +1810,12 @@ static void assign_np2m(struct vcpu *v, struct p2m_domain *p2m) } struct p2m_domain * -p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base) +p2m_get_nestedp2m(struct vcpu *v) { struct nestedvcpu *nv = &vcpu_nestedhvm(v); struct domain *d = v->domain; struct p2m_domain *p2m; + uint64_t np2m_base = nhvm_vcpu_p2m_base(v); /* Mask out low bits; this avoids collisions with P2M_BASE_EADDR */ np2m_base &= ~(0xfffull); @@ -1862,7 +1863,7 @@ p2m_get_p2m(struct vcpu *v) if (!nestedhvm_is_n2(v)) return p2m_get_hostp2m(v->domain); - return p2m_get_nestedp2m(v, nhvm_vcpu_p2m_base(v)); + return p2m_get_nestedp2m(v); } unsigned long paging_gva_to_gfn(struct vcpu *v, @@ -1877,13 +1878,12 @@ unsigned long paging_gva_to_gfn(struct vcpu *v, unsigned long l2_gfn, l1_gfn; struct p2m_domain *p2m; const struct paging_mode *mode; - uint64_t np2m_base = nhvm_vcpu_p2m_base(v); uint8_t l1_p2ma; unsigned int l1_page_order; int rv; /* translate l2 guest va into l2 guest gfn */ - p2m = p2m_get_nestedp2m(v, np2m_base); + p2m = p2m_get_nestedp2m(v); mode = paging_get_nestedmode(v); l2_gfn = mode->gva_to_gfn(v, p2m, va, pfec); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index cfb00591cd..1d17fd5f97 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -360,10 +360,9 @@ struct p2m_domain { #define p2m_get_hostp2m(d) ((d)->arch.p2m) /* - * Assigns an np2m with the specified np2m_base to the specified vCPU - * and returns that np2m. + * Updates vCPU's n2pm to match its np2m_base in VMCX12 and returns that np2m. */ -struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base); +struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v); /* If vcpu is in host mode then behaviour matches p2m_get_hostp2m(). * If vcpu is in guest mode then behaviour matches p2m_get_nestedp2m().