Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 2 | #ifndef _X86_IRQFLAGS_H_ |
| 3 | #define _X86_IRQFLAGS_H_ |
| 4 | |
| 5 | #include <asm/processor-flags.h> |
| 6 | |
| 7 | #ifndef __ASSEMBLY__ |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 8 | |
| 9 | /* Provide __cpuidle; we can't safely include <linux/cpu.h> */ |
| 10 | #define __cpuidle __attribute__((__section__(".cpuidle.text"))) |
| 11 | |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 12 | /* |
| 13 | * Interrupt control: |
| 14 | */ |
| 15 | |
| 16 | static inline unsigned long native_save_fl(void) |
| 17 | { |
| 18 | unsigned long flags; |
| 19 | |
H. Peter Anvin | f1f029c | 2009-08-03 16:33:40 -0700 | [diff] [blame] | 20 | /* |
H. Peter Anvin | ab94fcf | 2009-08-25 16:47:16 -0700 | [diff] [blame] | 21 | * "=rm" is safe here, because "pop" adjusts the stack before |
| 22 | * it evaluates its effective address -- this is part of the |
| 23 | * documented behavior of the "pop" instruction. |
H. Peter Anvin | f1f029c | 2009-08-03 16:33:40 -0700 | [diff] [blame] | 24 | */ |
Joe Perches | cf7f719 | 2008-03-23 01:02:30 -0700 | [diff] [blame] | 25 | asm volatile("# __raw_save_flags\n\t" |
| 26 | "pushf ; pop %0" |
H. Peter Anvin | ab94fcf | 2009-08-25 16:47:16 -0700 | [diff] [blame] | 27 | : "=rm" (flags) |
Joe Perches | cf7f719 | 2008-03-23 01:02:30 -0700 | [diff] [blame] | 28 | : /* no input */ |
| 29 | : "memory"); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 30 | |
| 31 | return flags; |
| 32 | } |
| 33 | |
| 34 | static inline void native_restore_fl(unsigned long flags) |
| 35 | { |
Joe Perches | cf7f719 | 2008-03-23 01:02:30 -0700 | [diff] [blame] | 36 | asm volatile("push %0 ; popf" |
| 37 | : /* no output */ |
| 38 | :"g" (flags) |
| 39 | :"memory", "cc"); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static inline void native_irq_disable(void) |
| 43 | { |
| 44 | asm volatile("cli": : :"memory"); |
| 45 | } |
| 46 | |
| 47 | static inline void native_irq_enable(void) |
| 48 | { |
| 49 | asm volatile("sti": : :"memory"); |
| 50 | } |
| 51 | |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 52 | static inline __cpuidle void native_safe_halt(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 53 | { |
| 54 | asm volatile("sti; hlt": : :"memory"); |
| 55 | } |
| 56 | |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 57 | static inline __cpuidle void native_halt(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 58 | { |
| 59 | asm volatile("hlt": : :"memory"); |
| 60 | } |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | #ifdef CONFIG_PARAVIRT |
| 65 | #include <asm/paravirt.h> |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 66 | #else |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 67 | #ifndef __ASSEMBLY__ |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 68 | #include <linux/types.h> |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 69 | |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 70 | static inline notrace unsigned long arch_local_save_flags(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 71 | { |
| 72 | return native_save_fl(); |
| 73 | } |
| 74 | |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 75 | static inline notrace void arch_local_irq_restore(unsigned long flags) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 76 | { |
| 77 | native_restore_fl(flags); |
| 78 | } |
| 79 | |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 80 | static inline notrace void arch_local_irq_disable(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 81 | { |
| 82 | native_irq_disable(); |
| 83 | } |
| 84 | |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 85 | static inline notrace void arch_local_irq_enable(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 86 | { |
| 87 | native_irq_enable(); |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Used in the idle loop; sti takes one instruction cycle |
| 92 | * to complete: |
| 93 | */ |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 94 | static inline __cpuidle void arch_safe_halt(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 95 | { |
| 96 | native_safe_halt(); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Used when interrupts are already enabled or to |
| 101 | * shutdown the processor: |
| 102 | */ |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 103 | static inline __cpuidle void halt(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 104 | { |
| 105 | native_halt(); |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * For spinlocks, etc: |
| 110 | */ |
Steven Rostedt | e08fbb7 | 2011-07-01 23:04:36 -0400 | [diff] [blame] | 111 | static inline notrace unsigned long arch_local_irq_save(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 112 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 113 | unsigned long flags = arch_local_save_flags(); |
| 114 | arch_local_irq_disable(); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 115 | return flags; |
| 116 | } |
| 117 | #else |
| 118 | |
| 119 | #define ENABLE_INTERRUPTS(x) sti |
| 120 | #define DISABLE_INTERRUPTS(x) cli |
| 121 | |
| 122 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | df366e9 | 2008-06-27 12:04:03 -0700 | [diff] [blame] | 123 | #define SWAPGS swapgs |
| 124 | /* |
| 125 | * Currently paravirt can't handle swapgs nicely when we |
| 126 | * don't have a stack we can rely on (such as a user space |
| 127 | * stack). So we either find a way around these or just fault |
| 128 | * and emulate if a guest tries to call swapgs directly. |
| 129 | * |
| 130 | * Either way, this is a good way to document that we don't |
| 131 | * have a reliable stack. x86_64 only. |
| 132 | */ |
Jeremy Fitzhardinge | a00394f | 2008-06-25 00:19:30 -0400 | [diff] [blame] | 133 | #define SWAPGS_UNSAFE_STACK swapgs |
Jeremy Fitzhardinge | df366e9 | 2008-06-27 12:04:03 -0700 | [diff] [blame] | 134 | |
| 135 | #define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */ |
| 136 | |
Andy Lutomirski | 7209a75 | 2014-07-23 08:34:11 -0700 | [diff] [blame] | 137 | #define INTERRUPT_RETURN jmp native_iret |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 138 | #define USERGS_SYSRET64 \ |
| 139 | swapgs; \ |
| 140 | sysretq; |
| 141 | #define USERGS_SYSRET32 \ |
| 142 | swapgs; \ |
| 143 | sysretl |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 144 | |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 145 | #else |
| 146 | #define INTERRUPT_RETURN iret |
Jeremy Fitzhardinge | d75cd22 | 2008-06-25 00:19:26 -0400 | [diff] [blame] | 147 | #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 148 | #define GET_CR0_INTO_EAX movl %cr0, %eax |
| 149 | #endif |
| 150 | |
| 151 | |
| 152 | #endif /* __ASSEMBLY__ */ |
| 153 | #endif /* CONFIG_PARAVIRT */ |
| 154 | |
| 155 | #ifndef __ASSEMBLY__ |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 156 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 157 | { |
| 158 | return !(flags & X86_EFLAGS_IF); |
| 159 | } |
| 160 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 161 | static inline int arch_irqs_disabled(void) |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 162 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 163 | unsigned long flags = arch_local_save_flags(); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 164 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 165 | return arch_irqs_disabled_flags(flags); |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 166 | } |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 167 | #endif /* !__ASSEMBLY__ */ |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 168 | |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 169 | #ifdef __ASSEMBLY__ |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 170 | #ifdef CONFIG_TRACE_IRQFLAGS |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 171 | # define TRACE_IRQS_ON call trace_hardirqs_on_thunk; |
| 172 | # define TRACE_IRQS_OFF call trace_hardirqs_off_thunk; |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 173 | #else |
| 174 | # define TRACE_IRQS_ON |
| 175 | # define TRACE_IRQS_OFF |
| 176 | #endif |
| 177 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 178 | # ifdef CONFIG_X86_64 |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 179 | # define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk |
| 180 | # define LOCKDEP_SYS_EXIT_IRQ \ |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 181 | TRACE_IRQS_ON; \ |
| 182 | sti; \ |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 183 | call lockdep_sys_exit_thunk; \ |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 184 | cli; \ |
| 185 | TRACE_IRQS_OFF; |
| 186 | # else |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 187 | # define LOCKDEP_SYS_EXIT \ |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 188 | pushl %eax; \ |
| 189 | pushl %ecx; \ |
| 190 | pushl %edx; \ |
| 191 | call lockdep_sys_exit; \ |
| 192 | popl %edx; \ |
| 193 | popl %ecx; \ |
| 194 | popl %eax; |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 195 | # define LOCKDEP_SYS_EXIT_IRQ |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 196 | # endif |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 197 | #else |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 198 | # define LOCKDEP_SYS_EXIT |
| 199 | # define LOCKDEP_SYS_EXIT_IRQ |
Denys Vlasenko | 7dc7cc0 | 2015-03-25 21:14:27 +0100 | [diff] [blame] | 200 | #endif |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 201 | #endif /* __ASSEMBLY__ */ |
Denys Vlasenko | 40e2ec6 | 2015-03-25 21:14:26 +0100 | [diff] [blame] | 202 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 203 | #endif |