Skip to content

Commit 4356e9f

Browse files
committed
work around gcc bugs with 'asm goto' with outputs
We've had issues with gcc and 'asm goto' before, and we created a 'asm_volatile_goto()' macro for that in the past: see commits 3f0116c ("compiler/gcc4: Add quirk for 'asm goto' miscompilation bug") and a9f1803 ("compiler/gcc4: Make quirk for asm_volatile_goto() unconditional"). Then, much later, we ended up removing the workaround in commit 43c249e ("compiler-gcc.h: remove ancient workaround for gcc PR 58670") because we no longer supported building the kernel with the affected gcc versions, but we left the macro uses around. Now, Sean Christopherson reports a new version of a very similar problem, which is fixed by re-applying that ancient workaround. But the problem in question is limited to only the 'asm goto with outputs' cases, so instead of re-introducing the old workaround as-is, let's rename and limit the workaround to just that much less common case. It looks like there are at least two separate issues that all hit in this area: (a) some versions of gcc don't mark the asm goto as 'volatile' when it has outputs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98619 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110420 which is easy to work around by just adding the 'volatile' by hand. (b) Internal compiler errors: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110422 which are worked around by adding the extra empty 'asm' as a barrier, as in the original workaround. but the problem Sean sees may be a third thing since it involves bad code generation (not an ICE) even with the manually added 'volatile'. but the same old workaround works for this case, even if this feels a bit like voodoo programming and may only be hiding the issue. Reported-and-tested-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/all/20240208220604.140859-1-seanjc@google.com/ Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Uros Bizjak <ubizjak@gmail.com> Cc: Jakub Jelinek <jakub@redhat.com> Cc: Andrew Pinski <quic_apinski@quicinc.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9ed18b0 commit 4356e9f

File tree

35 files changed

+96
-77
lines changed

35 files changed

+96
-77
lines changed

arch/arc/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
static __always_inline bool arch_static_branch(struct static_key *key,
3232
bool branch)
3333
{
34-
asm_volatile_goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)" \n"
34+
asm goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)" \n"
3535
"1: \n"
3636
"nop \n"
3737
".pushsection __jump_table, \"aw\" \n"
@@ -47,7 +47,7 @@ static __always_inline bool arch_static_branch(struct static_key *key,
4747
static __always_inline bool arch_static_branch_jump(struct static_key *key,
4848
bool branch)
4949
{
50-
asm_volatile_goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)" \n"
50+
asm goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)" \n"
5151
"1: \n"
5252
"b %l[l_yes] \n"
5353
".pushsection __jump_table, \"aw\" \n"

arch/arm/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1313
{
14-
asm_volatile_goto("1:\n\t"
14+
asm goto("1:\n\t"
1515
WASM(nop) "\n\t"
1616
".pushsection __jump_table, \"aw\"\n\t"
1717
".word 1b, %l[l_yes], %c0\n\t"
@@ -25,7 +25,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
2525

2626
static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
2727
{
28-
asm_volatile_goto("1:\n\t"
28+
asm goto("1:\n\t"
2929
WASM(b) " %l[l_yes]\n\t"
3030
".pushsection __jump_table, \"aw\"\n\t"
3131
".word 1b, %l[l_yes], %c0\n\t"

arch/arm64/include/asm/alternative-macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ alternative_has_cap_likely(const unsigned long cpucap)
229229
if (!cpucap_is_possible(cpucap))
230230
return false;
231231

232-
asm_volatile_goto(
232+
asm goto(
233233
ALTERNATIVE_CB("b %l[l_no]", %[cpucap], alt_cb_patch_nops)
234234
:
235235
: [cpucap] "i" (cpucap)
@@ -247,7 +247,7 @@ alternative_has_cap_unlikely(const unsigned long cpucap)
247247
if (!cpucap_is_possible(cpucap))
248248
return false;
249249

250-
asm_volatile_goto(
250+
asm goto(
251251
ALTERNATIVE("nop", "b %l[l_yes]", %[cpucap])
252252
:
253253
: [cpucap] "i" (cpucap)

arch/arm64/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
static __always_inline bool arch_static_branch(struct static_key * const key,
1919
const bool branch)
2020
{
21-
asm_volatile_goto(
21+
asm goto(
2222
"1: nop \n\t"
2323
" .pushsection __jump_table, \"aw\" \n\t"
2424
" .align 3 \n\t"
@@ -35,7 +35,7 @@ static __always_inline bool arch_static_branch(struct static_key * const key,
3535
static __always_inline bool arch_static_branch_jump(struct static_key * const key,
3636
const bool branch)
3737
{
38-
asm_volatile_goto(
38+
asm goto(
3939
"1: b %l[l_yes] \n\t"
4040
" .pushsection __jump_table, \"aw\" \n\t"
4141
" .align 3 \n\t"

arch/csky/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
static __always_inline bool arch_static_branch(struct static_key *key,
1313
bool branch)
1414
{
15-
asm_volatile_goto(
15+
asm goto(
1616
"1: nop32 \n"
1717
" .pushsection __jump_table, \"aw\" \n"
1818
" .align 2 \n"
@@ -29,7 +29,7 @@ static __always_inline bool arch_static_branch(struct static_key *key,
2929
static __always_inline bool arch_static_branch_jump(struct static_key *key,
3030
bool branch)
3131
{
32-
asm_volatile_goto(
32+
asm goto(
3333
"1: bsr32 %l[label] \n"
3434
" .pushsection __jump_table, \"aw\" \n"
3535
" .align 2 \n"

arch/loongarch/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
2424
{
25-
asm_volatile_goto(
25+
asm goto(
2626
"1: nop \n\t"
2727
JUMP_TABLE_ENTRY
2828
: : "i"(&((char *)key)[branch]) : : l_yes);
@@ -35,7 +35,7 @@ static __always_inline bool arch_static_branch(struct static_key * const key, co
3535

3636
static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
3737
{
38-
asm_volatile_goto(
38+
asm goto(
3939
"1: b %l[l_yes] \n\t"
4040
JUMP_TABLE_ENTRY
4141
: : "i"(&((char *)key)[branch]) : : l_yes);

arch/mips/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern void jump_label_apply_nops(struct module *mod);
3939

4040
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
4141
{
42-
asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
42+
asm goto("1:\t" B_INSN " 2f\n\t"
4343
"2:\t.insn\n\t"
4444
".pushsection __jump_table, \"aw\"\n\t"
4545
WORD_INSN " 1b, %l[l_yes], %0\n\t"
@@ -53,7 +53,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
5353

5454
static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
5555
{
56-
asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
56+
asm goto("1:\t" J_INSN " %l[l_yes]\n\t"
5757
".pushsection __jump_table, \"aw\"\n\t"
5858
WORD_INSN " 1b, %l[l_yes], %0\n\t"
5959
".popsection\n\t"

arch/parisc/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1414
{
15-
asm_volatile_goto("1:\n\t"
15+
asm goto("1:\n\t"
1616
"nop\n\t"
1717
".pushsection __jump_table, \"aw\"\n\t"
1818
".align %1\n\t"
@@ -29,7 +29,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
2929

3030
static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
3131
{
32-
asm_volatile_goto("1:\n\t"
32+
asm goto("1:\n\t"
3333
"b,n %l[l_yes]\n\t"
3434
".pushsection __jump_table, \"aw\"\n\t"
3535
".align %1\n\t"

arch/powerpc/include/asm/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
1919
{
20-
asm_volatile_goto("1:\n\t"
20+
asm goto("1:\n\t"
2121
"nop # arch_static_branch\n\t"
2222
".pushsection __jump_table, \"aw\"\n\t"
2323
".long 1b - ., %l[l_yes] - .\n\t"
@@ -32,7 +32,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
3232

3333
static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
3434
{
35-
asm_volatile_goto("1:\n\t"
35+
asm goto("1:\n\t"
3636
"b %l[l_yes] # arch_static_branch_jump\n\t"
3737
".pushsection __jump_table, \"aw\"\n\t"
3838
".long 1b - ., %l[l_yes] - .\n\t"

arch/powerpc/include/asm/uaccess.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ __pu_failed: \
7474
/* -mprefixed can generate offsets beyond range, fall back hack */
7575
#ifdef CONFIG_PPC_KERNEL_PREFIXED
7676
#define __put_user_asm_goto(x, addr, label, op) \
77-
asm_volatile_goto( \
77+
asm goto( \
7878
"1: " op " %0,0(%1) # put_user\n" \
7979
EX_TABLE(1b, %l2) \
8080
: \
@@ -83,7 +83,7 @@ __pu_failed: \
8383
: label)
8484
#else
8585
#define __put_user_asm_goto(x, addr, label, op) \
86-
asm_volatile_goto( \
86+
asm goto( \
8787
"1: " op "%U1%X1 %0,%1 # put_user\n" \
8888
EX_TABLE(1b, %l2) \
8989
: \
@@ -97,7 +97,7 @@ __pu_failed: \
9797
__put_user_asm_goto(x, ptr, label, "std")
9898
#else /* __powerpc64__ */
9999
#define __put_user_asm2_goto(x, addr, label) \
100-
asm_volatile_goto( \
100+
asm goto( \
101101
"1: stw%X1 %0, %1\n" \
102102
"2: stw%X1 %L0, %L1\n" \
103103
EX_TABLE(1b, %l2) \
@@ -146,7 +146,7 @@ do { \
146146
/* -mprefixed can generate offsets beyond range, fall back hack */
147147
#ifdef CONFIG_PPC_KERNEL_PREFIXED
148148
#define __get_user_asm_goto(x, addr, label, op) \
149-
asm_volatile_goto( \
149+
asm_goto_output( \
150150
"1: "op" %0,0(%1) # get_user\n" \
151151
EX_TABLE(1b, %l2) \
152152
: "=r" (x) \
@@ -155,7 +155,7 @@ do { \
155155
: label)
156156
#else
157157
#define __get_user_asm_goto(x, addr, label, op) \
158-
asm_volatile_goto( \
158+
asm_goto_output( \
159159
"1: "op"%U1%X1 %0, %1 # get_user\n" \
160160
EX_TABLE(1b, %l2) \
161161
: "=r" (x) \
@@ -169,7 +169,7 @@ do { \
169169
__get_user_asm_goto(x, addr, label, "ld")
170170
#else /* __powerpc64__ */
171171
#define __get_user_asm2_goto(x, addr, label) \
172-
asm_volatile_goto( \
172+
asm_goto_output( \
173173
"1: lwz%X1 %0, %1\n" \
174174
"2: lwz%X1 %L0, %L1\n" \
175175
EX_TABLE(1b, %l2) \

0 commit comments

Comments
 (0)