Skip to content

Commit 586ff7f

Browse files
ingomolnargregkh
authored andcommitted
compiler/gcc4: Add quirk for 'asm goto' miscompilation bug
commit 3f0116c upstream. Fengguang Wu, Oleg Nesterov and Peter Zijlstra tracked down a kernel crash to a GCC bug: GCC miscompiles certain 'asm goto' constructs, as outlined here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 Implement a workaround suggested by Jakub Jelinek. Reported-and-tested-by: Fengguang Wu <fengguang.wu@intel.com> Reported-by: Oleg Nesterov <oleg@redhat.com> Reported-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Suggested-by: Jakub Jelinek <jakub@redhat.com> Reviewed-by: Richard Henderson <rth@twiddle.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/20131015062351.GA4666@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 85c1992 commit 586ff7f

8 files changed

Lines changed: 24 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
static __always_inline bool arch_static_branch(struct static_key *key)
1818
{
19-
asm goto("1:\n\t"
19+
asm_volatile_goto("1:\n\t"
2020
JUMP_LABEL_NOP "\n\t"
2121
".pushsection __jump_table, \"aw\"\n\t"
2222
".word 1b, %l[l_yes], %c0\n\t"

‎arch/mips/include/asm/jump_label.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
static __always_inline bool arch_static_branch(struct static_key *key)
2424
{
25-
asm goto("1:\tnop\n\t"
25+
asm_volatile_goto("1:\tnop\n\t"
2626
"nop\n\t"
2727
".pushsection __jump_table, \"aw\"\n\t"
2828
WORD_INSN " 1b, %l[l_yes], %0\n\t"

‎arch/powerpc/include/asm/jump_label.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
static __always_inline bool arch_static_branch(struct static_key *key)
2121
{
22-
asm goto("1:\n\t"
22+
asm_volatile_goto("1:\n\t"
2323
"nop\n\t"
2424
".pushsection __jump_table, \"aw\"\n\t"
2525
JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"

‎arch/s390/include/asm/jump_label.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
static __always_inline bool arch_static_branch(struct static_key *key)
1717
{
18-
asm goto("0: brcl 0,0\n"
18+
asm_volatile_goto("0: brcl 0,0\n"
1919
".pushsection __jump_table, \"aw\"\n"
2020
ASM_ALIGN "\n"
2121
ASM_PTR " 0b, %l[label], %0\n"

‎arch/sparc/include/asm/jump_label.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static __always_inline bool arch_static_branch(struct static_key *key)
1111
{
12-
asm goto("1:\n\t"
12+
asm_volatile_goto("1:\n\t"
1313
"nop\n\t"
1414
"nop\n\t"
1515
".pushsection __jump_table, \"aw\"\n\t"

‎arch/x86/include/asm/cpufeature.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
373373
* Catch too early usage of this before alternatives
374374
* have run.
375375
*/
376-
asm goto("1: jmp %l[t_warn]\n"
376+
asm_volatile_goto("1: jmp %l[t_warn]\n"
377377
"2:\n"
378378
".section .altinstructions,\"a\"\n"
379379
" .long 1b - .\n"
@@ -386,7 +386,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
386386
: : "i" (X86_FEATURE_ALWAYS) : : t_warn);
387387
#endif
388388

389-
asm goto("1: jmp %l[t_no]\n"
389+
asm_volatile_goto("1: jmp %l[t_no]\n"
390390
"2:\n"
391391
".section .altinstructions,\"a\"\n"
392392
" .long 1b - .\n"
@@ -448,7 +448,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
448448
* have. Thus, we force the jump to the widest, 4-byte, signed relative
449449
* offset even though the last would often fit in less bytes.
450450
*/
451-
asm goto("1: .byte 0xe9\n .long %l[t_dynamic] - 2f\n"
451+
asm_volatile_goto("1: .byte 0xe9\n .long %l[t_dynamic] - 2f\n"
452452
"2:\n"
453453
".section .altinstructions,\"a\"\n"
454454
" .long 1b - .\n" /* src offset */

‎arch/x86/include/asm/jump_label.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static __always_inline bool arch_static_branch(struct static_key *key)
1515
{
16-
asm goto("1:"
16+
asm_volatile_goto("1:"
1717
STATIC_KEY_INITIAL_NOP
1818
".pushsection __jump_table, \"aw\" \n\t"
1919
_ASM_ALIGN "\n\t"

‎include/linux/compiler-gcc4.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@
6565
#define __visible __attribute__((externally_visible))
6666
#endif
6767

68+
/*
69+
* GCC 'asm goto' miscompiles certain code sequences:
70+
*
71+
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
72+
*
73+
* Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
74+
* Fixed in GCC 4.8.2 and later versions.
75+
*
76+
* (asm goto is automatically volatile - the naming reflects this.)
77+
*/
78+
#if GCC_VERSION <= 40801
79+
# define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
80+
#else
81+
# define asm_volatile_goto(x...) do { asm goto(x); } while (0)
82+
#endif
6883

6984
#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
7085
#if GCC_VERSION >= 40400

0 commit comments

Comments
 (0)