From patchwork Thu Sep 4 16:14:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 36735 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C86CE202E4 for ; Thu, 4 Sep 2014 16:15:55 +0000 (UTC) Received: by mail-oi0-f70.google.com with SMTP id u20sf49288472oif.1 for ; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=Le8x0IltGJwRhZ/8f8FIghyZwmZkFUzic7FQq+4LqCU=; b=lNeburOfYrLAB2WcOb3naDb2MAQklMY+f0wVUXjIbeR+v3GEuu9cvrQbClWmGLSVlx V+Gptfbje4Q5e/JU+v7tkF91nwCZLEO8e9hZfJ31/lNApPcmoLxxCEekxPL4oVEQuTV+ PeGAvUTbZSWYPx/i2ImVLSLRtXmb6By9Cyd6VeSGybfG8Cwg7dESER96Lc15gwDsTInO uC4dQJZL+YqC/0r/lWrHQ+lWF6CbFygwxwy7zuI467ZKH2kPKkxBIBrWK9mIQsNsx7Vf x7D+Z6hXwfsRp+wCw8C7Ft8+EzHgyPzo8evYMJlSTlQbl2WCS9eQw0JfSU5IPbAxc5tl RHrQ== X-Gm-Message-State: ALoCoQkcbWT0QR5GZmcRhUSPlTXti9nTMBWVStFSbNzkH7or6K1qW5IVHLhPOBKzNpkb3zTgsfdl X-Received: by 10.50.153.98 with SMTP id vf2mr2999370igb.5.1409847355374; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.182 with SMTP id h51ls386943qgf.80.gmail; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) X-Received: by 10.220.77.65 with SMTP id f1mr2536518vck.48.1409847355235; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id gm7si3274741vdc.87.2014.09.04.09.15.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 09:15:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lf12so10763630vcb.20 for ; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) X-Received: by 10.52.94.108 with SMTP id db12mr4359555vdb.8.1409847355157; Thu, 04 Sep 2014 09:15:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp863119vcb; Thu, 4 Sep 2014 09:15:54 -0700 (PDT) X-Received: by 10.52.4.69 with SMTP id i5mr4283107vdi.35.1409847354619; Thu, 04 Sep 2014 09:15:54 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id u2si3301288vdx.36.2014.09.04.09.15.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 09:15:54 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XPZg7-0001V1-IG; Thu, 04 Sep 2014 16:14:31 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XPZg6-0001T3-4C for xen-devel@lists.xen.org; Thu, 04 Sep 2014 16:14:30 +0000 Received: from [85.158.143.35:35279] by server-2.bemta-4.messagelabs.com id DA/E5-04525-5EF88045; Thu, 04 Sep 2014 16:14:29 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1409847265!13627072!4 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21809 invoked from network); 4 Sep 2014 16:14:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2014 16:14:28 -0000 X-IronPort-AV: E=Sophos;i="5.04,467,1406592000"; d="scan'208";a="168408683" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Thu, 4 Sep 2014 12:14:24 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1XPZfy-0004Qb-UJ; Thu, 04 Sep 2014 17:14:23 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Thu, 04 Sep 2014 17:14:22 +0100 From: Ian Campbell To: Date: Thu, 4 Sep 2014 17:14:14 +0100 Message-ID: <3e77449aeb97eeb9357d80a3ed703baac8dd1633.1409847257.git.ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <4427aba8dad3155fca151a0b63bfdf78e3a91033.1409847257.git.ian.campbell@citrix.com> References: <4427aba8dad3155fca151a0b63bfdf78e3a91033.1409847257.git.ian.campbell@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , vijay.kilari@gmail.com, stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v2 6/9] xen: arm: handle variable p2m levels in p2m_lookup X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This paves the way for boot-time selection of the number of levels to use in the p2m, which is required to support both 40-bit and 48-bit systems. For now the starting level remains a compile time constant. Implemented by turning the linear sequence of lookups into a loop. Signed-off-by: Ian Campbell Reviewed-by: Julien Grall --- v2: - pt level vars are unsigned int - spell concatenate properly - ASSERT() rather than BUG_ON() --- xen/arch/arm/p2m.c | 73 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 6e64f94..ea5e342 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -153,56 +153,77 @@ static lpae_t *p2m_map_first(struct p2m_domain *p2m, paddr_t addr) paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) { struct p2m_domain *p2m = &d->arch.p2m; - lpae_t pte, *first = NULL, *second = NULL, *third = NULL; + const unsigned int offsets[4] = { + zeroeth_table_offset(paddr), + first_table_offset(paddr), + second_table_offset(paddr), + third_table_offset(paddr) + }; + const paddr_t masks[4] = { + ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK + }; + lpae_t pte, *map; paddr_t maddr = INVALID_PADDR; - paddr_t mask; + paddr_t mask = 0; p2m_type_t _t; + unsigned int level, root_table; + + BUILD_BUG_ON(THIRD_MASK != PAGE_MASK); /* Allow t to be NULL */ t = 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; + spin_lock(&p2m->lock); - first = p2m_map_first(p2m, paddr); - if ( !first ) - goto err; + map = __map_domain_page(p2m->root + root_table); - mask = FIRST_MASK; - pte = first[first_table_offset(paddr)]; - if ( !p2m_table(pte) ) - goto done; + for ( level = P2M_ROOT_LEVEL ; level < 4 ; level++ ) + { + mask = masks[level]; - mask = SECOND_MASK; - second = map_domain_page(pte.p2m.base); - pte = second[second_table_offset(paddr)]; - if ( !p2m_table(pte) ) - goto done; + pte = map[offsets[level]]; - mask = THIRD_MASK; + if ( level == 3 && !p2m_table(pte) ) + /* Invalid, clobber the pte */ + pte.bits = 0; + if ( level == 3 || !p2m_table(pte) ) + /* Done */ + break; - BUILD_BUG_ON(THIRD_MASK != PAGE_MASK); + ASSERT(level < 3); - third = map_domain_page(pte.p2m.base); - pte = third[third_table_offset(paddr)]; + /* Map for next level */ + unmap_domain_page(map); + map = map_domain_page(pte.p2m.base); + } - /* This bit must be one in the level 3 entry */ - if ( !p2m_table(pte) ) - pte.bits = 0; + unmap_domain_page(map); -done: if ( p2m_valid(pte) ) { + ASSERT(mask); ASSERT(pte.p2m.type != p2m_invalid); maddr = (pte.bits & PADDR_MASK & mask) | (paddr & ~mask); *t = pte.p2m.type; } - if (third) unmap_domain_page(third); - if (second) unmap_domain_page(second); - if (first) unmap_domain_page(first); - err: spin_unlock(&p2m->lock);