This source file includes following definitions.
- alternatives_smp_module_add
- alternatives_smp_module_del
- alternatives_enable_smp
- alternatives_text_reserved
1
2 #ifndef _ASM_X86_ALTERNATIVE_H
3 #define _ASM_X86_ALTERNATIVE_H
4
5 #ifndef __ASSEMBLY__
6
7 #include <linux/types.h>
8 #include <linux/stddef.h>
9 #include <linux/stringify.h>
10 #include <asm/asm.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #ifdef CONFIG_SMP
34 #define LOCK_PREFIX_HERE \
35 ".pushsection .smp_locks,\"a\"\n" \
36 ".balign 4\n" \
37 ".long 671f - .\n" \
38 ".popsection\n" \
39 "671:"
40
41 #define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; "
42
43 #else
44 #define LOCK_PREFIX_HERE ""
45 #define LOCK_PREFIX ""
46 #endif
47
48
49
50
51
52 #define ANNOTATE_IGNORE_ALTERNATIVE \
53 "999:\n\t" \
54 ".pushsection .discard.ignore_alts\n\t" \
55 ".long 999b - .\n\t" \
56 ".popsection\n\t"
57
58 struct alt_instr {
59 s32 instr_offset;
60 s32 repl_offset;
61 u16 cpuid;
62 u8 instrlen;
63 u8 replacementlen;
64 u8 padlen;
65 } __packed;
66
67
68
69
70
71 extern int alternatives_patched;
72
73 extern void alternative_instructions(void);
74 extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
75
76 struct module;
77
78 #ifdef CONFIG_SMP
79 extern void alternatives_smp_module_add(struct module *mod, char *name,
80 void *locks, void *locks_end,
81 void *text, void *text_end);
82 extern void alternatives_smp_module_del(struct module *mod);
83 extern void alternatives_enable_smp(void);
84 extern int alternatives_text_reserved(void *start, void *end);
85 extern bool skip_smp_alternatives;
86 #else
87 static inline void alternatives_smp_module_add(struct module *mod, char *name,
88 void *locks, void *locks_end,
89 void *text, void *text_end) {}
90 static inline void alternatives_smp_module_del(struct module *mod) {}
91 static inline void alternatives_enable_smp(void) {}
92 static inline int alternatives_text_reserved(void *start, void *end)
93 {
94 return 0;
95 }
96 #endif
97
98 #define b_replacement(num) "664"#num
99 #define e_replacement(num) "665"#num
100
101 #define alt_end_marker "663"
102 #define alt_slen "662b-661b"
103 #define alt_pad_len alt_end_marker"b-662b"
104 #define alt_total_slen alt_end_marker"b-661b"
105 #define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f"
106
107 #define OLDINSTR(oldinstr, num) \
108 "# ALT: oldnstr\n" \
109 "661:\n\t" oldinstr "\n662:\n" \
110 "# ALT: padding\n" \
111 ".skip -(((" alt_rlen(num) ")-(" alt_slen ")) > 0) * " \
112 "((" alt_rlen(num) ")-(" alt_slen ")),0x90\n" \
113 alt_end_marker ":\n"
114
115
116
117
118
119
120
121 #define alt_max_short(a, b) "((" a ") ^ (((" a ") ^ (" b ")) & -(-((" a ") < (" b ")))))"
122
123
124
125
126
127 #define OLDINSTR_2(oldinstr, num1, num2) \
128 "# ALT: oldinstr2\n" \
129 "661:\n\t" oldinstr "\n662:\n" \
130 "# ALT: padding2\n" \
131 ".skip -((" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")) > 0) * " \
132 "(" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")), 0x90\n" \
133 alt_end_marker ":\n"
134
135 #define OLDINSTR_3(oldinsn, n1, n2, n3) \
136 "# ALT: oldinstr3\n" \
137 "661:\n\t" oldinsn "\n662:\n" \
138 "# ALT: padding3\n" \
139 ".skip -((" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
140 " - (" alt_slen ")) > 0) * " \
141 "(" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \
142 " - (" alt_slen ")), 0x90\n" \
143 alt_end_marker ":\n"
144
145 #define ALTINSTR_ENTRY(feature, num) \
146 " .long 661b - .\n" \
147 " .long " b_replacement(num)"f - .\n" \
148 " .word " __stringify(feature) "\n" \
149 " .byte " alt_total_slen "\n" \
150 " .byte " alt_rlen(num) "\n" \
151 " .byte " alt_pad_len "\n"
152
153 #define ALTINSTR_REPLACEMENT(newinstr, feature, num) \
154 "# ALT: replacement " #num "\n" \
155 b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n"
156
157
158 #define ALTERNATIVE(oldinstr, newinstr, feature) \
159 OLDINSTR(oldinstr, 1) \
160 ".pushsection .altinstructions,\"a\"\n" \
161 ALTINSTR_ENTRY(feature, 1) \
162 ".popsection\n" \
163 ".pushsection .altinstr_replacement, \"ax\"\n" \
164 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
165 ".popsection\n"
166
167 #define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)\
168 OLDINSTR_2(oldinstr, 1, 2) \
169 ".pushsection .altinstructions,\"a\"\n" \
170 ALTINSTR_ENTRY(feature1, 1) \
171 ALTINSTR_ENTRY(feature2, 2) \
172 ".popsection\n" \
173 ".pushsection .altinstr_replacement, \"ax\"\n" \
174 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
175 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
176 ".popsection\n"
177
178 #define ALTERNATIVE_3(oldinsn, newinsn1, feat1, newinsn2, feat2, newinsn3, feat3) \
179 OLDINSTR_3(oldinsn, 1, 2, 3) \
180 ".pushsection .altinstructions,\"a\"\n" \
181 ALTINSTR_ENTRY(feat1, 1) \
182 ALTINSTR_ENTRY(feat2, 2) \
183 ALTINSTR_ENTRY(feat3, 3) \
184 ".popsection\n" \
185 ".pushsection .altinstr_replacement, \"ax\"\n" \
186 ALTINSTR_REPLACEMENT(newinsn1, feat1, 1) \
187 ALTINSTR_REPLACEMENT(newinsn2, feat2, 2) \
188 ALTINSTR_REPLACEMENT(newinsn3, feat3, 3) \
189 ".popsection\n"
190
191
192
193
194
195
196
197
198
199
200
201
202
203 #define alternative(oldinstr, newinstr, feature) \
204 asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
205
206 #define alternative_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \
207 asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) ::: "memory")
208
209
210
211
212
213
214
215
216
217
218
219
220 #define alternative_input(oldinstr, newinstr, feature, input...) \
221 asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
222 : : "i" (0), ## input)
223
224
225
226
227
228
229
230
231
232 #define alternative_input_2(oldinstr, newinstr1, feature1, newinstr2, \
233 feature2, input...) \
234 asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, \
235 newinstr2, feature2) \
236 : : "i" (0), ## input)
237
238
239 #define alternative_io(oldinstr, newinstr, feature, output, input...) \
240 asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
241 : output : "i" (0), ## input)
242
243
244 #define alternative_call(oldfunc, newfunc, feature, output, input...) \
245 asm_inline volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
246 : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
247
248
249
250
251
252
253
254 #define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2, \
255 output, input...) \
256 asm_inline volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
257 "call %P[new2]", feature2) \
258 : output, ASM_CALL_CONSTRAINT \
259 : [old] "i" (oldfunc), [new1] "i" (newfunc1), \
260 [new2] "i" (newfunc2), ## input)
261
262
263
264
265
266 #define ASM_OUTPUT2(a...) a
267
268
269
270
271
272 #define ASM_NO_INPUT_CLOBBER(clbr...) "i" (0) : clbr
273
274 #endif
275
276 #endif