From patchwork Tue Jul 18 10:34:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9847685 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 5249B602C8 for ; Tue, 18 Jul 2017 10:36:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E7F528550 for ; Tue, 18 Jul 2017 10:36:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 437D52853A; Tue, 18 Jul 2017 10:36:45 +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 D996E2853A for ; Tue, 18 Jul 2017 10:36:44 +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 1dXPpv-000643-1C; Tue, 18 Jul 2017 10:34:39 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXPpt-00062U-CV for xen-devel@lists.xen.org; Tue, 18 Jul 2017 10:34:37 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id C7/C7-03406-C34ED695; Tue, 18 Jul 2017 10:34:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDva7Nk9x Ig3kXJCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owna9czFlySqtix8QZjA+M9kS5GTg4JAX+J RVcnMYLYbAJ6Ehtnv2ICsUUEZCVWd81hB7GZBT4xSTQccwSxhQUcJbY/XsoCYrMIqEosvrwAz OYVsJWYOvkME8RMeYldbRdZQWxOATuJec87wWqEgGpWX9jFCmGrSrx+sQuqV1Di5MwnLBC7JC QOvnjBPIGRdxaS1CwkqQWMTKsYNYpTi8pSi3QNTfSSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxK TivWS83M3MQKDhwEIdjBe3xhwiFGSg0lJlHf1gdxIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8 Rx8B5QSLUtNTK9Iyc4BhDJOW4OBREuENegyU5i0uSMwtzkyHSJ1i1OV4NeH/NyYhlrz8vFQpc d5gkCIBkKKM0jy4EbCYusQoKyXMywh0lBBPQWpRbmYJqvwrRnEORiVh3i0gl/Bk5pXAbXoFdA QT0BHCvjkgR5QkIqSkGhh9Ztx4n961p/nsoZfXfgifaehYvvoKl57PfB89/7snevyvloS/q2w 8mitxcf8hOc7kKs/fQV2RKmpbXZesXR7j/1LPUFV6Z7lin6FLR2WVz7Pe5w7cy5S4NgZd3nLo 4JZmcU4byftX49axRKcaHlpl/W0W942mI390BNa39SnlfuvrVUxxuKTEUpyRaKjFXFScCACoG fnzpAIAAA== X-Env-Sender: prvs=365bef495=sergey.dyasli@citrix.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1500374074!48111968!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34282 invoked from network); 18 Jul 2017 10:34:36 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-2.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 18 Jul 2017 10:34:36 -0000 X-IronPort-AV: E=Sophos;i="5.40,377,1496102400"; d="scan'208";a="440264635" From: Sergey Dyasli To: Date: Tue, 18 Jul 2017 11:34:18 +0100 Message-ID: <20170718103429.25020-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170718103429.25020-1-sergey.dyasli@citrix.com> References: <20170718103429.25020-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 RFC 01/12] 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 --- 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 e8a57d118c..b8c8bba421 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1773,14 +1773,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 */ @@ -1790,7 +1800,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 ) @@ -1798,15 +1807,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); @@ -1817,11 +1824,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 6395e8fd1d..9086bb35dc 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);