From patchwork Wed Jul 30 13:47: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: 34525 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A6AB420DCC for ; Wed, 30 Jul 2014 13:55:47 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hq11sf3571954vcb.7 for ; Wed, 30 Jul 2014 06:55: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=K+2xz0KE2Y8dntB1GNDg23tEomnFM9zRixqVD5B9oRQ=; b=cN/+gJ4c0/w6A2jtnHag+w94i57zdTwqYXfdGkualHIQs3l9u58sQu4NdKVfZBmTMa aqdjkgDebP0eJP0OZ2e+lfzfdq3WenSJiYH1M1nZrf+Yhmt9Pss8KN0nAppPYXrUIzZx git+9Hw0dJNjI9+wqtOFuJXB0Pu3NAR9aWu9Cp1g/EPqwUor78FSGMotimBHOy4N+yJU xzu1hrmN1oM7Y2VAcrtT5Qk7qTerPQUvX7mjHyXGMqlaNOCPn52ev2xOoICthEu8ILRU D1+ivNikNiUgdlXse+/fW9M+9Q72V6qcG1kMQJt9J3DmTVfZXzftIMKd8zs/DE3GDY95 hdWw== X-Gm-Message-State: ALoCoQmif2zntEP7sQkSIBOdbRBZ6ky+FJPuTyuaYDRLsi3IJKmG4X0s8aQZ0nmf3tFGPR/YSyka X-Received: by 10.236.122.236 with SMTP id t72mr1480808yhh.15.1406728547433; Wed, 30 Jul 2014 06:55:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.35 with SMTP id k32ls507276qgd.73.gmail; Wed, 30 Jul 2014 06:55:47 -0700 (PDT) X-Received: by 10.220.1.5 with SMTP id 5mr1510841vcd.74.1406728547302; Wed, 30 Jul 2014 06:55:47 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id w19si1700193vcu.38.2014.07.30.06.55.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 06:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so1836580vcb.1 for ; Wed, 30 Jul 2014 06:55:47 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr7992950vdc.40.1406728547222; Wed, 30 Jul 2014 06:55: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.221.37.5 with SMTP id tc5csp29555vcb; Wed, 30 Jul 2014 06:55:46 -0700 (PDT) X-Received: by 10.68.97.129 with SMTP id ea1mr4824189pbb.73.1406728546400; Wed, 30 Jul 2014 06:55:46 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id n7si6462607icz.38.2014.07.30.06.55.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 30 Jul 2014 06:55: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 1XCUKj-0006Ah-9C; Wed, 30 Jul 2014 13:54:21 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCUKh-00069s-Ht for xen-devel@lists.xen.org; Wed, 30 Jul 2014 13:54:19 +0000 Received: from [193.109.254.147:56262] by server-3.bemta-14.messagelabs.com id 2B/A1-23707-A09F8D35; Wed, 30 Jul 2014 13:54:18 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1406728457!12718668!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17165 invoked from network); 30 Jul 2014 13:54:18 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jul 2014 13:54:18 -0000 X-IronPort-AV: E=Sophos;i="5.01,764,1400025600"; d="scan'208";a="157704979" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 30 Jul 2014 13:54:16 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Wed, 30 Jul 2014 09:54:16 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1XCUDy-0006vK-Dl; Wed, 30 Jul 2014 14:47:23 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Wed, 30 Jul 2014 14:47:22 +0100 From: Ian Campbell To: Date: Wed, 30 Jul 2014 14:47:14 +0100 Message-ID: <5a0397cc676556da56a3204c9e056052f5dcb9da.1406728037.git.ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <3ef2b68c511f3e31de409b76757b95c78b99d750.1406728037.git.ian.campbell@citrix.com> References: <3ef2b68c511f3e31de409b76757b95c78b99d750.1406728037.git.ian.campbell@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , vijay.kilari@gmail.com, stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH RFC 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.170 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 --- xen/arch/arm/p2m.c | 70 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 225d125..557663f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -149,45 +149,69 @@ 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; p2m_type_t _t; + 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 + * concetenate a level-0 root. + */ + BUG_ON(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); + BUG_ON(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(pte.p2m.type != p2m_invalid); @@ -195,10 +219,6 @@ done: *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);