Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 1 | #ifndef _ASM_X86_JUMP_LABEL_H |
| 2 | #define _ASM_X86_JUMP_LABEL_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | |
Steven Rostedt | c3c7f14 | 2012-01-26 18:06:45 -0500 | [diff] [blame] | 6 | #include <linux/stringify.h> |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 7 | #include <linux/types.h> |
| 8 | #include <asm/nops.h> |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 9 | #include <asm/asm.h> |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 10 | |
| 11 | #define JUMP_LABEL_NOP_SIZE 5 |
| 12 | |
Steven Rostedt | c3c7f14 | 2012-01-26 18:06:45 -0500 | [diff] [blame] | 13 | #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 Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 18 | |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 19 | static __always_inline bool arch_static_branch(struct static_key *key) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 20 | { |
Ingo Molnar | 3f0116c | 2013-10-10 10:16:30 +0200 | [diff] [blame] | 21 | asm_volatile_goto("1:" |
Steven Rostedt | c3c7f14 | 2012-01-26 18:06:45 -0500 | [diff] [blame] | 22 | ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 23 | ".pushsection __jump_table, \"aw\" \n\t" |
Jason Baron | ef64789 | 2011-03-16 15:58:27 -0400 | [diff] [blame] | 24 | _ASM_ALIGN "\n\t" |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 25 | _ASM_PTR "1b, %l[l_yes], %c0 \n\t" |
| 26 | ".popsection \n\t" |
| 27 | : : "i" (key) : : l_yes); |
| 28 | return false; |
| 29 | l_yes: |
| 30 | return true; |
| 31 | } |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 32 | |
| 33 | #endif /* __KERNEL__ */ |
| 34 | |
| 35 | #ifdef CONFIG_X86_64 |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 36 | typedef u64 jump_label_t; |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 37 | #else |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 38 | typedef u32 jump_label_t; |
Steven Rostedt | 95fccd4 | 2010-09-22 17:37:43 -0400 | [diff] [blame] | 39 | #endif |
Jason Baron | d9f5ab7 | 2010-09-17 11:09:22 -0400 | [diff] [blame] | 40 | |
| 41 | struct jump_entry { |
| 42 | jump_label_t code; |
| 43 | jump_label_t target; |
| 44 | jump_label_t key; |
| 45 | }; |
| 46 | |
| 47 | #endif |