idtentry.h 22 KB

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