From patchwork Mon Jul 4 11:45:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9212419 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 385356086B for ; Mon, 4 Jul 2016 11:49:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A20D286DE for ; Mon, 4 Jul 2016 11:49:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E8F9286E2; Mon, 4 Jul 2016 11:49:18 +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 6ED10286DF for ; Mon, 4 Jul 2016 11:49:17 +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 1bK2LI-0008De-WE; Mon, 04 Jul 2016 11:47:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bK2KY-0007xP-Bf for xen-devel@lists.xenproject.org; Mon, 04 Jul 2016 11:46:26 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 4C/4C-20705-19C4A775; Mon, 04 Jul 2016 11:46:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsXSPJ+BQ3eiT1W 4wcrnTBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a627OZCj7KVRy7eoGpgXGDRBcjF4eQwEZG ibXLO5kgnOWMEhP372LrYuTkYBMwkJjyeiUriC0ioCRxb9VksCJmgSZGiXuND8CKhAXcJJb/v soEYrMIqEqs27KZvYuRg4NXwEZi72ZFkLCEgJzE5MWXGEFsTgFbiYaOT2DlQkAl3Xcfs01g5F 7AyLCKUb04tagstUjXWC+pKDM9oyQ3MTNH19DAWC83tbg4MT01JzGpWC85P3cTI9C/DECwg7H 5i9MhRkkOJiVR3nT3qnAhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErw+3kA5waLU9NSKtMwcYKDB pCU4eJREeAtB0rzFBYm5xZnpEKlTjIpS4rx+IAkBkERGaR5cGyy4LzHKSgnzMgIdIsRTkFqUm 1mCKv+KUZyDUUmYNwxkCk9mXgnc9FdAi5mAFrPGloMsLklESEk1MKY9u3hpRfPrRKPbjh/nzV Kbe8WkWY4z8G368yMpZw7F3Es6tcpkla9yfMzxm20H/3XfX+/8USdt157oec9ttk07OuXSY/1 URYG2rjOi2nLKrfYfWBJtdJ3/yif8WXklPOXleZ27TstNHupqNtqYfr71smnFM4MQg/9vM6Nu Svq4uxc+am5wFlNiKc5INNRiLipOBABAnFidaQIAAA== X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-16.tower-31.messagelabs.com!1467632784!41206106!1 X-Originating-IP: [131.159.0.8] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51708 invoked from network); 4 Jul 2016 11:46:25 -0000 Received: from mail-out1.informatik.tu-muenchen.de (HELO mail-out1.informatik.tu-muenchen.de) (131.159.0.8) by server-16.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 4 Jul 2016 11:46:25 -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 9712F100D1FAF; Mon, 4 Jul 2016 13:46:24 +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 940152EEF; Mon, 4 Jul 2016 13:46:24 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Mon, 4 Jul 2016 13:45:35 +0200 Message-Id: <20160704114605.10086-7-proskurin@sec.in.tum.de> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160704114605.10086-1-proskurin@sec.in.tum.de> References: <20160704114605.10086-1-proskurin@sec.in.tum.de> X-Mailman-Approved-At: Mon, 04 Jul 2016 11:47:10 +0000 Cc: Sergej Proskurin , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 06/18] arm/altp2m: Add a(p2m) table flushing routines. 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 The current implementation differentiates between flushing and destroying altp2m views. This commit adds the functions p2m_flush_altp2m, and p2m_flush_table, which allow to flush all or individual altp2m views without destroying the entire table. In this way, altp2m views can be reused at a later point in time. In addition, the implementation clears all altp2m entries during the process of flushing. The same applies to hostp2m entries, when it is destroyed. In this way, further domain and p2m allocations will not unintentionally reuse old p2m mappings. Signed-off-by: Sergej Proskurin --- Cc: Stefano Stabellini Cc: Julien Grall --- xen/arch/arm/p2m.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/p2m.h | 15 ++++++++--- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 4a745fd..ae789e6 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -2110,6 +2110,73 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) return rc; } +/* Reset this p2m table to be empty */ +static void p2m_flush_table(struct p2m_domain *p2m) +{ + struct page_info *top, *pg; + mfn_t mfn; + unsigned int i; + + /* Check whether the p2m table has already been flushed before. */ + if ( p2m->root == NULL) + return; + + spin_lock(&p2m->lock); + + /* + * "Host" p2m tables can have shared entries &c that need a bit more care + * when discarding them + */ + ASSERT(!p2m_is_hostp2m(p2m)); + + /* Zap the top level of the trie */ + top = p2m->root; + + /* Clear all concatenated first level pages */ + for ( i = 0; i < P2M_ROOT_PAGES; i++ ) + { + mfn = _mfn(page_to_mfn(top + i)); + clear_domain_page(mfn); + } + + /* Free the rest of the trie pages back to the paging pool */ + while ( (pg = page_list_remove_head(&p2m->pages)) ) + if ( pg != top ) + { + /* + * Before freeing the individual pages, we clear them to prevent + * reusing old table entries in future p2m allocations. + */ + mfn = _mfn(page_to_mfn(pg)); + clear_domain_page(mfn); + free_domheap_page(pg); + } + + page_list_add(top, &p2m->pages); + + /* Invalidate VTTBR */ + p2m->vttbr.vttbr = 0; + p2m->vttbr.vttbr_baddr = INVALID_MFN; + + spin_unlock(&p2m->lock); +} + +void p2m_flush_altp2m(struct domain *d) +{ + unsigned int i; + + altp2m_lock(d); + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + p2m_flush_table(d->arch.altp2m_p2m[i]); + flush_tlb(); + d->arch.altp2m_vttbr[i] = INVALID_MFN; + } + + altp2m_unlock(d); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 8ee78e0..51d784f 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -132,10 +132,7 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx) struct p2m_domain *p2m_get_altp2m(struct vcpu *v); /* Flush all the alternate p2m's for a domain */ -static inline void p2m_flush_altp2m(struct domain *d) -{ - /* Not supported on ARM. */ -} +void p2m_flush_altp2m(struct domain *d); /* Make a specific alternate p2m valid */ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx); @@ -289,6 +286,16 @@ static inline int get_page_and_type(struct page_info *page, /* get host p2m table */ #define p2m_get_hostp2m(d) (&(d)->arch.p2m) +static inline bool_t p2m_is_hostp2m(const struct p2m_domain *p2m) +{ + return p2m->p2m_class == p2m_host; +} + +static inline bool_t p2m_is_altp2m(const struct p2m_domain *p2m) +{ + return p2m->p2m_class == p2m_alternate; +} + /* vm_event and mem_access are supported on any ARM guest */ static inline bool_t p2m_mem_access_sanity_check(struct domain *d) {