Skip to content

Commit 6332807

Browse files
committed
ARM: Correct BUG() assembly to ensure it is endian-agnostic
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. This means that the BUG() macro does not get trapped properly. Change to using <asm/opcodes.h> to provide the necessary ARM instruction building as we cannot rely on gcc/gas having the `.inst` instructions which where added to try and resolve this issue (reported by Dave Martin <Dave.Martin@arm.com>). Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Dave Martin <Dave.Martin@arm.com>
1 parent 3460743 commit 6332807

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎arch/arm/include/asm/bug.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define _ASMARM_BUG_H
33

44
#include <linux/linkage.h>
5+
#include <linux/types.h>
6+
#include <asm/opcodes.h>
57

68
#ifdef CONFIG_BUG
79

@@ -12,10 +14,10 @@
1214
*/
1315
#ifdef CONFIG_THUMB2_KERNEL
1416
#define BUG_INSTR_VALUE 0xde02
15-
#define BUG_INSTR_TYPE ".hword "
17+
#define BUG_INSTR(__value) __inst_thumb16(__value)
1618
#else
1719
#define BUG_INSTR_VALUE 0xe7f001f2
18-
#define BUG_INSTR_TYPE ".word "
20+
#define BUG_INSTR(__value) __inst_arm(__value)
1921
#endif
2022

2123

@@ -33,7 +35,7 @@
3335

3436
#define __BUG(__file, __line, __value) \
3537
do { \
36-
asm volatile("1:\t" BUG_INSTR_TYPE #__value "\n" \
38+
asm volatile("1:\t" BUG_INSTR(__value) "\n" \
3739
".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \
3840
"2:\t.asciz " #__file "\n" \
3941
".popsection\n" \
@@ -48,7 +50,7 @@ do { \
4850

4951
#define __BUG(__file, __line, __value) \
5052
do { \
51-
asm volatile(BUG_INSTR_TYPE #__value); \
53+
asm volatile(BUG_INSTR(__value) "\n"); \
5254
unreachable(); \
5355
} while (0)
5456
#endif /* CONFIG_DEBUG_BUGVERBOSE */

‎arch/arm/kernel/traps.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,17 @@ void arm_notify_die(const char *str, struct pt_regs *regs,
342342
int is_valid_bugaddr(unsigned long pc)
343343
{
344344
#ifdef CONFIG_THUMB2_KERNEL
345-
unsigned short bkpt;
345+
u16 bkpt;
346+
u16 insn = __opcode_to_mem_thumb16(BUG_INSTR_VALUE);
346347
#else
347-
unsigned long bkpt;
348+
u32 bkpt;
349+
u32 insn = __opcode_to_mem_arm(BUG_INSTR_VALUE);
348350
#endif
349351

350352
if (probe_kernel_address((unsigned *)pc, bkpt))
351353
return 0;
352354

353-
return bkpt == BUG_INSTR_VALUE;
355+
return bkpt == insn;
354356
}
355357

356358
#endif

0 commit comments

Comments
 (0)