]>
Commit | Line | Data |
---|---|---|
d9f5ab7b JB |
1 | /* |
2 | * jump label x86 support | |
3 | * | |
4 | * Copyright (C) 2009 Jason Baron <jbaron@redhat.com> | |
5 | * | |
6 | */ | |
7 | #include <linux/jump_label.h> | |
8 | #include <linux/memory.h> | |
9 | #include <linux/uaccess.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/list.h> | |
12 | #include <linux/jhash.h> | |
13 | #include <linux/cpu.h> | |
14 | #include <asm/kprobes.h> | |
15 | #include <asm/alternative.h> | |
16 | ||
17 | #ifdef HAVE_JUMP_LABEL | |
18 | ||
19 | union jump_code_union { | |
20 | char code[JUMP_LABEL_NOP_SIZE]; | |
21 | struct { | |
22 | char jump; | |
23 | int offset; | |
24 | } __attribute__((packed)); | |
25 | }; | |
26 | ||
e71a5be1 JF |
27 | static void __jump_label_transform(struct jump_entry *entry, |
28 | enum jump_label_type type, | |
29 | void *(*poker)(void *, const void *, size_t)) | |
d9f5ab7b JB |
30 | { |
31 | union jump_code_union code; | |
32 | ||
33 | if (type == JUMP_LABEL_ENABLE) { | |
34 | code.jump = 0xe9; | |
35 | code.offset = entry->target - | |
36 | (entry->code + JUMP_LABEL_NOP_SIZE); | |
37 | } else | |
dc326fca | 38 | memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE); |
e71a5be1 JF |
39 | |
40 | (*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE); | |
41 | } | |
42 | ||
43 | void arch_jump_label_transform(struct jump_entry *entry, | |
44 | enum jump_label_type type) | |
45 | { | |
d9f5ab7b JB |
46 | get_online_cpus(); |
47 | mutex_lock(&text_mutex); | |
e71a5be1 | 48 | __jump_label_transform(entry, type, text_poke_smp); |
d9f5ab7b JB |
49 | mutex_unlock(&text_mutex); |
50 | put_online_cpus(); | |
51 | } | |
52 | ||
11570da1 SR |
53 | static enum { |
54 | JL_STATE_START, | |
55 | JL_STATE_NO_UPDATE, | |
56 | JL_STATE_UPDATE, | |
57 | } jlstate __initdata_or_module = JL_STATE_START; | |
58 | ||
9cdbe1cb | 59 | __init_or_module void arch_jump_label_transform_static(struct jump_entry *entry, |
e71a5be1 JF |
60 | enum jump_label_type type) |
61 | { | |
11570da1 SR |
62 | /* |
63 | * This function is called at boot up and when modules are | |
64 | * first loaded. Check if the default nop, the one that is | |
65 | * inserted at compile time, is the ideal nop. If it is, then | |
66 | * we do not need to update the nop, and we can leave it as is. | |
67 | * If it is not, then we need to update the nop to the ideal nop. | |
68 | */ | |
69 | if (jlstate == JL_STATE_START) { | |
70 | const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; | |
71 | const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; | |
72 | ||
73 | if (memcmp(ideal_nop, default_nop, 5) != 0) | |
74 | jlstate = JL_STATE_UPDATE; | |
75 | else | |
76 | jlstate = JL_STATE_NO_UPDATE; | |
77 | } | |
78 | if (jlstate == JL_STATE_UPDATE) | |
79 | __jump_label_transform(entry, type, text_poke_early); | |
e71a5be1 JF |
80 | } |
81 | ||
d9f5ab7b | 82 | #endif |