From patchwork Fri Sep 29 15:01:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 9978251 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 25D2960311 for ; Fri, 29 Sep 2017 15:04:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17F0C2766D for ; Fri, 29 Sep 2017 15:04:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C01328458; Fri, 29 Sep 2017 15:04:00 +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 7F5172766D for ; Fri, 29 Sep 2017 15:03:59 +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 1dxwnY-0003ZO-Jr; Fri, 29 Sep 2017 15:01:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dxwnX-0003ZB-6p for xen-devel@lists.xenproject.org; Fri, 29 Sep 2017 15:01:51 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id E6/3D-03616-E506EC95; Fri, 29 Sep 2017 15:01:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGLMWRWlGSWpSXmKPExsXitHRDpG5swrl Ig9eLjS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oydm7+zFPTJVFw88Ye9gbFDrIuRk0NCwF+i +cosNhCbTUBPYt7xryxdjBwcIgIqErf3GoCYzAKVEqdmJYNUCAtYS0w8t4gVxGYRUJVoO30fr JNXwEbi6JtLrBAT5SXOPbjNDGILAdUsfnCUHaJGUOLkzCcsIDazgITEwRcvmCcwcs9CkpqFJL WAkWkVo3pxalFZapGusV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJSsV5yfu4mRmAYMADBDsa Of06HGCU5mJREeQViz0UK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuB1iQfKCRalpqdWpGXmAAMS Ji3BwaMkwrsHJM1bXJCYW5yZDpE6xajL0XHz7h8mIZa8/LxUKXHeHpAiAZCijNI8uBGw6LjEK CslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYd4pcUBTeDLzSuA2vQI6ggnoiMkTz4AcUZKIkJJqYE y4c31HT0j6z/9R6qdm/E+Je9nOePmAYU7hrNV8ytlh4QmuaXunqH7ee2PaytiwPzlbTuZa3L9 0elFY1VbjyTO0DnN5VmWcyvgwhfnb2TyXo3tq4+SmN7ne9LmavHhb5tfpq7/fLtpxjsn5g7xb rG6SotgB72WWMifnnJsbZ39uwl+jQ6IZGgeVWIozEg21mIuKEwHzp2etiQIAAA== X-Env-Sender: prvs=438a79e6a=George.Dunlap@citrix.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1506697308!117748685!1 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 43950 invoked from network); 29 Sep 2017 15:01:49 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 29 Sep 2017 15:01:49 -0000 X-IronPort-AV: E=Sophos;i="5.42,452,1500940800"; d="scan'208";a="441800563" From: George Dunlap To: Date: Fri, 29 Sep 2017 16:01:36 +0100 Message-ID: <20170929150144.7602-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Cc: Sergey Dyasli , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH 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 From: Sergey Dyasli 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 --- CC: Andrew Cooper CC: Jan Beulich --- 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 10cdfc09a9..78f51a6ce6 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);