From patchwork Thu Jul 28 14:51:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 72991 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp895089qga; Thu, 28 Jul 2016 07:55:18 -0700 (PDT) X-Received: by 10.36.95.202 with SMTP id r193mr52792039itb.48.1469717712983; Thu, 28 Jul 2016 07:55:12 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id j67si13451821iof.236.2016.07.28.07.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 07:55:12 -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 1bSmfS-00032R-KN; Thu, 28 Jul 2016 14:52:10 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSmfR-0002zz-7x for xen-devel@lists.xen.org; Thu, 28 Jul 2016 14:52:09 +0000 Received: from [193.109.254.147] by server-2.bemta-14.messagelabs.com id DA/96-30017-81C1A975; Thu, 28 Jul 2016 14:52:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTVdCZla 4weQfjBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aPqX8YC46KVvx8v5mxgXG2QBcjF4eQwCZG iXnzvjBCOKcZJU4d7mTvYuTkYBPQlLjz+RMTiC0iIC1x7fNlsCJmgXZGibX9vcwgCWGBGIktd 2axdTFycLAIqEo831kAEuYVcJG4tG4qC4gtISAncfLYZFaQEk6g+OtuIZCwkICzxPSZSxknMH IvYGRYxahRnFpUllqka2iml1SUmZ5RkpuYmaNraGiil5taXJyYnpqTmFSsl5yfu4kR6N96Bgb GHYxfT3seYpTkYFIS5Q0LnRkuxJeUn1KZkVicEV9UmpNafIhRhoNDSYLXX2pWuJBgUWp6akVa Zg4w0GDSEhw8SiK8D0HSvMUFibnFmekQqVOMilLivDUgCQGQREZpHlwbLLgvMcpKCfMyMjAwC PEUpBblZpagyr9iFOdgVBLmbQaZwpOZVwI3/RXQYiagxcWxM0AWlyQipKQaGFMb8y9NM8l+N6 3KPmXO1RnzzDskXXn69G/vmLrNvtd34+KdO+dWN33t3WC2/tw5l/9Xz/RrlWf3z0/f8W17xim 1JafdJ83hanZvNL6zS1p4j3tK7CJZkUlPAmc+ya9c5FGjEPhmLb/tssMlH+9v7+uVFOhf73pa LT/FLFciz+zL5GTbmZbcFUosxRmJhlrMRcWJACPJRbppAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1469717527!3969225!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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47239 invoked from network); 28 Jul 2016 14:52:07 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-2.tower-27.messagelabs.com with SMTP; 28 Jul 2016 14:52:07 -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 6BDF4BBC; Thu, 28 Jul 2016 07:53:24 -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 365163F21A; Thu, 28 Jul 2016 07:52:06 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 28 Jul 2016 15:51:34 +0100 Message-Id: <1469717505-8026-12-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469717505-8026-1-git-send-email-julien.grall@arm.com> References: <1469717505-8026-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] [RFC 11/22] xen/arm: p2m: Introduce p2m_get_root_pointer and use it in __p2m_lookup 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" Mapping the root table is always done the same way. To avoid duplicating the code in a later patch, move the code in a separate helper. Signed-off-by: Julien Grall --- xen/arch/arm/p2m.c | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ea582c8..d4a4b62 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -204,6 +204,37 @@ static void p2m_flush_tlb_sync(struct p2m_domain *p2m) } /* + * Find and map the root page table. The caller is responsible for + * unmapping the table. + * + * The function will return NULL if the offset of the root table is + * invalid. + */ +static lpae_t *p2m_get_root_pointer(struct p2m_domain *p2m, + gfn_t gfn) +{ + unsigned int root_table; + + if ( P2M_ROOT_PAGES == 1 ) + return __map_domain_page(p2m->root); + + /* + * Concatenated root-level tables. The table number will be the + * offset at the previous level. It is not possible to + * concatenate a level-0 root. + */ + ASSERT(P2M_ROOT_LEVEL > 0); + + root_table = gfn_x(gfn) >> (level_shifts[P2M_ROOT_LEVEL - 1] - PAGE_SHIFT); + root_table &= LPAE_ENTRY_MASK; + + if ( root_table >= P2M_ROOT_PAGES ) + return NULL; + + return __map_domain_page(p2m->root + root_table); +} + +/* * Lookup the MFN corresponding to a domain's GFN. * * There are no processor functions to do a stage 2 only lookup therefore we @@ -226,7 +257,7 @@ static mfn_t __p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) mfn_t mfn = INVALID_MFN; paddr_t mask = 0; p2m_type_t _t; - unsigned int level, root_table; + unsigned int level; ASSERT(p2m_is_locked(p2m)); BUILD_BUG_ON(THIRD_MASK != PAGE_MASK); @@ -236,22 +267,9 @@ static mfn_t __p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) *t = p2m_invalid; - if ( P2M_ROOT_PAGES > 1 ) - { - /* - * Concatenated root-level tables. The table number will be - * the offset at the previous level. It is not possible to - * concatenate a level-0 root. - */ - ASSERT(P2M_ROOT_LEVEL > 0); - root_table = offsets[P2M_ROOT_LEVEL - 1]; - if ( root_table >= P2M_ROOT_PAGES ) - goto err; - } - else - root_table = 0; - - map = __map_domain_page(p2m->root + root_table); + map = p2m_get_root_pointer(p2m, gfn); + if ( !map ) + return INVALID_MFN; ASSERT(P2M_ROOT_LEVEL < 4); @@ -286,7 +304,6 @@ static mfn_t __p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) *t = pte.p2m.type; } -err: return mfn; }