blob: 6a2cefb4395a4228cce550ef8b231f3e7158d9d1 [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
4#ifdef __KERNEL__
5
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
Ingo Molnarc5905af2012-02-24 08:31:31 +010019static __always_inline bool arch_static_branch(struct static_key *key)
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"
27 : : "i" (key) : : l_yes);
28 return false;
29l_yes:
30 return true;
31}
Jason Barond9f5ab72010-09-17 11:09:22 -040032
33#endif /* __KERNEL__ */
34
35#ifdef CONFIG_X86_64
Jason Barond9f5ab72010-09-17 11:09:22 -040036typedef u64 jump_label_t;
Jason Barond9f5ab72010-09-17 11:09:22 -040037#else
Jason Barond9f5ab72010-09-17 11:09:22 -040038typedef u32 jump_label_t;
Steven Rostedt95fccd42010-09-22 17:37:43 -040039#endif
Jason Barond9f5ab72010-09-17 11:09:22 -040040
41struct jump_entry {
42 jump_label_t code;
43 jump_label_t target;
44 jump_label_t key;
45};
46
47#endif