irqflags.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef _X86_IRQFLAGS_H_
  2. #define _X86_IRQFLAGS_H_
  3. #include <asm/processor-flags.h>
  4. #ifndef __ASSEMBLY__
  5. /*
  6. * Interrupt control:
  7. */
  8. static inline unsigned long native_save_fl(void)
  9. {
  10. unsigned long flags;
  11. asm volatile("# __raw_save_flags\n\t"
  12. "pushf ; pop %0"
  13. : "=g" (flags)
  14. : /* no input */
  15. : "memory");
  16. return flags;
  17. }
  18. static inline void native_restore_fl(unsigned long flags)
  19. {
  20. asm volatile("push %0 ; popf"
  21. : /* no output */
  22. :"g" (flags)
  23. :"memory", "cc");
  24. }
  25. static inline void native_irq_disable(void)
  26. {
  27. asm volatile("cli": : :"memory");
  28. }
  29. static inline void native_irq_enable(void)
  30. {
  31. asm volatile("sti": : :"memory");
  32. }
  33. static inline void native_safe_halt(void)
  34. {
  35. asm volatile("sti; hlt": : :"memory");
  36. }
  37. static inline void native_halt(void)
  38. {
  39. asm volatile("hlt": : :"memory");
  40. }
  41. #endif
  42. #ifdef CONFIG_PARAVIRT
  43. #include <asm/paravirt.h>
  44. #else
  45. #ifndef __ASSEMBLY__
  46. static inline unsigned long __raw_local_save_flags(void)
  47. {
  48. return native_save_fl();
  49. }
  50. static inline void raw_local_irq_restore(unsigned long flags)
  51. {
  52. native_restore_fl(flags);
  53. }
  54. static inline void raw_local_irq_disable(void)
  55. {
  56. native_irq_disable();
  57. }
  58. static inline void raw_local_irq_enable(void)
  59. {
  60. native_irq_enable();
  61. }
  62. /*
  63. * Used in the idle loop; sti takes one instruction cycle
  64. * to complete:
  65. */
  66. static inline void raw_safe_halt(void)
  67. {
  68. native_safe_halt();
  69. }
  70. /*
  71. * Used when interrupts are already enabled or to
  72. * shutdown the processor:
  73. */
  74. static inline void halt(void)
  75. {
  76. native_halt();
  77. }
  78. /*
  79. * For spinlocks, etc:
  80. */
  81. static inline unsigned long __raw_local_irq_save(void)
  82. {
  83. unsigned long flags = __raw_local_save_flags();
  84. raw_local_irq_disable();
  85. return flags;
  86. }
  87. #else
  88. #define ENABLE_INTERRUPTS(x) sti
  89. #define DISABLE_INTERRUPTS(x) cli
  90. #ifdef CONFIG_X86_64
  91. #define INTERRUPT_RETURN iretq
  92. #define USERGS_SYSRET64 \
  93. swapgs; \
  94. sysretq;
  95. #define USERGS_SYSRET32 \
  96. swapgs; \
  97. sysretl
  98. #define ENABLE_INTERRUPTS_SYSEXIT32 \
  99. swapgs; \
  100. sti; \
  101. sysexit
  102. #else
  103. #define INTERRUPT_RETURN iret
  104. #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
  105. #define GET_CR0_INTO_EAX movl %cr0, %eax
  106. #endif
  107. #endif /* __ASSEMBLY__ */
  108. #endif /* CONFIG_PARAVIRT */
  109. #ifndef __ASSEMBLY__
  110. #define raw_local_save_flags(flags) \
  111. do { (flags) = __raw_local_save_flags(); } while (0)
  112. #define raw_local_irq_save(flags) \
  113. do { (flags) = __raw_local_irq_save(); } while (0)
  114. static inline int raw_irqs_disabled_flags(unsigned long flags)
  115. {
  116. return !(flags & X86_EFLAGS_IF);
  117. }
  118. static inline int raw_irqs_disabled(void)
  119. {
  120. unsigned long flags = __raw_local_save_flags();
  121. return raw_irqs_disabled_flags(flags);
  122. }
  123. /*
  124. * makes the traced hardirq state match with the machine state
  125. *
  126. * should be a rarely used function, only in places where its
  127. * otherwise impossible to know the irq state, like in traps.
  128. */
  129. static inline void trace_hardirqs_fixup_flags(unsigned long flags)
  130. {
  131. if (raw_irqs_disabled_flags(flags))
  132. trace_hardirqs_off();
  133. else
  134. trace_hardirqs_on();
  135. }
  136. static inline void trace_hardirqs_fixup(void)
  137. {
  138. unsigned long flags = __raw_local_save_flags();
  139. trace_hardirqs_fixup_flags(flags);
  140. }
  141. #else
  142. #ifdef CONFIG_X86_64
  143. /*
  144. * Currently paravirt can't handle swapgs nicely when we
  145. * don't have a stack we can rely on (such as a user space
  146. * stack). So we either find a way around these or just fault
  147. * and emulate if a guest tries to call swapgs directly.
  148. *
  149. * Either way, this is a good way to document that we don't
  150. * have a reliable stack. x86_64 only.
  151. */
  152. #define SWAPGS_UNSAFE_STACK swapgs
  153. #define ARCH_TRACE_IRQS_ON call trace_hardirqs_on_thunk
  154. #define ARCH_TRACE_IRQS_OFF call trace_hardirqs_off_thunk
  155. #define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
  156. #define ARCH_LOCKDEP_SYS_EXIT_IRQ \
  157. TRACE_IRQS_ON; \
  158. sti; \
  159. SAVE_REST; \
  160. LOCKDEP_SYS_EXIT; \
  161. RESTORE_REST; \
  162. cli; \
  163. TRACE_IRQS_OFF;
  164. #else
  165. #define ARCH_TRACE_IRQS_ON \
  166. pushl %eax; \
  167. pushl %ecx; \
  168. pushl %edx; \
  169. call trace_hardirqs_on; \
  170. popl %edx; \
  171. popl %ecx; \
  172. popl %eax;
  173. #define ARCH_TRACE_IRQS_OFF \
  174. pushl %eax; \
  175. pushl %ecx; \
  176. pushl %edx; \
  177. call trace_hardirqs_off; \
  178. popl %edx; \
  179. popl %ecx; \
  180. popl %eax;
  181. #define ARCH_LOCKDEP_SYS_EXIT \
  182. pushl %eax; \
  183. pushl %ecx; \
  184. pushl %edx; \
  185. call lockdep_sys_exit; \
  186. popl %edx; \
  187. popl %ecx; \
  188. popl %eax;
  189. #define ARCH_LOCKDEP_SYS_EXIT_IRQ
  190. #endif
  191. #ifdef CONFIG_TRACE_IRQFLAGS
  192. # define TRACE_IRQS_ON ARCH_TRACE_IRQS_ON
  193. # define TRACE_IRQS_OFF ARCH_TRACE_IRQS_OFF
  194. #else
  195. # define TRACE_IRQS_ON
  196. # define TRACE_IRQS_OFF
  197. #endif
  198. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  199. # define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
  200. # define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
  201. # else
  202. # define LOCKDEP_SYS_EXIT
  203. # define LOCKDEP_SYS_EXIT_IRQ
  204. # endif
  205. #endif /* __ASSEMBLY__ */
  206. #endif