1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _X86_IRQFLAGS_H_
3 #define _X86_IRQFLAGS_H_
5 #include <asm/processor-flags.h>
9 #include <asm/nospec-branch.h>
11 /* Provide __cpuidle; we can't safely include <linux/cpu.h> */
12 #define __cpuidle __section(".cpuidle.text")
18 /* Declaration required for gcc < 4.9 to prevent -Werror=missing-prototypes */
19 extern inline unsigned long native_save_fl(void);
20 extern __always_inline unsigned long native_save_fl(void)
25 * "=rm" is safe here, because "pop" adjusts the stack before
26 * it evaluates its effective address -- this is part of the
27 * documented behavior of the "pop" instruction.
29 asm volatile("# __raw_save_flags\n\t"
38 static __always_inline void native_irq_disable(void)
40 asm volatile("cli": : :"memory");
43 static __always_inline void native_irq_enable(void)
45 asm volatile("sti": : :"memory");
48 static inline __cpuidle void native_safe_halt(void)
50 mds_idle_clear_cpu_buffers();
51 asm volatile("sti; hlt": : :"memory");
54 static inline __cpuidle void native_halt(void)
56 mds_idle_clear_cpu_buffers();
57 asm volatile("hlt": : :"memory");
62 #ifdef CONFIG_PARAVIRT_XXL
63 #include <asm/paravirt.h>
66 #include <linux/types.h>
68 static __always_inline unsigned long arch_local_save_flags(void)
70 return native_save_fl();
73 static __always_inline void arch_local_irq_disable(void)
78 static __always_inline void arch_local_irq_enable(void)
84 * Used in the idle loop; sti takes one instruction cycle
87 static inline __cpuidle void arch_safe_halt(void)
93 * Used when interrupts are already enabled or to
94 * shutdown the processor:
96 static inline __cpuidle void halt(void)
102 * For spinlocks, etc:
104 static __always_inline unsigned long arch_local_irq_save(void)
106 unsigned long flags = arch_local_save_flags();
107 arch_local_irq_disable();
113 #ifdef CONFIG_DEBUG_ENTRY
114 #define SAVE_FLAGS pushfq; popq %rax
117 #define INTERRUPT_RETURN jmp native_iret
121 #endif /* __ASSEMBLY__ */
122 #endif /* CONFIG_PARAVIRT_XXL */
125 static __always_inline int arch_irqs_disabled_flags(unsigned long flags)
127 return !(flags & X86_EFLAGS_IF);
130 static __always_inline int arch_irqs_disabled(void)
132 unsigned long flags = arch_local_save_flags();
134 return arch_irqs_disabled_flags(flags);
137 static __always_inline void arch_local_irq_restore(unsigned long flags)
139 if (!arch_irqs_disabled_flags(flags))
140 arch_local_irq_enable();
145 #define SWAPGS ALTERNATIVE "swapgs", "", X86_FEATURE_XENPV
147 #define SWAPGS swapgs
150 #endif /* !__ASSEMBLY__ */