From patchwork Mon Sep 4 08:14:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9936797 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 1D88A601EB for ; Mon, 4 Sep 2017 08:17:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F3DB28770 for ; Mon, 4 Sep 2017 08:17:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03F102877D; Mon, 4 Sep 2017 08:17:42 +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 3208C28780 for ; Mon, 4 Sep 2017 08:17:40 +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 1domXI-0006kK-JK; Mon, 04 Sep 2017 08:15:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domXH-0006jy-OH for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:15:11 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 73/B9-03874-F8B0DA95; Mon, 04 Sep 2017 08:15:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrrBXrePe22 kwaNNGhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aTtesZCy5JVezYeIOxgfGeSBcjJ4eEgL/E 46kLGEFsNgE9iY2zXzGB2CICshKru+awg9jMAp+YJBqOOYLYwgIOEvcvbwaLswioSPTu2czWx cjBwStgK3HycDbESHmJXW0XWUFsTgE7ibOr34CNFwIq6Vl8mBnCVpV4/WIXC4jNKyAocXLmEx aIVRISB1+8YJ7AyDsLSWoWktQCRqZVjBrFqUVlqUW6xsZ6SUWZ6RkluYmZObqGBmZ6uanFxYn pqTmJScV6yfm5mxiBocMABDsYd64PPMQoycGkJMp7//GaSCG+pPyUyozE4oz4otKc1OJDjDIc HEoSvMc510YKCRalpqdWpGXmAIMYJi3BwaMkwqsNkuYtLkjMLc5Mh0idYlSUEuc9CpIQAElkl ObBtcEi5xKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeZm4gKbwZOaVwE1/BbSYCWhx1cs1II tLEhFSUg2M6eUWsy/aFptMcOZjWrPMxGyC6+Vt4Q5aYb5yUzMiHumb1l25z/h89oy21Oaru05 NvCH5covL8gf1q71XKUZL3nPq09p7i32q/TFHGeWeqefW+8y7vWiBzt9pD2/8vfKsfe/u4zX/ upZ1z1gz4e7yLYv+veu4ME2U539ZbdfrnAflHr8WTl4eUaXEUpyRaKjFXFScCAA7k3cClwIAA A== X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1504512908!77498317!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 41239 invoked from network); 4 Sep 2017 08:15:10 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-21.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="446424742" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:39 +0100 Message-ID: <20170904081452.12960-2-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 01/14] 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 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);