1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_JUMP_LABEL_H
3 #define _ASM_X86_JUMP_LABEL_H
5 #ifndef HAVE_JUMP_LABEL
7 * For better or for worse, if jump labels (the gcc extension) are missing,
8 * then the entire static branch patching infrastructure is compiled out.
9 * If that happens, the code in here will malfunction. Raise a compiler
12 * In theory, jump labels and the static branch patching infrastructure
13 * could be decoupled to fix this.
15 #error asm/jump_label.h included on a non-jump-label kernel
18 #define JUMP_LABEL_NOP_SIZE 5
21 # define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
23 # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
31 #include <linux/stringify.h>
32 #include <linux/types.h>
34 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
36 asm_volatile_goto("1:"
37 ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
38 ".pushsection __jump_table, \"aw\" \n\t"
40 ".long 1b - ., %l[l_yes] - . \n\t"
41 _ASM_PTR "%c0 + %c1 - .\n\t"
43 : : "i" (key), "i" (branch) : : l_yes);
50 static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
52 asm_volatile_goto("1:"
53 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
55 ".pushsection __jump_table, \"aw\" \n\t"
57 ".long 1b - ., %l[l_yes] - . \n\t"
58 _ASM_PTR "%c0 + %c1 - .\n\t"
60 : : "i" (key), "i" (branch) : : l_yes);
67 #else /* __ASSEMBLY__ */
69 .macro STATIC_JUMP_IF_TRUE target, key, def
72 /* Equivalent to "jmp.d32 \target" */
74 .long \target - .Lstatic_jump_after_\@
75 .Lstatic_jump_after_\@:
77 .byte STATIC_KEY_INIT_NOP
79 .pushsection __jump_table, "aw"
81 .long .Lstatic_jump_\@ - ., \target - .
86 .macro STATIC_JUMP_IF_FALSE target, key, def
89 .byte STATIC_KEY_INIT_NOP
91 /* Equivalent to "jmp.d32 \target" */
93 .long \target - .Lstatic_jump_after_\@
94 .Lstatic_jump_after_\@:
96 .pushsection __jump_table, "aw"
98 .long .Lstatic_jump_\@ - ., \target - .
103 #endif /* __ASSEMBLY__ */