From patchwork Wed Jul 9 11:48:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 33281 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f70.google.com (mail-qg0-f70.google.com [209.85.192.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1E84203F4 for ; Wed, 9 Jul 2014 11:50:36 +0000 (UTC) Received: by mail-qg0-f70.google.com with SMTP id z60sf16918769qgd.5 for ; Wed, 09 Jul 2014 04:50:36 -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:date:from:to:subject:message-id :references:mime-version:in-reply-to:user-agent:cc:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-disposition :content-type:content-transfer-encoding; bh=RYdrem2XjiCQiHzKeDHn3x0dnMenxL6o2D6bR5/lKWU=; b=mP3u/bqu77+/jfJHlGAIHefwZV2jtNuULyI41gy6I52I8/9jVb4mhLz+n60s2J9BE1 J6zj2KRkqDy4zdJZ8NQtonwOfT+1ImfFr1Jw9yib8Qv+E+lfoedQA8cdyAOXjplsLQly WW3V30Rk3eps7DIkDFjU/5VtI+biJcIjc86jgSRMFXky7vcAjQN5QWSl3g/e/AxmQ3Bh V0H97++EYa7x1A/qEoIRq7nj29Du/90phvfddVlxIpf8RoEw1w96zSFDmAXoxcU/FtK7 h8Wyskxql8MSmrrlK0g05e0lBUjvG9xl2QFS7KVeiGewTjN0t39DZGpABPzdYO3Uuq49 ULEg== X-Gm-Message-State: ALoCoQkiQ7E6IuQo4GT2sOdogaoOjLJJElC+2jx7OxZQC/D89BWCFPYpwp7Wmp60oDlL3mt7Qw7k X-Received: by 10.58.105.74 with SMTP id gk10mr20468124veb.4.1404906636487; Wed, 09 Jul 2014 04:50:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.28.4 with SMTP id 4ls2598857qgy.98.gmail; Wed, 09 Jul 2014 04:50:36 -0700 (PDT) X-Received: by 10.220.166.9 with SMTP id k9mr38960723vcy.20.1404906636393; Wed, 09 Jul 2014 04:50:36 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id iq4si43032vdb.57.2014.07.09.04.50.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Jul 2014 04:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.173 as permitted sender) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id db11so6968848veb.4 for ; Wed, 09 Jul 2014 04:50:36 -0700 (PDT) X-Received: by 10.220.114.140 with SMTP id e12mr185473vcq.37.1404906636257; Wed, 09 Jul 2014 04:50:36 -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 tc5csp40525vcb; Wed, 9 Jul 2014 04:50:35 -0700 (PDT) X-Received: by 10.68.68.168 with SMTP id x8mr8761408pbt.115.1404906635316; Wed, 09 Jul 2014 04:50:35 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id an4si45874829pad.149.2014.07.09.04.50.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jul 2014 04:50:35 -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 1X4qMx-0002bv-JT; Wed, 09 Jul 2014 11:49:03 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X4qMs-0002Iw-EK for linux-arm-kernel@lists.infradead.org; Wed, 09 Jul 2014 11:48:59 +0000 Received: by mail-wi0-f171.google.com with SMTP id f8so2106415wiw.16 for ; Wed, 09 Jul 2014 04:48:35 -0700 (PDT) X-Received: by 10.194.216.196 with SMTP id os4mr41217653wjc.70.1404906515676; Wed, 09 Jul 2014 04:48:35 -0700 (PDT) Received: from bivouac.eciton.net ([2a00:1098:0:86:1000:23:0:2]) by mx.google.com with ESMTPSA id gq4sm18558725wib.8.2014.07.09.04.48.34 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 09 Jul 2014 04:48:34 -0700 (PDT) Date: Wed, 9 Jul 2014 12:48:32 +0100 From: Leif Lindholm To: Russell King - ARM Linux Subject: Re: [PATCH 2/2] arm: add early_ioremap support Message-ID: <20140709114832.GS4179@bivouac.eciton.net> References: <1404898792-4201-1-git-send-email-leif.lindholm@linaro.org> <1404898792-4201-3-git-send-email-leif.lindholm@linaro.org> <20140709094926.GP21766@n2100.arm.linux.org.uk> MIME-Version: 1.0 In-Reply-To: <20140709094926.GP21766@n2100.arm.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140709_044858_640141_CDAF87D6 X-CRM114-Status: GOOD ( 30.88 ) 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 [209.85.212.171 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.171 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: robh@kernel.org, arnd@arndb.de, catalin.marinas@arm.com, will.deacon@arm.com, msalter@redhat.com, linux-arm-kernel@lists.infradead.org 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: , 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: leif.lindholm@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.128.173 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 Content-Disposition: inline Hi Russell, On Wed, Jul 09, 2014 at 10:49:26AM +0100, Russell King - ARM Linux wrote: > On Wed, Jul 09, 2014 at 10:39:52AM +0100, Leif Lindholm wrote: > > +config EARLY_IOREMAP > > + depends on MMU > > + bool "Provide early_ioremap() support for kernel initialization." > > + select GENERIC_EARLY_IOREMAP > > Nit: please order as bool, then depends, then select. Fixed in attached. > > diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c > > index 8a16ee5..aa2621a 100644 > > --- a/arch/arm/kernel/setup.c > > +++ b/arch/arm/kernel/setup.c > > @@ -36,6 +36,7 @@ > > #include > > #include > > #include > > +#include > > Please always use linux/io.h in preference to asm/io.h. Fixed in attached. > > +static inline pmd_t * __init early_ioremap_pmd(unsigned long addr) > > +{ > > + unsigned int index = pgd_index(addr); > > + pgd_t *pgd = cpu_get_pgd() + index; > > What is the reasoning for using cpu_get_pgd() ? Is there some specific > reason you want to read from the hardware register rather than using > the pgd_offset_k() macro here? No, merely picked the wrong interface, and it seemed to work. Fixed in attached. > > +void __init > > +early_ioremap_shutdown(void) > > Nit: should be a single line. Fixed in attached. > The rest of the patch looks fine, thanks. Thank you for your comments. / Leif >From 6937e88fc0bc62e125d891889334b6659f2efd28 Mon Sep 17 00:00:00 2001 From: Mark Salter Date: Wed, 27 Nov 2013 10:21:11 -0500 Subject: [PATCH 2/2] arm: add early_ioremap support This patch uses the generic early_ioremap code to implement early_ioremap for ARM. The ARM-specific bits come mostly from an earlier patch from Leif Lindholm here: https://lkml.org/lkml/2013/10/3/279 Signed-off-by: Mark Salter Signed-off-by: Leif Lindholm Tested-by: Leif Lindholm Acked-by: Catalin Marinas CC: linux-arm-kernel@lists.infradead.org CC: Russell King CC: Catalin Marinas CC: Will Deacon CC: Arnd Bergmann --- arch/arm/Kconfig | 11 ++++++ arch/arm/include/asm/Kbuild | 1 + arch/arm/include/asm/io.h | 1 + arch/arm/kernel/setup.c | 3 ++ arch/arm/mm/Makefile | 1 + arch/arm/mm/early_ioremap.c | 84 +++++++++++++++++++++++++++++++++++++++++++ arch/arm/mm/mmu.c | 2 ++ 7 files changed, 103 insertions(+) create mode 100644 arch/arm/mm/early_ioremap.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 245058b..5ddafaf 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1800,6 +1800,17 @@ config UACCESS_WITH_MEMCPY However, if the CPU data cache is using a write-allocate mode, this option is unlikely to provide any performance gain. +config EARLY_IOREMAP + bool "Provide early_ioremap() support for kernel initialization." + depends on MMU + select GENERIC_EARLY_IOREMAP + help + Provide a mechanism for kernel initialisation code to temporarily + map, in a highmem-agnostic way, memory pages in before ioremap() + and friends are available (before paging_init() has run). It uses + the same virtual memory range as kmap so all early mappings must + be unmapped before paging_init() is called. + config SECCOMP bool prompt "Enable seccomp to safely compute untrusted bytecode" diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild index f5a3576..0bc5a02 100644 --- a/arch/arm/include/asm/Kbuild +++ b/arch/arm/include/asm/Kbuild @@ -4,6 +4,7 @@ generic-y += auxvec.h generic-y += bitsperlong.h generic-y += cputime.h generic-y += current.h +generic-y += early_ioremap.h generic-y += emergency-restart.h generic-y += errno.h generic-y += exec.h diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h index 3d23418..7b8a981 100644 --- a/arch/arm/include/asm/io.h +++ b/arch/arm/include/asm/io.h @@ -28,6 +28,7 @@ #include #include #include +#include #include /* diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 8a16ee5..b1f397c 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -894,6 +895,8 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); + early_ioremap_init(); + early_paging_init(mdesc, lookup_processor_type(read_cpuid_id())); setup_dma_zone(mdesc); sanity_check_meminfo(); diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile index 91da64d..1c8ce752 100644 --- a/arch/arm/mm/Makefile +++ b/arch/arm/mm/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_ARM_PTDUMP) += dump.o obj-$(CONFIG_MODULES) += proc-syms.o obj-$(CONFIG_ALIGNMENT_TRAP) += alignment.o +obj-$(CONFIG_EARLY_IOREMAP) += early_ioremap.o obj-$(CONFIG_HIGHMEM) += highmem.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o diff --git a/arch/arm/mm/early_ioremap.c b/arch/arm/mm/early_ioremap.c new file mode 100644 index 0000000..6444454 --- /dev/null +++ b/arch/arm/mm/early_ioremap.c @@ -0,0 +1,84 @@ +/* + * early_ioremap() support for ARM + * + * Based on existing support in arch/x86/mm/ioremap.c + * + * Restrictions: currently only functional before paging_init() + */ + +#include +#include + +#include +#include +#include +#include + +#include + +static pte_t bm_pte[PTRS_PER_PTE] __aligned(PTE_HWTABLE_SIZE) __initdata; + +static inline pmd_t * __init early_ioremap_pmd(unsigned long addr) +{ + pgd_t *pgd = pgd_offset_k(addr); + pud_t *pud = pud_offset(pgd, addr); + pmd_t *pmd = pmd_offset(pud, addr); + + return pmd; +} + +static inline pte_t * __init early_ioremap_pte(unsigned long addr) +{ + return &bm_pte[pte_index(addr)]; +} + +void __init early_ioremap_init(void) +{ + pmd_t *pmd; + + pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)); + pmd_populate_kernel(NULL, pmd, bm_pte); + + if (pmd != early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END))) { + WARN_ON(1); + pr_warn("pmd %p != %p\n", + pmd, early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END))); + pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n", + fix_to_virt(FIX_BTMAP_BEGIN)); + pr_warn("fix_to_virt(FIX_BTMAP_END): %08lx\n", + fix_to_virt(FIX_BTMAP_END)); + pr_warn("FIX_BTMAP_END: %d\n", FIX_BTMAP_END); + pr_warn("FIX_BTMAP_BEGIN: %d\n", FIX_BTMAP_BEGIN); + } + + early_ioremap_setup(); +} + +void __init __early_set_fixmap(enum fixed_addresses idx, + phys_addr_t phys, pgprot_t flags) +{ + unsigned long addr = __fix_to_virt(idx); + pte_t *pte; + u64 desc; + + if (idx > FIX_KMAP_END) { + BUG(); + return; + } + pte = early_ioremap_pte(addr); + + if (pgprot_val(flags)) + set_pte_at(NULL, addr, pte, + pfn_pte(phys >> PAGE_SHIFT, flags)); + else + pte_clear(NULL, addr, pte); + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); + desc = *pte; +} + +void __init early_ioremap_shutdown(void) +{ + pmd_t *pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)); + + pmd_clear(pmd); +} diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index ab14b79..608dc36 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "mm.h" #include "tcm.h" @@ -1474,6 +1475,7 @@ void __init paging_init(const struct machine_desc *mdesc) { void *zero_page; + early_ioremap_reset(); build_mem_type_table(); prepare_page_table(); map_lowmem();