From patchwork Tue Oct 3 15:21:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9983055 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 3C1F3602B8 for ; Tue, 3 Oct 2017 15:23:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E2B22889D for ; Tue, 3 Oct 2017 15:23:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22E40289B1; Tue, 3 Oct 2017 15:23:43 +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 868B42889D for ; Tue, 3 Oct 2017 15:23:41 +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 1dzP0Z-0002yr-W5; Tue, 03 Oct 2017 15:21:19 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzP0Y-0002wg-AP for xen-devel@lists.xen.org; Tue, 03 Oct 2017 15:21:18 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 4B/5D-25121-DEAA3D95; Tue, 03 Oct 2017 15:21:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHRDpO7bVZc jDbYKWSz5uJjFgdHj6O7fTAGMUayZeUn5FQmsGW9/3GErWCpZMXvDWaYGxutCXYwcHBIC/hKL 3jh3MXJysAnoSWyc/YoJxBYRkJVY3TWHvYuRi4NZYC6zxMwNvawgCWEBT4l5JyeA2SwCKhLHZ zayg9i8AjYSh579YgaxJQTkJXa1XQSr4RSwlZhybD4LiC0EVPP9yx5GCFtV4vWLXSwQvYISJ2 c+AbOZBSQkDr54wTyBkXcWktQsJKkFjEyrGDWKU4vKUot0Dc31kooy0zNKchMzc3QNDYz1clO LixPTU3MSk4r1kvNzNzECQ4cBCHYwvjzteYhRkoNJSZT39bLLkUJ8SfkplRmJxRnxRaU5qcWH GGU4OJQkeH1XAuUEi1LTUyvSMnOAQQyTluDgURLhtVwBlOYtLkjMLc5Mh0idYtTl6Lh59w+TE Etefl6qlDhvEcgMAZCijNI8uBGwiLrEKCslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYd5SkCk8mX klcJteAR3BBHTEnK4LIEeUJCKkpBoYW2efFZwo0aKY65Nf5GUTuZKhMlmg5tdKJj0fz/TdysY icm5TRP5zp3xh/MAeIDfB+JXtmpXSXI9WfTuk7Pr89/fSi35SYaYGXfeYqzgkt5SqqISUFN6b FNimKcLMsyso9FxJffq63iutN/PYVnoy2drpXVjRd5g91G3i7uediczWX2Rt1iqxFGckGmoxF xUnAgBWYPAKowIAAA== X-Env-Sender: prvs=4422f64de=sergey.dyasli@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1507044071!79182981!5 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 37912 invoked from network); 3 Oct 2017 15:21:16 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 3 Oct 2017 15:21:16 -0000 X-IronPort-AV: E=Sophos;i="5.42,474,1500940800"; d="scan'208";a="442358107" From: Sergey Dyasli To: Date: Tue, 3 Oct 2017 16:21:02 +0100 Message-ID: <20171003152104.1432-8-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003152104.1432-1-sergey.dyasli@citrix.com> References: <20171003152104.1432-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jun Nakajima , George Dunlap , Andrew Cooper , Tim Deegan , George Dunlap , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v3 7/9] x86/np2m: implement sharing of np2m between vCPUs 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 At the moment, nested p2ms are not shared between vcpus even if they share the same base pointer. Modify p2m_get_nestedp2m() to allow sharing a np2m between multiple vcpus with the same np2m_base (L1 np2m_base value in VMCx12). If the current np2m doesn't match the current base pointer, first look for another nested p2m in the same domain with the same base pointer, before reclaiming one from the LRU. Signed-off-by: Sergey Dyasli Signed-off-by: George Dunlap --- xen/arch/x86/hvm/vmx/vvmx.c | 1 + xen/arch/x86/mm/p2m.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index 198ca72f2a..dde02c076b 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1201,6 +1201,7 @@ static void virtual_vmentry(struct cpu_user_regs *regs) /* Setup virtual ETP for L2 guest*/ if ( nestedhvm_paging_mode_hap(v) ) + /* This will setup the initial np2m for the nested vCPU */ __vmwrite(EPT_POINTER, get_shadow_eptp(v)); else __vmwrite(EPT_POINTER, get_host_eptp(v)); diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 3c62292165..90bf382a49 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1828,6 +1828,7 @@ p2m_get_nestedp2m_locked(struct vcpu *v) struct domain *d = v->domain; struct p2m_domain *p2m; uint64_t np2m_base = nhvm_vcpu_p2m_base(v); + unsigned int i; /* Mask out low bits; this avoids collisions with P2M_BASE_EADDR */ np2m_base &= ~(0xfffull); @@ -1841,19 +1842,19 @@ p2m_get_nestedp2m_locked(struct vcpu *v) if ( p2m ) { p2m_lock(p2m); - if ( p2m->np2m_base == np2m_base || p2m->np2m_base == P2M_BASE_EADDR ) + if ( p2m->np2m_base == np2m_base ) { /* Check if np2m was flushed just before the lock */ - if ( p2m->np2m_base == P2M_BASE_EADDR || - nv->np2m_generation != p2m->np2m_generation ) + if ( nv->np2m_generation != p2m->np2m_generation ) nvcpu_flush(v); + /* np2m is up-to-date */ p2m->np2m_base = np2m_base; assign_np2m(v, p2m); nestedp2m_unlock(d); return p2m; } - else + else if ( p2m->np2m_base != P2M_BASE_EADDR ) { /* vCPU is switching from some other valid np2m */ cpumask_clear_cpu(v->processor, p2m->dirty_cpumask); @@ -1861,6 +1862,23 @@ p2m_get_nestedp2m_locked(struct vcpu *v) p2m_unlock(p2m); } + /* Share a np2m if possible */ + for ( i = 0; i < MAX_NESTEDP2M; i++ ) + { + p2m = d->arch.nested_p2m[i]; + p2m_lock(p2m); + if ( p2m->np2m_base == np2m_base ) + { + nvcpu_flush(v); + p2m->np2m_base = np2m_base; + assign_np2m(v, p2m); + nestedp2m_unlock(d); + + return p2m; + } + p2m_unlock(p2m); + } + /* All p2m's are or were in use. Take the least recent used one, * flush it and reuse. */ p2m = p2m_getlru_nestedp2m(d, NULL);