From patchwork Tue Oct 3 15:21:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9983059 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 18611602B8 for ; Tue, 3 Oct 2017 15:23:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AD42289AC for ; Tue, 3 Oct 2017 15:23:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3D96289C1; Tue, 3 Oct 2017 15:23: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 ACDC9289AC for ; Tue, 3 Oct 2017 15:23:45 +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 1dzP0Y-0002wt-2j; Tue, 03 Oct 2017 15:21:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzP0W-0002vq-Hm for xen-devel@lists.xen.org; Tue, 03 Oct 2017 15:21:16 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 32/71-02224-BEAA3D95; Tue, 03 Oct 2017 15:21:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHRDpO7rVZc jDTpPClgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnLNyxmKfgvUPHx6iHmBsaZPF2MnBwSAv4S vw7+Ywax2QT0JDbOfsUEYosIyEqs7prDDmIzC3xikmg45ghiCwu4Ssy/tQosziKgIvFgyURWE JtXwEZi2s0XrBAz5SV2tV0EszkFbCWmHJvPAmILAdV8/7KHEcJWlXj9YhcLRK+gxMmZT1ggdk lIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGprrJRVlpmeU5CZm5ugaGhjr5aYWFyemp+Y kJhXrJefnbmIEBg8DEOxgfHna8xCjJAeTkijv62WXI4X4kvJTKjMSizPii0pzUosPMcpwcChJ 8PquBMoJFqWmp1akZeYAwxgmLcHBoyTCa7kCKM1bXJCYW5yZDpE6xajL0XHz7h8mIZa8/LxUK XHeIpAZAiBFGaV5cCNgMXWJUVZKmJcR6CghnoLUotzMElT5V4ziHIxKwrylIFN4MvNK4Da9Aj qCCeiIOV0XQI4oSURISTUwzmjiagy6ofRVly2vfBnn7xwzXrsfk5avaA+xyqs6On1ubeemtL2 +v8uczQsOBFiv2nHtROVO+0vFc5l751oYf1omnqbTe++CecPBB09z/9VsCDTbHeduEneXIfNb mZbdGdWKs+JeTAEPvlwNWL9u8THXxV9yIy+3uQfPOeTmafL7v+Kbst48JZbijERDLeai4kQAB LVQN6QCAAA= X-Env-Sender: prvs=4422f64de=sergey.dyasli@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1507044071!79182981!3 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 37813 invoked from network); 3 Oct 2017 15:21:15 -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:15 -0000 X-IronPort-AV: E=Sophos;i="5.42,474,1500940800"; d="scan'208";a="442358101" From: Sergey Dyasli To: Date: Tue, 3 Oct 2017 16:21:03 +0100 Message-ID: <20171003152104.1432-9-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 8/9] x86/np2m: refactor p2m_get_nestedp2m_locked() 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 Remove some code duplication. Suggested-by: George Dunlap Signed-off-by: Sergey Dyasli Reviewed-by: George Dunlap --- xen/arch/x86/mm/p2m.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 90bf382a49..6c937c9e17 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1829,6 +1829,7 @@ p2m_get_nestedp2m_locked(struct vcpu *v) struct p2m_domain *p2m; uint64_t np2m_base = nhvm_vcpu_p2m_base(v); unsigned int i; + bool needs_flush = true; /* Mask out low bits; this avoids collisions with P2M_BASE_EADDR */ np2m_base &= ~(0xfffull); @@ -1845,14 +1846,10 @@ p2m_get_nestedp2m_locked(struct vcpu *v) if ( p2m->np2m_base == np2m_base ) { /* Check if np2m was flushed just before the lock */ - if ( nv->np2m_generation != p2m->np2m_generation ) - nvcpu_flush(v); + if ( nv->np2m_generation == p2m->np2m_generation ) + needs_flush = false; /* np2m is up-to-date */ - p2m->np2m_base = np2m_base; - assign_np2m(v, p2m); - nestedp2m_unlock(d); - - return p2m; + goto found; } else if ( p2m->np2m_base != P2M_BASE_EADDR ) { @@ -1867,15 +1864,10 @@ p2m_get_nestedp2m_locked(struct vcpu *v) { 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); + goto found; - return p2m; - } p2m_unlock(p2m); } @@ -1884,8 +1876,11 @@ p2m_get_nestedp2m_locked(struct vcpu *v) p2m = p2m_getlru_nestedp2m(d, NULL); p2m_flush_table(p2m); p2m_lock(p2m); + + found: + if ( needs_flush ) + nvcpu_flush(v); p2m->np2m_base = np2m_base; - nvcpu_flush(v); assign_np2m(v, p2m); nestedp2m_unlock(d);