blob: 39f747d63758e5333ef9d8d4885b5b84eaaa1510 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jan Glauber5373db82011-03-16 15:58:30 -04002#ifndef _ASM_S390_JUMP_LABEL_H
3#define _ASM_S390_JUMP_LABEL_H
4
Anton Blanchard55dd0df2015-04-09 13:51:30 +10005#ifndef __ASSEMBLY__
6
Jan Glauber5373db82011-03-16 15:58:30 -04007#include <linux/types.h>
Jason Baronac314182016-05-20 17:16:35 -04008#include <linux/stringify.h>
Jan Glauber5373db82011-03-16 15:58:30 -04009
10#define JUMP_LABEL_NOP_SIZE 6
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010011#define JUMP_LABEL_NOP_OFFSET 2
Jan Glauber5373db82011-03-16 15:58:30 -040012
Ilya Leoshkevich14644852019-02-06 12:35:58 +010013#if __GNUC__ < 9
14#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "X"
15#else
16#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "jdd"
17#endif
18
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010019/*
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 */
Heiko Carstens7f032fe2019-10-04 12:29:18 +020023static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
Jan Glauber5373db82011-03-16 15:58:30 -040024{
Heiko Carstens13ddb522018-09-18 23:51:44 -070025 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"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010029 ".quad %0+%1-.\n"
Heiko Carstens13ddb522018-09-18 23:51:44 -070030 ".popsection\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010031 : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
Peter Zijlstra11276d52015-07-24 15:09:55 +020032 return false;
33label:
34 return true;
35}
36
Heiko Carstens7f032fe2019-10-04 12:29:18 +020037static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
Peter Zijlstra11276d52015-07-24 15:09:55 +020038{
Heiko Carstens13ddb522018-09-18 23:51:44 -070039 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"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010043 ".quad %0+%1-.\n"
Heiko Carstens13ddb522018-09-18 23:51:44 -070044 ".popsection\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010045 : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
Jan Glauber5373db82011-03-16 15:58:30 -040046 return false;
47label:
48 return true;
49}
50
Anton Blanchard55dd0df2015-04-09 13:51:30 +100051#endif /* __ASSEMBLY__ */
Jan Glauber5373db82011-03-16 15:58:30 -040052#endif