1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _ASM_X86_JUMP_LABEL_H |
3 | #define _ASM_X86_JUMP_LABEL_H |
4 | |
5 | #define HAVE_JUMP_LABEL_BATCH |
6 | |
7 | #include <asm/asm.h> |
8 | #include <asm/nops.h> |
9 | |
10 | #ifndef __ASSEMBLY__ |
11 | |
12 | #include <linux/stringify.h> |
13 | #include <linux/types.h> |
14 | |
15 | #define JUMP_TABLE_ENTRY \ |
16 | ".pushsection __jump_table, \"aw\" \n\t" \ |
17 | _ASM_ALIGN "\n\t" \ |
18 | ".long 1b - . \n\t" \ |
19 | ".long %l[l_yes] - . \n\t" \ |
20 | _ASM_PTR "%c0 + %c1 - .\n\t" \ |
21 | ".popsection \n\t" |
22 | |
23 | #ifdef CONFIG_HAVE_JUMP_LABEL_HACK |
24 | |
25 | static __always_inline bool arch_static_branch(struct static_key *key, bool branch) |
26 | { |
27 | asm goto("1:" |
28 | "jmp %l[l_yes] # objtool NOPs this \n\t" |
29 | JUMP_TABLE_ENTRY |
30 | : : "i" (key), "i" (2 | branch) : : l_yes); |
31 | |
32 | return false; |
33 | l_yes: |
34 | return true; |
35 | } |
36 | |
37 | #else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ |
38 | |
39 | static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) |
40 | { |
41 | asm goto("1:" |
42 | ".byte " __stringify(BYTES_NOP5) "\n\t" |
43 | JUMP_TABLE_ENTRY |
44 | : : "i" (key), "i" (branch) : : l_yes); |
45 | |
46 | return false; |
47 | l_yes: |
48 | return true; |
49 | } |
50 | |
51 | #endif /* CONFIG_HAVE_JUMP_LABEL_HACK */ |
52 | |
53 | static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) |
54 | { |
55 | asm goto("1:" |
56 | "jmp %l[l_yes]\n\t" |
57 | JUMP_TABLE_ENTRY |
58 | : : "i" (key), "i" (branch) : : l_yes); |
59 | |
60 | return false; |
61 | l_yes: |
62 | return true; |
63 | } |
64 | |
65 | extern int arch_jump_entry_size(struct jump_entry *entry); |
66 | |
67 | #endif /* __ASSEMBLY__ */ |
68 | |
69 | #endif |
70 | |