blob: 916cfcb36d8ac91278a3f11b6de0624f0ce911ed [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
Heiko Carstens4e0502b2021-10-04 12:02:35 +02005#define HAVE_JUMP_LABEL_BATCH
6
Anton Blanchard55dd0df2015-04-09 13:51:30 +10007#ifndef __ASSEMBLY__
8
Jan Glauber5373db82011-03-16 15:58:30 -04009#include <linux/types.h>
Jason Baronac314182016-05-20 17:16:35 -040010#include <linux/stringify.h>
Jan Glauber5373db82011-03-16 15:58:30 -040011
12#define JUMP_LABEL_NOP_SIZE 6
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010013#define JUMP_LABEL_NOP_OFFSET 2
Jan Glauber5373db82011-03-16 15:58:30 -040014
Vasily Gorbikc4e5c222019-12-25 14:13:32 +010015#ifdef CONFIG_CC_IS_CLANG
16#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "i"
17#elif __GNUC__ < 9
Ilya Leoshkevich14644852019-02-06 12:35:58 +010018#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "X"
19#else
20#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "jdd"
21#endif
22
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010023/*
24 * We use a brcl 0,2 instruction for jump labels at compile time so it
25 * can be easily distinguished from a hotpatch generated instruction.
26 */
Heiko Carstens7f032fe2019-10-04 12:29:18 +020027static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
Jan Glauber5373db82011-03-16 15:58:30 -040028{
Heiko Carstens13ddb522018-09-18 23:51:44 -070029 asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
30 ".pushsection __jump_table,\"aw\"\n"
31 ".balign 8\n"
32 ".long 0b-.,%l[label]-.\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010033 ".quad %0+%1-.\n"
Heiko Carstens13ddb522018-09-18 23:51:44 -070034 ".popsection\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010035 : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
Peter Zijlstra11276d52015-07-24 15:09:55 +020036 return false;
37label:
38 return true;
39}
40
Heiko Carstens7f032fe2019-10-04 12:29:18 +020041static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
Peter Zijlstra11276d52015-07-24 15:09:55 +020042{
Heiko Carstens13ddb522018-09-18 23:51:44 -070043 asm_volatile_goto("0: brcl 15,%l[label]\n"
44 ".pushsection __jump_table,\"aw\"\n"
45 ".balign 8\n"
46 ".long 0b-.,%l[label]-.\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010047 ".quad %0+%1-.\n"
Heiko Carstens13ddb522018-09-18 23:51:44 -070048 ".popsection\n"
Ilya Leoshkevich14644852019-02-06 12:35:58 +010049 : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);
Jan Glauber5373db82011-03-16 15:58:30 -040050 return false;
51label:
52 return true;
53}
54
Anton Blanchard55dd0df2015-04-09 13:51:30 +100055#endif /* __ASSEMBLY__ */
Jan Glauber5373db82011-03-16 15:58:30 -040056#endif