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 _ASM_PTR
"1b, %l[l_yes], %c0 + %c1 \n\t"
42 : : "i" (key
), "i" (branch
) : : l_yes
);
49 static __always_inline
bool arch_static_branch_jump(struct static_key
*key
, bool branch
)
51 asm_volatile_goto("1:"
52 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
54 ".pushsection __jump_table, \"aw\" \n\t"
56 _ASM_PTR
"1b, %l[l_yes], %c0 + %c1 \n\t"
58 : : "i" (key
), "i" (branch
) : : l_yes
);
66 typedef u64 jump_label_t
;
68 typedef u32 jump_label_t
;
77 #else /* __ASSEMBLY__ */
79 .macro STATIC_JUMP_IF_TRUE target
, key
, def
82 /* Equivalent to "jmp.d32 \target" */
84 .long \target
- .Lstatic_jump_after_\@
85 .Lstatic_jump_after_\@
:
87 .byte STATIC_KEY_INIT_NOP
89 .pushsection __jump_table
, "aw"
91 _ASM_PTR
.Lstatic_jump_\@
, \target
, \key
95 .macro STATIC_JUMP_IF_FALSE target
, key
, def
98 .byte STATIC_KEY_INIT_NOP
100 /* Equivalent to "jmp.d32 \target" */
102 .long \target
- .Lstatic_jump_after_\@
103 .Lstatic_jump_after_\@
:
105 .pushsection __jump_table
, "aw"
107 _ASM_PTR
.Lstatic_jump_\@
, \target
, \key
+ 1
111 #endif /* __ASSEMBLY__ */