From patchwork Tue Mar 21 17:30:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jon Medhurst (Tixy)" X-Patchwork-Id: 9637199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A9C6860216 for ; Tue, 21 Mar 2017 17:30:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9911828405 for ; Tue, 21 Mar 2017 17:30:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B2FE2841A; Tue, 21 Mar 2017 17:30:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1CB6428405 for ; Tue, 21 Mar 2017 17:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=CaM6oZeTeJ+CEObdxctyr+TABvSHJfThjX0whEkcdUk=; b=iDS ni+/KDlNWkujVwjKbxENowSUZ3Ne9Q58vDom4dPjyaOM+x7FweZ1NsZXOJ/ZYfqAWeHIMjaZVRs7p sjOk1Sn5T9tCnaJJil+tz9UP44pc8XfQkWilCS/T3DdnRCCFKaaSDorhVgZcB0b8YgGYAioNHZ6F3 f17fT1GxV2kk41k7c2m8u6GB5oRbdZbcfUGvG/RzksNRwj/BmBVVDJGfIpRoxVQjse0t0O69f2B0d N2Lw7dB+LvrI49gwh7qrsyvcPlyGziPQ2Arrh1FGelS1Y8OzejYoqZlh+RrR6VgysmcM/fh+mPw+V t4WKxMfnlRyo9oDiKgLJC+Iez2ymsXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqNcY-0004nz-MJ; Tue, 21 Mar 2017 17:30:58 +0000 Received: from smarthost01d.mail.zen.net.uk ([212.23.1.7]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqNcU-0004jz-RT for linux-arm-kernel@lists.infradead.org; Tue, 21 Mar 2017 17:30:56 +0000 Received: from [82.69.122.217] (helo=plug1) by smarthost01d.mail.zen.net.uk with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1cqNc7-000Dqb-PW; Tue, 21 Mar 2017 17:30:32 +0000 Received: from linaro1 ([192.168.2.110] helo=linaro2.home) by plug1 with esmtp (Exim 4.80) (envelope-from ) id 1cqNc6-00020z-IH; Tue, 21 Mar 2017 17:30:30 +0000 Received: from tixy by linaro2.home with local (Exim 4.88) (envelope-from ) id 1cqNc6-00021i-GM; Tue, 21 Mar 2017 17:30:30 +0000 From: Jon Medhurst To: Russell King Subject: [PATCH v2] arm: Fix memory attribute inconsistencies when using fixmap Date: Tue, 21 Mar 2017 17:30:30 +0000 Message-Id: <20170321173030.7751-1-tixy@linaro.org> X-Mailer: git-send-email 2.11.0 X-Originating-smarthost01d-IP: [82.69.122.217] Feedback-ID: 82.69.122.217 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170321_103055_043190_02591DC4 X-CRM114-Status: GOOD ( 15.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Agner , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP To cope with the variety in ARM architectures and configurations, the pagetable attributes for kernel memory are generated at runtime to match the system the kernel finds itself on. This calculated value is stored in pgprot_kernel. However, when early fixmap support was added for arm (commit a5f4c561b3b1) the attributes used for mappings were hard coded because pgprot_kernel is not set up early enough. Unfortunately, when fixmap is used after early boot this means the memory being mapped can have different attributes to existing mappings, potentially leading to unpredictable behaviour. A specific problem also exists due to the hard coded values not include the 'shareable' attribute which means on systems where this matters (e.g. those with multiple CPU clusters) the cache contents for a memory location can become inconsistent between CPUs. To resolve these issues we change fixmap to use the same memory attributes (from pgprot_kernel) that the rest of the kernel uses. To enable this we need to refactor the initialisation code so build_mem_type_table is called early enough. Note, that relies on early param parsing for memory type overrides passed via the kernel command line, so we need to make sure this call is still after parse_early_params(). Fixes: a5f4c561b3b1 ("ARM: 8415/1: early fixmap support for earlycon") Cc: stable@vger.kernel.org # v4.3+ Signed-off-by: Jon Medhurst Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- Changes since v1: - Completely rewritten based on Russell's and Ard's sugestions - Subject changed from "arm: Fix cache inconsistency when using fixmap" arch/arm/include/asm/fixmap.h | 7 +------ arch/arm/include/asm/mmu.h | 2 ++ arch/arm/kernel/setup.c | 5 +---- arch/arm/mm/mmu.c | 12 ++++++++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/arm/include/asm/fixmap.h b/arch/arm/include/asm/fixmap.h index 5c17d2dec777..c54f06ace2a1 100644 --- a/arch/arm/include/asm/fixmap.h +++ b/arch/arm/include/asm/fixmap.h @@ -41,7 +41,7 @@ static const enum fixed_addresses __end_of_fixed_addresses = #define FIXMAP_PAGE_COMMON (L_PTE_YOUNG | L_PTE_PRESENT | L_PTE_XN | L_PTE_DIRTY) -#define FIXMAP_PAGE_NORMAL (FIXMAP_PAGE_COMMON | L_PTE_MT_WRITEBACK) +#define FIXMAP_PAGE_NORMAL (pgprot_kernel | L_PTE_XN) #define FIXMAP_PAGE_RO (FIXMAP_PAGE_NORMAL | L_PTE_RDONLY) /* Used by set_fixmap_(io|nocache), both meant for mapping a device */ @@ -53,13 +53,8 @@ static const enum fixed_addresses __end_of_fixed_addresses = #ifdef CONFIG_MMU void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot); -void __init early_fixmap_init(void); #include -#else - -static inline void early_fixmap_init(void) { } - #endif #endif diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h index a5b47421059d..920d29ca5c3b 100644 --- a/arch/arm/include/asm/mmu.h +++ b/arch/arm/include/asm/mmu.h @@ -24,6 +24,8 @@ typedef struct { #define ASID(mm) (0) #endif +void early_mm_init(void); + #else /* diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index f4e54503afa9..37c59589aac3 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -1082,12 +1081,10 @@ void __init setup_arch(char **cmdline_p) strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE); *cmdline_p = cmd_line; - early_fixmap_init(); - early_ioremap_init(); - parse_early_param(); #ifdef CONFIG_MMU + early_mm_init(); early_paging_init(mdesc); #endif setup_dma_zone(mdesc); diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 4e016d7f37b3..f81809e6bd10 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -382,7 +383,7 @@ static inline pmd_t * __init fixmap_pmd(unsigned long addr) return pmd; } -void __init early_fixmap_init(void) +static void __init early_fixmap_init(void) { pmd_t *pmd; @@ -1616,7 +1617,6 @@ void __init paging_init(const struct machine_desc *mdesc) { void *zero_page; - build_mem_type_table(); prepare_page_table(); map_lowmem(); memblock_set_current_limit(arm_lowmem_limit); @@ -1636,3 +1636,11 @@ void __init paging_init(const struct machine_desc *mdesc) empty_zero_page = virt_to_page(zero_page); __flush_dcache_page(NULL, empty_zero_page); } + +void __init early_mm_init(void) +{ + build_mem_type_table(); + + early_fixmap_init(); + early_ioremap_init(); +}