1 #ifndef _ASM_X86_JUMP_LABEL_H
2 #define _ASM_X86_JUMP_LABEL_H
4 #ifndef HAVE_JUMP_LABEL
6 * For better or for worse, if jump labels (the gcc extension) are missing,
7 * then the entire static branch patching infrastructure is compiled out.
8 * If that happens, the code in here will malfunction. Raise a compiler
11 * In theory, jump labels and the static branch patching infrastructure
12 * could be decoupled to fix this.
14 #error asm/jump_label.h included on a non-jump-label kernel
17 #define JUMP_LABEL_NOP_SIZE 5
20 # define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
22 # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
30 #include <linux/stringify.h>
31 #include <linux/types.h>
33 static __always_inline
bool arch_static_branch(struct static_key
*key
, bool branch
)
35 asm_volatile_goto("1:"
36 ".byte " __stringify(STATIC_KEY_INIT_NOP
) "\n\t"
37 ".pushsection __jump_table, \"aw\" \n\t"
39 _ASM_PTR
"1b, %l[l_yes], %c0 + %c1 \n\t"
41 : : "i" (key
), "i" (branch
) : : l_yes
);
48 static __always_inline
bool arch_static_branch_jump(struct static_key
*key
, bool branch
)
50 asm_volatile_goto("1:"
51 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
53 ".pushsection __jump_table, \"aw\" \n\t"
55 _ASM_PTR
"1b, %l[l_yes], %c0 + %c1 \n\t"
57 : : "i" (key
), "i" (branch
) : : l_yes
);
65 typedef u64 jump_label_t
;
67 typedef u32 jump_label_t
;
76 #else /* __ASSEMBLY__ */
78 .macro STATIC_JUMP_IF_TRUE target
, key
, def
81 /* Equivalent to "jmp.d32 \target" */
83 .long \target
- .Lstatic_jump_after_\@
84 .Lstatic_jump_after_\@
:
86 .byte STATIC_KEY_INIT_NOP
88 .pushsection __jump_table
, "aw"
90 _ASM_PTR
.Lstatic_jump_\@
, \target
, \key
94 .macro STATIC_JUMP_IF_FALSE target
, key
, def
97 .byte STATIC_KEY_INIT_NOP
99 /* Equivalent to "jmp.d32 \target" */
101 .long \target
- .Lstatic_jump_after_\@
102 .Lstatic_jump_after_\@
:
104 .pushsection __jump_table
, "aw"
106 _ASM_PTR
.Lstatic_jump_\@
, \target
, \key
+ 1
110 #endif /* __ASSEMBLY__ */