Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_JUMP_LABEL_H |
| 2 | #define _LINUX_JUMP_LABEL_H |
| 3 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 4 | #include <linux/types.h> |
| 5 | #include <linux/compiler.h> |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 6 | #include <linux/workqueue.h> |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 7 | |
Steven Rostedt | 45f81b1 | 2010-10-29 12:33:43 -0400 | [diff] [blame] | 8 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 9 | |
| 10 | struct jump_label_key { |
| 11 | atomic_t enabled; |
| 12 | struct jump_entry *entries; |
| 13 | #ifdef CONFIG_MODULES |
| 14 | struct jump_label_mod *next; |
| 15 | #endif |
| 16 | }; |
| 17 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 18 | struct jump_label_key_deferred { |
| 19 | struct jump_label_key key; |
| 20 | unsigned long timeout; |
| 21 | struct delayed_work work; |
| 22 | }; |
| 23 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 24 | # include <asm/jump_label.h> |
| 25 | # define HAVE_JUMP_LABEL |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 26 | #endif /* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 27 | |
| 28 | enum jump_label_type { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 29 | JUMP_LABEL_DISABLE = 0, |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 30 | JUMP_LABEL_ENABLE, |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct module; |
| 34 | |
| 35 | #ifdef HAVE_JUMP_LABEL |
| 36 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 37 | #ifdef CONFIG_MODULES |
Jeremy Fitzhardinge | d5d9a3b | 2011-09-28 17:45:15 -0700 | [diff] [blame] | 38 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL} |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 39 | #else |
Jeremy Fitzhardinge | d5d9a3b | 2011-09-28 17:45:15 -0700 | [diff] [blame] | 40 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL} |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | static __always_inline bool static_branch(struct jump_label_key *key) |
| 44 | { |
| 45 | return arch_static_branch(key); |
| 46 | } |
| 47 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 48 | extern struct jump_entry __start___jump_table[]; |
| 49 | extern struct jump_entry __stop___jump_table[]; |
| 50 | |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 51 | extern void jump_label_init(void); |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 52 | extern void jump_label_lock(void); |
| 53 | extern void jump_label_unlock(void); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 54 | extern void arch_jump_label_transform(struct jump_entry *entry, |
Jeremy Fitzhardinge | 3734880 | 2011-09-29 11:10:05 -0700 | [diff] [blame] | 55 | enum jump_label_type type); |
Jeremy Fitzhardinge | 20284aa | 2011-10-03 11:01:46 -0700 | [diff] [blame] | 56 | extern void arch_jump_label_transform_static(struct jump_entry *entry, |
| 57 | enum jump_label_type type); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 58 | extern int jump_label_text_reserved(void *start, void *end); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 59 | extern void jump_label_inc(struct jump_label_key *key); |
| 60 | extern void jump_label_dec(struct jump_label_key *key); |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 61 | extern void jump_label_dec_deferred(struct jump_label_key_deferred *key); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 62 | extern bool jump_label_enabled(struct jump_label_key *key); |
| 63 | extern void jump_label_apply_nops(struct module *mod); |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 64 | extern void jump_label_rate_limit(struct jump_label_key_deferred *key, |
| 65 | unsigned long rl); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 66 | |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 67 | #else /* !HAVE_JUMP_LABEL */ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 68 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 69 | #include <linux/atomic.h> |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 70 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 71 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0)} |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 72 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 73 | struct jump_label_key { |
| 74 | atomic_t enabled; |
| 75 | }; |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 76 | |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 77 | static __always_inline void jump_label_init(void) |
| 78 | { |
| 79 | } |
| 80 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 81 | struct jump_label_key_deferred { |
| 82 | struct jump_label_key key; |
| 83 | }; |
| 84 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 85 | static __always_inline bool static_branch(struct jump_label_key *key) |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 86 | { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 87 | if (unlikely(atomic_read(&key->enabled))) |
| 88 | return true; |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | static inline void jump_label_inc(struct jump_label_key *key) |
| 93 | { |
| 94 | atomic_inc(&key->enabled); |
| 95 | } |
| 96 | |
| 97 | static inline void jump_label_dec(struct jump_label_key *key) |
| 98 | { |
| 99 | atomic_dec(&key->enabled); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 102 | static inline void jump_label_dec_deferred(struct jump_label_key_deferred *key) |
| 103 | { |
| 104 | jump_label_dec(&key->key); |
| 105 | } |
| 106 | |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 107 | static inline int jump_label_text_reserved(void *start, void *end) |
| 108 | { |
| 109 | return 0; |
| 110 | } |
| 111 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 112 | static inline void jump_label_lock(void) {} |
| 113 | static inline void jump_label_unlock(void) {} |
| 114 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 115 | static inline bool jump_label_enabled(struct jump_label_key *key) |
| 116 | { |
| 117 | return !!atomic_read(&key->enabled); |
| 118 | } |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 119 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 120 | static inline int jump_label_apply_nops(struct module *mod) |
| 121 | { |
| 122 | return 0; |
| 123 | } |
Gleb Natapov | b202952 | 2011-11-27 17:59:09 +0200 | [diff] [blame] | 124 | |
| 125 | static inline void jump_label_rate_limit(struct jump_label_key_deferred *key, |
| 126 | unsigned long rl) |
| 127 | { |
| 128 | } |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 129 | #endif /* HAVE_JUMP_LABEL */ |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 130 | |
Peter Zijlstra | ac99b86 | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 131 | #define jump_label_key_enabled ((struct jump_label_key){ .enabled = ATOMIC_INIT(1), }) |
| 132 | #define jump_label_key_disabled ((struct jump_label_key){ .enabled = ATOMIC_INIT(0), }) |
| 133 | |
Jeremy Fitzhardinge | 97ce2c8 | 2011-10-12 16:17:54 -0700 | [diff] [blame] | 134 | #endif /* _LINUX_JUMP_LABEL_H */ |