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