From patchwork Thu Sep 18 00:09:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 37562 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 951F32057E for ; Thu, 18 Sep 2014 00:11:48 +0000 (UTC) Received: by mail-we0-f200.google.com with SMTP id u57sf47797wes.11 for ; Wed, 17 Sep 2014 17:11:47 -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=MevClNh0iD2Q/ijt4/32Rs9kjBF0DCo2g4fb2xdGefE=; b=OxPErIydUvnw11dzt/LC+if5OiFdbzDgVnp5tYSDHCrn8tV0imUsUCwNBXz0GWLtN9 bvOR6wc+W4pq7ypbuZeeClN0jJreWYhedE51up8Q6GYBupbsNT1ZI/xfFD7NQLyS4P8U lsMhwD5fAF+l20GGMts9cIYiE+DsdCaHHxTv1bRdXxVGkftQ+LcLJh/vES+9uAWDfoQt wXpFeeTffl59z+RdscGOi70JD5MzGf8v7hm3jmAjYomsP2UOkpgg8fvE7nBTvhHttNQs IqGuHKZJUl/twCjJ4hZjF74itbU4kvYFcyVXxklVSJ7OYfms0lX54MdQY1tFEAkiY4Xe JXVA== X-Gm-Message-State: ALoCoQmyHV1vlzdQRkE4TAMegqsvYcH5ohGqGdHKom7TK0GKq9FgaMhZSZkB0mkDG9dCaSM4uPiJ X-Received: by 10.112.184.197 with SMTP id ew5mr127798lbc.0.1410999107757; Wed, 17 Sep 2014 17:11:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.199 with SMTP id d7ls180195lah.79.gmail; Wed, 17 Sep 2014 17:11:47 -0700 (PDT) X-Received: by 10.112.13.10 with SMTP id d10mr703672lbc.10.1410999107589; Wed, 17 Sep 2014 17:11:47 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx.google.com with ESMTPS id d7si30190479lah.87.2014.09.17.17.11.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Sep 2014 17:11:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id ge10so121987lab.41 for ; Wed, 17 Sep 2014 17:11:47 -0700 (PDT) X-Received: by 10.152.198.204 with SMTP id je12mr1070910lac.52.1410999107480; Wed, 17 Sep 2014 17:11:47 -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.112.130.169 with SMTP id of9csp673214lbb; Wed, 17 Sep 2014 17:11:47 -0700 (PDT) X-Received: by 10.180.103.131 with SMTP id fw3mr24917155wib.77.1410999106794; Wed, 17 Sep 2014 17:11:46 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id o15si749373wiw.74.2014.09.17.17.11.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 17 Sep 2014 17:11:46 -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 1XUPIo-0006kX-2t; Thu, 18 Sep 2014 00:10:26 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XUPIi-0006ez-OZ for xen-devel@lists.xen.org; Thu, 18 Sep 2014 00:10:20 +0000 Received: from [193.109.254.147:63591] by server-8.bemta-14.messagelabs.com id A5/7E-01875-BE22A145; Thu, 18 Sep 2014 00:10:19 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1410999014!16266718!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 2809 invoked from network); 18 Sep 2014 00:10:18 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 18 Sep 2014 00:10:18 -0000 X-IronPort-AV: E=Sophos;i="5.04,542,1406592000"; d="scan'208";a="172653390" 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; Wed, 17 Sep 2014 20:10:01 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1XUPIO-0000t8-Ku; Thu, 18 Sep 2014 01:10:01 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Thu, 18 Sep 2014 01:10:00 +0100 From: Ian Campbell To: Date: Thu, 18 Sep 2014 01:09:52 +0100 Message-ID: <1410998995-27449-6-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1410998960.1920.2.camel@citrix.com> References: <1410998960.1920.2.camel@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 v3 for-4.5 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.215.54 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 e953ca3..eac3ce4 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);