From patchwork Thu Sep 15 11:28:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 76279 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2387149qgf; Thu, 15 Sep 2016 04:30:37 -0700 (PDT) X-Received: by 10.107.47.227 with SMTP id v96mr18152518iov.172.1473939037391; Thu, 15 Sep 2016 04:30:37 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id j123si5434321ioj.233.2016.09.15.04.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 04:30:37 -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 1bkUqm-0004jq-MW; Thu, 15 Sep 2016 11:29:04 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUql-0004g7-SZ for xen-devel@lists.xen.org; Thu, 15 Sep 2016 11:29:03 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 24/CA-11394-EF58AD75; Thu, 15 Sep 2016 11:29:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTfdf661 wg1eb5CyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozjB9exFHQpV2w428LewLhAuouRk0NIYBOj xLPVKV2MXED2aUaJg+enMoMk2AQ0Je58/sQEYosISEtc+3yZEaSIWaCdUWJtfy9YkbBAlsT8z +0sIDaLgKrE6jV97CA2r4CrxOId/9lAbAkBOYmTxyazdjFycHACxZc8F4VY7CJx7MROtgmM3A sYGVYxahSnFpWlFukameolFWWmZ5TkJmbm6BoaGOvlphYXJ6an5iQmFesl5+duYgT6t56BgXE HY+sJv0OMkhxMSqK8bmm3woX4kvJTKjMSizPii0pzUosPMcpwcChJ8O5rAcoJFqWmp1akZeYA Aw0mLcHBoyTC+wMkzVtckJhbnJkOkTrFqCglDtEnAJLIKM2Da4MF9yVGWSlhXkYGBgYhnoLUo tzMElT5V4ziHIxKwrxdIFN4MvNK4Ka/AlrMBLR4y5rrIItLEhFSUg2MdRv1JwikLF+bfUgz73 XFnvxjU5UrnFoaDTP+berVrklZGPR8Y9a0jsT07JplHrpHJlWc0Mn+OWGm7eOqN+oLX+1Mu9f +7dovTcZqtmUv7xgbr+MOPvtaqdpY45/0Mr2jtySCGu/qyywScSrxvuRl4j37U2vt1rNce1ct y5rwheWTh8edM3lySizFGYmGWsxFxYkAOWym+GkCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1473938941!53315918!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests=UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23289 invoked from network); 15 Sep 2016 11:29:02 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-16.tower-31.messagelabs.com with SMTP; 15 Sep 2016 11:29:02 -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 869A77FF; Thu, 15 Sep 2016 04:29:01 -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 84DD03F251; Thu, 15 Sep 2016 04:29:00 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 15 Sep 2016 12:28:27 +0100 Message-Id: <1473938919-31976-12-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 11/23] 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 --- Changes in v2: - Use level_orders rather than level_shifts - PAGE_SHIFT - Move the definition of level_orders in this patch * use uint8_t rather than unsigned * define *_ORDER in term of *_SHIFT --- xen/arch/arm/p2m.c | 55 +++++++++++++++++++++++++++++++--------------- xen/include/asm-arm/page.h | 4 ++++ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 413780b..b2a29ad 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -36,6 +36,8 @@ static const paddr_t level_masks[] = { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK }; static const uint8_t level_shifts[] = { ZEROETH_SHIFT, FIRST_SHIFT, SECOND_SHIFT, THIRD_SHIFT }; +static const uint8_t level_orders[] = + { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; static bool_t p2m_valid(lpae_t pte) { @@ -204,6 +206,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_orders[P2M_ROOT_LEVEL - 1]); + 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 +259,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 +269,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 +306,6 @@ static mfn_t __p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) *t = pte.p2m.type; } -err: return mfn; } diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h index 05d9f82..a43b0fa 100644 --- a/xen/include/asm-arm/page.h +++ b/xen/include/asm-arm/page.h @@ -457,15 +457,19 @@ static inline int gva_to_ipa(vaddr_t va, paddr_t *paddr, unsigned int flags) #define LPAE_ENTRY_MASK (LPAE_ENTRIES - 1) #define THIRD_SHIFT (PAGE_SHIFT) +#define THIRD_ORDER (THIRD_SHIFT - PAGE_SHIFT) #define THIRD_SIZE ((paddr_t)1 << THIRD_SHIFT) #define THIRD_MASK (~(THIRD_SIZE - 1)) #define SECOND_SHIFT (THIRD_SHIFT + LPAE_SHIFT) +#define SECOND_ORDER (SECOND_SHIFT - PAGE_SHIFT) #define SECOND_SIZE ((paddr_t)1 << SECOND_SHIFT) #define SECOND_MASK (~(SECOND_SIZE - 1)) #define FIRST_SHIFT (SECOND_SHIFT + LPAE_SHIFT) +#define FIRST_ORDER (FIRST_SHIFT - PAGE_SHIFT) #define FIRST_SIZE ((paddr_t)1 << FIRST_SHIFT) #define FIRST_MASK (~(FIRST_SIZE - 1)) #define ZEROETH_SHIFT (FIRST_SHIFT + LPAE_SHIFT) +#define ZEROETH_ORDER (ZEROETH_SHIFT - PAGE_SHIFT) #define ZEROETH_SIZE ((paddr_t)1 << ZEROETH_SHIFT) #define ZEROETH_MASK (~(ZEROETH_SIZE - 1))