Skip to content

Commit

Permalink
jump_label: move 'asm goto' support test to Kconfig
Browse files Browse the repository at this point in the history
Currently, CONFIG_JUMP_LABEL just means "I _want_ to use jump label".

The jump label is controlled by HAVE_JUMP_LABEL, which is defined
like this:

  #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
  # define HAVE_JUMP_LABEL
  #endif

We can improve this by testing 'asm goto' support in Kconfig, then
make JUMP_LABEL depend on CC_HAS_ASM_GOTO.

Ugly #ifdef HAVE_JUMP_LABEL will go away, and CONFIG_JUMP_LABEL will
match to the real kernel capability.

Signed-off-by: Masahiro Yamada <[email protected]>
Acked-by: Michael Ellerman <[email protected]> (powerpc)
Tested-by: Sedat Dilek <[email protected]>
  • Loading branch information
masahir0y committed Jan 6, 2019
1 parent 72d3ebb commit e9666d1
Show file tree
Hide file tree
Showing 42 changed files with 65 additions and 119 deletions.
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,6 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc
export RETPOLINE_CFLAGS
export RETPOLINE_VDSO_CFLAGS

# check for 'asm goto'
ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
CC_HAVE_ASM_GOTO := 1
KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
endif

# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
Expand Down
1 change: 1 addition & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ config KPROBES
config JUMP_LABEL
bool "Optimize very unlikely/likely branches"
depends on HAVE_ARCH_JUMP_LABEL
depends on CC_HAS_ASM_GOTO
help
This option enables a transparent branch optimization that
makes certain almost-always-true or almost-always-false branch
Expand Down
4 changes: 0 additions & 4 deletions arch/arm/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <asm/patch.h>
#include <asm/insn.h>

#ifdef HAVE_JUMP_LABEL

static void __arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type,
bool is_static)
Expand Down Expand Up @@ -35,5 +33,3 @@ void arch_jump_label_transform_static(struct jump_entry *entry,
{
__arch_jump_label_transform(entry, type, true);
}

#endif
4 changes: 0 additions & 4 deletions arch/arm64/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <linux/jump_label.h>
#include <asm/insn.h>

#ifdef HAVE_JUMP_LABEL

void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
Expand Down Expand Up @@ -49,5 +47,3 @@ void arch_jump_label_transform_static(struct jump_entry *entry,
* NOP needs to be replaced by a branch.
*/
}

#endif /* HAVE_JUMP_LABEL */
4 changes: 0 additions & 4 deletions arch/mips/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <asm/cacheflush.h>
#include <asm/inst.h>

#ifdef HAVE_JUMP_LABEL

/*
* Define parameters for the standard MIPS and the microMIPS jump
* instruction encoding respectively:
Expand Down Expand Up @@ -70,5 +68,3 @@ void arch_jump_label_transform(struct jump_entry *e,

mutex_unlock(&text_mutex);
}

#endif /* HAVE_JUMP_LABEL */
2 changes: 1 addition & 1 deletion arch/powerpc/include/asm/asm-prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern struct static_key hcall_tracepoint_key;
void __trace_hcall_entry(unsigned long opcode, unsigned long *args);
void __trace_hcall_exit(long opcode, long retval, unsigned long *retbuf);
/* OPAL tracing */
#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
extern struct static_key opal_tracepoint_key;
#endif

Expand Down
2 changes: 0 additions & 2 deletions arch/powerpc/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <linux/jump_label.h>
#include <asm/code-patching.h>

#ifdef HAVE_JUMP_LABEL
void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
Expand All @@ -22,4 +21,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
else
patch_instruction(addr, PPC_INST_NOP);
}
#endif
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/powernv/opal-tracepoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <asm/trace.h>
#include <asm/asm-prototypes.h>

#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
struct static_key opal_tracepoint_key = STATIC_KEY_INIT;

int opal_tracepoint_regfunc(void)
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/powernv/opal-wrappers.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
.section ".text"

#ifdef CONFIG_TRACEPOINTS
#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
#define OPAL_BRANCH(LABEL) \
ARCH_STATIC_BRANCH(LABEL, opal_tracepoint_key)
#else
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/platforms/pseries/hvCall.S
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifdef CONFIG_TRACEPOINTS

#ifndef HAVE_JUMP_LABEL
#ifndef CONFIG_JUMP_LABEL
.section ".toc","aw"

.globl hcall_tracepoint_refcount
Expand Down Expand Up @@ -79,7 +79,7 @@ hcall_tracepoint_refcount:
mr r5,BUFREG; \
__HCALL_INST_POSTCALL

#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
#define HCALL_BRANCH(LABEL) \
ARCH_STATIC_BRANCH(LABEL, hcall_tracepoint_key)
#else
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/pseries/lpar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ EXPORT_SYMBOL(arch_free_page);
#endif /* CONFIG_PPC_BOOK3S_64 */

#ifdef CONFIG_TRACEPOINTS
#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
struct static_key hcall_tracepoint_key = STATIC_KEY_INIT;

int hcall_tracepoint_regfunc(void)
Expand Down
3 changes: 2 additions & 1 deletion arch/s390/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
obj-y := traps.o time.o process.o base.o early.o setup.o idle.o vtime.o
obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o early_nobss.o
obj-y += sysinfo.o jump_label.o lgr.o os_info.o machine_kexec.o pgm_check.o
obj-y += sysinfo.o lgr.o os_info.o machine_kexec.o pgm_check.o
obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o
obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
obj-y += nospec-branch.o ipl_vmparm.o
Expand All @@ -72,6 +72,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o
obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
obj-$(CONFIG_UPROBES) += uprobes.o
obj-$(CONFIG_JUMP_LABEL) += jump_label.o

obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o
obj-$(CONFIG_KEXEC_FILE) += kexec_elf.o
Expand Down
4 changes: 0 additions & 4 deletions arch/s390/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <linux/jump_label.h>
#include <asm/ipl.h>

#ifdef HAVE_JUMP_LABEL

struct insn {
u16 opcode;
s32 offset;
Expand Down Expand Up @@ -103,5 +101,3 @@ void arch_jump_label_transform_static(struct jump_entry *entry,
{
__jump_label_transform(entry, type, 1);
}

#endif
2 changes: 1 addition & 1 deletion arch/sparc/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ pc--$(CONFIG_PERF_EVENTS) := perf_event.o
obj-$(CONFIG_SPARC64) += $(pc--y)

obj-$(CONFIG_UPROBES) += uprobes.o
obj-$(CONFIG_SPARC64) += jump_label.o
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
4 changes: 0 additions & 4 deletions arch/sparc/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include <asm/cacheflush.h>

#ifdef HAVE_JUMP_LABEL

void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
Expand Down Expand Up @@ -47,5 +45,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
flushi(insn);
mutex_unlock(&text_mutex);
}

#endif
2 changes: 1 addition & 1 deletion arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ vdso_install:

archprepare: checkbin
checkbin:
ifndef CC_HAVE_ASM_GOTO
ifndef CONFIG_CC_HAS_ASM_GOTO
@echo Compiler lacks asm-goto support.
@exit 1
endif
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/entry/calling.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ For 32-bit we have the following conventions - kernel is built with
*/
.macro CALL_enter_from_user_mode
#ifdef CONFIG_CONTEXT_TRACKING
#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
STATIC_JUMP_IF_FALSE .Lafter_call_\@, context_tracking_enabled, def=0
#endif
call enter_from_user_mode
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/cpufeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ 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(CC_HAVE_ASM_GOTO)
#if defined(__clang__) && !defined(CONFIG_CC_HAS_ASM_GOTO)

/*
* Workaround for the sake of BPF compilation which utilizes kernel
Expand Down
13 changes: 0 additions & 13 deletions arch/x86/include/asm/jump_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
#ifndef _ASM_X86_JUMP_LABEL_H
#define _ASM_X86_JUMP_LABEL_H

#ifndef HAVE_JUMP_LABEL
/*
* For better or for worse, if jump labels (the gcc extension) are missing,
* then the entire static branch patching infrastructure is compiled out.
* If that happens, the code in here will malfunction. Raise a compiler
* error instead.
*
* In theory, jump labels and the static branch patching infrastructure
* could be decoupled to fix this.
*/
#error asm/jump_label.h included on a non-jump-label kernel
#endif

#define JUMP_LABEL_NOP_SIZE 5

#ifdef CONFIG_X86_64
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(CC_HAVE_ASM_GOTO)
#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CONFIG_CC_HAS_ASM_GOTO)

/* Use asm goto */

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

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

/* 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(CC_HAVE_ASM_GOTO) */
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CONFIG_CC_HAS_ASM_GOTO) */

#define GEN_UNARY_RMWcc_4(op, var, cc, arg0) \
__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM())
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ obj-$(CONFIG_COMPAT) += signal_compat.o
obj-y += traps.o idt.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
obj-y += time.o ioport.o dumpstack.o nmi.o
obj-$(CONFIG_MODIFY_LDT_SYSCALL) += ldt.o
obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
obj-y += setup.o x86_init.o i8259.o irqinit.o
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_IRQ_WORK) += irq_work.o
obj-y += probe_roms.o
obj-$(CONFIG_X86_64) += sys_x86_64.o
Expand Down
4 changes: 0 additions & 4 deletions arch/x86/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <asm/alternative.h>
#include <asm/text-patching.h>

#ifdef HAVE_JUMP_LABEL

union jump_code_union {
char code[JUMP_LABEL_NOP_SIZE];
struct {
Expand Down Expand Up @@ -130,5 +128,3 @@ __init_or_module void arch_jump_label_transform_static(struct jump_entry *entry,
if (jlstate == JL_STATE_UPDATE)
__jump_label_transform(entry, type, text_poke_early, 1);
}

#endif
2 changes: 1 addition & 1 deletion arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ FOP_END;

/*
* XXX: inoutclob user must know where the argument is being expanded.
* Relying on CC_HAVE_ASM_GOTO would allow us to remove _fault.
* Relying on CONFIG_CC_HAS_ASM_GOTO would allow us to remove _fault.
*/
#define asm_safe(insn, inoutclob...) \
({ \
Expand Down
4 changes: 0 additions & 4 deletions arch/xtensa/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#include <asm/cacheflush.h>

#ifdef HAVE_JUMP_LABEL

#define J_OFFSET_MASK 0x0003ffff
#define J_SIGN_MASK (~(J_OFFSET_MASK >> 1))

Expand Down Expand Up @@ -95,5 +93,3 @@ void arch_jump_label_transform(struct jump_entry *e,

patch_text(jump_entry_code(e), &insn, JUMP_LABEL_NOP_SIZE);
}

#endif /* HAVE_JUMP_LABEL */
6 changes: 3 additions & 3 deletions include/linux/dynamic_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef _DYNAMIC_DEBUG_H
#define _DYNAMIC_DEBUG_H

#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
#if defined(CONFIG_JUMP_LABEL)
#include <linux/jump_label.h>
#endif

Expand Down Expand Up @@ -38,7 +38,7 @@ struct _ddebug {
#define _DPRINTK_FLAGS_DEFAULT 0
#endif
unsigned int flags:8;
#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL
union {
struct static_key_true dd_key_true;
struct static_key_false dd_key_false;
Expand Down Expand Up @@ -83,7 +83,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
dd_key_init(key, init) \
}

#ifdef HAVE_JUMP_LABEL
#ifdef CONFIG_JUMP_LABEL

#define dd_key_init(key, init) key = (init)

Expand Down
Loading

0 comments on commit e9666d1

Please sign in to comment.