irq_64.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  3. *
  4. * This file contains the lowest level x86_64-specific interrupt
  5. * entry and irq statistics code. All the remaining irq logic is
  6. * done by the generic kernel/irq/ code and in the
  7. * x86_64-specific irq controller code. (e.g. i8259.c and
  8. * io_apic.c.)
  9. */
  10. #include <linux/kernel_stat.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/seq_file.h>
  13. #include <linux/module.h>
  14. #include <linux/delay.h>
  15. #include <linux/ftrace.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/smp.h>
  18. #include <asm/io_apic.h>
  19. #include <asm/idle.h>
  20. #include <asm/apic.h>
  21. DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
  22. EXPORT_PER_CPU_SYMBOL(irq_stat);
  23. DEFINE_PER_CPU(struct pt_regs *, irq_regs);
  24. EXPORT_PER_CPU_SYMBOL(irq_regs);
  25. int sysctl_panic_on_stackoverflow;
  26. /*
  27. * Probabilistic stack overflow check:
  28. *
  29. * Only check the stack in process context, because everything else
  30. * runs on the big interrupt stacks. Checking reliably is too expensive,
  31. * so we just check from interrupts.
  32. */
  33. static inline void stack_overflow_check(struct pt_regs *regs)
  34. {
  35. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  36. #define STACK_TOP_MARGIN 128
  37. struct orig_ist *oist;
  38. u64 irq_stack_top, irq_stack_bottom;
  39. u64 estack_top, estack_bottom;
  40. u64 curbase = (u64)task_stack_page(current);
  41. if (user_mode_vm(regs))
  42. return;
  43. if (regs->sp >= curbase + sizeof(struct thread_info) +
  44. sizeof(struct pt_regs) + STACK_TOP_MARGIN &&
  45. regs->sp <= curbase + THREAD_SIZE)
  46. return;
  47. irq_stack_top = (u64)__get_cpu_var(irq_stack_union.irq_stack) +
  48. STACK_TOP_MARGIN;
  49. irq_stack_bottom = (u64)__get_cpu_var(irq_stack_ptr);
  50. if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom)
  51. return;
  52. oist = &__get_cpu_var(orig_ist);
  53. estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN;
  54. estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1];
  55. if (regs->sp >= estack_top && regs->sp <= estack_bottom)
  56. return;
  57. WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx,irq stk top-bottom:%Lx-%Lx,exception stk top-bottom:%Lx-%Lx)\n",
  58. current->comm, curbase, regs->sp,
  59. irq_stack_top, irq_stack_bottom,
  60. estack_top, estack_bottom);
  61. if (sysctl_panic_on_stackoverflow)
  62. panic("low stack detected by irq handler - check messages\n");
  63. #endif
  64. }
  65. bool handle_irq(unsigned irq, struct pt_regs *regs)
  66. {
  67. struct irq_desc *desc;
  68. stack_overflow_check(regs);
  69. desc = irq_to_desc(irq);
  70. if (unlikely(!desc))
  71. return false;
  72. generic_handle_irq_desc(irq, desc);
  73. return true;
  74. }
  75. extern void call_softirq(void);
  76. asmlinkage void do_softirq(void)
  77. {
  78. __u32 pending;
  79. unsigned long flags;
  80. if (in_interrupt())
  81. return;
  82. local_irq_save(flags);
  83. pending = local_softirq_pending();
  84. /* Switch to interrupt stack */
  85. if (pending) {
  86. call_softirq();
  87. WARN_ON_ONCE(softirq_count());
  88. }
  89. local_irq_restore(flags);
  90. }