From patchwork Tue Aug 16 22:16:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9284819 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 3732660839 for ; Tue, 16 Aug 2016 22:33:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F1E28768 for ; Tue, 16 Aug 2016 22:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A7CB28798; Tue, 16 Aug 2016 22:33:21 +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 96BCD28768 for ; Tue, 16 Aug 2016 22:33:20 +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 1bZmth-0004u6-Lh; Tue, 16 Aug 2016 22:31:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZmfr-0002cP-Ns for xen-devel@lists.xenproject.org; Tue, 16 Aug 2016 22:17:31 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id AC/97-13744-BF093B75; Tue, 16 Aug 2016 22:17:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsXSPJ9BRffXhM3 hBusXcVl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBl/t99nLOjQqnizaAFrA+MnxS5GTg4hgY2M Eo0fsroYuYDs5YwSqze0sYAk2AQMJKa8XskKYosIKEncWzWZCaSIWaCJUeJe4wM2kISwQKjE2 7XvmUBsFgFVia9fV4I18wrYSiy4uxqsRkJATqLh/H1mEJsTKH7g5WQ2iM02EjtXT2SewMi9gJ FhFaNGcWpRWWqRrqG5XlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGoIcZgGAH4+2 NAYcYJTmYlER5Z07cGC7El5SfUpmRWJwRX1Sak1p8iFGGg0NJgrcUGDBCgkWp6akVaZk5wFCD SUtw8CiJ8GqBpHmLCxJzizPTIVKnGBWlxHl1QRICIImM0jy4Nlh4X2KUlRLmZQQ6RIinILUoN 7MEVf4VozgHo5IwrwvIFJ7MvBK46a+AFjMBLdaX3gCyuCQRISXVwMjaPGVp56H7mQfcgpq8pd fxlu87PfGy6+oOzwCd1IWVbFo6z3h+MPoprzQ+mGlYrPlwnuyMBQ2PzJeuNnj++fpWRl2GjzI rZv+axmb988jr/jz3+2v/uAbNTT17T/7w3RNO2fdWnPM+Gre6nOHYrfv+rjPEJn9J7oo6sfWJ sMIpkbdvSw5Zu1UrsRRnJBpqMRcVJwIAWCQIS2oCAAA= X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-16.tower-21.messagelabs.com!1471385849!24340934!1 X-Originating-IP: [131.159.0.36] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42554 invoked from network); 16 Aug 2016 22:17:30 -0000 Received: from mail-out2.informatik.tu-muenchen.de (HELO mail-out1.informatik.tu-muenchen.de) (131.159.0.36) by server-16.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Aug 2016 22:17:30 -0000 Received: from files.sec.in.tum.de (files.sec.in.tum.de [131.159.50.1]) by services.sec.in.tum.de (Postfix) with ESMTP id 2E45D1032685B; Wed, 17 Aug 2016 00:17:29 +0200 (CEST) Received: from ker.sec.in.tum.de (ker.sec.in.tum.de [131.159.50.36]) by files.sec.in.tum.de (Postfix) with ESMTP id 21957442E; Wed, 17 Aug 2016 00:17:29 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Wed, 17 Aug 2016 00:16:46 +0200 Message-Id: <20160816221714.22041-11-proskurin@sec.in.tum.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160816221714.22041-1-proskurin@sec.in.tum.de> References: <20160816221714.22041-1-proskurin@sec.in.tum.de> Cc: Sergej Proskurin , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH v3 10/38] arm/p2m: Move hostp2m init/teardown to individual functions 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" X-Virus-Scanned: ClamAV using ClamSMTP This commit pulls out generic init/teardown functionality out of "p2m_init" and "p2m_teardown" into "p2m_init_one", "p2m_teardown_one", and "p2m_flush_table" functions. This allows our future implementation to reuse existing code for the initialization/teardown of altp2m views. Signed-off-by: Sergej Proskurin --- Cc: Stefano Stabellini Cc: Julien Grall --- v2: Added the function p2m_flush_table to the previous version. v3: Removed struct vttbr. Moved define INVALID_VTTBR to p2m.h. Exported function prototypes of "p2m_flush_table", "p2m_init_one", and "p2m_teardown_one" in p2m.h. Extended the function "p2m_flush_table" by additionally resetting the fields lowest_mapped_gfn and max_mapped_gfn. Added a "p2m_flush_tlb" call in "p2m_flush_table". On altp2m reset in function "altp2m_reset", it is important to flush the TLBs after clearing the root table pages and before clearing the intermediate altp2m page tables to prevent illegal access to stalled TLB entries on currently active VCPUs. Added a check checking whether p2m->root is NULL in p2m_flush_table. Renamed the function "p2m_free_one" to "p2m_teardown_one". Removed resetting p2m->vttbr in "p2m_teardown_one", as it the p2m will be destroyed afterwards. Moved call to "p2m_alloc_table" back to "p2m_init_one". Moved the introduction of the type p2m_class_t out of this patch. Moved the backpointer to the struct domain out of the struct p2m_domain. --- xen/arch/arm/p2m.c | 71 +++++++++++++++++++++++++++++++++++++++++------ xen/include/asm-arm/p2m.h | 11 ++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index e859fca..9ef19d4 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1245,27 +1245,53 @@ static void p2m_free_vmid(struct domain *d) spin_unlock(&vmid_alloc_lock); } -void p2m_teardown(struct domain *d) +/* Reset this p2m table to be empty. */ +void p2m_flush_table(struct p2m_domain *p2m) { - struct p2m_domain *p2m = p2m_get_hostp2m(d); - struct page_info *pg; + struct page_info *page, *pg; + unsigned int i; + + if ( p2m->root ) + { + page = p2m->root; + + /* Clear all concatenated first level pages. */ + for ( i = 0; i < P2M_ROOT_PAGES; i++ ) + clear_and_clean_page(page + i); + } + + /* + * Flush TLBs before releasing remaining intermediate p2m page tables to + * prevent illegal access to stalled TLB entries. + */ + p2m_flush_tlb(p2m); + /* Free the rest of the trie pages back to the paging pool. */ while ( (pg = page_list_remove_head(&p2m->pages)) ) free_domheap_page(pg); + p2m->lowest_mapped_gfn = INVALID_GFN; + p2m->max_mapped_gfn = _gfn(0); +} + +void p2m_teardown_one(struct p2m_domain *p2m) +{ + p2m_flush_table(p2m); + if ( p2m->root ) free_domheap_pages(p2m->root, P2M_ROOT_ORDER); p2m->root = NULL; - p2m_free_vmid(d); + p2m_free_vmid(p2m->domain); + + p2m->vttbr = INVALID_VTTBR; radix_tree_destroy(&p2m->mem_access_settings, NULL); } -int p2m_init(struct domain *d) +int p2m_init_one(struct domain *d, struct p2m_domain *p2m) { - struct p2m_domain *p2m = p2m_get_hostp2m(d); int rc = 0; rwlock_init(&p2m->lock); @@ -1278,11 +1304,14 @@ int p2m_init(struct domain *d) return rc; p2m->max_mapped_gfn = _gfn(0); - p2m->lowest_mapped_gfn = _gfn(ULONG_MAX); + p2m->lowest_mapped_gfn = INVALID_GFN; p2m->domain = d; + p2m->access_required = false; p2m->default_access = p2m_access_rwx; p2m->mem_access_enabled = false; + p2m->root = NULL; + p2m->vttbr = INVALID_VTTBR; radix_tree_init(&p2m->mem_access_settings); /* @@ -1293,9 +1322,33 @@ int p2m_init(struct domain *d) p2m->clean_pte = iommu_enabled && !iommu_has_feature(d, IOMMU_FEAT_COHERENT_WALK); - rc = p2m_alloc_table(d); + return p2m_alloc_table(d); +} - return rc; +static void p2m_teardown_hostp2m(struct domain *d) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + + p2m_teardown_one(p2m); +} + +void p2m_teardown(struct domain *d) +{ + p2m_teardown_hostp2m(d); +} + +static int p2m_init_hostp2m(struct domain *d) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + + p2m->p2m_class = p2m_host; + + return p2m_init_one(d, p2m); +} + +int p2m_init(struct domain *d) +{ + return p2m_init_hostp2m(d); } /* diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index fa07e19..1a004ed 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -11,6 +11,8 @@ #define paddr_bits PADDR_BITS +#define INVALID_VTTBR (0UL) + /* Holds the bit size of IPAs in p2m tables. */ extern unsigned int p2m_ipa_bits; @@ -226,6 +228,15 @@ void guest_physmap_remove_page(struct domain *d, mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn); +/* Flushes the page table held by the p2m. */ +void p2m_flush_table(struct p2m_domain *p2m); + +/* Initialize the p2m structure. */ +int p2m_init_one(struct domain *d, struct p2m_domain *p2m); + +/* Release resources held by the p2m structure. */ +void p2m_teardown_one(struct p2m_domain *p2m); + /* * P2M rwlock helpers. */