From patchwork Tue Oct 8 17:45:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 3004621 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 ED103BF924 for ; Tue, 8 Oct 2013 17:46:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1FA820134 for ; Tue, 8 Oct 2013 17:46:22 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10A6220126 for ; Tue, 8 Oct 2013 17:46:21 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTbMO-0003if-QY; Tue, 08 Oct 2013 17:46:17 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTbMM-00084U-CB; Tue, 08 Oct 2013 17:46:14 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTbMJ-000846-5k for linux-arm-kernel@lists.infradead.org; Tue, 08 Oct 2013 17:46:12 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id r98HjY40032308; Tue, 8 Oct 2013 12:45:34 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r98HjYSd004730; Tue, 8 Oct 2013 12:45:34 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Tue, 8 Oct 2013 12:45:34 -0500 Received: from [158.218.103.117] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id r98HjXe6012516; Tue, 8 Oct 2013 12:45:33 -0500 Message-ID: <525444BD.80304@ti.com> Date: Tue, 8 Oct 2013 13:45:33 -0400 From: Santosh Shilimkar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Will Deacon Subject: Re: [PATCH v3 5/6] ARM: mm: Recreate kernel mappings in early_paging_init() References: <1380835081-12129-1-git-send-email-santosh.shilimkar@ti.com> <1380835081-12129-6-git-send-email-santosh.shilimkar@ti.com> <20131004155958.GU24303@mudshark.cambridge.arm.com> <524EE8F4.4060407@ti.com> <52530CD1.5010309@ti.com> <20131008102642.GC17148@mudshark.cambridge.arm.com> In-Reply-To: <20131008102642.GC17148@mudshark.cambridge.arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131008_134611_379918_9F0797D4 X-CRM114-Status: GOOD ( 37.46 ) X-Spam-Score: -7.2 (-------) Cc: "nicolas.pitre@linaro.org" , "linux@arm.linux.org.uk" , Nicolas Pitre , R Sricharan , "arm@kernel.org" , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Will, On Tuesday 08 October 2013 06:26 AM, Will Deacon wrote: > On Mon, Oct 07, 2013 at 08:34:41PM +0100, Santosh Shilimkar wrote: >> Will, > > Hi Santosh, > [..] >> +void __init early_paging_init(const struct machine_desc *mdesc, >> + struct proc_info_list *procinfo) >> +{ >> + pmdval_t pmdprot = procinfo->__cpu_mm_mmu_flags; >> + unsigned long map_start, map_end; >> + pgd_t *pgd0, *pgdk; >> + pud_t *pud0, *pudk, *pud_start; >> + pmd_t *pmd0, *pmdk, *pmd_start; >> + phys_addr_t phys; >> + int i; >> + >> + /* remap kernel code and data */ >> + map_start = init_mm.start_code; >> + map_end = init_mm.brk; >> + >> + /* get a handle on things... */ >> + pgd0 = pgd_offset_k(0); >> + pud_start = pud0 = pud_offset(pgd0, 0); >> + pmd0 = pmd_offset(pud0, 0); >> + >> + pgdk = pgd_offset_k(map_start); >> + pudk = pud_offset(pgdk, map_start); >> + pmd_start = pmdk = pmd_offset(pudk, map_start); >> + >> + phys = PHYS_OFFSET; >> + >> + if (mdesc->init_meminfo) { >> + mdesc->init_meminfo(); >> + /* Run the patch stub to update the constants */ >> + fixup_pv_table(&__pv_table_begin, >> + (&__pv_table_end - &__pv_table_begin) << 2); >> + >> + /* >> + * Cache cleaning operations for self-modifying code >> + * We should clean the entries by MVA but running a >> + * for loop over every pv_table entry pointer would >> + * just complicate the code. isb() is added to commit >> + * all the prior cp15 operations. >> + */ >> + flush_cache_louis(); >> + isb(); > > I see, you need the new __pv_tables to be visible for your page table > population below, right? In which case, I'm afraid I have to go back on my > original statement; you *do* need that dsb() prior to the isb() if you want > to ensure that the icache maintenance is complete and synchronised. > Need of dsb and isb is what ARM ARM says but then I got bit biased after your reply. > However, this really looks like an issue with the v7 cache flushing > routines. Why on Earth do they only guarantee completion on the D-side? > Indeed. >> + } >> + >> + /* remap level 1 table */ >> + for (i = 0; i < PTRS_PER_PGD; i++) { >> + *pud0++ = __pud(__pa(pmd0) | PMD_TYPE_TABLE | L_PGD_SWAPPER); >> + pmd0 += PTRS_PER_PMD; >> + } >> + >> + __cpuc_flush_dcache_area(pud_start, sizeof(pud_start) * PTRS_PER_PGD); >> + outer_clean_range(virt_to_phys(pud_start), sizeof(pud_start) * PTRS_PER_PGD); > > You don't need to flush these page tables if you're SMP. If you use > clean_dcache_area instead, it will do the right thing. The again, why can't > you use pud_populate and pmd_populate for these two loops? Is there an > interaction with coherency here? (if so, why don't you need to flush the > entire cache hierarchy anyway?) > You mean AMRMv7 SMP PT walkers can read from L1 cache and hence doesn't need flushing L1. While this could be true, for some reason we don't the same behavior and seeing that without flush we are seeing the issue. Initially we were doing entire cache flush but moved to the mva based routines on your suggestion. Regarding the pud_populate(), since we needed L_PGD_SWAPPER, we couldn't use that version but updated patch uses the set_pud() which takes the flag. And pmd_populate() can't be used either because it creates pte based tables which is not what we want. So the current working patch as it stands is end of the email. Do let us know if we are missing anything for the PTW L1 allocation behavior. Regards, Santosh From 832ea2ba84ad8a012ec7d4dad4d8085cca2cd598 Mon Sep 17 00:00:00 2001 From: Santosh Shilimkar Date: Wed, 31 Jul 2013 12:44:46 -0400 Subject: [PATCH v3 5/8] ARM: mm: Recreate kernel mappings in early_paging_init() This patch adds a step in the init sequence, in order to recreate the kernel code/data page table mappings prior to full paging initialization. This is necessary on LPAE systems that run out of a physical address space outside the 4G limit. On these systems, this implementation provides a machine descriptor hook that allows the PHYS_OFFSET to be overridden in a machine specific fashion. Based on Cyril's initial patch. The pv_table needs to be patched again after switching to higher address space. Cc: Nicolas Pitre Cc: Russell King Acked-by: Nicolas Pitre Signed-off-by: R Sricharan Signed-off-by: Santosh Shilimkar --- arch/arm/include/asm/mach/arch.h | 1 + arch/arm/kernel/setup.c | 4 ++ arch/arm/mm/mmu.c | 91 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/arch/arm/include/asm/mach/arch.h b/arch/arm/include/asm/mach/arch.h index 402a2bc..17a3fa2 100644 --- a/arch/arm/include/asm/mach/arch.h +++ b/arch/arm/include/asm/mach/arch.h @@ -49,6 +49,7 @@ struct machine_desc { bool (*smp_init)(void); void (*fixup)(struct tag *, char **, struct meminfo *); + void (*init_meminfo)(void); void (*reserve)(void);/* reserve mem blocks */ void (*map_io)(void);/* IO mapping function */ void (*init_early)(void); diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 0e1e2b3..af7b7db 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -73,6 +73,8 @@ __setup("fpe=", fpe_setup); #endif extern void paging_init(const struct machine_desc *desc); +extern void early_paging_init(const struct machine_desc *, + struct proc_info_list *); extern void sanity_check_meminfo(void); extern enum reboot_mode reboot_mode; extern void setup_dma_zone(const struct machine_desc *desc); @@ -878,6 +880,8 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL); + + early_paging_init(mdesc, lookup_processor_type(read_cpuid_id())); sanity_check_meminfo(); arm_memblock_init(&meminfo, mdesc); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index b1d17ee..e9e5276 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1315,6 +1316,96 @@ static void __init map_lowmem(void) } } +#ifdef CONFIG_ARM_LPAE +extern void fixup_pv_table(const void *, unsigned long); +extern const void *__pv_table_begin, *__pv_table_end; + +/* + * early_paging_init() recreates boot time page table setup, allowing machines + * to switch over to a high (>4G) address space on LPAE systems + */ +void __init early_paging_init(const struct machine_desc *mdesc, + struct proc_info_list *procinfo) +{ + pmdval_t pmdprot = procinfo->__cpu_mm_mmu_flags; + unsigned long map_start, map_end; + pgd_t *pgd0, *pgdk; + pud_t *pud0, *pudk, *pud_start; + pmd_t *pmd0, *pmdk, *pmd_start; + phys_addr_t phys; + int i; + + /* remap kernel code and data */ + map_start = init_mm.start_code; + map_end = init_mm.brk; + + /* get a handle on things... */ + pgd0 = pgd_offset_k(0); + pud_start = pud0 = pud_offset(pgd0, 0); + pmd0 = pmd_offset(pud0, 0); + + pgdk = pgd_offset_k(map_start); + pudk = pud_offset(pgdk, map_start); + pmd_start = pmdk = pmd_offset(pudk, map_start); + + if (mdesc->init_meminfo) { + mdesc->init_meminfo(); + /* Run the patch stub to update the constants */ + fixup_pv_table(&__pv_table_begin, + (&__pv_table_end - &__pv_table_begin) << 2); + + /* + * Cache cleaning operations for self-modifying code + * We should clean the entries by MVA but running a + * for loop over every pv_table entry pointer would + * just complicate the code. + */ + flush_cache_louis(); + dsb(); + isb(); + } + + /* remap level 1 table */ + for (i = 0; i < PTRS_PER_PGD; pud0++, i++) { + set_pud(pud0, + __pud(__pa(pmd0) | PMD_TYPE_TABLE | L_PGD_SWAPPER)); + pmd0 += PTRS_PER_PMD; + } + + __cpuc_flush_dcache_area(pud_start, sizeof(pud_start) * PTRS_PER_PGD); + outer_clean_range(virt_to_phys(pud_start), + sizeof(pud_start) * PTRS_PER_PGD); + + /* remap pmds for kernel mapping */ + phys = __pa(map_start) & PMD_MASK; + i = 0; + do { + *pmdk++ = __pmd(phys | pmdprot); + phys += PMD_SIZE; + i++; + } while (phys < map_end); + + __cpuc_flush_dcache_area(pmd_start, sizeof(pmd_start) * i); + outer_clean_range(virt_to_phys(pmd_start), + sizeof(pmd_start) * i); + + cpu_switch_mm(pgd0, &init_mm); + cpu_set_ttbr(1, __pa(pgd0) + TTBR1_OFFSET); + local_flush_bp_all(); + local_flush_tlb_all(); +} + +#else + +void __init early_paging_init(struct machine_desc *mdesc, + struct proc_info_list *procinfo) +{ + if (mdesc->init_meminfo) + mdesc->init_meminfo(); +} + +#endif + /* * paging_init() sets up the page tables, initialises the zone memory * maps, and sets up the zero page, bad page and bad page tables.