jump_label.h 2.2 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 49
extern void arch_jump_label_transform_static(struct jump_entry *entry,
					     enum jump_label_type type);
50
extern int jump_label_text_reserved(void *start, void *end);
51 52 53 54
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);
55

56
#else
57

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

60
#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
61

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

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

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

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

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

88 89 90
static inline void jump_label_lock(void) {}
static inline void jump_label_unlock(void) {}

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

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

#endif
102

103
#endif