jump_label.h 2.4 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
# include <asm/jump_label.h>
# define HAVE_JUMP_LABEL
19
#endif	/* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */
20 21

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
extern void jump_label_init(void);
45 46
extern void jump_label_lock(void);
extern void jump_label_unlock(void);
47
extern void arch_jump_label_transform(struct jump_entry *entry,
48
				      enum jump_label_type type);
49 50
extern void arch_jump_label_transform_static(struct jump_entry *entry,
					     enum jump_label_type type);
51
extern int jump_label_text_reserved(void *start, void *end);
52 53 54 55
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);
56

57
#else  /* !HAVE_JUMP_LABEL */
58

A
Arun Sharma 已提交
59
#include <linux/atomic.h>
60

61
#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
62

63 64 65
struct jump_label_key {
	atomic_t enabled;
};
66

67 68 69 70
static __always_inline void jump_label_init(void)
{
}

71 72 73 74 75 76
static __always_inline bool static_branch(struct jump_label_key *key)
{
	if (unlikely(atomic_read(&key->enabled)))
		return true;
	return false;
}
77

78 79 80 81
static inline void jump_label_inc(struct jump_label_key *key)
{
	atomic_inc(&key->enabled);
}
82

83
static inline void jump_label_dec(struct jump_label_key *key)
84
{
85
	atomic_dec(&key->enabled);
86 87
}

88 89 90 91 92
static inline int jump_label_text_reserved(void *start, void *end)
{
	return 0;
}

93 94 95
static inline void jump_label_lock(void) {}
static inline void jump_label_unlock(void) {}

96 97 98 99
static inline bool jump_label_enabled(struct jump_label_key *key)
{
	return !!atomic_read(&key->enabled);
}
100

101 102 103 104
static inline int jump_label_apply_nops(struct module *mod)
{
	return 0;
}
105
#endif	/* HAVE_JUMP_LABEL */
106

107
#endif	/* _LINUX_JUMP_LABEL_H */