jump_label.h 2.1 KB
Newer Older
1 2 3
#ifndef _LINUX_JUMP_LABEL_H
#define _LINUX_JUMP_LABEL_H

4 5 6
#include <linux/types.h>
#include <linux/compiler.h>

7
#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
8 9 10 11 12 13 14 15 16

struct jump_label_key {
	atomic_t enabled;
	struct jump_entry *entries;
#ifdef CONFIG_MODULES
	struct jump_label_mod *next;
#endif
};

17 18 19 20 21
# include <asm/jump_label.h>
# define HAVE_JUMP_LABEL
#endif

enum jump_label_type {
22
	JUMP_LABEL_DISABLE = 0,
23 24 25 26 27 28 29
	JUMP_LABEL_ENABLE,
};

struct module;

#ifdef HAVE_JUMP_LABEL

30
#ifdef CONFIG_MODULES
31
#define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL}
32
#else
33
#define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL}
34 35 36 37 38 39 40
#endif

static __always_inline bool static_branch(struct jump_label_key *key)
{
	return arch_static_branch(key);
}

41 42 43
extern struct jump_entry __start___jump_table[];
extern struct jump_entry __stop___jump_table[];

44 45
extern void jump_label_lock(void);
extern void jump_label_unlock(void);
46
extern void arch_jump_label_transform(struct jump_entry *entry,
47
				      enum jump_label_type type);
48
extern int jump_label_text_reserved(void *start, void *end);
49 50 51 52
extern void jump_label_inc(struct jump_label_key *key);
extern void jump_label_dec(struct jump_label_key *key);
extern bool jump_label_enabled(struct jump_label_key *key);
extern void jump_label_apply_nops(struct module *mod);
53

54
#else
55

A
Arun Sharma 已提交
56
#include <linux/atomic.h>
57

58
#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
59

60 61 62
struct jump_label_key {
	atomic_t enabled;
};
63

64 65 66 67 68 69
static __always_inline bool static_branch(struct jump_label_key *key)
{
	if (unlikely(atomic_read(&key->enabled)))
		return true;
	return false;
}
70

71 72 73 74
static inline void jump_label_inc(struct jump_label_key *key)
{
	atomic_inc(&key->enabled);
}
75

76
static inline void jump_label_dec(struct jump_label_key *key)
77
{
78
	atomic_dec(&key->enabled);
79 80
}

81 82 83 84 85
static inline int jump_label_text_reserved(void *start, void *end)
{
	return 0;
}

86 87 88
static inline void jump_label_lock(void) {}
static inline void jump_label_unlock(void) {}

89 90 91 92
static inline bool jump_label_enabled(struct jump_label_key *key)
{
	return !!atomic_read(&key->enabled);
}
93

94 95 96 97 98 99
static inline int jump_label_apply_nops(struct module *mod)
{
	return 0;
}

#endif
100

101
#endif