1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * include/linux/irqflags.h 3 * include/linux/irqflags.h 4 * 4 * 5 * IRQ flags tracing: follow the state of the 5 * IRQ flags tracing: follow the state of the hardirq and softirq flags and 6 * provide callbacks for transitions between O 6 * provide callbacks for transitions between ON and OFF states. 7 * 7 * 8 * This file gets included from lowlevel asm h 8 * This file gets included from lowlevel asm headers too, to provide 9 * wrapped versions of the local_irq_*() APIs, 9 * wrapped versions of the local_irq_*() APIs, based on the 10 * raw_local_irq_*() macros from the lowlevel 10 * raw_local_irq_*() macros from the lowlevel headers. 11 */ 11 */ 12 #ifndef _LINUX_TRACE_IRQFLAGS_H 12 #ifndef _LINUX_TRACE_IRQFLAGS_H 13 #define _LINUX_TRACE_IRQFLAGS_H 13 #define _LINUX_TRACE_IRQFLAGS_H 14 14 15 #include <linux/irqflags_types.h> << 16 #include <linux/typecheck.h> 15 #include <linux/typecheck.h> 17 #include <linux/cleanup.h> << 18 #include <asm/irqflags.h> 16 #include <asm/irqflags.h> 19 #include <asm/percpu.h> << 20 << 21 /* Currently lockdep_softirqs_on/off is used o << 22 #ifdef CONFIG_PROVE_LOCKING << 23 extern void lockdep_softirqs_on(unsigned lon << 24 extern void lockdep_softirqs_off(unsigned lo << 25 extern void lockdep_hardirqs_on_prepare(void << 26 extern void lockdep_hardirqs_on(unsigned lon << 27 extern void lockdep_hardirqs_off(unsigned lo << 28 #else << 29 static inline void lockdep_softirqs_on(unsig << 30 static inline void lockdep_softirqs_off(unsi << 31 static inline void lockdep_hardirqs_on_prepa << 32 static inline void lockdep_hardirqs_on(unsig << 33 static inline void lockdep_hardirqs_off(unsi << 34 #endif << 35 17 36 #ifdef CONFIG_TRACE_IRQFLAGS 18 #ifdef CONFIG_TRACE_IRQFLAGS 37 !! 19 extern void trace_softirqs_on(unsigned long ip); 38 DECLARE_PER_CPU(int, hardirqs_enabled); !! 20 extern void trace_softirqs_off(unsigned long ip); 39 DECLARE_PER_CPU(int, hardirq_context); !! 21 extern void trace_hardirqs_on(void); 40 !! 22 extern void trace_hardirqs_off(void); 41 extern void trace_hardirqs_on_prepare(void); !! 23 # define trace_hardirq_context(p) ((p)->hardirq_context) 42 extern void trace_hardirqs_off_finish(void); !! 24 # define trace_softirq_context(p) ((p)->softirq_context) 43 extern void trace_hardirqs_on(void); !! 25 # define trace_hardirqs_enabled(p) ((p)->hardirqs_enabled) 44 extern void trace_hardirqs_off(void); !! 26 # define trace_softirqs_enabled(p) ((p)->softirqs_enabled) 45 !! 27 # define trace_hardirq_enter() \ 46 # define lockdep_hardirq_context() (raw_c << 47 # define lockdep_softirq_context(p) ((p)-> << 48 # define lockdep_hardirqs_enabled() (this_ << 49 # define lockdep_softirqs_enabled(p) ((p)-> << 50 # define lockdep_hardirq_enter() << 51 do { << 52 if (__this_cpu_inc_return(hardirq_cont << 53 current->hardirq_threaded = 0; << 54 } while (0) << 55 # define lockdep_hardirq_threaded() << 56 do { 28 do { \ 57 current->hardirq_threaded = 1; !! 29 current->hardirq_context++; \ >> 30 crossrelease_hist_start(XHLOCK_HARD); \ 58 } while (0) 31 } while (0) 59 # define lockdep_hardirq_exit() !! 32 # define trace_hardirq_exit() \ 60 do { 33 do { \ 61 __this_cpu_dec(hardirq_context); !! 34 current->hardirq_context--; \ >> 35 crossrelease_hist_end(XHLOCK_HARD); \ 62 } while (0) 36 } while (0) 63 << 64 # define lockdep_hrtimer_enter(__hrtimer) << 65 ({ << 66 bool __expires_hardirq = true; << 67 << 68 if (!__hrtimer->is_hard) { << 69 current->irq_config = 1; << 70 __expires_hardirq = false; << 71 } << 72 __expires_hardirq; << 73 }) << 74 << 75 # define lockdep_hrtimer_exit(__expires_hardir << 76 do { << 77 if (!__expires_hardirq) << 78 current->irq_config = << 79 } while (0) << 80 << 81 # define lockdep_posixtimer_enter() << 82 do { << 83 current->irq_config = 1; << 84 } while (0) << 85 << 86 # define lockdep_posixtimer_exit() << 87 do { << 88 current->irq_config = 0; << 89 } while (0) << 90 << 91 # define lockdep_irq_work_enter(_flags) << 92 do { << 93 if (!((_flags) & IRQ_WORK_HA << 94 current->irq_config = << 95 } while (0) << 96 # define lockdep_irq_work_exit(_flags) << 97 do { << 98 if (!((_flags) & IRQ_WORK_HA << 99 current->irq_config = << 100 } while (0) << 101 << 102 #else << 103 # define trace_hardirqs_on_prepare() << 104 # define trace_hardirqs_off_finish() << 105 # define trace_hardirqs_on() << 106 # define trace_hardirqs_off() << 107 # define lockdep_hardirq_context() << 108 # define lockdep_softirq_context(p) << 109 # define lockdep_hardirqs_enabled() << 110 # define lockdep_softirqs_enabled(p) << 111 # define lockdep_hardirq_enter() << 112 # define lockdep_hardirq_threaded() << 113 # define lockdep_hardirq_exit() << 114 # define lockdep_softirq_enter() << 115 # define lockdep_softirq_exit() << 116 # define lockdep_hrtimer_enter(__hrtimer) << 117 # define lockdep_hrtimer_exit(__context) << 118 # define lockdep_posixtimer_enter() << 119 # define lockdep_posixtimer_exit() << 120 # define lockdep_irq_work_enter(__work) << 121 # define lockdep_irq_work_exit(__work) << 122 #endif << 123 << 124 #if defined(CONFIG_TRACE_IRQFLAGS) && !defined << 125 # define lockdep_softirq_enter() 37 # define lockdep_softirq_enter() \ 126 do { 38 do { \ 127 current->softirq_context++; 39 current->softirq_context++; \ >> 40 crossrelease_hist_start(XHLOCK_SOFT); \ 128 } while (0) 41 } while (0) 129 # define lockdep_softirq_exit() 42 # define lockdep_softirq_exit() \ 130 do { 43 do { \ 131 current->softirq_context--; 44 current->softirq_context--; \ >> 45 crossrelease_hist_end(XHLOCK_SOFT); \ 132 } while (0) 46 } while (0) 133 !! 47 # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1, 134 #else 48 #else 135 # define lockdep_softirq_enter() !! 49 # define trace_hardirqs_on() do { } while (0) 136 # define lockdep_softirq_exit() !! 50 # define trace_hardirqs_off() do { } while (0) >> 51 # define trace_softirqs_on(ip) do { } while (0) >> 52 # define trace_softirqs_off(ip) do { } while (0) >> 53 # define trace_hardirq_context(p) 0 >> 54 # define trace_softirq_context(p) 0 >> 55 # define trace_hardirqs_enabled(p) 0 >> 56 # define trace_softirqs_enabled(p) 0 >> 57 # define trace_hardirq_enter() do { } while (0) >> 58 # define trace_hardirq_exit() do { } while (0) >> 59 # define lockdep_softirq_enter() do { } while (0) >> 60 # define lockdep_softirq_exit() do { } while (0) >> 61 # define INIT_TRACE_IRQFLAGS 137 #endif 62 #endif 138 63 139 #if defined(CONFIG_IRQSOFF_TRACER) || \ 64 #if defined(CONFIG_IRQSOFF_TRACER) || \ 140 defined(CONFIG_PREEMPT_TRACER) 65 defined(CONFIG_PREEMPT_TRACER) 141 extern void stop_critical_timings(void); 66 extern void stop_critical_timings(void); 142 extern void start_critical_timings(void); 67 extern void start_critical_timings(void); 143 #else 68 #else 144 # define stop_critical_timings() do { } while 69 # define stop_critical_timings() do { } while (0) 145 # define start_critical_timings() do { } while 70 # define start_critical_timings() do { } while (0) 146 #endif 71 #endif 147 72 148 #ifdef CONFIG_DEBUG_IRQFLAGS << 149 extern void warn_bogus_irq_restore(void); << 150 #define raw_check_bogus_irq_restore() << 151 do { << 152 if (unlikely(!arch_irqs_disabl << 153 warn_bogus_irq_restore << 154 } while (0) << 155 #else << 156 #define raw_check_bogus_irq_restore() do { } w << 157 #endif << 158 << 159 /* 73 /* 160 * Wrap the arch provided IRQ routines to prov 74 * Wrap the arch provided IRQ routines to provide appropriate checks. 161 */ 75 */ 162 #define raw_local_irq_disable() arch_l 76 #define raw_local_irq_disable() arch_local_irq_disable() 163 #define raw_local_irq_enable() arch_l 77 #define raw_local_irq_enable() arch_local_irq_enable() 164 #define raw_local_irq_save(flags) 78 #define raw_local_irq_save(flags) \ 165 do { 79 do { \ 166 typecheck(unsigned long, flags 80 typecheck(unsigned long, flags); \ 167 flags = arch_local_irq_save(); 81 flags = arch_local_irq_save(); \ 168 } while (0) 82 } while (0) 169 #define raw_local_irq_restore(flags) 83 #define raw_local_irq_restore(flags) \ 170 do { 84 do { \ 171 typecheck(unsigned long, flags 85 typecheck(unsigned long, flags); \ 172 raw_check_bogus_irq_restore(); << 173 arch_local_irq_restore(flags); 86 arch_local_irq_restore(flags); \ 174 } while (0) 87 } while (0) 175 #define raw_local_save_flags(flags) 88 #define raw_local_save_flags(flags) \ 176 do { 89 do { \ 177 typecheck(unsigned long, flags 90 typecheck(unsigned long, flags); \ 178 flags = arch_local_save_flags( 91 flags = arch_local_save_flags(); \ 179 } while (0) 92 } while (0) 180 #define raw_irqs_disabled_flags(flags) 93 #define raw_irqs_disabled_flags(flags) \ 181 ({ 94 ({ \ 182 typecheck(unsigned long, flags 95 typecheck(unsigned long, flags); \ 183 arch_irqs_disabled_flags(flags 96 arch_irqs_disabled_flags(flags); \ 184 }) 97 }) 185 #define raw_irqs_disabled() (arch_ 98 #define raw_irqs_disabled() (arch_irqs_disabled()) 186 #define raw_safe_halt() arch_s 99 #define raw_safe_halt() arch_safe_halt() 187 100 188 /* 101 /* 189 * The local_irq_*() APIs are equal to the raw 102 * The local_irq_*() APIs are equal to the raw_local_irq*() 190 * if !TRACE_IRQFLAGS. 103 * if !TRACE_IRQFLAGS. 191 */ 104 */ 192 #ifdef CONFIG_TRACE_IRQFLAGS 105 #ifdef CONFIG_TRACE_IRQFLAGS 193 !! 106 #define local_irq_enable() \ 194 #define local_irq_enable() !! 107 do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0) 195 do { !! 108 #define local_irq_disable() \ 196 trace_hardirqs_on(); !! 109 do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) 197 raw_local_irq_enable(); << 198 } while (0) << 199 << 200 #define local_irq_disable() << 201 do { << 202 bool was_disabled = raw_irqs_d << 203 raw_local_irq_disable(); << 204 if (!was_disabled) << 205 trace_hardirqs_off(); << 206 } while (0) << 207 << 208 #define local_irq_save(flags) 110 #define local_irq_save(flags) \ 209 do { 111 do { \ 210 raw_local_irq_save(flags); 112 raw_local_irq_save(flags); \ 211 if (!raw_irqs_disabled_flags(f !! 113 trace_hardirqs_off(); \ 212 trace_hardirqs_off(); << 213 } while (0) 114 } while (0) 214 115 >> 116 215 #define local_irq_restore(flags) 117 #define local_irq_restore(flags) \ 216 do { 118 do { \ 217 if (!raw_irqs_disabled_flags(f !! 119 if (raw_irqs_disabled_flags(flags)) { \ >> 120 raw_local_irq_restore(flags); \ >> 121 trace_hardirqs_off(); \ >> 122 } else { \ 218 trace_hardirqs_on(); 123 trace_hardirqs_on(); \ 219 raw_local_irq_restore(flags); !! 124 raw_local_irq_restore(flags); \ >> 125 } \ 220 } while (0) 126 } while (0) 221 127 222 #define safe_halt() 128 #define safe_halt() \ 223 do { 129 do { \ 224 trace_hardirqs_on(); 130 trace_hardirqs_on(); \ 225 raw_safe_halt(); 131 raw_safe_halt(); \ 226 } while (0) 132 } while (0) 227 133 228 134 229 #else /* !CONFIG_TRACE_IRQFLAGS */ 135 #else /* !CONFIG_TRACE_IRQFLAGS */ 230 136 231 #define local_irq_enable() do { raw_local 137 #define local_irq_enable() do { raw_local_irq_enable(); } while (0) 232 #define local_irq_disable() do { raw_local 138 #define local_irq_disable() do { raw_local_irq_disable(); } while (0) 233 #define local_irq_save(flags) do { raw_local !! 139 #define local_irq_save(flags) \ >> 140 do { \ >> 141 raw_local_irq_save(flags); \ >> 142 } while (0) 234 #define local_irq_restore(flags) do { raw_loca 143 #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0) 235 #define safe_halt() do { raw_safe_ 144 #define safe_halt() do { raw_safe_halt(); } while (0) 236 145 237 #endif /* CONFIG_TRACE_IRQFLAGS */ 146 #endif /* CONFIG_TRACE_IRQFLAGS */ 238 147 239 #define local_save_flags(flags) raw_local_save 148 #define local_save_flags(flags) raw_local_save_flags(flags) 240 149 241 /* 150 /* 242 * Some architectures don't define arch_irqs_d 151 * Some architectures don't define arch_irqs_disabled(), so even if either 243 * definition would be fine we need to use dif 152 * definition would be fine we need to use different ones for the time being 244 * to avoid build issues. 153 * to avoid build issues. 245 */ 154 */ 246 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT 155 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT 247 #define irqs_disabled() 156 #define irqs_disabled() \ 248 ({ 157 ({ \ 249 unsigned long _flags; 158 unsigned long _flags; \ 250 raw_local_save_flags(_flags); 159 raw_local_save_flags(_flags); \ 251 raw_irqs_disabled_flags(_flags 160 raw_irqs_disabled_flags(_flags); \ 252 }) 161 }) 253 #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */ 162 #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */ 254 #define irqs_disabled() raw_irqs_disabled() 163 #define irqs_disabled() raw_irqs_disabled() 255 #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ 164 #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ 256 165 257 #define irqs_disabled_flags(flags) raw_irqs_di 166 #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags) 258 << 259 DEFINE_LOCK_GUARD_0(irq, local_irq_disable(), << 260 DEFINE_LOCK_GUARD_0(irqsave, << 261 local_irq_save(_T->flags), << 262 local_irq_restore(_T->flag << 263 unsigned long flags) << 264 167 265 #endif 168 #endif 266 169
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.