From patchwork Tue Oct 3 15:20:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9983057 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 714EF602B8 for ; Tue, 3 Oct 2017 15:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 632E72889D for ; Tue, 3 Oct 2017 15:23:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57F46289B1; Tue, 3 Oct 2017 15:23:44 +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 EFD012889D for ; Tue, 3 Oct 2017 15:23:43 +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 1dzP0W-0002w4-E5; Tue, 03 Oct 2017 15:21:16 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzP0V-0002v0-0w for xen-devel@lists.xen.org; Tue, 03 Oct 2017 15:21:15 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 62/9C-17770-AEAA3D95; Tue, 03 Oct 2017 15:21:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrrBXvflqsu RBq2frC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oy7W24wF3RIV+w4ENfAOEG0i5GTQ0LAX6Lt 2zVWEJtNQE9i4+xXTCC2iICsxOquOewgNrPAJyaJhmOOXYwcHMICdhL3LuiBhFkEVCQ+HHkG1 sorYCOx5eQ0FoiR8hK72i6CxTkFbCWmHJsPFhcCqvn+ZQ8jhK0q8frFLhaIXkGJkzOfsECskp A4+OIF8wRG3llIUrOQpBYwMq1i1ChOLSpLLdI1NNBLKspMzyjJTczMAfLM9HJTi4sT01NzEpO K9ZLzczcxAgOHAQh2MB5/H3eIUZKDSUmU9/Wyy5FCfEn5KZUZicUZ8UWlOanFhxhlODiUJHgv rATKCRalpqdWpGXmAEMYJi3BwaMkwmu5AijNW1yQmFucmQ6ROsWoy9Fx8+4fJiGWvPy8VClx3 kcgMwRAijJK8+BGwOLpEqOslDAvI9BRQjwFqUW5mSWo8q8YxTkYlYR5v4BM4cnMK4Hb9AroCC agI+Z0XQA5oiQRISXVwMhxii/tZs/ebzy+4oYStmaLlzWpm3sU8+mv2n3VXODPf9s3dz/opEx i3ZlQcz/rSmyRbJS3i8SZdeUXwnSjZ12r1P2jcE3syrpnL45b2Wx6wlml3zyJYUPZMpF7PRs4 1NnL/vxy/v/M92tl0/KDJtcDXuZYaDBnck61rOv7++Nz8dEDV9OMy5VYijMSDbWYi4oTAQuIE 6eiAgAA X-Env-Sender: prvs=4422f64de=sergey.dyasli@citrix.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1507044071!79162960!2 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.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28495 invoked from network); 3 Oct 2017 15:21:13 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 3 Oct 2017 15:21:13 -0000 X-IronPort-AV: E=Sophos;i="5.42,474,1500940800"; d="scan'208";a="450330535" From: Sergey Dyasli To: Date: Tue, 3 Oct 2017 16:20:56 +0100 Message-ID: <20171003152104.1432-2-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 , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v3 1/9] x86/np2m: refactor 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 1. Add a helper function assign_np2m() 2. Remove useless volatile 3. Update function's comment in the header 4. Minor style fixes ('\n' and d) Signed-off-by: Sergey Dyasli Reviewed-by: George Dunlap --- xen/arch/x86/mm/p2m.c | 31 ++++++++++++++++++------------- xen/include/asm-x86/p2m.h | 6 +++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 0b479105b9..27b90eb815 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1776,14 +1776,24 @@ p2m_flush_nestedp2m(struct domain *d) p2m_flush_table(d->arch.nested_p2m[i]); } +static void assign_np2m(struct vcpu *v, struct p2m_domain *p2m) +{ + struct nestedvcpu *nv = &vcpu_nestedhvm(v); + struct domain *d = v->domain; + + /* Bring this np2m to the top of the LRU list */ + p2m_getlru_nestedp2m(d, p2m); + + nv->nv_flushp2m = 0; + nv->nv_p2m = p2m; + cpumask_set_cpu(v->processor, p2m->dirty_cpumask); +} + struct p2m_domain * p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base) { - /* Use volatile to prevent gcc to cache nv->nv_p2m in a cpu register as - * this may change within the loop by an other (v)cpu. - */ - volatile struct nestedvcpu *nv = &vcpu_nestedhvm(v); - struct domain *d; + struct nestedvcpu *nv = &vcpu_nestedhvm(v); + struct domain *d = v->domain; struct p2m_domain *p2m; /* Mask out low bits; this avoids collisions with P2M_BASE_EADDR */ @@ -1793,7 +1803,6 @@ p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base) nv->nv_p2m = NULL; } - d = v->domain; nestedp2m_lock(d); p2m = nv->nv_p2m; if ( p2m ) @@ -1801,15 +1810,13 @@ p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base) p2m_lock(p2m); if ( p2m->np2m_base == np2m_base || p2m->np2m_base == P2M_BASE_EADDR ) { - nv->nv_flushp2m = 0; - p2m_getlru_nestedp2m(d, p2m); - nv->nv_p2m = p2m; if ( p2m->np2m_base == P2M_BASE_EADDR ) hvm_asid_flush_vcpu(v); p2m->np2m_base = np2m_base; - cpumask_set_cpu(v->processor, p2m->dirty_cpumask); + assign_np2m(v, p2m); p2m_unlock(p2m); nestedp2m_unlock(d); + return p2m; } p2m_unlock(p2m); @@ -1820,11 +1827,9 @@ p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base) p2m = p2m_getlru_nestedp2m(d, NULL); p2m_flush_table(p2m); p2m_lock(p2m); - nv->nv_p2m = p2m; p2m->np2m_base = np2m_base; - nv->nv_flushp2m = 0; hvm_asid_flush_vcpu(v); - cpumask_set_cpu(v->processor, p2m->dirty_cpumask); + assign_np2m(v, p2m); p2m_unlock(p2m); nestedp2m_unlock(d); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 8f3409b400..338317a782 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -359,9 +359,9 @@ struct p2m_domain { /* get host p2m table */ #define p2m_get_hostp2m(d) ((d)->arch.p2m) -/* Get p2m table (re)usable for specified np2m base. - * Automatically destroys and re-initializes a p2m if none found. - * If np2m_base == 0 then v->arch.hvm_vcpu.guest_cr[3] is used. +/* + * Assigns an np2m with the specified np2m_base to the specified vCPU + * and returns that np2m. */ struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v, uint64_t np2m_base);