Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
d9f5ab7b JB |
2 | #ifndef _ASM_X86_JUMP_LABEL_H |
3 | #define _ASM_X86_JUMP_LABEL_H | |
4 | ||
d9f5ab7b JB |
5 | #define JUMP_LABEL_NOP_SIZE 5 |
6 | ||
c3c7f14a SR |
7 | #ifdef CONFIG_X86_64 |
8 | # define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC | |
9 | #else | |
10 | # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC | |
11 | #endif | |
d430d3d7 | 12 | |
2671c3e4 AL |
13 | #include <asm/asm.h> |
14 | #include <asm/nops.h> | |
15 | ||
16 | #ifndef __ASSEMBLY__ | |
17 | ||
18 | #include <linux/stringify.h> | |
19 | #include <linux/types.h> | |
20 | ||
11276d53 | 21 | static __always_inline bool arch_static_branch(struct static_key *key, bool branch) |
d430d3d7 | 22 | { |
5bdcd510 NA |
23 | asm_volatile_goto("STATIC_BRANCH_NOP l_yes=\"%l[l_yes]\" key=\"%c0\" " |
24 | "branch=\"%c1\"" | |
25 | : : "i" (key), "i" (branch) : : l_yes); | |
11276d53 PZ |
26 | return false; |
27 | l_yes: | |
28 | return true; | |
29 | } | |
30 | ||
31 | static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) | |
32 | { | |
5bdcd510 NA |
33 | asm_volatile_goto("STATIC_BRANCH_JMP l_yes=\"%l[l_yes]\" key=\"%c0\" " |
34 | "branch=\"%c1\"" | |
d420acd8 | 35 | : : "i" (key), "i" (branch) : : l_yes); |
11276d53 | 36 | |
d430d3d7 JB |
37 | return false; |
38 | l_yes: | |
39 | return true; | |
40 | } | |
d9f5ab7b | 41 | |
2671c3e4 AL |
42 | #else /* __ASSEMBLY__ */ |
43 | ||
5bdcd510 NA |
44 | .macro STATIC_BRANCH_NOP l_yes:req key:req branch:req |
45 | .Lstatic_branch_nop_\@: | |
46 | .byte STATIC_KEY_INIT_NOP | |
47 | .Lstatic_branch_no_after_\@: | |
2671c3e4 AL |
48 | .pushsection __jump_table, "aw" |
49 | _ASM_ALIGN | |
5bdcd510 NA |
50 | .long .Lstatic_branch_nop_\@ - ., \l_yes - . |
51 | _ASM_PTR \key + \branch - . | |
2671c3e4 AL |
52 | .popsection |
53 | .endm | |
54 | ||
5bdcd510 NA |
55 | .macro STATIC_BRANCH_JMP l_yes:req key:req branch:req |
56 | .Lstatic_branch_jmp_\@: | |
57 | .byte 0xe9 | |
58 | .long \l_yes - .Lstatic_branch_jmp_after_\@ | |
59 | .Lstatic_branch_jmp_after_\@: | |
2671c3e4 AL |
60 | .pushsection __jump_table, "aw" |
61 | _ASM_ALIGN | |
5bdcd510 NA |
62 | .long .Lstatic_branch_jmp_\@ - ., \l_yes - . |
63 | _ASM_PTR \key + \branch - . | |
2671c3e4 AL |
64 | .popsection |
65 | .endm | |
66 | ||
67 | #endif /* __ASSEMBLY__ */ | |
68 | ||
d9f5ab7b | 69 | #endif |