From patchwork Thu Oct 1 17:04:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 54384 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id C40D623010 for ; Thu, 1 Oct 2015 17:07:25 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf8638523lbc.1 for ; Thu, 01 Oct 2015 10:07:24 -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:subject:date:message-id :in-reply-to:references:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=8aTglLXQuKK005Ed6/7lhY0pkhzVf0hnO0cOOXU7cNs=; b=b2s8610EPhP4aGaF1fVlJxKhx1CR9ZMsLMW7HaM2GiOkJJitaDxveb8TVNF+xGzvb6 +hVPOkqf+QWKG1IIFskR5TkYuw9wCYGLrrBQGVo61V3CUXOB3fsJJStTKZQVS+hNfc1T MByXgG2KMWDKhF/bzQoJVpztRyWzJorgBFBMiXbJF06yBFp6gj5gNMz7WHUL+T81ESwK fn8s34Nqp6cIpHqkMFBGdnMIqzPxlLkDNvXZyTwm1v8Io0rEd4EVUdzQyDcY20qDV5Ky AQDPAukRl09qnsRl02fyApr3lFTBcaJJAmux84dQO46ynTfzqiTW6h9MZTH2oXk8Trdh 2whg== X-Gm-Message-State: ALoCoQk1Tq0yQZjG0wzeXaOzwM+GlhYPOLSTfstTZ6oW2dy9+CoBTU2EEr/0NNzX2bNxqPzJ5/WY X-Received: by 10.112.144.99 with SMTP id sl3mr1609076lbb.12.1443719244233; Thu, 01 Oct 2015 10:07:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.153.196 with SMTP id b187ls141332lfe.80.gmail; Thu, 01 Oct 2015 10:07:24 -0700 (PDT) X-Received: by 10.112.199.100 with SMTP id jj4mr3548584lbc.122.1443719244099; Thu, 01 Oct 2015 10:07:24 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id f14si3335356lfg.131.2015.10.01.10.07.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 10:07:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lahh2 with SMTP id h2so78799795lah.0 for ; Thu, 01 Oct 2015 10:07:24 -0700 (PDT) X-Received: by 10.112.159.136 with SMTP id xc8mr1407553lbb.76.1443719243883; Thu, 01 Oct 2015 10:07:23 -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.59.35 with SMTP id w3csp729918lbq; Thu, 1 Oct 2015 10:07:23 -0700 (PDT) X-Received: by 10.180.87.225 with SMTP id bb1mr4789757wib.0.1443719241987; Thu, 01 Oct 2015 10:07:21 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id e17si8445688wjr.24.2015.10.01.10.07.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 10:07:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZhhIp-0003sP-RQ; Thu, 01 Oct 2015 17:05:55 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZhhHz-00020D-Or for linux-arm-kernel@lists.infradead.org; Thu, 01 Oct 2015 17:05:06 +0000 Received: by wiclk2 with SMTP id lk2so37900878wic.1 for ; Thu, 01 Oct 2015 10:04:42 -0700 (PDT) X-Received: by 10.180.184.138 with SMTP id eu10mr4738431wic.25.1443719081979; Thu, 01 Oct 2015 10:04:41 -0700 (PDT) Received: from localhost.localdomain ([83.225.55.104]) by smtp.gmail.com with ESMTPSA id x9sm7036760wjf.44.2015.10.01.10.04.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Oct 2015 10:04:41 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, matt.fleming@intel.com, linux@arm.linux.org.uk, will.deacon@arm.com, grant.likely@linaro.org, leif.lindholm@linaro.org, roy.franz@linaro.org, mark.rutland@arm.com, catalin.marinas@arm.com Subject: [PATCH 6/9] ARM: factor out allocation routine from __create_mapping() Date: Thu, 1 Oct 2015 19:04:20 +0200 Message-Id: <1443719063-6832-7-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443719063-6832-1-git-send-email-ard.biesheuvel@linaro.org> References: <1443719063-6832-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151001_100504_100309_FC40B2F2 X-CRM114-Status: GOOD ( 14.52 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.177 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.177 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: ryan.harkin@linaro.org, Ard Biesheuvel , msalter@redhat.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org 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.53 as permitted sender) smtp.mailfrom=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 To allow __create_mapping() to be used for populating UEFI Runtime Services page tables, factor out the allocation routine 'early_alloc' and pass it down as a function pointer into alloc_init_[pud|pmd|pte]. This way, new users of __create_mapping() can supply another allocation function. Signed-off-by: Ard Biesheuvel --- arch/arm/mm/mmu.c | 34 +++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 3930bad44a61..dd0967ee23b7 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -723,21 +723,30 @@ static void __init *early_alloc(unsigned long sz) return early_alloc_aligned(sz, sz); } -static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot) +static pte_t * __init pte_alloc(pmd_t *pmd, unsigned long addr, + unsigned long prot, + void *(*alloc)(unsigned long sz)) { if (pmd_none(*pmd)) { - pte_t *pte = early_alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE); + pte_t *pte = alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE); __pmd_populate(pmd, __pa(pte), prot); } BUG_ON(pmd_bad(*pmd)); return pte_offset_kernel(pmd, addr); } +static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, + unsigned long prot) +{ + return pte_alloc(pmd, addr, prot, early_alloc); +} + static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr, unsigned long end, unsigned long pfn, - const struct mem_type *type) + const struct mem_type *type, + void *(*alloc)(unsigned long sz)) { - pte_t *pte = early_pte_alloc(pmd, addr, type->prot_l1); + pte_t *pte = pte_alloc(pmd, addr, type->prot_l1, alloc); do { set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 0); pfn++; @@ -773,7 +782,8 @@ static void __init __map_init_section(pmd_t *pmd, unsigned long addr, static void __init alloc_init_pmd(pud_t *pud, unsigned long addr, unsigned long end, phys_addr_t phys, - const struct mem_type *type) + const struct mem_type *type, + void *(*alloc)(unsigned long sz)) { pmd_t *pmd = pmd_offset(pud, addr); unsigned long next; @@ -794,7 +804,7 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr, __map_init_section(pmd, addr, next, phys, type); } else { alloc_init_pte(pmd, addr, next, - __phys_to_pfn(phys), type); + __phys_to_pfn(phys), type, alloc); } phys += next - addr; @@ -804,14 +814,15 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr, static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end, phys_addr_t phys, - const struct mem_type *type) + const struct mem_type *type, + void *(*alloc)(unsigned long sz)) { pud_t *pud = pud_offset(pgd, addr); unsigned long next; do { next = pud_addr_end(addr, end); - alloc_init_pmd(pud, addr, next, phys, type); + alloc_init_pmd(pud, addr, next, phys, type, alloc); phys += next - addr; } while (pud++, addr = next, addr != end); } @@ -876,7 +887,8 @@ static void __init create_36bit_mapping(struct mm_struct *mm, } #endif /* !CONFIG_ARM_LPAE */ -static void __init __create_mapping(struct mm_struct *mm, struct map_desc *md) +static void __init __create_mapping(struct mm_struct *mm, struct map_desc *md, + void *(*alloc)(unsigned long sz)) { unsigned long addr, length, end; phys_addr_t phys; @@ -910,7 +922,7 @@ static void __init __create_mapping(struct mm_struct *mm, struct map_desc *md) do { unsigned long next = pgd_addr_end(addr, end); - alloc_init_pud(pgd, addr, next, phys, type); + alloc_init_pud(pgd, addr, next, phys, type, alloc); phys += next - addr; addr = next; @@ -939,7 +951,7 @@ static void __init create_mapping(struct map_desc *md) (long long)__pfn_to_phys((u64)md->pfn), md->virtual); } - __create_mapping(&init_mm, md); + __create_mapping(&init_mm, md, early_alloc); } /*