Merge tag 'x86-irq-2021-06-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 29 Jun 2021 19:36:59 +0000 (12:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 29 Jun 2021 19:36:59 +0000 (12:36 -0700)
Pull x86 interrupt related updates from Thomas Gleixner:

 - Consolidate the VECTOR defines and the usage sites.

 - Cleanup GDT/IDT related code and replace open coded ASM with proper
   native helper functions.

* tag 'x86-irq-2021-06-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/kexec: Set_[gi]dt() -> native_[gi]dt_invalidate() in machine_kexec_*.c
  x86: Add native_[ig]dt_invalidate()
  x86/idt: Remove address argument from idt_invalidate()
  x86/irq: Add and use NR_EXTERNAL_VECTORS and NR_SYSTEM_VECTORS
  x86/irq: Remove unused vectors defines

1  2 
arch/x86/include/asm/desc.h
arch/x86/include/asm/idtentry.h
arch/x86/kernel/idt.c

@@@ -224,6 -224,26 +224,26 @@@ static inline void store_idt(struct des
        asm volatile("sidt %0":"=m" (*dtr));
  }
  
+ static inline void native_gdt_invalidate(void)
+ {
+       const struct desc_ptr invalid_gdt = {
+               .address = 0,
+               .size = 0
+       };
+       native_load_gdt(&invalid_gdt);
+ }
+ static inline void native_idt_invalidate(void)
+ {
+       const struct desc_ptr invalid_idt = {
+               .address = 0,
+               .size = 0
+       };
+       native_load_idt(&invalid_idt);
+ }
  /*
   * The LTR instruction marks the TSS GDT entry as busy. On 64-bit, the GDT is
   * a read-only remapping. To prevent a page fault, the GDT is switched to the
@@@ -421,10 -441,12 +441,10 @@@ extern bool idt_is_f00f_address(unsigne
  
  #ifdef CONFIG_X86_64
  extern void idt_setup_early_pf(void);
 -extern void idt_setup_ist_traps(void);
  #else
  static inline void idt_setup_early_pf(void) { }
 -static inline void idt_setup_ist_traps(void) { }
  #endif
  
- extern void idt_invalidate(void *addr);
+ extern void idt_invalidate(void);
  
  #endif /* _ASM_X86_DESC_H */
@@@ -312,8 -312,8 +312,8 @@@ static __always_inline void __##func(st
   */
  #define DECLARE_IDTENTRY_VC(vector, func)                             \
        DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func);                   \
 -      __visible noinstr void ist_##func(struct pt_regs *regs, unsigned long error_code);      \
 -      __visible noinstr void safe_stack_##func(struct pt_regs *regs, unsigned long error_code)
 +      __visible noinstr void kernel_##func(struct pt_regs *regs, unsigned long error_code);   \
 +      __visible noinstr void   user_##func(struct pt_regs *regs, unsigned long error_code)
  
  /**
   * DEFINE_IDTENTRY_IST - Emit code for IST entry points
        DEFINE_IDTENTRY_RAW_ERRORCODE(func)
  
  /**
 - * DEFINE_IDTENTRY_VC_SAFE_STACK - Emit code for VMM communication handler
 -                                 which runs on a safe stack.
 + * DEFINE_IDTENTRY_VC_KERNEL - Emit code for VMM communication handler
 +                             when raised from kernel mode
   * @func:     Function name of the entry point
   *
   * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE
   */
 -#define DEFINE_IDTENTRY_VC_SAFE_STACK(func)                           \
 -      DEFINE_IDTENTRY_RAW_ERRORCODE(safe_stack_##func)
 +#define DEFINE_IDTENTRY_VC_KERNEL(func)                               \
 +      DEFINE_IDTENTRY_RAW_ERRORCODE(kernel_##func)
  
  /**
 - * DEFINE_IDTENTRY_VC_IST - Emit code for VMM communication handler
 -                          which runs on the VC fall-back stack
 + * DEFINE_IDTENTRY_VC_USER - Emit code for VMM communication handler
 +                           when raised from user mode
   * @func:     Function name of the entry point
   *
   * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE
   */
 -#define DEFINE_IDTENTRY_VC_IST(func)                          \
 -      DEFINE_IDTENTRY_RAW_ERRORCODE(ist_##func)
 -
 -/**
 - * DEFINE_IDTENTRY_VC - Emit code for VMM communication handler
 - * @func:     Function name of the entry point
 - *
 - * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE
 - */
 -#define DEFINE_IDTENTRY_VC(func)                                      \
 -      DEFINE_IDTENTRY_RAW_ERRORCODE(func)
 +#define DEFINE_IDTENTRY_VC_USER(func)                         \
 +      DEFINE_IDTENTRY_RAW_ERRORCODE(user_##func)
  
  #else /* CONFIG_X86_64 */
  
@@@ -495,7 -504,7 +495,7 @@@ __visible noinstr void func(struct pt_r
        .align 8
  SYM_CODE_START(irq_entries_start)
      vector=FIRST_EXTERNAL_VECTOR
-     .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
+     .rept NR_EXTERNAL_VECTORS
        UNWIND_HINT_IRET_REGS
  0 :
        .byte   0x6a, vector
@@@ -511,7 -520,7 +511,7 @@@ SYM_CODE_END(irq_entries_start
        .align 8
  SYM_CODE_START(spurious_entries_start)
      vector=FIRST_SYSTEM_VECTOR
-     .rept (NR_VECTORS - FIRST_SYSTEM_VECTOR)
+     .rept NR_SYSTEM_VECTORS
        UNWIND_HINT_IRET_REGS
  0 :
        .byte   0x6a, vector
diff --combined arch/x86/kernel/idt.c
  #define SYSG(_vector, _addr)                          \
        G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL3, __KERNEL_CS)
  
 +#ifdef CONFIG_X86_64
  /*
   * Interrupt gate with interrupt stack. The _ist index is the index in
   * the tss.ist[] array, but for the descriptor it needs to start at 1.
   */
  #define ISTG(_vector, _addr, _ist)                    \
        G(_vector, _addr, _ist + 1, GATE_INTERRUPT, DPL0, __KERNEL_CS)
 +#else
 +#define ISTG(_vector, _addr, _ist)    INTG(_vector, _addr)
 +#endif
  
  /* Task gate */
  #define TSKG(_vector, _gdt)                           \
@@@ -78,7 -74,7 +78,7 @@@ static const __initconst struct idt_dat
   */
  static const __initconst struct idt_data def_idts[] = {
        INTG(X86_TRAP_DE,               asm_exc_divide_error),
 -      INTG(X86_TRAP_NMI,              asm_exc_nmi),
 +      ISTG(X86_TRAP_NMI,              asm_exc_nmi, IST_INDEX_NMI),
        INTG(X86_TRAP_BR,               asm_exc_bounds),
        INTG(X86_TRAP_UD,               asm_exc_invalid_op),
        INTG(X86_TRAP_NM,               asm_exc_device_not_available),
  #ifdef CONFIG_X86_32
        TSKG(X86_TRAP_DF,               GDT_ENTRY_DOUBLEFAULT_TSS),
  #else
 -      INTG(X86_TRAP_DF,               asm_exc_double_fault),
 +      ISTG(X86_TRAP_DF,               asm_exc_double_fault, IST_INDEX_DF),
  #endif
 -      INTG(X86_TRAP_DB,               asm_exc_debug),
 +      ISTG(X86_TRAP_DB,               asm_exc_debug, IST_INDEX_DB),
  
  #ifdef CONFIG_X86_MCE
 -      INTG(X86_TRAP_MC,               asm_exc_machine_check),
 +      ISTG(X86_TRAP_MC,               asm_exc_machine_check, IST_INDEX_MCE),
 +#endif
 +
 +#ifdef CONFIG_AMD_MEM_ENCRYPT
 +      ISTG(X86_TRAP_VC,               asm_exc_vmm_communication, IST_INDEX_VC),
  #endif
  
        SYSG(X86_TRAP_OF,               asm_exc_overflow),
@@@ -229,6 -221,22 +229,6 @@@ static const __initconst struct idt_dat
        INTG(X86_TRAP_PF,               asm_exc_page_fault),
  };
  
 -/*
 - * The exceptions which use Interrupt stacks. They are setup after
 - * cpu_init() when the TSS has been initialized.
 - */
 -static const __initconst struct idt_data ist_idts[] = {
 -      ISTG(X86_TRAP_DB,       asm_exc_debug,                  IST_INDEX_DB),
 -      ISTG(X86_TRAP_NMI,      asm_exc_nmi,                    IST_INDEX_NMI),
 -      ISTG(X86_TRAP_DF,       asm_exc_double_fault,           IST_INDEX_DF),
 -#ifdef CONFIG_X86_MCE
 -      ISTG(X86_TRAP_MC,       asm_exc_machine_check,          IST_INDEX_MCE),
 -#endif
 -#ifdef CONFIG_AMD_MEM_ENCRYPT
 -      ISTG(X86_TRAP_VC,       asm_exc_vmm_communication,      IST_INDEX_VC),
 -#endif
 -};
 -
  /**
   * idt_setup_early_pf - Initialize the idt table with early pagefault handler
   *
@@@ -246,6 -254,14 +246,6 @@@ void __init idt_setup_early_pf(void
        idt_setup_from_table(idt_table, early_pf_idts,
                             ARRAY_SIZE(early_pf_idts), true);
  }
 -
 -/**
 - * idt_setup_ist_traps - Initialize the idt table with traps using IST
 - */
 -void __init idt_setup_ist_traps(void)
 -{
 -      idt_setup_from_table(idt_table, ist_idts, ARRAY_SIZE(ist_idts), true);
 -}
  #endif
  
  static void __init idt_map_in_cea(void)
@@@ -315,11 -331,10 +315,10 @@@ void __init idt_setup_early_handler(voi
  
  /**
   * idt_invalidate - Invalidate interrupt descriptor table
-  * @addr:     The virtual address of the 'invalid' IDT
   */
- void idt_invalidate(void *addr)
+ void idt_invalidate(void)
  {
-       struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
+       static const struct desc_ptr idt = { .address = 0, .size = 0 };
  
        load_idt(&idt);
  }