jump_label.h 1.3 KB
Newer Older
J
Jason Baron 已提交
1 2 3
#ifndef _ASM_X86_JUMP_LABEL_H
#define _ASM_X86_JUMP_LABEL_H

4
#ifndef __ASSEMBLY__
J
Jason Baron 已提交
5

6
#include <linux/stringify.h>
J
Jason Baron 已提交
7 8
#include <linux/types.h>
#include <asm/nops.h>
9
#include <asm/asm.h>
J
Jason Baron 已提交
10 11 12

#define JUMP_LABEL_NOP_SIZE 5

13 14 15 16 17
#ifdef CONFIG_X86_64
# define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC
#else
# define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC
#endif
18

19
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
20
{
21
	asm_volatile_goto("1:"
22
		".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
23
		".pushsection __jump_table,  \"aw\" \n\t"
24
		_ASM_ALIGN "\n\t"
25
		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
26
		".popsection \n\t"
27
		: :  "i" (key), "i" (branch) : : l_yes);
28 29 30 31 32 33 34 35 36 37 38 39 40

	return false;
l_yes:
	return true;
}

static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
{
	asm_volatile_goto("1:"
		".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
		"2:\n\t"
		".pushsection __jump_table,  \"aw\" \n\t"
		_ASM_ALIGN "\n\t"
41
		_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
42
		".popsection \n\t"
43
		: :  "i" (key), "i" (branch) : : l_yes);
44

45 46 47 48
	return false;
l_yes:
	return true;
}
J
Jason Baron 已提交
49 50 51 52 53

#ifdef CONFIG_X86_64
typedef u64 jump_label_t;
#else
typedef u32 jump_label_t;
54
#endif
J
Jason Baron 已提交
55 56 57 58 59 60 61

struct jump_entry {
	jump_label_t code;
	jump_label_t target;
	jump_label_t key;
};

62
#endif  /* __ASSEMBLY__ */
J
Jason Baron 已提交
63
#endif