aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/jump_label.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/jump_label.h')
-rw-r--r--include/linux/jump_label.h89
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
9struct 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
9enum jump_label_type { 21enum jump_label_type {
22 JUMP_LABEL_DISABLE = 0,
10 JUMP_LABEL_ENABLE, 23 JUMP_LABEL_ENABLE,
11 JUMP_LABEL_DISABLE
12}; 24};
13 25
14struct module; 26struct 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
36static __always_inline bool static_branch(struct jump_label_key *key)
37{
38 return arch_static_branch(key);
39}
40
18extern struct jump_entry __start___jump_table[]; 41extern struct jump_entry __start___jump_table[];
19extern struct jump_entry __stop___jump_table[]; 42extern struct jump_entry __stop___jump_table[];
20 43
@@ -23,37 +46,37 @@ extern void jump_label_unlock(void);
23extern void arch_jump_label_transform(struct jump_entry *entry, 46extern void arch_jump_label_transform(struct jump_entry *entry,
24 enum jump_label_type type); 47 enum jump_label_type type);
25extern void arch_jump_label_text_poke_early(jump_label_t addr); 48extern void arch_jump_label_text_poke_early(jump_label_t addr);
26extern void jump_label_update(unsigned long key, enum jump_label_type type);
27extern void jump_label_apply_nops(struct module *mod);
28extern int jump_label_text_reserved(void *start, void *end); 49extern int jump_label_text_reserved(void *start, void *end);
50extern void jump_label_inc(struct jump_label_key *key);
51extern void jump_label_dec(struct jump_label_key *key);
52extern bool jump_label_enabled(struct jump_label_key *key);
53extern 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) \ 61struct jump_label_key {
39do { \ 62 atomic_t enabled;
40 if (unlikely(*key)) \ 63};
41 goto label; \
42} while (0)
43 64
44#define jump_label_enable(cond_var) \ 65static __always_inline bool static_branch(struct jump_label_key *key)
45do { \ 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) \ 72static inline void jump_label_inc(struct jump_label_key *key)
50do { \ 73{
51 *(cond_var) = 0; \ 74 atomic_inc(&key->enabled);
52} while (0) 75}
53 76
54static inline int jump_label_apply_nops(struct module *mod) 77static inline void jump_label_dec(struct jump_label_key *key)
55{ 78{
56 return 0; 79 atomic_dec(&key->enabled);
57} 80}
58 81
59static inline int jump_label_text_reserved(void *start, void *end) 82static 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)
64static inline void jump_label_lock(void) {} 87static inline void jump_label_lock(void) {}
65static inline void jump_label_unlock(void) {} 88static inline void jump_label_unlock(void) {}
66 89
67#endif 90static 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) \ 95static inline int jump_label_apply_nops(struct module *mod)
70do { \ 96{
71 __label__ jl_enabled; \ 97 return 0;
72 JUMP_LABEL(key, jl_enabled); \ 98}
73 if (0) { \ 99
74jl_enabled: \ 100#endif
75 stmt; \
76 } \
77} while (0)
78 101
79#endif 102#endif