From patchwork Wed Sep 7 13:35:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 1127872 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p87GrtNG022672 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 Sep 2011 16:54:18 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1R1IHg-0000MI-7p; Wed, 07 Sep 2011 13:35:20 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1R1IHf-0002Rt-Nv; Wed, 07 Sep 2011 13:35:19 +0000 Received: from galois.linutronix.de ([2001:470:1f0b:1c35:abcd:42:0:1]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1R1IHW-0002RW-VF for linux-arm-kernel@lists.infradead.org; Wed, 07 Sep 2011 13:35:16 +0000 Received: from localhost ([127.0.0.1] helo=vostro.fn.ogness.net) by Galois.linutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1R1IHS-0003iY-KG; Wed, 07 Sep 2011 15:35:06 +0200 From: John Ogness To: Russell King Subject: [PATCH] ARM: alignment: setup alignment handler earlier Date: Wed, 07 Sep 2011 15:35:04 +0200 Message-ID: <87ehzstr07.fsf@vostro.fn.ogness.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110907_093511_617737_5379F9BC X-CRM114-Status: GOOD ( 17.54 ) X-Spam-Score: -0.5 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Nicolas Pitre , Dave Martin , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Grant Likely , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 07 Sep 2011 16:54:18 +0000 (UTC) From 6f3f381800367127dc6430d9b9fa9bd6fc6d8ed0 Mon Sep 17 00:00:00 2001 From: John Ogness The alignment exception handler is setup fairly late in the boot process (fs_initcall). However, with newer gcc versions and the compiler option -fconserve-stack, code accessing unaligned data is generated in functions that are called earlier, for example pcpu_dump_alloc_info(). This results in unhandled alignment exceptions during boot. By setting up the exception handler sooner, we reduce the window where a compiler may generate code accessing unaligned data. Here is a minimal example that shows the issue seen with pcpu_dump_alloc_info(): =========== begin align_test.c ========== extern void exfunc(char *str); void somefunc(void) { char mystr[] = "--------"; /* 9 bytes */ exfunc(mystr); } ============ end align_test.c =========== Using the cross toolchain: arm-none-linux-gnueabi-gcc (Sourcery G++ Lite 2011.03-41) 4.5.2 $ arm-none-linux-gnueabi-gcc \ -march=armv6 \ -mtune=arm1136j-s \ -marm \ -Os \ -fconserve-stack \ -c align_test.c The object dump of align_test.o shows: 00000000 : 0: e92d401f push {r0, r1, r2, r3, r4, lr} 4: e28d0007 add r0, sp, #7 8: e59f3020 ldr r3, [pc, #32] ; 30 c: e5932000 ldr r2, [r3] 10: e58d2007 str r2, [sp, #7] ... ... At address 0x10 there is unaligned access. Signed-off-by: John Ogness --- Patch against linux-next-20110831. arch/arm/include/asm/setup.h | 1 + arch/arm/kernel/setup.c | 2 ++ arch/arm/mm/alignment.c | 10 +++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/setup.h b/arch/arm/include/asm/setup.h index a3ca303..b3e18f8 100644 --- a/arch/arm/include/asm/setup.h +++ b/arch/arm/include/asm/setup.h @@ -232,6 +232,7 @@ extern struct meminfo meminfo; extern int arm_add_memory(phys_addr_t start, unsigned long size); extern void early_print(const char *str, ...); extern void dump_machine_table(void); +extern int __init alignment_init(void); #endif /* __KERNEL__ */ diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 0ca06f7..0f1b2b5 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -950,6 +950,8 @@ void __init setup_arch(char **cmdline_p) #endif early_trap_init(); + alignment_init(); + if (mdesc->init_early) mdesc->init_early(); } diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c index 715eb1d..5f013cb 100644 --- a/arch/arm/mm/alignment.c +++ b/arch/arm/mm/alignment.c @@ -950,7 +950,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) * it isn't a sysctl, and it doesn't contain sysctl information. * We now locate it in /proc/cpu/alignment instead. */ -static int __init alignment_init(void) +static int __init alignment_sysfs_init(void) { #ifdef CONFIG_PROC_FS struct proc_dir_entry *res; @@ -960,7 +960,13 @@ static int __init alignment_init(void) if (!res) return -ENOMEM; #endif + return 0; +} + +fs_initcall(alignment_sysfs_init); +int __init alignment_init(void) +{ if (cpu_is_v6_unaligned()) { cr_alignment &= ~CR_A; cr_no_alignment &= ~CR_A; @@ -985,5 +991,3 @@ static int __init alignment_init(void) return 0; } - -fs_initcall(alignment_init);