From patchwork Thu Jul 25 15:57:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 2833475 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E96049F4E2 for ; Thu, 25 Jul 2013 16:26:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB6F020208 for ; Thu, 25 Jul 2013 16:26:26 +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 55A21201CE for ; Thu, 25 Jul 2013 16:26:25 +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 1V2Nvl-0004wA-27; Thu, 25 Jul 2013 15:58:18 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2NvC-0005jA-PB; Thu, 25 Jul 2013 15:57:42 +0000 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2Nv2-0005h7-Ru for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2013 15:57:34 +0000 Received: from localhost.localdomain (e103592.cambridge.arm.com [10.1.203.144]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id r6PFuxnc023071; Thu, 25 Jul 2013 16:57:00 +0100 Date: Thu, 25 Jul 2013 16:57:00 +0100 From: Dave Martin To: Ben Dooks Subject: Re: [PATCH 1/2] ARM: Correct BUG() assembly to ensure it is endian-agnostic Message-ID: <20130725155700.GD2546@localhost.localdomain> References: <1374763357-4893-1-git-send-email-ben.dooks@codethink.co.uk> <1374763357-4893-2-git-send-email-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1374763357-4893-2-git-send-email-ben.dooks@codethink.co.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130725_115733_196154_DF514A89 X-CRM114-Status: GOOD ( 21.26 ) X-Spam-Score: -2.6 (--) Cc: rmk@arm.linux.org.uk, 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.2 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 On Thu, Jul 25, 2013 at 03:42:36PM +0100, Ben Dooks wrote: > Currently BUG() uses .word or .hword to create the necessary illegal > instructions. However if we are building BE8 then these get swapped > by the linker into different illegal instructions in the text. In the case of Thumb, the resulting instruction is actually not illegal, which is even worse... > Change to using .inst and .inst.w to create the instructions and mark > them as instructions so that the linker acts correctly. > > Signed-off-by: Ben Dooks > --- > arch/arm/include/asm/bug.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h > index 7af5c6c..b95da52 100644 > --- a/arch/arm/include/asm/bug.h > +++ b/arch/arm/include/asm/bug.h > @@ -12,10 +12,10 @@ > */ > #ifdef CONFIG_THUMB2_KERNEL > #define BUG_INSTR_VALUE 0xde02 > -#define BUG_INSTR_TYPE ".hword " > +#define BUG_INSTR_TYPE ".inst.w " > #else > #define BUG_INSTR_VALUE 0xe7f001f2 > -#define BUG_INSTR_TYPE ".word " > +#define BUG_INSTR_TYPE ".inst " > #endif There was some uncertainty a while ago about precisely which versions of gas support .inst. implements an abstracted workaround for this issue, whereby you can emit instructions using the __inst*() macros, and the swabbing and assembler directives should be generated for you. The patch below ought to do this for BUG(), but I've only briefly build-tested it. Note that the disassembly of the injected instructions in .o files can be a bit confusing, because they are marked as data, do ld --be8 doesn't swab them (unlike the instructions, which do get swabbed). objdump may also do extra swabbing during disassembly. You can sanity-check what is really in the image by dumping the text section of vmlinux with objdump -s. The change to is due to a missing include which is really required for correctness, but which didn't show up without the change (this causes opcodes.h to get included way more often than is otherwise the case). Cheers ---Dave diff --git a/arch/arm/include/asm/bug.h b/arch/arm/include/asm/bug.h index 7af5c6c..e36fe85 100644 --- a/arch/arm/include/asm/bug.h +++ b/arch/arm/include/asm/bug.h @@ -2,6 +2,7 @@ #define _ASMARM_BUG_H #include +#include #ifdef CONFIG_BUG @@ -12,15 +13,15 @@ */ #ifdef CONFIG_THUMB2_KERNEL #define BUG_INSTR_VALUE 0xde02 -#define BUG_INSTR_TYPE ".hword " +#define __BUG_INSTR __inst_thumb16(BUG_INSTR_VALUE) #else #define BUG_INSTR_VALUE 0xe7f001f2 -#define BUG_INSTR_TYPE ".word " +#define __BUG_INSTR __inst_arm(BUG_INSTR_VALUE) #endif -#define BUG() _BUG(__FILE__, __LINE__, BUG_INSTR_VALUE) -#define _BUG(file, line, value) __BUG(file, line, value) +#define BUG() _BUG(__FILE__, __LINE__) +#define _BUG(file, line) __BUG(file, line) #ifdef CONFIG_DEBUG_BUGVERBOSE @@ -31,9 +32,9 @@ * avoid multiple copies of the string appearing in the kernel image. */ -#define __BUG(__file, __line, __value) \ +#define __BUG(__file, __line) \ do { \ - asm volatile("1:\t" BUG_INSTR_TYPE #__value "\n" \ + asm volatile("1:\t" __BUG_INSTR "\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " #__file "\n" \ ".popsection\n" \ @@ -46,9 +47,9 @@ do { \ #else /* not CONFIG_DEBUG_BUGVERBOSE */ -#define __BUG(__file, __line, __value) \ +#define __BUG(__file, __line) \ do { \ - asm volatile(BUG_INSTR_TYPE #__value); \ + asm volatile(__BUG_INSTR) \ unreachable(); \ } while (0) #endif /* CONFIG_DEBUG_BUGVERBOSE */ diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h index e796c59..e94ebfd 100644 --- a/arch/arm/include/asm/opcodes.h +++ b/arch/arm/include/asm/opcodes.h @@ -11,6 +11,8 @@ #ifndef __ASSEMBLY__ #include +#include + extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); #endif