0001
0002 #ifndef _ASM_X86_IDTENTRY_H
0003 #define _ASM_X86_IDTENTRY_H
0004
0005
0006 #include <asm/trapnr.h>
0007
0008 #define IDT_ALIGN (8 * (1 + HAS_KERNEL_IBT))
0009
0010 #ifndef __ASSEMBLY__
0011 #include <linux/entry-common.h>
0012 #include <linux/hardirq.h>
0013
0014 #include <asm/irq_stack.h>
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #define DECLARE_IDTENTRY(vector, func) \
0032 asmlinkage void asm_##func(void); \
0033 asmlinkage void xen_asm_##func(void); \
0034 __visible void func(struct pt_regs *regs)
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 #define DEFINE_IDTENTRY(func) \
0050 static __always_inline void __##func(struct pt_regs *regs); \
0051 \
0052 __visible noinstr void func(struct pt_regs *regs) \
0053 { \
0054 irqentry_state_t state = irqentry_enter(regs); \
0055 \
0056 instrumentation_begin(); \
0057 __##func (regs); \
0058 instrumentation_end(); \
0059 irqentry_exit(regs, state); \
0060 } \
0061 \
0062 static __always_inline void __##func(struct pt_regs *regs)
0063
0064
0065 #define DECLARE_IDTENTRY_SW DECLARE_IDTENTRY
0066 #define DEFINE_IDTENTRY_SW DEFINE_IDTENTRY
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \
0083 asmlinkage void asm_##func(void); \
0084 asmlinkage void xen_asm_##func(void); \
0085 __visible void func(struct pt_regs *regs, unsigned long error_code)
0086
0087
0088
0089
0090
0091
0092
0093
0094 #define DEFINE_IDTENTRY_ERRORCODE(func) \
0095 static __always_inline void __##func(struct pt_regs *regs, \
0096 unsigned long error_code); \
0097 \
0098 __visible noinstr void func(struct pt_regs *regs, \
0099 unsigned long error_code) \
0100 { \
0101 irqentry_state_t state = irqentry_enter(regs); \
0102 \
0103 instrumentation_begin(); \
0104 __##func (regs, error_code); \
0105 instrumentation_end(); \
0106 irqentry_exit(regs, state); \
0107 } \
0108 \
0109 static __always_inline void __##func(struct pt_regs *regs, \
0110 unsigned long error_code)
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 #define DECLARE_IDTENTRY_RAW(vector, func) \
0121 DECLARE_IDTENTRY(vector, func)
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 #define DEFINE_IDTENTRY_RAW(func) \
0138 __visible noinstr void func(struct pt_regs *regs)
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \
0149 DECLARE_IDTENTRY_ERRORCODE(vector, func)
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 #define DEFINE_IDTENTRY_RAW_ERRORCODE(func) \
0166 __visible noinstr void func(struct pt_regs *regs, unsigned long error_code)
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 #define DECLARE_IDTENTRY_IRQ(vector, func) \
0177 DECLARE_IDTENTRY_ERRORCODE(vector, func)
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 #define DEFINE_IDTENTRY_IRQ(func) \
0192 static void __##func(struct pt_regs *regs, u32 vector); \
0193 \
0194 __visible noinstr void func(struct pt_regs *regs, \
0195 unsigned long error_code) \
0196 { \
0197 irqentry_state_t state = irqentry_enter(regs); \
0198 u32 vector = (u32)(u8)error_code; \
0199 \
0200 instrumentation_begin(); \
0201 kvm_set_cpu_l1tf_flush_l1d(); \
0202 run_irq_on_irqstack_cond(__##func, regs, vector); \
0203 instrumentation_end(); \
0204 irqentry_exit(regs, state); \
0205 } \
0206 \
0207 static noinline void __##func(struct pt_regs *regs, u32 vector)
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221 #define DECLARE_IDTENTRY_SYSVEC(vector, func) \
0222 DECLARE_IDTENTRY(vector, func)
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 #define DEFINE_IDTENTRY_SYSVEC(func) \
0234 static void __##func(struct pt_regs *regs); \
0235 \
0236 __visible noinstr void func(struct pt_regs *regs) \
0237 { \
0238 irqentry_state_t state = irqentry_enter(regs); \
0239 \
0240 instrumentation_begin(); \
0241 kvm_set_cpu_l1tf_flush_l1d(); \
0242 run_sysvec_on_irqstack_cond(__##func, regs); \
0243 instrumentation_end(); \
0244 irqentry_exit(regs, state); \
0245 } \
0246 \
0247 static noinline void __##func(struct pt_regs *regs)
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 #define DEFINE_IDTENTRY_SYSVEC_SIMPLE(func) \
0261 static __always_inline void __##func(struct pt_regs *regs); \
0262 \
0263 __visible noinstr void func(struct pt_regs *regs) \
0264 { \
0265 irqentry_state_t state = irqentry_enter(regs); \
0266 \
0267 instrumentation_begin(); \
0268 __irq_enter_raw(); \
0269 kvm_set_cpu_l1tf_flush_l1d(); \
0270 __##func (regs); \
0271 __irq_exit_raw(); \
0272 instrumentation_end(); \
0273 irqentry_exit(regs, state); \
0274 } \
0275 \
0276 static __always_inline void __##func(struct pt_regs *regs)
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291 #define DECLARE_IDTENTRY_XENCB(vector, func) \
0292 DECLARE_IDTENTRY(vector, func)
0293
0294 #ifdef CONFIG_X86_64
0295
0296
0297
0298
0299
0300
0301
0302
0303 #define DECLARE_IDTENTRY_IST(vector, func) \
0304 DECLARE_IDTENTRY_RAW(vector, func); \
0305 __visible void noist_##func(struct pt_regs *regs)
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 #define DECLARE_IDTENTRY_VC(vector, func) \
0316 DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); \
0317 __visible noinstr void kernel_##func(struct pt_regs *regs, unsigned long error_code); \
0318 __visible noinstr void user_##func(struct pt_regs *regs, unsigned long error_code)
0319
0320
0321
0322
0323
0324
0325
0326 #define DEFINE_IDTENTRY_IST(func) \
0327 DEFINE_IDTENTRY_RAW(func)
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337 #define DEFINE_IDTENTRY_NOIST(func) \
0338 DEFINE_IDTENTRY_RAW(noist_##func)
0339
0340
0341
0342
0343
0344
0345
0346
0347 #define DECLARE_IDTENTRY_DF(vector, func) \
0348 DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func)
0349
0350
0351
0352
0353
0354
0355
0356 #define DEFINE_IDTENTRY_DF(func) \
0357 DEFINE_IDTENTRY_RAW_ERRORCODE(func)
0358
0359
0360
0361
0362
0363
0364
0365
0366 #define DEFINE_IDTENTRY_VC_KERNEL(func) \
0367 DEFINE_IDTENTRY_RAW_ERRORCODE(kernel_##func)
0368
0369
0370
0371
0372
0373
0374
0375
0376 #define DEFINE_IDTENTRY_VC_USER(func) \
0377 DEFINE_IDTENTRY_RAW_ERRORCODE(user_##func)
0378
0379 #else
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390 #define DECLARE_IDTENTRY_DF(vector, func) \
0391 asmlinkage void asm_##func(void); \
0392 __visible void func(struct pt_regs *regs, \
0393 unsigned long error_code, \
0394 unsigned long address)
0395
0396
0397
0398
0399
0400
0401
0402
0403 #define DEFINE_IDTENTRY_DF(func) \
0404 __visible noinstr void func(struct pt_regs *regs, \
0405 unsigned long error_code, \
0406 unsigned long address)
0407
0408 #endif
0409
0410
0411 #define DECLARE_IDTENTRY_NMI DECLARE_IDTENTRY_RAW
0412 #define DEFINE_IDTENTRY_NMI DEFINE_IDTENTRY_RAW
0413
0414 #ifdef CONFIG_X86_64
0415 #define DECLARE_IDTENTRY_MCE DECLARE_IDTENTRY_IST
0416 #define DEFINE_IDTENTRY_MCE DEFINE_IDTENTRY_IST
0417 #define DEFINE_IDTENTRY_MCE_USER DEFINE_IDTENTRY_NOIST
0418
0419 #define DECLARE_IDTENTRY_DEBUG DECLARE_IDTENTRY_IST
0420 #define DEFINE_IDTENTRY_DEBUG DEFINE_IDTENTRY_IST
0421 #define DEFINE_IDTENTRY_DEBUG_USER DEFINE_IDTENTRY_NOIST
0422 #endif
0423
0424 #else
0425
0426
0427
0428
0429 #define DECLARE_IDTENTRY(vector, func) \
0430 idtentry vector asm_##func func has_error_code=0
0431
0432 #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \
0433 idtentry vector asm_##func func has_error_code=1
0434
0435
0436 #define DECLARE_IDTENTRY_SW(vector, func)
0437
0438 #define DECLARE_IDTENTRY_RAW(vector, func) \
0439 DECLARE_IDTENTRY(vector, func)
0440
0441 #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \
0442 DECLARE_IDTENTRY_ERRORCODE(vector, func)
0443
0444
0445 #define DECLARE_IDTENTRY_IRQ(vector, func) \
0446 idtentry_irq vector func
0447
0448
0449 #define DECLARE_IDTENTRY_SYSVEC(vector, func) \
0450 idtentry_sysvec vector func
0451
0452 #ifdef CONFIG_X86_64
0453 # define DECLARE_IDTENTRY_MCE(vector, func) \
0454 idtentry_mce_db vector asm_##func func
0455
0456 # define DECLARE_IDTENTRY_DEBUG(vector, func) \
0457 idtentry_mce_db vector asm_##func func
0458
0459 # define DECLARE_IDTENTRY_DF(vector, func) \
0460 idtentry_df vector asm_##func func
0461
0462 # define DECLARE_IDTENTRY_XENCB(vector, func) \
0463 DECLARE_IDTENTRY(vector, func)
0464
0465 # define DECLARE_IDTENTRY_VC(vector, func) \
0466 idtentry_vc vector asm_##func func
0467
0468 #else
0469 # define DECLARE_IDTENTRY_MCE(vector, func) \
0470 DECLARE_IDTENTRY(vector, func)
0471
0472
0473 # define DECLARE_IDTENTRY_DF(vector, func)
0474
0475
0476 # define DECLARE_IDTENTRY_XENCB(vector, func)
0477
0478 #endif
0479
0480
0481 #define DECLARE_IDTENTRY_NMI(vector, func)
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497 .align IDT_ALIGN
0498 SYM_CODE_START(irq_entries_start)
0499 vector=FIRST_EXTERNAL_VECTOR
0500 .rept NR_EXTERNAL_VECTORS
0501 UNWIND_HINT_IRET_REGS
0502 0 :
0503 ENDBR
0504 .byte 0x6a, vector
0505 jmp asm_common_interrupt
0506
0507 .fill 0b + IDT_ALIGN - ., 1, 0xcc
0508 vector = vector+1
0509 .endr
0510 SYM_CODE_END(irq_entries_start)
0511
0512 #ifdef CONFIG_X86_LOCAL_APIC
0513 .align IDT_ALIGN
0514 SYM_CODE_START(spurious_entries_start)
0515 vector=FIRST_SYSTEM_VECTOR
0516 .rept NR_SYSTEM_VECTORS
0517 UNWIND_HINT_IRET_REGS
0518 0 :
0519 ENDBR
0520 .byte 0x6a, vector
0521 jmp asm_spurious_interrupt
0522
0523 .fill 0b + IDT_ALIGN - ., 1, 0xcc
0524 vector = vector+1
0525 .endr
0526 SYM_CODE_END(spurious_entries_start)
0527 #endif
0528
0529 #endif
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545 #define X86_TRAP_OTHER 0xFFFF
0546
0547
0548 DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error);
0549 DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow);
0550 DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds);
0551 DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available);
0552 DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);
0553 DECLARE_IDTENTRY(X86_TRAP_SPURIOUS, exc_spurious_interrupt_bug);
0554 DECLARE_IDTENTRY(X86_TRAP_MF, exc_coprocessor_error);
0555 DECLARE_IDTENTRY(X86_TRAP_XF, exc_simd_coprocessor_error);
0556
0557
0558 DECLARE_IDTENTRY_SW(X86_TRAP_IRET, iret_error);
0559
0560
0561 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss);
0562 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_NP, exc_segment_not_present);
0563 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_SS, exc_stack_segment);
0564 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_GP, exc_general_protection);
0565 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_AC, exc_alignment_check);
0566
0567
0568 DECLARE_IDTENTRY_RAW(X86_TRAP_UD, exc_invalid_op);
0569 DECLARE_IDTENTRY_RAW(X86_TRAP_BP, exc_int3);
0570 DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_PF, exc_page_fault);
0571
0572 #ifdef CONFIG_X86_MCE
0573 #ifdef CONFIG_X86_64
0574 DECLARE_IDTENTRY_MCE(X86_TRAP_MC, exc_machine_check);
0575 #else
0576 DECLARE_IDTENTRY_RAW(X86_TRAP_MC, exc_machine_check);
0577 #endif
0578 #ifdef CONFIG_XEN_PV
0579 DECLARE_IDTENTRY_RAW(X86_TRAP_MC, xenpv_exc_machine_check);
0580 #endif
0581 #endif
0582
0583
0584
0585 #if defined(CONFIG_X86_64) && IS_ENABLED(CONFIG_KVM_INTEL)
0586
0587
0588
0589
0590
0591
0592
0593
0594 DECLARE_IDTENTRY(X86_TRAP_NMI, exc_nmi_noist);
0595 #else
0596 #define asm_exc_nmi_noist asm_exc_nmi
0597 #endif
0598
0599 DECLARE_IDTENTRY_NMI(X86_TRAP_NMI, exc_nmi);
0600 #ifdef CONFIG_XEN_PV
0601 DECLARE_IDTENTRY_RAW(X86_TRAP_NMI, xenpv_exc_nmi);
0602 #endif
0603
0604
0605 #ifdef CONFIG_X86_64
0606 DECLARE_IDTENTRY_DEBUG(X86_TRAP_DB, exc_debug);
0607 #else
0608 DECLARE_IDTENTRY_RAW(X86_TRAP_DB, exc_debug);
0609 #endif
0610 #ifdef CONFIG_XEN_PV
0611 DECLARE_IDTENTRY_RAW(X86_TRAP_DB, xenpv_exc_debug);
0612 #endif
0613
0614
0615 DECLARE_IDTENTRY_DF(X86_TRAP_DF, exc_double_fault);
0616 #ifdef CONFIG_XEN_PV
0617 DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_DF, xenpv_exc_double_fault);
0618 #endif
0619
0620
0621 #ifdef CONFIG_X86_KERNEL_IBT
0622 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_CP, exc_control_protection);
0623 #endif
0624
0625
0626 #ifdef CONFIG_AMD_MEM_ENCRYPT
0627 DECLARE_IDTENTRY_VC(X86_TRAP_VC, exc_vmm_communication);
0628 #endif
0629
0630 #ifdef CONFIG_XEN_PV
0631 DECLARE_IDTENTRY_XENCB(X86_TRAP_OTHER, exc_xen_hypervisor_callback);
0632 DECLARE_IDTENTRY_RAW(X86_TRAP_OTHER, exc_xen_unknown_trap);
0633 #endif
0634
0635 #ifdef CONFIG_INTEL_TDX_GUEST
0636 DECLARE_IDTENTRY(X86_TRAP_VE, exc_virtualization_exception);
0637 #endif
0638
0639
0640 DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, common_interrupt);
0641 #ifdef CONFIG_X86_LOCAL_APIC
0642 DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, spurious_interrupt);
0643 #endif
0644
0645
0646 #ifdef CONFIG_X86_LOCAL_APIC
0647 DECLARE_IDTENTRY_SYSVEC(ERROR_APIC_VECTOR, sysvec_error_interrupt);
0648 DECLARE_IDTENTRY_SYSVEC(SPURIOUS_APIC_VECTOR, sysvec_spurious_apic_interrupt);
0649 DECLARE_IDTENTRY_SYSVEC(LOCAL_TIMER_VECTOR, sysvec_apic_timer_interrupt);
0650 DECLARE_IDTENTRY_SYSVEC(X86_PLATFORM_IPI_VECTOR, sysvec_x86_platform_ipi);
0651 #endif
0652
0653 #ifdef CONFIG_SMP
0654 DECLARE_IDTENTRY(RESCHEDULE_VECTOR, sysvec_reschedule_ipi);
0655 DECLARE_IDTENTRY_SYSVEC(IRQ_MOVE_CLEANUP_VECTOR, sysvec_irq_move_cleanup);
0656 DECLARE_IDTENTRY_SYSVEC(REBOOT_VECTOR, sysvec_reboot);
0657 DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_SINGLE_VECTOR, sysvec_call_function_single);
0658 DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_VECTOR, sysvec_call_function);
0659 #endif
0660
0661 #ifdef CONFIG_X86_LOCAL_APIC
0662 # ifdef CONFIG_X86_MCE_THRESHOLD
0663 DECLARE_IDTENTRY_SYSVEC(THRESHOLD_APIC_VECTOR, sysvec_threshold);
0664 # endif
0665
0666 # ifdef CONFIG_X86_MCE_AMD
0667 DECLARE_IDTENTRY_SYSVEC(DEFERRED_ERROR_VECTOR, sysvec_deferred_error);
0668 # endif
0669
0670 # ifdef CONFIG_X86_THERMAL_VECTOR
0671 DECLARE_IDTENTRY_SYSVEC(THERMAL_APIC_VECTOR, sysvec_thermal);
0672 # endif
0673
0674 # ifdef CONFIG_IRQ_WORK
0675 DECLARE_IDTENTRY_SYSVEC(IRQ_WORK_VECTOR, sysvec_irq_work);
0676 # endif
0677 #endif
0678
0679 #ifdef CONFIG_HAVE_KVM
0680 DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_VECTOR, sysvec_kvm_posted_intr_ipi);
0681 DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_WAKEUP_VECTOR, sysvec_kvm_posted_intr_wakeup_ipi);
0682 DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_NESTED_VECTOR, sysvec_kvm_posted_intr_nested_ipi);
0683 #endif
0684
0685 #if IS_ENABLED(CONFIG_HYPERV)
0686 DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback);
0687 DECLARE_IDTENTRY_SYSVEC(HYPERV_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment);
0688 DECLARE_IDTENTRY_SYSVEC(HYPERV_STIMER0_VECTOR, sysvec_hyperv_stimer0);
0689 #endif
0690
0691 #if IS_ENABLED(CONFIG_ACRN_GUEST)
0692 DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callback);
0693 #endif
0694
0695 #ifdef CONFIG_XEN_PVHVM
0696 DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_xen_hvm_callback);
0697 #endif
0698
0699 #ifdef CONFIG_KVM_GUEST
0700 DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_kvm_asyncpf_interrupt);
0701 #endif
0702
0703 #undef X86_TRAP_OTHER
0704
0705 #endif