xref: /openbmc/linux/arch/x86/include/asm/jump_label.h (revision 2209fda3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_JUMP_LABEL_H
3 #define _ASM_X86_JUMP_LABEL_H
4 
5 #define JUMP_LABEL_NOP_SIZE 5
6 
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
12 
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 
21 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
22 {
23 	asm_volatile_goto("STATIC_BRANCH_NOP l_yes=\"%l[l_yes]\" key=\"%c0\" "
24 			  "branch=\"%c1\""
25 			: :  "i" (key), "i" (branch) : : l_yes);
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 {
33 	asm_volatile_goto("STATIC_BRANCH_JMP l_yes=\"%l[l_yes]\" key=\"%c0\" "
34 			  "branch=\"%c1\""
35 		: :  "i" (key), "i" (branch) : : l_yes);
36 
37 	return false;
38 l_yes:
39 	return true;
40 }
41 
42 #else	/* __ASSEMBLY__ */
43 
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_\@:
48 	.pushsection __jump_table, "aw"
49 	_ASM_ALIGN
50 	.long		.Lstatic_branch_nop_\@ - ., \l_yes - .
51 	_ASM_PTR        \key + \branch - .
52 	.popsection
53 .endm
54 
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_\@:
60 	.pushsection __jump_table, "aw"
61 	_ASM_ALIGN
62 	.long		.Lstatic_branch_jmp_\@ - ., \l_yes - .
63 	_ASM_PTR	\key + \branch - .
64 	.popsection
65 .endm
66 
67 #endif	/* __ASSEMBLY__ */
68 
69 #endif
70