Commit | Line | Data |
---|---|---|
53aaf262 TG |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _ASM_X86_IDTENTRY_H | |
3 | #define _ASM_X86_IDTENTRY_H | |
4 | ||
5 | /* Interrupts/Exceptions */ | |
6 | #include <asm/trapnr.h> | |
7 | ||
8f93402b PZ |
8 | #define IDT_ALIGN (8 * (1 + HAS_KERNEL_IBT)) |
9 | ||
53aaf262 | 10 | #ifndef __ASSEMBLY__ |
27d6b4d1 | 11 | #include <linux/entry-common.h> |
6368558c TG |
12 | #include <linux/hardirq.h> |
13 | ||
14 | #include <asm/irq_stack.h> | |
53aaf262 TG |
15 | |
16 | /** | |
17 | * DECLARE_IDTENTRY - Declare functions for simple IDT entry points | |
18 | * No error code pushed by hardware | |
19 | * @vector: Vector number (ignored for C) | |
20 | * @func: Function name of the entry point | |
21 | * | |
22 | * Declares three functions: | |
23 | * - The ASM entry point: asm_##func | |
24 | * - The XEN PV trap entry point: xen_##func (maybe unused) | |
25 | * - The C handler called from the ASM entry point | |
26 | * | |
27 | * Note: This is the C variant of DECLARE_IDTENTRY(). As the name says it | |
28 | * declares the entry points for usage in C code. There is an ASM variant | |
29 | * as well which is used to emit the entry stubs in entry_32/64.S. | |
30 | */ | |
31 | #define DECLARE_IDTENTRY(vector, func) \ | |
32 | asmlinkage void asm_##func(void); \ | |
33 | asmlinkage void xen_asm_##func(void); \ | |
34 | __visible void func(struct pt_regs *regs) | |
35 | ||
36 | /** | |
37 | * DEFINE_IDTENTRY - Emit code for simple IDT entry points | |
38 | * @func: Function name of the entry point | |
39 | * | |
40 | * @func is called from ASM entry code with interrupts disabled. | |
41 | * | |
42 | * The macro is written so it acts as function definition. Append the | |
43 | * body with a pair of curly brackets. | |
44 | * | |
a27a0a55 TG |
45 | * irqentry_enter() contains common code which has to be invoked before |
46 | * arbitrary code in the body. irqentry_exit() contains common code | |
53aaf262 TG |
47 | * which has to run before returning to the low level assembly code. |
48 | */ | |
49 | #define DEFINE_IDTENTRY(func) \ | |
50 | static __always_inline void __##func(struct pt_regs *regs); \ | |
51 | \ | |
52 | __visible noinstr void func(struct pt_regs *regs) \ | |
53 | { \ | |
a27a0a55 | 54 | irqentry_state_t state = irqentry_enter(regs); \ |
fa95d7dc | 55 | \ |
53aaf262 TG |
56 | instrumentation_begin(); \ |
57 | __##func (regs); \ | |
58 | instrumentation_end(); \ | |
a27a0a55 | 59 | irqentry_exit(regs, state); \ |
53aaf262 TG |
60 | } \ |
61 | \ | |
62 | static __always_inline void __##func(struct pt_regs *regs) | |
63 | ||
d7729050 TG |
64 | /* Special case for 32bit IRET 'trap' */ |
65 | #define DECLARE_IDTENTRY_SW DECLARE_IDTENTRY | |
66 | #define DEFINE_IDTENTRY_SW DEFINE_IDTENTRY | |
67 | ||
aabfe538 TG |
68 | /** |
69 | * DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points | |
70 | * Error code pushed by hardware | |
71 | * @vector: Vector number (ignored for C) | |
72 | * @func: Function name of the entry point | |
73 | * | |
74 | * Declares three functions: | |
75 | * - The ASM entry point: asm_##func | |
76 | * - The XEN PV trap entry point: xen_##func (maybe unused) | |
77 | * - The C handler called from the ASM entry point | |
78 | * | |
79 | * Same as DECLARE_IDTENTRY, but has an extra error_code argument for the | |
80 | * C-handler. | |
81 | */ | |
82 | #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ | |
83 | asmlinkage void asm_##func(void); \ | |
84 | asmlinkage void xen_asm_##func(void); \ | |
85 | __visible void func(struct pt_regs *regs, unsigned long error_code) | |
86 | ||
87 | /** | |
88 | * DEFINE_IDTENTRY_ERRORCODE - Emit code for simple IDT entry points | |
89 | * Error code pushed by hardware | |
90 | * @func: Function name of the entry point | |
91 | * | |
92 | * Same as DEFINE_IDTENTRY, but has an extra error_code argument | |
93 | */ | |
94 | #define DEFINE_IDTENTRY_ERRORCODE(func) \ | |
95 | static __always_inline void __##func(struct pt_regs *regs, \ | |
96 | unsigned long error_code); \ | |
97 | \ | |
98 | __visible noinstr void func(struct pt_regs *regs, \ | |
99 | unsigned long error_code) \ | |
100 | { \ | |
a27a0a55 | 101 | irqentry_state_t state = irqentry_enter(regs); \ |
fa95d7dc | 102 | \ |
aabfe538 TG |
103 | instrumentation_begin(); \ |
104 | __##func (regs, error_code); \ | |
105 | instrumentation_end(); \ | |
a27a0a55 | 106 | irqentry_exit(regs, state); \ |
aabfe538 TG |
107 | } \ |
108 | \ | |
109 | static __always_inline void __##func(struct pt_regs *regs, \ | |
110 | unsigned long error_code) | |
111 | ||
0dc6cdc2 TG |
112 | /** |
113 | * DECLARE_IDTENTRY_RAW - Declare functions for raw IDT entry points | |
114 | * No error code pushed by hardware | |
115 | * @vector: Vector number (ignored for C) | |
116 | * @func: Function name of the entry point | |
117 | * | |
118 | * Maps to DECLARE_IDTENTRY(). | |
119 | */ | |
120 | #define DECLARE_IDTENTRY_RAW(vector, func) \ | |
121 | DECLARE_IDTENTRY(vector, func) | |
122 | ||
123 | /** | |
124 | * DEFINE_IDTENTRY_RAW - Emit code for raw IDT entry points | |
125 | * @func: Function name of the entry point | |
126 | * | |
127 | * @func is called from ASM entry code with interrupts disabled. | |
128 | * | |
129 | * The macro is written so it acts as function definition. Append the | |
130 | * body with a pair of curly brackets. | |
131 | * | |
132 | * Contrary to DEFINE_IDTENTRY() this does not invoke the | |
133 | * idtentry_enter/exit() helpers before and after the body invocation. This | |
134 | * needs to be done in the body itself if applicable. Use if extra work | |
135 | * is required before the enter/exit() helpers are invoked. | |
136 | */ | |
137 | #define DEFINE_IDTENTRY_RAW(func) \ | |
138 | __visible noinstr void func(struct pt_regs *regs) | |
139 | ||
6a8dfa8e TG |
140 | /** |
141 | * DECLARE_IDTENTRY_RAW_ERRORCODE - Declare functions for raw IDT entry points | |
142 | * Error code pushed by hardware | |
143 | * @vector: Vector number (ignored for C) | |
144 | * @func: Function name of the entry point | |
145 | * | |
146 | * Maps to DECLARE_IDTENTRY_ERRORCODE() | |
147 | */ | |
148 | #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \ | |
149 | DECLARE_IDTENTRY_ERRORCODE(vector, func) | |
150 | ||
151 | /** | |
152 | * DEFINE_IDTENTRY_RAW_ERRORCODE - Emit code for raw IDT entry points | |
153 | * @func: Function name of the entry point | |
154 | * | |
155 | * @func is called from ASM entry code with interrupts disabled. | |
156 | * | |
157 | * The macro is written so it acts as function definition. Append the | |
158 | * body with a pair of curly brackets. | |
159 | * | |
160 | * Contrary to DEFINE_IDTENTRY_ERRORCODE() this does not invoke the | |
a27a0a55 | 161 | * irqentry_enter/exit() helpers before and after the body invocation. This |
6a8dfa8e TG |
162 | * needs to be done in the body itself if applicable. Use if extra work |
163 | * is required before the enter/exit() helpers are invoked. | |
164 | */ | |
165 | #define DEFINE_IDTENTRY_RAW_ERRORCODE(func) \ | |
166 | __visible noinstr void func(struct pt_regs *regs, unsigned long error_code) | |
167 | ||
0bf7c314 TG |
168 | /** |
169 | * DECLARE_IDTENTRY_IRQ - Declare functions for device interrupt IDT entry | |
170 | * points (common/spurious) | |
171 | * @vector: Vector number (ignored for C) | |
172 | * @func: Function name of the entry point | |
173 | * | |
174 | * Maps to DECLARE_IDTENTRY_ERRORCODE() | |
175 | */ | |
176 | #define DECLARE_IDTENTRY_IRQ(vector, func) \ | |
177 | DECLARE_IDTENTRY_ERRORCODE(vector, func) | |
178 | ||
179 | /** | |
180 | * DEFINE_IDTENTRY_IRQ - Emit code for device interrupt IDT entry points | |
181 | * @func: Function name of the entry point | |
182 | * | |
183 | * The vector number is pushed by the low level entry stub and handed | |
184 | * to the function as error_code argument which needs to be truncated | |
185 | * to an u8 because the push is sign extending. | |
186 | * | |
0bf7c314 | 187 | * irq_enter/exit_rcu() are invoked before the function body and the |
790ce3b4 TG |
188 | * KVM L1D flush request is set. Stack switching to the interrupt stack |
189 | * has to be done in the function body if necessary. | |
0bf7c314 TG |
190 | */ |
191 | #define DEFINE_IDTENTRY_IRQ(func) \ | |
5b51e1db | 192 | static void __##func(struct pt_regs *regs, u32 vector); \ |
0bf7c314 TG |
193 | \ |
194 | __visible noinstr void func(struct pt_regs *regs, \ | |
195 | unsigned long error_code) \ | |
196 | { \ | |
a27a0a55 | 197 | irqentry_state_t state = irqentry_enter(regs); \ |
5b51e1db | 198 | u32 vector = (u32)(u8)error_code; \ |
0bf7c314 TG |
199 | \ |
200 | instrumentation_begin(); \ | |
0bf7c314 | 201 | kvm_set_cpu_l1tf_flush_l1d(); \ |
5b51e1db | 202 | run_irq_on_irqstack_cond(__##func, regs, vector); \ |
0bf7c314 | 203 | instrumentation_end(); \ |
a27a0a55 | 204 | irqentry_exit(regs, state); \ |
0bf7c314 TG |
205 | } \ |
206 | \ | |
5b51e1db | 207 | static noinline void __##func(struct pt_regs *regs, u32 vector) |
0bf7c314 | 208 | |
6368558c TG |
209 | /** |
210 | * DECLARE_IDTENTRY_SYSVEC - Declare functions for system vector entry points | |
211 | * @vector: Vector number (ignored for C) | |
212 | * @func: Function name of the entry point | |
213 | * | |
214 | * Declares three functions: | |
215 | * - The ASM entry point: asm_##func | |
216 | * - The XEN PV trap entry point: xen_##func (maybe unused) | |
217 | * - The C handler called from the ASM entry point | |
218 | * | |
219 | * Maps to DECLARE_IDTENTRY(). | |
220 | */ | |
221 | #define DECLARE_IDTENTRY_SYSVEC(vector, func) \ | |
222 | DECLARE_IDTENTRY(vector, func) | |
223 | ||
224 | /** | |
225 | * DEFINE_IDTENTRY_SYSVEC - Emit code for system vector IDT entry points | |
226 | * @func: Function name of the entry point | |
227 | * | |
a27a0a55 | 228 | * irqentry_enter/exit() and irq_enter/exit_rcu() are invoked before the |
6368558c TG |
229 | * function body. KVM L1D flush request is set. |
230 | * | |
231 | * Runs the function on the interrupt stack if the entry hit kernel mode | |
232 | */ | |
233 | #define DEFINE_IDTENTRY_SYSVEC(func) \ | |
234 | static void __##func(struct pt_regs *regs); \ | |
235 | \ | |
236 | __visible noinstr void func(struct pt_regs *regs) \ | |
237 | { \ | |
a27a0a55 | 238 | irqentry_state_t state = irqentry_enter(regs); \ |
6368558c TG |
239 | \ |
240 | instrumentation_begin(); \ | |
6368558c | 241 | kvm_set_cpu_l1tf_flush_l1d(); \ |
a7b3474c | 242 | run_sysvec_on_irqstack_cond(__##func, regs); \ |
6368558c | 243 | instrumentation_end(); \ |
a27a0a55 | 244 | irqentry_exit(regs, state); \ |
6368558c TG |
245 | } \ |
246 | \ | |
247 | static noinline void __##func(struct pt_regs *regs) | |
248 | ||
249 | /** | |
250 | * DEFINE_IDTENTRY_SYSVEC_SIMPLE - Emit code for simple system vector IDT | |
251 | * entry points | |
252 | * @func: Function name of the entry point | |
253 | * | |
254 | * Runs the function on the interrupted stack. No switch to IRQ stack and | |
255 | * only the minimal __irq_enter/exit() handling. | |
256 | * | |
257 | * Only use for 'empty' vectors like reschedule IPI and KVM posted | |
258 | * interrupt vectors. | |
259 | */ | |
260 | #define DEFINE_IDTENTRY_SYSVEC_SIMPLE(func) \ | |
261 | static __always_inline void __##func(struct pt_regs *regs); \ | |
262 | \ | |
263 | __visible noinstr void func(struct pt_regs *regs) \ | |
264 | { \ | |
a27a0a55 | 265 | irqentry_state_t state = irqentry_enter(regs); \ |
6368558c TG |
266 | \ |
267 | instrumentation_begin(); \ | |
268 | __irq_enter_raw(); \ | |
269 | kvm_set_cpu_l1tf_flush_l1d(); \ | |
270 | __##func (regs); \ | |
271 | __irq_exit_raw(); \ | |
272 | instrumentation_end(); \ | |
a27a0a55 | 273 | irqentry_exit(regs, state); \ |
6368558c TG |
274 | } \ |
275 | \ | |
276 | static __always_inline void __##func(struct pt_regs *regs) | |
277 | ||
2f6474e4 TG |
278 | /** |
279 | * DECLARE_IDTENTRY_XENCB - Declare functions for XEN HV callback entry point | |
280 | * @vector: Vector number (ignored for C) | |
281 | * @func: Function name of the entry point | |
282 | * | |
283 | * Declares three functions: | |
284 | * - The ASM entry point: asm_##func | |
285 | * - The XEN PV trap entry point: xen_##func (maybe unused) | |
286 | * - The C handler called from the ASM entry point | |
287 | * | |
288 | * Maps to DECLARE_IDTENTRY(). Distinct entry point to handle the 32/64-bit | |
289 | * difference | |
290 | */ | |
291 | #define DECLARE_IDTENTRY_XENCB(vector, func) \ | |
292 | DECLARE_IDTENTRY(vector, func) | |
6a8dfa8e | 293 | |
2c058b03 TG |
294 | #ifdef CONFIG_X86_64 |
295 | /** | |
296 | * DECLARE_IDTENTRY_IST - Declare functions for IST handling IDT entry points | |
297 | * @vector: Vector number (ignored for C) | |
298 | * @func: Function name of the entry point | |
299 | * | |
f08e32ec TG |
300 | * Maps to DECLARE_IDTENTRY_RAW, but declares also the NOIST C handler |
301 | * which is called from the ASM entry point on user mode entry | |
2c058b03 TG |
302 | */ |
303 | #define DECLARE_IDTENTRY_IST(vector, func) \ | |
f08e32ec TG |
304 | DECLARE_IDTENTRY_RAW(vector, func); \ |
305 | __visible void noist_##func(struct pt_regs *regs) | |
2c058b03 | 306 | |
a13644f3 JR |
307 | /** |
308 | * DECLARE_IDTENTRY_VC - Declare functions for the VC entry point | |
309 | * @vector: Vector number (ignored for C) | |
310 | * @func: Function name of the entry point | |
311 | * | |
312 | * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE, but declares also the | |
313 | * safe_stack C handler. | |
314 | */ | |
315 | #define DECLARE_IDTENTRY_VC(vector, func) \ | |
316 | DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); \ | |
be1a5408 JR |
317 | __visible noinstr void kernel_##func(struct pt_regs *regs, unsigned long error_code); \ |
318 | __visible noinstr void user_##func(struct pt_regs *regs, unsigned long error_code) | |
a13644f3 | 319 | |
2c058b03 TG |
320 | /** |
321 | * DEFINE_IDTENTRY_IST - Emit code for IST entry points | |
322 | * @func: Function name of the entry point | |
323 | * | |
324 | * Maps to DEFINE_IDTENTRY_RAW | |
325 | */ | |
326 | #define DEFINE_IDTENTRY_IST(func) \ | |
327 | DEFINE_IDTENTRY_RAW(func) | |
328 | ||
f08e32ec TG |
329 | /** |
330 | * DEFINE_IDTENTRY_NOIST - Emit code for NOIST entry points which | |
331 | * belong to a IST entry point (MCE, DB) | |
332 | * @func: Function name of the entry point. Must be the same as | |
333 | * the function name of the corresponding IST variant | |
334 | * | |
335 | * Maps to DEFINE_IDTENTRY_RAW(). | |
336 | */ | |
337 | #define DEFINE_IDTENTRY_NOIST(func) \ | |
338 | DEFINE_IDTENTRY_RAW(noist_##func) | |
339 | ||
6a8dfa8e TG |
340 | /** |
341 | * DECLARE_IDTENTRY_DF - Declare functions for double fault | |
342 | * @vector: Vector number (ignored for C) | |
343 | * @func: Function name of the entry point | |
344 | * | |
345 | * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE | |
346 | */ | |
347 | #define DECLARE_IDTENTRY_DF(vector, func) \ | |
348 | DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) | |
349 | ||
350 | /** | |
351 | * DEFINE_IDTENTRY_DF - Emit code for double fault | |
352 | * @func: Function name of the entry point | |
353 | * | |
354 | * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE | |
355 | */ | |
356 | #define DEFINE_IDTENTRY_DF(func) \ | |
357 | DEFINE_IDTENTRY_RAW_ERRORCODE(func) | |
358 | ||
a13644f3 | 359 | /** |
be1a5408 JR |
360 | * DEFINE_IDTENTRY_VC_KERNEL - Emit code for VMM communication handler |
361 | when raised from kernel mode | |
a13644f3 JR |
362 | * @func: Function name of the entry point |
363 | * | |
364 | * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE | |
365 | */ | |
be1a5408 JR |
366 | #define DEFINE_IDTENTRY_VC_KERNEL(func) \ |
367 | DEFINE_IDTENTRY_RAW_ERRORCODE(kernel_##func) | |
a13644f3 JR |
368 | |
369 | /** | |
be1a5408 JR |
370 | * DEFINE_IDTENTRY_VC_USER - Emit code for VMM communication handler |
371 | when raised from user mode | |
a13644f3 JR |
372 | * @func: Function name of the entry point |
373 | * | |
374 | * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE | |
375 | */ | |
be1a5408 JR |
376 | #define DEFINE_IDTENTRY_VC_USER(func) \ |
377 | DEFINE_IDTENTRY_RAW_ERRORCODE(user_##func) | |
a13644f3 | 378 | |
2c058b03 | 379 | #else /* CONFIG_X86_64 */ |
6a8dfa8e | 380 | |
6a8dfa8e TG |
381 | /** |
382 | * DECLARE_IDTENTRY_DF - Declare functions for double fault 32bit variant | |
383 | * @vector: Vector number (ignored for C) | |
384 | * @func: Function name of the entry point | |
385 | * | |
386 | * Declares two functions: | |
387 | * - The ASM entry point: asm_##func | |
388 | * - The C handler called from the C shim | |
389 | */ | |
390 | #define DECLARE_IDTENTRY_DF(vector, func) \ | |
391 | asmlinkage void asm_##func(void); \ | |
392 | __visible void func(struct pt_regs *regs, \ | |
393 | unsigned long error_code, \ | |
394 | unsigned long address) | |
395 | ||
396 | /** | |
397 | * DEFINE_IDTENTRY_DF - Emit code for double fault on 32bit | |
398 | * @func: Function name of the entry point | |
399 | * | |
400 | * This is called through the doublefault shim which already provides | |
401 | * cr2 in the address argument. | |
402 | */ | |
403 | #define DEFINE_IDTENTRY_DF(func) \ | |
404 | __visible noinstr void func(struct pt_regs *regs, \ | |
405 | unsigned long error_code, \ | |
406 | unsigned long address) | |
407 | ||
2c058b03 TG |
408 | #endif /* !CONFIG_X86_64 */ |
409 | ||
410 | /* C-Code mapping */ | |
13cbc0cd AL |
411 | #define DECLARE_IDTENTRY_NMI DECLARE_IDTENTRY_RAW |
412 | #define DEFINE_IDTENTRY_NMI DEFINE_IDTENTRY_RAW | |
413 | ||
414 | #ifdef CONFIG_X86_64 | |
2c058b03 TG |
415 | #define DECLARE_IDTENTRY_MCE DECLARE_IDTENTRY_IST |
416 | #define DEFINE_IDTENTRY_MCE DEFINE_IDTENTRY_IST | |
f08e32ec | 417 | #define DEFINE_IDTENTRY_MCE_USER DEFINE_IDTENTRY_NOIST |
2c058b03 | 418 | |
2c058b03 TG |
419 | #define DECLARE_IDTENTRY_DEBUG DECLARE_IDTENTRY_IST |
420 | #define DEFINE_IDTENTRY_DEBUG DEFINE_IDTENTRY_IST | |
f08e32ec | 421 | #define DEFINE_IDTENTRY_DEBUG_USER DEFINE_IDTENTRY_NOIST |
13cbc0cd | 422 | #endif |
2c058b03 | 423 | |
53aaf262 TG |
424 | #else /* !__ASSEMBLY__ */ |
425 | ||
426 | /* | |
427 | * The ASM variants for DECLARE_IDTENTRY*() which emit the ASM entry stubs. | |
428 | */ | |
429 | #define DECLARE_IDTENTRY(vector, func) \ | |
e2dcb5f1 | 430 | idtentry vector asm_##func func has_error_code=0 |
53aaf262 | 431 | |
aabfe538 | 432 | #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ |
e2dcb5f1 | 433 | idtentry vector asm_##func func has_error_code=1 |
aabfe538 | 434 | |
d7729050 TG |
435 | /* Special case for 32bit IRET 'trap'. Do not emit ASM code */ |
436 | #define DECLARE_IDTENTRY_SW(vector, func) | |
437 | ||
0dc6cdc2 TG |
438 | #define DECLARE_IDTENTRY_RAW(vector, func) \ |
439 | DECLARE_IDTENTRY(vector, func) | |
440 | ||
6a8dfa8e TG |
441 | #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \ |
442 | DECLARE_IDTENTRY_ERRORCODE(vector, func) | |
443 | ||
0bf7c314 TG |
444 | /* Entries for common/spurious (device) interrupts */ |
445 | #define DECLARE_IDTENTRY_IRQ(vector, func) \ | |
446 | idtentry_irq vector func | |
447 | ||
6368558c TG |
448 | /* System vector entries */ |
449 | #define DECLARE_IDTENTRY_SYSVEC(vector, func) \ | |
450 | idtentry_sysvec vector func | |
451 | ||
2c058b03 TG |
452 | #ifdef CONFIG_X86_64 |
453 | # define DECLARE_IDTENTRY_MCE(vector, func) \ | |
454 | idtentry_mce_db vector asm_##func func | |
455 | ||
456 | # define DECLARE_IDTENTRY_DEBUG(vector, func) \ | |
457 | idtentry_mce_db vector asm_##func func | |
458 | ||
6a8dfa8e TG |
459 | # define DECLARE_IDTENTRY_DF(vector, func) \ |
460 | idtentry_df vector asm_##func func | |
461 | ||
2f6474e4 TG |
462 | # define DECLARE_IDTENTRY_XENCB(vector, func) \ |
463 | DECLARE_IDTENTRY(vector, func) | |
464 | ||
a13644f3 JR |
465 | # define DECLARE_IDTENTRY_VC(vector, func) \ |
466 | idtentry_vc vector asm_##func func | |
467 | ||
2c058b03 TG |
468 | #else |
469 | # define DECLARE_IDTENTRY_MCE(vector, func) \ | |
470 | DECLARE_IDTENTRY(vector, func) | |
471 | ||
6a8dfa8e TG |
472 | /* No ASM emitted for DF as this goes through a C shim */ |
473 | # define DECLARE_IDTENTRY_DF(vector, func) | |
474 | ||
2f6474e4 TG |
475 | /* No ASM emitted for XEN hypervisor callback */ |
476 | # define DECLARE_IDTENTRY_XENCB(vector, func) | |
477 | ||
2c058b03 TG |
478 | #endif |
479 | ||
480 | /* No ASM code emitted for NMI */ | |
481 | #define DECLARE_IDTENTRY_NMI(vector, func) | |
482 | ||
633260fa TG |
483 | /* |
484 | * ASM code to emit the common vector entry stubs where each stub is | |
8f93402b | 485 | * packed into IDT_ALIGN bytes. |
633260fa TG |
486 | * |
487 | * Note, that the 'pushq imm8' is emitted via '.byte 0x6a, vector' because | |
488 | * GCC treats the local vector variable as unsigned int and would expand | |
489 | * all vectors above 0x7F to a 5 byte push. The original code did an | |
490 | * adjustment of the vector number to be in the signed byte range to avoid | |
491 | * this. While clever it's mindboggling counterintuitive and requires the | |
492 | * odd conversion back to a real vector number in the C entry points. Using | |
493 | * .byte achieves the same thing and the only fixup needed in the C entry | |
494 | * point is to mask off the bits above bit 7 because the push is sign | |
495 | * extending. | |
496 | */ | |
8f93402b | 497 | .align IDT_ALIGN |
633260fa TG |
498 | SYM_CODE_START(irq_entries_start) |
499 | vector=FIRST_EXTERNAL_VECTOR | |
ff851003 | 500 | .rept NR_EXTERNAL_VECTORS |
633260fa | 501 | UNWIND_HINT_IRET_REGS |
6ee93f8d | 502 | 0 : |
8f93402b | 503 | ENDBR |
633260fa | 504 | .byte 0x6a, vector |
fa5e5c40 | 505 | jmp asm_common_interrupt |
8f93402b PZ |
506 | /* Ensure that the above is IDT_ALIGN bytes max */ |
507 | .fill 0b + IDT_ALIGN - ., 1, 0xcc | |
6ee93f8d | 508 | vector = vector+1 |
633260fa TG |
509 | .endr |
510 | SYM_CODE_END(irq_entries_start) | |
511 | ||
512 | #ifdef CONFIG_X86_LOCAL_APIC | |
8f93402b | 513 | .align IDT_ALIGN |
633260fa TG |
514 | SYM_CODE_START(spurious_entries_start) |
515 | vector=FIRST_SYSTEM_VECTOR | |
ff851003 | 516 | .rept NR_SYSTEM_VECTORS |
633260fa | 517 | UNWIND_HINT_IRET_REGS |
6ee93f8d | 518 | 0 : |
8f93402b | 519 | ENDBR |
633260fa | 520 | .byte 0x6a, vector |
fa5e5c40 | 521 | jmp asm_spurious_interrupt |
8f93402b PZ |
522 | /* Ensure that the above is IDT_ALIGN bytes max */ |
523 | .fill 0b + IDT_ALIGN - ., 1, 0xcc | |
6ee93f8d | 524 | vector = vector+1 |
633260fa TG |
525 | .endr |
526 | SYM_CODE_END(spurious_entries_start) | |
527 | #endif | |
528 | ||
53aaf262 TG |
529 | #endif /* __ASSEMBLY__ */ |
530 | ||
9d06c402 TG |
531 | /* |
532 | * The actual entry points. Note that DECLARE_IDTENTRY*() serves two | |
533 | * purposes: | |
534 | * - provide the function declarations when included from C-Code | |
535 | * - emit the ASM stubs when included from entry_32/64.S | |
536 | * | |
537 | * This avoids duplicate defines and ensures that everything is consistent. | |
538 | */ | |
539 | ||
2f6474e4 TG |
540 | /* |
541 | * Dummy trap number so the low level ASM macro vector number checks do not | |
542 | * match which results in emitting plain IDTENTRY stubs without bells and | |
d9f6e12f | 543 | * whistles. |
2f6474e4 TG |
544 | */ |
545 | #define X86_TRAP_OTHER 0xFFFF | |
546 | ||
9d06c402 TG |
547 | /* Simple exception entry points. No hardware error code */ |
548 | DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error); | |
4b6b9111 | 549 | DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow); |
58d9c81f | 550 | DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds); |
866ae2cc | 551 | DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available); |
f95658fd | 552 | DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun); |
dad7106f | 553 | DECLARE_IDTENTRY(X86_TRAP_SPURIOUS, exc_spurious_interrupt_bug); |
14a8bd2a | 554 | DECLARE_IDTENTRY(X86_TRAP_MF, exc_coprocessor_error); |
48227e21 | 555 | DECLARE_IDTENTRY(X86_TRAP_XF, exc_simd_coprocessor_error); |
9d06c402 | 556 | |
d7729050 TG |
557 | /* 32bit software IRET trap. Do not emit ASM code */ |
558 | DECLARE_IDTENTRY_SW(X86_TRAP_IRET, iret_error); | |
559 | ||
97b3d290 TG |
560 | /* Simple exception entries with error code pushed by hardware */ |
561 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss); | |
99a3fb8d | 562 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_NP, exc_segment_not_present); |
fd9689bf | 563 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_SS, exc_stack_segment); |
be4c11af | 564 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_GP, exc_general_protection); |
436608bb | 565 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_AC, exc_alignment_check); |
97b3d290 | 566 | |
8edd7e37 | 567 | /* Raw exception entries which need extra work */ |
15a416e8 | 568 | DECLARE_IDTENTRY_RAW(X86_TRAP_UD, exc_invalid_op); |
91eeafea TG |
569 | DECLARE_IDTENTRY_RAW(X86_TRAP_BP, exc_int3); |
570 | DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_PF, exc_page_fault); | |
8edd7e37 | 571 | |
8cd501c1 | 572 | #ifdef CONFIG_X86_MCE |
13cbc0cd | 573 | #ifdef CONFIG_X86_64 |
8cd501c1 | 574 | DECLARE_IDTENTRY_MCE(X86_TRAP_MC, exc_machine_check); |
13cbc0cd AL |
575 | #else |
576 | DECLARE_IDTENTRY_RAW(X86_TRAP_MC, exc_machine_check); | |
577 | #endif | |
c3d7fa66 JG |
578 | #ifdef CONFIG_XEN_PV |
579 | DECLARE_IDTENTRY_RAW(X86_TRAP_MC, xenpv_exc_machine_check); | |
580 | #endif | |
8cd501c1 TG |
581 | #endif |
582 | ||
6271fef0 | 583 | /* NMI */ |
a217a659 | 584 | |
54a3b70a | 585 | #if IS_ENABLED(CONFIG_KVM_INTEL) |
a217a659 | 586 | /* |
54a3b70a SC |
587 | * Special entry point for VMX which invokes this on the kernel stack, even for |
588 | * 64-bit, i.e. without using an IST. asm_exc_nmi() requires an IST to work | |
589 | * correctly vs. the NMI 'executing' marker. Used for 32-bit kernels as well | |
590 | * to avoid more ifdeffery. | |
a217a659 | 591 | */ |
54a3b70a | 592 | DECLARE_IDTENTRY(X86_TRAP_NMI, exc_nmi_kvm_vmx); |
a217a659 LJ |
593 | #endif |
594 | ||
6271fef0 | 595 | DECLARE_IDTENTRY_NMI(X86_TRAP_NMI, exc_nmi); |
76fdb041 | 596 | #ifdef CONFIG_XEN_PV |
f41f0824 AL |
597 | DECLARE_IDTENTRY_RAW(X86_TRAP_NMI, xenpv_exc_nmi); |
598 | #endif | |
6271fef0 | 599 | |
2bbc68f8 | 600 | /* #DB */ |
13cbc0cd | 601 | #ifdef CONFIG_X86_64 |
2bbc68f8 | 602 | DECLARE_IDTENTRY_DEBUG(X86_TRAP_DB, exc_debug); |
13cbc0cd AL |
603 | #else |
604 | DECLARE_IDTENTRY_RAW(X86_TRAP_DB, exc_debug); | |
605 | #endif | |
76fdb041 | 606 | #ifdef CONFIG_XEN_PV |
f41f0824 AL |
607 | DECLARE_IDTENTRY_RAW(X86_TRAP_DB, xenpv_exc_debug); |
608 | #endif | |
2bbc68f8 | 609 | |
c29c775a TG |
610 | /* #DF */ |
611 | DECLARE_IDTENTRY_DF(X86_TRAP_DF, exc_double_fault); | |
5b4c6d65 JG |
612 | #ifdef CONFIG_XEN_PV |
613 | DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_DF, xenpv_exc_double_fault); | |
614 | #endif | |
c29c775a | 615 | |
991625f3 PZ |
616 | /* #CP */ |
617 | #ifdef CONFIG_X86_KERNEL_IBT | |
618 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_CP, exc_control_protection); | |
619 | #endif | |
620 | ||
0786138c TL |
621 | /* #VC */ |
622 | #ifdef CONFIG_AMD_MEM_ENCRYPT | |
623 | DECLARE_IDTENTRY_VC(X86_TRAP_VC, exc_vmm_communication); | |
624 | #endif | |
625 | ||
2f6474e4 TG |
626 | #ifdef CONFIG_XEN_PV |
627 | DECLARE_IDTENTRY_XENCB(X86_TRAP_OTHER, exc_xen_hypervisor_callback); | |
2e924936 | 628 | DECLARE_IDTENTRY_RAW(X86_TRAP_OTHER, exc_xen_unknown_trap); |
2f6474e4 TG |
629 | #endif |
630 | ||
9a22bf6d KS |
631 | #ifdef CONFIG_INTEL_TDX_GUEST |
632 | DECLARE_IDTENTRY(X86_TRAP_VE, exc_virtualization_exception); | |
633 | #endif | |
634 | ||
fa5e5c40 TG |
635 | /* Device interrupts common/spurious */ |
636 | DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, common_interrupt); | |
637 | #ifdef CONFIG_X86_LOCAL_APIC | |
638 | DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, spurious_interrupt); | |
639 | #endif | |
640 | ||
db0338ee TG |
641 | /* System vector entry points */ |
642 | #ifdef CONFIG_X86_LOCAL_APIC | |
643 | DECLARE_IDTENTRY_SYSVEC(ERROR_APIC_VECTOR, sysvec_error_interrupt); | |
644 | DECLARE_IDTENTRY_SYSVEC(SPURIOUS_APIC_VECTOR, sysvec_spurious_apic_interrupt); | |
645 | DECLARE_IDTENTRY_SYSVEC(LOCAL_TIMER_VECTOR, sysvec_apic_timer_interrupt); | |
646 | DECLARE_IDTENTRY_SYSVEC(X86_PLATFORM_IPI_VECTOR, sysvec_x86_platform_ipi); | |
647 | #endif | |
648 | ||
582f9191 | 649 | #ifdef CONFIG_SMP |
13cad985 | 650 | DECLARE_IDTENTRY(RESCHEDULE_VECTOR, sysvec_reschedule_ipi); |
582f9191 TG |
651 | DECLARE_IDTENTRY_SYSVEC(IRQ_MOVE_CLEANUP_VECTOR, sysvec_irq_move_cleanup); |
652 | DECLARE_IDTENTRY_SYSVEC(REBOOT_VECTOR, sysvec_reboot); | |
653 | DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_SINGLE_VECTOR, sysvec_call_function_single); | |
654 | DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_VECTOR, sysvec_call_function); | |
655 | #endif | |
656 | ||
720909a7 | 657 | #ifdef CONFIG_X86_LOCAL_APIC |
720909a7 TG |
658 | # ifdef CONFIG_X86_MCE_THRESHOLD |
659 | DECLARE_IDTENTRY_SYSVEC(THRESHOLD_APIC_VECTOR, sysvec_threshold); | |
660 | # endif | |
661 | ||
662 | # ifdef CONFIG_X86_MCE_AMD | |
663 | DECLARE_IDTENTRY_SYSVEC(DEFERRED_ERROR_VECTOR, sysvec_deferred_error); | |
664 | # endif | |
665 | ||
666 | # ifdef CONFIG_X86_THERMAL_VECTOR | |
667 | DECLARE_IDTENTRY_SYSVEC(THERMAL_APIC_VECTOR, sysvec_thermal); | |
668 | # endif | |
669 | ||
670 | # ifdef CONFIG_IRQ_WORK | |
671 | DECLARE_IDTENTRY_SYSVEC(IRQ_WORK_VECTOR, sysvec_irq_work); | |
672 | # endif | |
673 | #endif | |
674 | ||
9c3b1f49 TG |
675 | #ifdef CONFIG_HAVE_KVM |
676 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_VECTOR, sysvec_kvm_posted_intr_ipi); | |
677 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_WAKEUP_VECTOR, sysvec_kvm_posted_intr_wakeup_ipi); | |
678 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_NESTED_VECTOR, sysvec_kvm_posted_intr_nested_ipi); | |
679 | #endif | |
680 | ||
a16be368 TG |
681 | #if IS_ENABLED(CONFIG_HYPERV) |
682 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback); | |
5769fe26 SD |
683 | DECLARE_IDTENTRY_SYSVEC(HYPERV_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment); |
684 | DECLARE_IDTENTRY_SYSVEC(HYPERV_STIMER0_VECTOR, sysvec_hyperv_stimer0); | |
a16be368 TG |
685 | #endif |
686 | ||
687 | #if IS_ENABLED(CONFIG_ACRN_GUEST) | |
688 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callback); | |
689 | #endif | |
690 | ||
cb09ea29 TG |
691 | #ifdef CONFIG_XEN_PVHVM |
692 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_xen_hvm_callback); | |
693 | #endif | |
694 | ||
26d05b36 PB |
695 | #ifdef CONFIG_KVM_GUEST |
696 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_kvm_asyncpf_interrupt); | |
697 | #endif | |
698 | ||
2f6474e4 TG |
699 | #undef X86_TRAP_OTHER |
700 | ||
53aaf262 | 701 | #endif |