Skip to content

Commit

Permalink
asm goto: eradicate CC_HAS_ASM_GOTO
Browse files Browse the repository at this point in the history
GCC has supported asm goto since 4.5, and Clang has since version 9.0.0.
The minimum supported versions of these tools for the build according to
Documentation/process/changes.rst are 5.1 and 11.0.0 respectively.

Remove the feature detection script, Kconfig option, and clean up some
fallback code that is no longer supported.

The removed script was also testing for a GCC specific bug that was
fixed in the 4.7 release.

Also remove workarounds for bpftrace using clang older than 9.0.0, since
other BPF backend fixes are required at this point.

Link: https://lore.kernel.org/lkml/CAK7LNATSr=BXKfkdW8f-H5VT_w=xBpT2ZQcZ7rm6JfkdE+QnmA@mail.gmail.com/
Link: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48637
Acked-by: Borislav Petkov <[email protected]>
Suggested-by: Masahiro Yamada <[email protected]>
Suggested-by: Alexei Starovoitov <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
Reviewed-by: Nathan Chancellor <[email protected]>
Reviewed-by: Alexandre Belloni <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
nickdesaulniers authored and torvalds committed Aug 21, 2022
1 parent 15b3f48 commit a0a12c3
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Documentation/kbuild/kconfig-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ followed by a test macro::
If you need to expose a compiler capability to makefiles and/or C source files,
`CC_HAS_` is the recommended prefix for the config option::

config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
config CC_HAS_FOO
def_bool $(success,$(srctree)/scripts/cc-check-foo.sh $(CC))

Build as module only
~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ config KPROBES
config JUMP_LABEL
bool "Optimize very unlikely/likely branches"
depends on HAVE_ARCH_JUMP_LABEL
depends on CC_HAS_ASM_GOTO
select OBJTOOL if HAVE_JUMP_LABEL_HACK
help
This option enables a transparent branch optimization that
Expand Down Expand Up @@ -1361,7 +1360,7 @@ config HAVE_PREEMPT_DYNAMIC_CALL

config HAVE_PREEMPT_DYNAMIC_KEY
bool
depends on HAVE_ARCH_JUMP_LABEL && CC_HAS_ASM_GOTO
depends on HAVE_ARCH_JUMP_LABEL
select HAVE_PREEMPT_DYNAMIC
help
An architecture should select this if it can handle the preemption
Expand Down
15 changes: 0 additions & 15 deletions arch/um/include/asm/cpufeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ extern void setup_clear_cpu_cap(unsigned int bit);

#define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)

#if defined(__clang__) && !defined(CONFIG_CC_HAS_ASM_GOTO)

/*
* Workaround for the sake of BPF compilation which utilizes kernel
* headers, but clang does not support ASM GOTO and fails the build.
*/
#ifndef __BPF_TRACING__
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
#endif

#define static_cpu_has(bit) boot_cpu_has(bit)

#else

/*
* Static testing of CPU features. Used the same as boot_cpu_has(). It
* statically patches the target code for additional performance. Use
Expand Down Expand Up @@ -137,7 +123,6 @@ static __always_inline bool _static_cpu_has(u16 bit)
boot_cpu_has(bit) : \
_static_cpu_has(bit) \
)
#endif

#define cpu_has_bug(c, bit) cpu_has(c, (bit))
#define set_cpu_bug(c, bit) set_cpu_cap(c, (bit))
Expand Down
4 changes: 0 additions & 4 deletions arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,6 @@ vdso_install:

archprepare: checkbin
checkbin:
ifndef CONFIG_CC_HAS_ASM_GOTO
@echo Compiler lacks asm-goto support.
@exit 1
endif
ifdef CONFIG_RETPOLINE
ifeq ($(RETPOLINE_CFLAGS),)
@echo "You are building kernel with non-retpoline compiler." >&2
Expand Down
15 changes: 0 additions & 15 deletions arch/x86/include/asm/cpufeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,6 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);

#define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)

#if defined(__clang__) && !defined(CONFIG_CC_HAS_ASM_GOTO)

/*
* Workaround for the sake of BPF compilation which utilizes kernel
* headers, but clang does not support ASM GOTO and fails the build.
*/
#ifndef __BPF_TRACING__
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
#endif

#define static_cpu_has(bit) boot_cpu_has(bit)

#else

/*
* Static testing of CPU features. Used the same as boot_cpu_has(). It
* statically patches the target code for additional performance. Use
Expand Down Expand Up @@ -208,7 +194,6 @@ static __always_inline bool _static_cpu_has(u16 bit)
boot_cpu_has(bit) : \
_static_cpu_has(bit) \
)
#endif

#define cpu_has_bug(c, bit) cpu_has(c, (bit))
#define set_cpu_bug(c, bit) set_cpu_cap(c, (bit))
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/include/asm/rmwcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define __CLOBBERS_MEM(clb...) "memory", ## clb

#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CONFIG_CC_HAS_ASM_GOTO)
#ifndef __GCC_ASM_FLAG_OUTPUTS__

/* Use asm goto */

Expand All @@ -27,7 +27,7 @@ cc_label: c = true; \
c; \
})

#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CONFIG_CC_HAS_ASM_GOTO) */
#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) */

/* Use flags output or a set instruction */

Expand All @@ -40,7 +40,7 @@ cc_label: c = true; \
c; \
})

#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CONFIG_CC_HAS_ASM_GOTO) */
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) */

#define GEN_UNARY_RMWcc_4(op, var, cc, arg0) \
__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM())
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ FOP_END;

/*
* XXX: inoutclob user must know where the argument is being expanded.
* Relying on CONFIG_CC_HAS_ASM_GOTO would allow us to remove _fault.
* Using asm goto would allow us to remove _fault.
*/
#define asm_safe(insn, inoutclob...) \
({ \
Expand Down
4 changes: 0 additions & 4 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ config CC_CAN_LINK_STATIC
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag) -static) if 64BIT
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag) -static)

config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))

config CC_HAS_ASM_GOTO_OUTPUT
depends on CC_HAS_ASM_GOTO
def_bool $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null)

config CC_HAS_ASM_GOTO_TIED_OUTPUT
Expand Down
22 changes: 0 additions & 22 deletions scripts/gcc-goto.sh

This file was deleted.

21 changes: 0 additions & 21 deletions tools/arch/x86/include/asm/rmwcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#ifndef _TOOLS_LINUX_ASM_X86_RMWcc
#define _TOOLS_LINUX_ASM_X86_RMWcc

#ifdef CONFIG_CC_HAS_ASM_GOTO

#define __GEN_RMWcc(fullop, var, cc, ...) \
do { \
asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
Expand All @@ -20,23 +18,4 @@ cc_label: \
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
__GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))

#else /* !CONFIG_CC_HAS_ASM_GOTO */

#define __GEN_RMWcc(fullop, var, cc, ...) \
do { \
char c; \
asm volatile (fullop "; set" cc " %1" \
: "+m" (var), "=qm" (c) \
: __VA_ARGS__ : "memory"); \
return c != 0; \
} while (0)

#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
__GEN_RMWcc(op " " arg0, var, cc)

#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
__GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))

#endif /* CONFIG_CC_HAS_ASM_GOTO */

#endif /* _TOOLS_LINUX_ASM_X86_RMWcc */

0 comments on commit a0a12c3

Please sign in to comment.