From patchwork Thu Sep 15 11:28:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 76294 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2387456qgf; Thu, 15 Sep 2016 04:31:11 -0700 (PDT) X-Received: by 10.107.20.16 with SMTP id 16mr10762151iou.13.1473939070992; Thu, 15 Sep 2016 04:31:10 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a141si3209984itb.112.2016.09.15.04.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 04:31:10 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUqi-0004ea-S8; Thu, 15 Sep 2016 11:29:00 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUqh-0004dl-IF for xen-devel@lists.xen.org; Thu, 15 Sep 2016 11:28:59 +0000 Received: from [85.158.139.211] by server-14.bemta-5.messagelabs.com id BC/76-11508-AF58AD75; Thu, 15 Sep 2016 11:28:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTfdX661 wg6NzZCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oxdDx+zF/TIVJz83szcwDhRrIuRi0NIYBOj RMOBHnYI5zSjxIHdv4EcTg42AU2JO58/MYHYIgLSEtc+X2YEKWIWaGeUWNvfywySEBZIlLjb2 gPWwCKgKjHzRjdYA6+Ai8TBB6tYQWwJATmJk8cmA9kcHJwCrhJLnouChIWASo6d2Mk2gZF7AS PDKkaN4tSistQiXSMDvaSizPSMktzEzBxdQwNTvdzU4uLE9NScxKRiveT83E2MQA/XMzAw7mB snO13iFGSg0lJlNct7Va4EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQnefS1AOcGi1PTUirTMHGCo waQlOHiURHjZQdK8xQWJucWZ6RCpU4yKUuIQfQIgiYzSPLg2WHhfYpSVEuZlZGBgEOIpSC3Kz SxBlX/FKM7BqCTMewRkCk9mXgnc9FdAi5mAFm9Zcx1kcUkiQkqqgTH4boMP0w3215nBHDPv8d 85a83wqrTaqcpUMZHdrOrEhpoCiQI7h6vGTOv6XPv9Y7utQ97t1zZZGxdhJcxxJyDp7lHmV0Z vT1gsemhu+lyQpzgqboXi1HnxanYKeTeFVReXzEt5MCO92a9eny/q56nDcbIfY6+G1H8rzDS4 o64j/XHZlB38SizFGYmGWsxFxYkAcG+FbGoCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1473938937!23350663!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28258 invoked from network); 15 Sep 2016 11:28:58 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-206.messagelabs.com with SMTP; 15 Sep 2016 11:28:58 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7F6737FA; Thu, 15 Sep 2016 04:28:57 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7AC113F251; Thu, 15 Sep 2016 04:28:56 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 15 Sep 2016 12:28:24 +0100 Message-Id: <1473938919-31976-9-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473938919-31976-1-git-send-email-julien.grall@arm.com> References: <1473938919-31976-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [for-4.8][PATCH v2 08/23] xen/arm: p2m: Invalidate the TLBs when write unlocking the p2m 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Sometimes the invalidation of the TLBs can be deferred until the p2m is unlocked. This is for instance the case when multiple mappings are removed. In other case, such as shattering a superpage, an immediate flush is required. Keep track whether a flush is needed directly in the p2m_domain structure to allow serializing multiple changes. The TLBs will be invalidated when write unlocking the p2m if necessary. Also a new helper, p2m_flush_sync, has been introduced to force a synchronous TLB invalidation. Finally, replace the call to p2m_flush_tlb by p2m_flush_tlb_sync in apply_p2m_changes. Note this patch is not useful today, however follow-up patches will make advantage of it. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/p2m.c | 33 ++++++++++++++++++++++++++++++++- xen/include/asm-arm/p2m.h | 11 +++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 5cf136f..b53d4cf 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -52,8 +52,21 @@ static inline void p2m_write_lock(struct p2m_domain *p2m) write_lock(&p2m->lock); } +static void p2m_flush_tlb(struct p2m_domain *p2m); + static inline void p2m_write_unlock(struct p2m_domain *p2m) { + if ( p2m->need_flush ) + { + p2m->need_flush = false; + /* + * The final flush is done with the P2M write lock taken to + * to avoid someone else modify the P2M before the TLB + * invalidation has completed. + */ + p2m_flush_tlb(p2m); + } + write_unlock(&p2m->lock); } @@ -72,6 +85,11 @@ static inline int p2m_is_locked(struct p2m_domain *p2m) return rw_is_locked(&p2m->lock); } +static inline int p2m_is_write_locked(struct p2m_domain *p2m) +{ + return rw_is_write_locked(&p2m->lock); +} + void p2m_dump_info(struct domain *d) { struct p2m_domain *p2m = &d->arch.p2m; @@ -165,6 +183,19 @@ static void p2m_flush_tlb(struct p2m_domain *p2m) } /* + * Force a synchronous P2M TLB flush. + * + * Must be called with the p2m lock held. + */ +static void p2m_flush_tlb_sync(struct p2m_domain *p2m) +{ + ASSERT(p2m_is_write_locked(p2m)); + + p2m_flush_tlb(p2m); + p2m->need_flush = false; +} + +/* * Lookup the MFN corresponding to a domain's GFN. * * There are no processor functions to do a stage 2 only lookup therefore we @@ -1153,7 +1184,7 @@ static int apply_p2m_changes(struct domain *d, out: if ( flush ) { - p2m_flush_tlb(&d->arch.p2m); + p2m_flush_tlb_sync(&d->arch.p2m); ret = iommu_iotlb_flush(d, gfn_x(sgfn), nr); if ( !rc ) rc = ret; diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index b27a3a1..156df5e 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -51,6 +51,17 @@ struct p2m_domain { /* Indicate if it is required to clean the cache when writing an entry */ bool clean_pte; + /* + * P2M updates may required TLBs to be flushed (invalidated). + * + * Flushes may be deferred by setting 'need_flush' and then flushing + * when the p2m write lock is released. + * + * If an immediate flush is required (e.g, if a super page is + * shattered), call p2m_tlb_flush_sync(). + */ + bool need_flush; + /* Gather some statistics for information purposes only */ struct { /* Number of mappings at each p2m tree level */