diff options
Diffstat (limited to 'include/linux/jump_label.h')
| -rw-r--r-- | include/linux/jump_label.h | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index 7880f18e4b86..83e745f3ead7 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h | |||
| @@ -1,20 +1,43 @@ | |||
| 1 | #ifndef _LINUX_JUMP_LABEL_H | 1 | #ifndef _LINUX_JUMP_LABEL_H |
| 2 | #define _LINUX_JUMP_LABEL_H | 2 | #define _LINUX_JUMP_LABEL_H |
| 3 | 3 | ||
| 4 | #include <linux/types.h> | ||
| 5 | #include <linux/compiler.h> | ||
| 6 | |||
| 4 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) | 7 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) |
| 8 | |||
| 9 | struct jump_label_key { | ||
| 10 | atomic_t enabled; | ||
| 11 | struct jump_entry *entries; | ||
| 12 | #ifdef CONFIG_MODULES | ||
| 13 | struct jump_label_mod *next; | ||
| 14 | #endif | ||
| 15 | }; | ||
| 16 | |||
| 5 | # include <asm/jump_label.h> | 17 | # include <asm/jump_label.h> |
| 6 | # define HAVE_JUMP_LABEL | 18 | # define HAVE_JUMP_LABEL |
| 7 | #endif | 19 | #endif |
| 8 | 20 | ||
| 9 | enum jump_label_type { | 21 | enum jump_label_type { |
| 22 | JUMP_LABEL_DISABLE = 0, | ||
| 10 | JUMP_LABEL_ENABLE, | 23 | JUMP_LABEL_ENABLE, |
| 11 | JUMP_LABEL_DISABLE | ||
| 12 | }; | 24 | }; |
| 13 | 25 | ||
| 14 | struct module; | 26 | struct module; |
| 15 | 27 | ||
| 16 | #ifdef HAVE_JUMP_LABEL | 28 | #ifdef HAVE_JUMP_LABEL |
| 17 | 29 | ||
| 30 | #ifdef CONFIG_MODULES | ||
| 31 | #define JUMP_LABEL_INIT {{ 0 }, NULL, NULL} | ||
| 32 | #else | ||
| 33 | #define JUMP_LABEL_INIT {{ 0 }, NULL} | ||
| 34 | #endif | ||
| 35 | |||
| 36 | static __always_inline bool static_branch(struct jump_label_key *key) | ||
| 37 | { | ||
| 38 | return arch_static_branch(key); | ||
| 39 | } | ||
| 40 | |||
| 18 | extern struct jump_entry __start___jump_table[]; | 41 | extern struct jump_entry __start___jump_table[]; |
| 19 | extern struct jump_entry __stop___jump_table[]; | 42 | extern struct jump_entry __stop___jump_table[]; |
| 20 | 43 | ||
| @@ -23,37 +46,37 @@ extern void jump_label_unlock(void); | |||
| 23 | extern void arch_jump_label_transform(struct jump_entry *entry, | 46 | extern void arch_jump_label_transform(struct jump_entry *entry, |
| 24 | enum jump_label_type type); | 47 | enum jump_label_type type); |
| 25 | extern void arch_jump_label_text_poke_early(jump_label_t addr); | 48 | extern void arch_jump_label_text_poke_early(jump_label_t addr); |
| 26 | extern void jump_label_update(unsigned long key, enum jump_label_type type); | ||
| 27 | extern void jump_label_apply_nops(struct module *mod); | ||
| 28 | extern int jump_label_text_reserved(void *start, void *end); | 49 | extern int jump_label_text_reserved(void *start, void *end); |
| 50 | extern void jump_label_inc(struct jump_label_key *key); | ||
| 51 | extern void jump_label_dec(struct jump_label_key *key); | ||
| 52 | extern bool jump_label_enabled(struct jump_label_key *key); | ||
| 53 | extern void jump_label_apply_nops(struct module *mod); | ||
| 29 | 54 | ||
| 30 | #define jump_label_enable(key) \ | 55 | #else |
| 31 | jump_label_update((unsigned long)key, JUMP_LABEL_ENABLE); | ||
| 32 | 56 | ||
| 33 | #define jump_label_disable(key) \ | 57 | #include <asm/atomic.h> |
| 34 | jump_label_update((unsigned long)key, JUMP_LABEL_DISABLE); | ||
| 35 | 58 | ||
| 36 | #else | 59 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0)} |
| 37 | 60 | ||
| 38 | #define JUMP_LABEL(key, label) \ | 61 | struct jump_label_key { |
| 39 | do { \ | 62 | atomic_t enabled; |
| 40 | if (unlikely(*key)) \ | 63 | }; |
| 41 | goto label; \ | ||
| 42 | } while (0) | ||
| 43 | 64 | ||
| 44 | #define jump_label_enable(cond_var) \ | 65 | static __always_inline bool static_branch(struct jump_label_key *key) |
| 45 | do { \ | 66 | { |
| 46 | *(cond_var) = 1; \ | 67 | if (unlikely(atomic_read(&key->enabled))) |
| 47 | } while (0) | 68 | return true; |
| 69 | return false; | ||
| 70 | } | ||
| 48 | 71 | ||
| 49 | #define jump_label_disable(cond_var) \ | 72 | static inline void jump_label_inc(struct jump_label_key *key) |
| 50 | do { \ | 73 | { |
| 51 | *(cond_var) = 0; \ | 74 | atomic_inc(&key->enabled); |
| 52 | } while (0) | 75 | } |
| 53 | 76 | ||
| 54 | static inline int jump_label_apply_nops(struct module *mod) | 77 | static inline void jump_label_dec(struct jump_label_key *key) |
| 55 | { | 78 | { |
| 56 | return 0; | 79 | atomic_dec(&key->enabled); |
| 57 | } | 80 | } |
| 58 | 81 | ||
| 59 | static inline int jump_label_text_reserved(void *start, void *end) | 82 | static inline int jump_label_text_reserved(void *start, void *end) |
| @@ -64,16 +87,16 @@ static inline int jump_label_text_reserved(void *start, void *end) | |||
| 64 | static inline void jump_label_lock(void) {} | 87 | static inline void jump_label_lock(void) {} |
| 65 | static inline void jump_label_unlock(void) {} | 88 | static inline void jump_label_unlock(void) {} |
| 66 | 89 | ||
| 67 | #endif | 90 | static inline bool jump_label_enabled(struct jump_label_key *key) |
| 91 | { | ||
| 92 | return !!atomic_read(&key->enabled); | ||
| 93 | } | ||
| 68 | 94 | ||
| 69 | #define COND_STMT(key, stmt) \ | 95 | static inline int jump_label_apply_nops(struct module *mod) |
| 70 | do { \ | 96 | { |
| 71 | __label__ jl_enabled; \ | 97 | return 0; |
| 72 | JUMP_LABEL(key, jl_enabled); \ | 98 | } |
| 73 | if (0) { \ | 99 | |
| 74 | jl_enabled: \ | 100 | #endif |
| 75 | stmt; \ | ||
| 76 | } \ | ||
| 77 | } while (0) | ||
| 78 | 101 | ||
| 79 | #endif | 102 | #endif |
