xref: /openbmc/linux/arch/s390/include/asm/jump_label.h (revision 03638e62)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_JUMP_LABEL_H
3 #define _ASM_S390_JUMP_LABEL_H
4 
5 #ifndef __ASSEMBLY__
6 
7 #include <linux/types.h>
8 #include <linux/stringify.h>
9 
10 #define JUMP_LABEL_NOP_SIZE 6
11 #define JUMP_LABEL_NOP_OFFSET 2
12 
13 #if __GNUC__ < 9
14 #define JUMP_LABEL_STATIC_KEY_CONSTRAINT "X"
15 #else
16 #define JUMP_LABEL_STATIC_KEY_CONSTRAINT "jdd"
17 #endif
18 
19 /*
20  * We use a brcl 0,2 instruction for jump labels at compile time so it
21  * can be easily distinguished from a hotpatch generated instruction.
22  */
23 static inline bool arch_static_branch(struct static_key *key, bool branch)
24 {
25 	asm_volatile_goto("0:	brcl	0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
26 			  ".pushsection __jump_table,\"aw\"\n"
27 			  ".balign	8\n"
28 			  ".long	0b-.,%l[label]-.\n"
29 			  ".quad	%0+%1-.\n"
30 			  ".popsection\n"
31 			  : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
32 	return false;
33 label:
34 	return true;
35 }
36 
37 static inline bool arch_static_branch_jump(struct static_key *key, bool branch)
38 {
39 	asm_volatile_goto("0:	brcl 15,%l[label]\n"
40 			  ".pushsection __jump_table,\"aw\"\n"
41 			  ".balign	8\n"
42 			  ".long	0b-.,%l[label]-.\n"
43 			  ".quad	%0+%1-.\n"
44 			  ".popsection\n"
45 			  : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
46 	return false;
47 label:
48 	return true;
49 }
50 
51 #endif  /* __ASSEMBLY__ */
52 #endif
53