From patchwork Fri Oct 24 12:39:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 39474 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 318BA24026 for ; Fri, 24 Oct 2014 12:42:23 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf1795578lab.3 for ; Fri, 24 Oct 2014 05:42:22 -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:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=gjFkl8ksmrNiFnicFrA8483xDRESOj+dh2WEczTxPa0=; b=fGyB2yHq3xXoMnSwCEe/D0p7fgReBhWmOY+9FNAgdkXtCi+6twO+3hNbW2afJdBja3 pP79gGHWtEbyPU6kbHrfcNQ6q8QAnRSyvwgpRwmQ8zJeYIQhfoh/CjfECMLPz2/u50aa qVxx4wPKlEdBVPguBKTRc9e/JJirn+vAyYDC4DN7TzMUb7v/4o7MXvo2CYmTGFVRl/pD 9BCgRAyMcYdhowmsvhs7NmOQvTopyfoAmd6EtiSEuLzTsdLfJ1cNI0zK/U8aedcF3+GM CX/0XIxG6MzXjJxjpfX5Vm1y1GyRxtJbTDas89FXHhC8gTG/PcbDR7nJVvtY947imZdL yHYg== X-Gm-Message-State: ALoCoQlmb71+cdiewtNd99LDcAVcvlp0f58T+10r+mj9EkHlIVdZuiZqkSUSz1LF9eWZ+Mh4GE0x X-Received: by 10.181.8.194 with SMTP id dm2mr800559wid.2.1414154541978; Fri, 24 Oct 2014 05:42:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.52 with SMTP id o20ls461225laa.3.gmail; Fri, 24 Oct 2014 05:42:21 -0700 (PDT) X-Received: by 10.112.221.226 with SMTP id qh2mr4278262lbc.5.1414154541573; Fri, 24 Oct 2014 05:42:21 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id ka2si6900981lbc.9.2014.10.24.05.42.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Oct 2014 05:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id p9so2530721lbv.35 for ; Fri, 24 Oct 2014 05:42:21 -0700 (PDT) X-Received: by 10.153.8.164 with SMTP id dl4mr4233749lad.29.1414154541139; Fri, 24 Oct 2014 05:42:21 -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.84.229 with SMTP id c5csp420541lbz; Fri, 24 Oct 2014 05:42:20 -0700 (PDT) X-Received: by 10.70.37.236 with SMTP id b12mr4231352pdk.75.1414154539470; Fri, 24 Oct 2014 05:42:19 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id iu2si4213650pac.21.2014.10.24.05.42.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Oct 2014 05:42:19 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) 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 1XheAn-0007Sp-Dt; Fri, 24 Oct 2014 12:40:53 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XheA8-00063M-G4 for linux-arm-kernel@lists.infradead.org; Fri, 24 Oct 2014 12:40:14 +0000 Received: by mail-wg0-f43.google.com with SMTP id n12so992919wgh.14 for ; Fri, 24 Oct 2014 05:39:50 -0700 (PDT) X-Received: by 10.194.190.130 with SMTP id gq2mr4527398wjc.18.1414154389991; Fri, 24 Oct 2014 05:39:49 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id ny6sm1877350wic.22.2014.10.24.05.39.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Oct 2014 05:39:48 -0700 (PDT) From: Ard Biesheuvel To: leif.lindholm@linaro.org, roy.franz@linaro.org, msalter@redhat.com, mark.rutland@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, matt.fleming@intel.com, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dyoung@redhat.com Subject: [PATCH 2/6] arm64/mm: add create_pgd_mapping() to create private page tables Date: Fri, 24 Oct 2014 14:39:40 +0200 Message-Id: <1414154384-15385-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1414154384-15385-1-git-send-email-ard.biesheuvel@linaro.org> References: <1414154384-15385-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141024_054012_739029_989511C7 X-CRM114-Status: GOOD ( 13.26 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.43 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.43 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: grant.likely@linaro.org, Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , 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.217.176 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 For UEFI, we need to install the memory mappings used for Runtime Services in a dedicated set of page tables. Add create_pgd_mapping(), which allows us to allocate and install those page table entries early. This also adds a 'map_xn' option, that creates regions with the PXN and UXN bits set. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu.h | 3 +++ arch/arm64/mm/mmu.c | 28 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index c2f006c48bdb..bcf166043a8b 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -33,5 +33,8 @@ extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt); extern void init_mem_pgprot(void); /* create an identity mapping for memory (or io if map_io is true) */ extern void create_id_mapping(phys_addr_t addr, phys_addr_t size, int map_io); +extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, + unsigned long virt, phys_addr_t size, + int map_io, int map_xn); #endif diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 7eaa6a8c8467..f7d17a5a1f56 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -157,7 +157,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr, static void __init alloc_init_pmd(struct mm_struct *mm, pud_t *pud, unsigned long addr, unsigned long end, - phys_addr_t phys, int map_io) + phys_addr_t phys, int map_io, int map_xn) { pmd_t *pmd; unsigned long next; @@ -167,6 +167,9 @@ static void __init alloc_init_pmd(struct mm_struct *mm, pud_t *pud, if (map_io) { prot_sect = PROT_SECT_DEVICE_nGnRE; prot_pte = __pgprot(PROT_DEVICE_nGnRE); + } else if (map_xn) { + prot_sect = PROT_SECT_NORMAL; + prot_pte = PAGE_KERNEL; } else { prot_sect = PROT_SECT_NORMAL_EXEC; prot_pte = PAGE_KERNEL_EXEC; @@ -203,7 +206,7 @@ static void __init alloc_init_pmd(struct mm_struct *mm, pud_t *pud, static void __init alloc_init_pud(struct mm_struct *mm, pgd_t *pgd, unsigned long addr, unsigned long end, - unsigned long phys, int map_io) + unsigned long phys, int map_io, int map_xn) { pud_t *pud; unsigned long next; @@ -221,7 +224,7 @@ static void __init alloc_init_pud(struct mm_struct *mm, pgd_t *pgd, /* * For 4K granule only, attempt to put down a 1GB block */ - if (!map_io && (PAGE_SHIFT == 12) && + if (!map_io && !map_xn && (PAGE_SHIFT == 12) && ((addr | next | phys) & ~PUD_MASK) == 0) { pud_t old_pud = *pud; set_pud(pud, __pud(phys | PROT_SECT_NORMAL_EXEC)); @@ -239,7 +242,8 @@ static void __init alloc_init_pud(struct mm_struct *mm, pgd_t *pgd, flush_tlb_all(); } } else { - alloc_init_pmd(mm, pud, addr, next, phys, map_io); + alloc_init_pmd(mm, pud, addr, next, phys, map_io, + map_xn); } phys += next - addr; } while (pud++, addr = next, addr != end); @@ -251,7 +255,7 @@ static void __init alloc_init_pud(struct mm_struct *mm, pgd_t *pgd, */ static void __init __create_mapping(struct mm_struct *mm, pgd_t *pgd, phys_addr_t phys, unsigned long virt, - phys_addr_t size, int map_io) + phys_addr_t size, int map_io, int map_xn) { unsigned long addr, length, end, next; @@ -261,7 +265,7 @@ static void __init __create_mapping(struct mm_struct *mm, pgd_t *pgd, end = addr + length; do { next = pgd_addr_end(addr, end); - alloc_init_pud(mm, pgd, addr, next, phys, map_io); + alloc_init_pud(mm, pgd, addr, next, phys, map_io, map_xn); phys += next - addr; } while (pgd++, addr = next, addr != end); } @@ -275,7 +279,7 @@ static void __init create_mapping(phys_addr_t phys, unsigned long virt, return; } __create_mapping(&init_mm, pgd_offset_k(virt & PAGE_MASK), phys, virt, - size, 0); + size, 0, 0); } void __init create_id_mapping(phys_addr_t addr, phys_addr_t size, int map_io) @@ -285,7 +289,15 @@ void __init create_id_mapping(phys_addr_t addr, phys_addr_t size, int map_io) return; } __create_mapping(&init_mm, &idmap_pg_dir[pgd_index(addr)], - addr, addr, size, map_io); + addr, addr, size, map_io, 0); +} + +void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, + unsigned long virt, phys_addr_t size, + int map_io, int map_xn) +{ + __create_mapping(mm, pgd_offset(mm, virt), phys, virt, size, map_io, + map_xn); } static void __init map_mem(void)