blob: 9be198f5ee79213bd1cf48f53991121bdf12785a [file] [log] [blame]
Jan Glauber5373db82011-03-16 15:58:30 -04001#ifndef _ASM_S390_JUMP_LABEL_H
2#define _ASM_S390_JUMP_LABEL_H
3
Anton Blanchard55dd0df2015-04-09 13:51:30 +10004#ifndef __ASSEMBLY__
5
Jan Glauber5373db82011-03-16 15:58:30 -04006#include <linux/types.h>
Jason Baronac314182016-05-20 17:16:35 -04007#include <linux/stringify.h>
Jan Glauber5373db82011-03-16 15:58:30 -04008
9#define JUMP_LABEL_NOP_SIZE 6
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010010#define JUMP_LABEL_NOP_OFFSET 2
Jan Glauber5373db82011-03-16 15:58:30 -040011
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010012/*
13 * We use a brcl 0,2 instruction for jump labels at compile time so it
14 * can be easily distinguished from a hotpatch generated instruction.
15 */
Peter Zijlstra11276d52015-07-24 15:09:55 +020016static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
Jan Glauber5373db82011-03-16 15:58:30 -040017{
Heiko Carstensd5caa4d2015-01-29 14:10:22 +010018 asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
Jan Glauber5373db82011-03-16 15:58:30 -040019 ".pushsection __jump_table, \"aw\"\n"
Heiko Carstens5a798592015-02-12 13:08:27 +010020 ".balign 8\n"
21 ".quad 0b, %l[label], %0\n"
Jan Glauber5373db82011-03-16 15:58:30 -040022 ".popsection\n"
Peter Zijlstra11276d52015-07-24 15:09:55 +020023 : : "X" (&((char *)key)[branch]) : : label);
24
25 return false;
26label:
27 return true;
28}
29
30static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
31{
32 asm_volatile_goto("0: brcl 15, %l[label]\n"
33 ".pushsection __jump_table, \"aw\"\n"
34 ".balign 8\n"
35 ".quad 0b, %l[label], %0\n"
36 ".popsection\n"
37 : : "X" (&((char *)key)[branch]) : : label);
38
Jan Glauber5373db82011-03-16 15:58:30 -040039 return false;
40label:
41 return true;
42}
43
44typedef unsigned long jump_label_t;
45
46struct jump_entry {
47 jump_label_t code;
48 jump_label_t target;
49 jump_label_t key;
50};
51
Anton Blanchard55dd0df2015-04-09 13:51:30 +100052#endif /* __ASSEMBLY__ */
Jan Glauber5373db82011-03-16 15:58:30 -040053#endif