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: 4514341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 24355BEEAA for ; Wed, 9 Jul 2014 11:51:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 03021200F3 for ; Wed, 9 Jul 2014 11:51:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C6F4A202FF for ; Wed, 9 Jul 2014 11:51:22 +0000 (UTC) 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=tOYTKHLzx0E3tP/fh3tko6UC8N+O8DcK1wvrxIDh4FY=; b=aZbeB/3mDsy+uddx0RrJ06n9ql+rLGgyp7R1/z7PDYFMPuEYQicLRHh/LQoWK7T43Z fqmLwf8A94bUIvhXfM+xlyFOPrURqEyA9bXG8/q+fuDU2jpGYrn7oHw7mQHfw78J4Otz UDb6gXS3UnRMuC09y3Wu0FAjVEW/1zT1M0/3RwTY+Ft0a5BApFvQtAbM6qZRs5YUp9LR FonFbi8Y5deSM61DuO2F6GfIH/qda9DRy3HUtoKZmh9JMObhvWjQFEoAO0QrTKRMLKU4 aig//GAOJFHKUq5bvaowL/R1gV/S6cJRqvFWwN9hzitQ0+mi3phOtNOgVA+uAqq+BF7k d9SA== X-Gm-Message-State: ALoCoQkchpfDDrt4lYoZWtVRmWp1PhxdaBDZofd1l98GI+IpAEgQ/hxGLjQgjsSmmeuwBopHShtB 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 Content-Disposition: inline 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 (/) 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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();