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 | { |
e769742d IM |
23 | asm_volatile_goto("1:" |
24 | ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" | |
25 | ".pushsection __jump_table, \"aw\" \n\t" | |
26 | _ASM_ALIGN "\n\t" | |
27 | ".long 1b - ., %l[l_yes] - . \n\t" | |
28 | _ASM_PTR "%c0 + %c1 - .\n\t" | |
29 | ".popsection \n\t" | |
30 | : : "i" (key), "i" (branch) : : l_yes); | |
31 | ||
11276d53 PZ |
32 | return false; |
33 | l_yes: | |
34 | return true; | |
35 | } | |
36 | ||
37 | static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) | |
38 | { | |
e769742d IM |
39 | asm_volatile_goto("1:" |
40 | ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t" | |
41 | "2:\n\t" | |
42 | ".pushsection __jump_table, \"aw\" \n\t" | |
43 | _ASM_ALIGN "\n\t" | |
44 | ".long 1b - ., %l[l_yes] - . \n\t" | |
45 | _ASM_PTR "%c0 + %c1 - .\n\t" | |
46 | ".popsection \n\t" | |
d420acd8 | 47 | : : "i" (key), "i" (branch) : : l_yes); |
11276d53 | 48 | |
d430d3d7 JB |
49 | return false; |
50 | l_yes: | |
51 | return true; | |
52 | } | |
d9f5ab7b | 53 | |
2671c3e4 AL |
54 | #else /* __ASSEMBLY__ */ |
55 | ||
e769742d IM |
56 | .macro STATIC_JUMP_IF_TRUE target, key, def |
57 | .Lstatic_jump_\@: | |
58 | .if \def | |
59 | /* Equivalent to "jmp.d32 \target" */ | |
60 | .byte 0xe9 | |
61 | .long \target - .Lstatic_jump_after_\@ | |
62 | .Lstatic_jump_after_\@: | |
63 | .else | |
64 | .byte STATIC_KEY_INIT_NOP | |
65 | .endif | |
2671c3e4 AL |
66 | .pushsection __jump_table, "aw" |
67 | _ASM_ALIGN | |
e769742d IM |
68 | .long .Lstatic_jump_\@ - ., \target - . |
69 | _ASM_PTR \key - . | |
2671c3e4 AL |
70 | .popsection |
71 | .endm | |
72 | ||
e769742d IM |
73 | .macro STATIC_JUMP_IF_FALSE target, key, def |
74 | .Lstatic_jump_\@: | |
75 | .if \def | |
76 | .byte STATIC_KEY_INIT_NOP | |
77 | .else | |
78 | /* Equivalent to "jmp.d32 \target" */ | |
79 | .byte 0xe9 | |
80 | .long \target - .Lstatic_jump_after_\@ | |
81 | .Lstatic_jump_after_\@: | |
82 | .endif | |
2671c3e4 AL |
83 | .pushsection __jump_table, "aw" |
84 | _ASM_ALIGN | |
e769742d IM |
85 | .long .Lstatic_jump_\@ - ., \target - . |
86 | _ASM_PTR \key + 1 - . | |
2671c3e4 AL |
87 | .popsection |
88 | .endm | |
89 | ||
90 | #endif /* __ASSEMBLY__ */ | |
91 | ||
d9f5ab7b | 92 | #endif |