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