blob: 28d7a857f9d125b292b3ac0b56ce76e0a6a39930 [file] [log] [blame]
Jason Barond9f5ab72010-09-17 11:09:22 -04001#ifndef _ASM_X86_JUMP_LABEL_H
2#define _ASM_X86_JUMP_LABEL_H
3
Anton Blanchard55dd0df2015-04-09 13:51:30 +10004#ifndef __ASSEMBLY__
Jason Barond9f5ab72010-09-17 11:09:22 -04005
Steven Rostedtc3c7f142012-01-26 18:06:45 -05006#include <linux/stringify.h>
Jason Barond9f5ab72010-09-17 11:09:22 -04007#include <linux/types.h>
8#include <asm/nops.h>
Jason Barond430d3d2011-03-16 17:29:47 -04009#include <asm/asm.h>
Jason Barond9f5ab72010-09-17 11:09:22 -040010
11#define JUMP_LABEL_NOP_SIZE 5
12
Steven Rostedtc3c7f142012-01-26 18:06:45 -050013#ifdef CONFIG_X86_64
14# define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
15#else
16# define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
17#endif
Jason Barond9f5ab72010-09-17 11:09:22 -040018
Peter Zijlstra11276d52015-07-24 15:09:55 +020019static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
Jason Barond430d3d2011-03-16 17:29:47 -040020{
Ingo Molnar3f0116c2013-10-10 10:16:30 +020021 asm_volatile_goto("1:"
Steven Rostedtc3c7f142012-01-26 18:06:45 -050022 ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
Jason Barond430d3d2011-03-16 17:29:47 -040023 ".pushsection __jump_table, \"aw\" \n\t"
Jason Baronef647892011-03-16 15:58:27 -040024 _ASM_ALIGN "\n\t"
Jason Barond430d3d2011-03-16 17:29:47 -040025 _ASM_PTR "1b, %l[l_yes], %c0 \n\t"
26 ".popsection \n\t"
Peter Zijlstra11276d52015-07-24 15:09:55 +020027 : : "i" (&((char *)key)[branch]) : : l_yes);
28
29 return false;
30l_yes:
31 return true;
32}
33
34static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
35{
36 asm_volatile_goto("1:"
37 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
38 "2:\n\t"
39 ".pushsection __jump_table, \"aw\" \n\t"
40 _ASM_ALIGN "\n\t"
41 _ASM_PTR "1b, %l[l_yes], %c0 \n\t"
42 ".popsection \n\t"
43 : : "i" (&((char *)key)[branch]) : : l_yes);
44
Jason Barond430d3d2011-03-16 17:29:47 -040045 return false;
46l_yes:
47 return true;
48}
Jason Barond9f5ab72010-09-17 11:09:22 -040049
Jason Barond9f5ab72010-09-17 11:09:22 -040050#ifdef CONFIG_X86_64
Jason Barond9f5ab72010-09-17 11:09:22 -040051typedef u64 jump_label_t;
Jason Barond9f5ab72010-09-17 11:09:22 -040052#else
Jason Barond9f5ab72010-09-17 11:09:22 -040053typedef u32 jump_label_t;
Steven Rostedt95fccd42010-09-22 17:37:43 -040054#endif
Jason Barond9f5ab72010-09-17 11:09:22 -040055
56struct jump_entry {
57 jump_label_t code;
58 jump_label_t target;
59 jump_label_t key;
60};
61
Anton Blanchard55dd0df2015-04-09 13:51:30 +100062#endif /* __ASSEMBLY__ */
Jason Barond9f5ab72010-09-17 11:09:22 -040063#endif