From patchwork Sun Jul 28 20:16:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Walmsley X-Patchwork-Id: 2834724 Return-Path: X-Original-To: patchwork-linux-omap@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 51B92C0319 for ; Sun, 28 Jul 2013 20:16:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F42E2012E for ; Sun, 28 Jul 2013 20:16:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A7E320126 for ; Sun, 28 Jul 2013 20:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133Ab3G1UQa (ORCPT ); Sun, 28 Jul 2013 16:16:30 -0400 Received: from utopia.booyaka.com ([74.50.51.50]:51751 "EHLO utopia.booyaka.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750882Ab3G1UQa (ORCPT ); Sun, 28 Jul 2013 16:16:30 -0400 Received: (qmail 27205 invoked by uid 1019); 28 Jul 2013 20:16:29 -0000 Date: Sun, 28 Jul 2013 20:16:29 +0000 (UTC) From: Paul Walmsley To: Russell King - ARM Linux , Will Deacon cc: Santosh Shilimkar , Rajendra Nayak , "linux-omap@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: [PATCH] ARM: v6: prevent gcc from reordering extended CP15 reads above is_smp() test In-Reply-To: Message-ID: References: <20130722184325.GA21614@n2100.arm.linux.org.uk> <51EE2AA7.5060503@ti.com> <51EE474D.5070804@ti.com> <20130724135617.GI11072@mudshark.cambridge.arm.com> <51EFE1DD.8070801@ti.com> <20130724142059.GJ11072@mudshark.cambridge.arm.com> <20130727122221.GB6618@mudshark.cambridge.arm.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Commit 621a0147d5c921f4cc33636ccd0602ad5d7cbfbc ("ARM: 7757/1: mm: don't flush icache in switch_mm with hardware broadcasting") breaks the boot on OMAP2430SDP with omap2plus_defconfig. Tracked to an undefined instruction abort from the CP15 read in cache_ops_need_broadcast(). It turns out that gcc reorders the extended CP15 read above the is_smp() test. This breaks ARM1136 r0 cores, since they don't support several CP15 registers that later ARM cores do. ARM1136JF-S TRM section 3.2.1 "Register allocation" has the details. So, when the kernel is built for ARMv6 cores, mark the extended CP15 read as clobbering memory, which seems to prevent the compiler from reordering it before the is_smp() test. Russell states that the code generated from this approach is preferable to marking the inline asm as volatile. This patch was developed in collaboration with Will Deacon and Russell King. Signed-off-by: Paul Walmsley Cc: Will Deacon Cc: Russell King Acked-by: Tony Lindgren --- Thought I'd respin this to have a discussion strawman. It boots cleanly on 2430SDP. [ Updated "ARM: v6: avoid read_cpuid_ext() on ARM1136r0 in cache_ops_need_broadcast()" to drop the unnecessary ARM1136 r0 test, to switch to a memory clobber per rmk's suggestion, and to update the commit message. ] Intended for v3.11-rc. arch/arm/include/asm/cputype.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/cputype.h b/arch/arm/include/asm/cputype.h index 8c25dc4..f428eb0 100644 --- a/arch/arm/include/asm/cputype.h +++ b/arch/arm/include/asm/cputype.h @@ -89,13 +89,25 @@ extern unsigned int processor_id; __val; \ }) + +# if defined(CONFIG_CPU_V6) +/* + * The mrc in the read_cpuid_ext macro must not be reordered on ARMv6, + * else the compiler may move it before an is_smp() test, causing + * undefined instruction aborts on ARM1136 r0. + */ +# define CPUID_EXT_REORDER "cc", "memory" +# else +# define CPUID_EXT_REORDER "cc" +# endif + #define read_cpuid_ext(ext_reg) \ ({ \ unsigned int __val; \ asm("mrc p15, 0, %0, c0, " ext_reg \ : "=r" (__val) \ : \ - : "cc"); \ + : CPUID_EXT_REORDER); \ __val; \ })