From patchwork Thu Mar 16 13:29:57 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: 9628185 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 7B0FB6048C for ; Thu, 16 Mar 2017 13:30:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C942285EB for ; Thu, 16 Mar 2017 13:30:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 613B128644; Thu, 16 Mar 2017 13:30:46 +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 94217285EB for ; Thu, 16 Mar 2017 13:30:44 +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=uTWjc6ZAANOc7yllFTNcIkM1GLz2I4nwZEkluhT4gDQ=; b=MQc jBIwVaepxxNE9DW+lOjDAFkaqt1LQ7R5oKU5rOADMXTnR8lV83NQjwwN74cJUAxr7keUaWYfULsdf 6/N/sLLvzrpVqMTX6s27OL5a6FX6qQ7t61lCmwtTnYaHSa7ZxBNg3zAImCicRqv8/tcFEnve3BSQt C/ZZHqX+Q/eo3CzwCleKuKhdm6ph+GpSwEQwO/JXZxiCtu6m/twlJMRhjBz3QoHMv2MqGNz6nk5kV DHeM8n/YzugLcigGm6k94TM4tY8HR7706bCQHaw4Ojn7AIcFYjpyn/C+WlUyxAjV55qOSyUUz83eb 6v0PbQ4NckAKB8ywHRd4O6l0Hd5oVkQ==; 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 1coVUK-0000bR-0G; Thu, 16 Mar 2017 13:30:44 +0000 Received: from smarthost03c.mail.zen.net.uk ([212.23.1.22]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1coVU0-0007dF-9e for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2017 13:30:31 +0000 Received: from [82.69.122.217] (helo=plug1) by smarthost03c.mail.zen.net.uk with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1coVTc-0007GV-7n; Thu, 16 Mar 2017 13:30:00 +0000 Received: from linaro1 ([192.168.2.110] helo=linaro2.home) by plug1 with esmtp (Exim 4.80) (envelope-from ) id 1coVTa-0000y8-5k; Thu, 16 Mar 2017 13:29:58 +0000 Received: from tixy by linaro2.home with local (Exim 4.88) (envelope-from ) id 1coVTa-0005ot-3y; Thu, 16 Mar 2017 13:29:58 +0000 From: Jon Medhurst To: Russell King Subject: [PATCH 1/2] arm: Fix cache inconsistency when using fixmap Date: Thu, 16 Mar 2017 13:29:57 +0000 Message-Id: <20170316132958.22227-1-tixy@linaro.org> X-Mailer: git-send-email 2.11.0 X-Originating-smarthost03c-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-20170316_063024_491293_0DA92357 X-CRM114-Status: GOOD ( 16.00 ) 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, the values used didn't include the 'shareable' attribute which means that for later non-early fixmap use, when multiple CPUs are running, any cache entries allocated for fixmap memory aren't kept consistent between CPUs. This can result in different CPUs seeing different memory contents. This issue was discovered on a dual cluster system by failures with kprobes, which uses fixmap to modify the kernel image if CONFIG_DEBUG_RODATA is enabled. It will also affect kgdb and jump_labels which also make use of the same code to modify the kernel, and any other uses of fixmap after secondary CPUs are brought online. To fix this issue, and to help avoid other potential problems where pagetable attributes are incorrect, we change the fixmap code to use the same generated value in pgprot_kernel that the rest of the kernel uses, and only fall back to a hard coded value if this isn't set - which will be early on in boot before other CPUs are brought online. Fixes: a5f4c561b3b1 ("ARM: 8415/1: early fixmap support for earlycon") Cc: stable@vger.kernel.org # v4.3+ Reviewed-by: Stefan Agner Reviewed-by: Ard Biesheuvel Signed-off-by: Jon Medhurst --- Stefan and Ard reviewed the code in these 2 patches but not the commit wording... https://www.spinics.net/lists/arm-kernel/msg565126.html arch/arm/include/asm/fixmap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/fixmap.h b/arch/arm/include/asm/fixmap.h index 5c17d2dec777..4e6784dc5668 100644 --- a/arch/arm/include/asm/fixmap.h +++ b/arch/arm/include/asm/fixmap.h @@ -41,7 +41,8 @@ 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 ? pgprot_kernel | L_PTE_XN : \ + FIXMAP_PAGE_COMMON | L_PTE_MT_WRITEBACK) #define FIXMAP_PAGE_RO (FIXMAP_PAGE_NORMAL | L_PTE_RDONLY) /* Used by set_fixmap_(io|nocache), both meant for mapping a device */