Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 2 | /* |
| 3 | * include/linux/irqflags.h |
| 4 | * |
| 5 | * IRQ flags tracing: follow the state of the hardirq and softirq flags and |
| 6 | * provide callbacks for transitions between ON and OFF states. |
| 7 | * |
| 8 | * This file gets included from lowlevel asm headers too, to provide |
| 9 | * wrapped versions of the local_irq_*() APIs, based on the |
| 10 | * raw_local_irq_*() macros from the lowlevel headers. |
| 11 | */ |
| 12 | #ifndef _LINUX_TRACE_IRQFLAGS_H |
| 13 | #define _LINUX_TRACE_IRQFLAGS_H |
| 14 | |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 15 | #include <linux/typecheck.h> |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 16 | #include <asm/irqflags.h> |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 17 | |
Peter Zijlstra | 0d38453 | 2020-03-20 12:56:41 +0100 | [diff] [blame] | 18 | /* Currently lockdep_softirqs_on/off is used only by lockdep */ |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_PROVE_LOCKING |
Peter Zijlstra | 0d38453 | 2020-03-20 12:56:41 +0100 | [diff] [blame] | 20 | extern void lockdep_softirqs_on(unsigned long ip); |
| 21 | extern void lockdep_softirqs_off(unsigned long ip); |
Steven Rostedt (VMware) | bff1b20 | 2018-08-06 15:50:58 -0400 | [diff] [blame] | 22 | extern void lockdep_hardirqs_on(unsigned long ip); |
| 23 | extern void lockdep_hardirqs_off(unsigned long ip); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 24 | #else |
Peter Zijlstra | 0d38453 | 2020-03-20 12:56:41 +0100 | [diff] [blame] | 25 | static inline void lockdep_softirqs_on(unsigned long ip) { } |
| 26 | static inline void lockdep_softirqs_off(unsigned long ip) { } |
Steven Rostedt (VMware) | bff1b20 | 2018-08-06 15:50:58 -0400 | [diff] [blame] | 27 | static inline void lockdep_hardirqs_on(unsigned long ip) { } |
| 28 | static inline void lockdep_hardirqs_off(unsigned long ip) { } |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #ifdef CONFIG_TRACE_IRQFLAGS |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 32 | extern void trace_hardirqs_on(void); |
| 33 | extern void trace_hardirqs_off(void); |
Peter Zijlstra | ef99691 | 2020-03-20 12:56:42 +0100 | [diff] [blame] | 34 | # define lockdep_hardirq_context(p) ((p)->hardirq_context) |
| 35 | # define lockdep_softirq_context(p) ((p)->softirq_context) |
| 36 | # define lockdep_hardirqs_enabled(p) ((p)->hardirqs_enabled) |
| 37 | # define lockdep_softirqs_enabled(p) ((p)->softirqs_enabled) |
Thomas Gleixner | 2502ec3 | 2020-03-20 12:56:40 +0100 | [diff] [blame] | 38 | # define lockdep_hardirq_enter() \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 39 | do { \ |
Peter Zijlstra | de8f5e4 | 2020-03-21 12:26:01 +0100 | [diff] [blame] | 40 | if (!current->hardirq_context++) \ |
| 41 | current->hardirq_threaded = 0; \ |
| 42 | } while (0) |
Linus Torvalds | d5f744f | 2020-03-30 19:14:28 -0700 | [diff] [blame] | 43 | # define lockdep_hardirq_threaded() \ |
Peter Zijlstra | de8f5e4 | 2020-03-21 12:26:01 +0100 | [diff] [blame] | 44 | do { \ |
| 45 | current->hardirq_threaded = 1; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 46 | } while (0) |
Thomas Gleixner | 2502ec3 | 2020-03-20 12:56:40 +0100 | [diff] [blame] | 47 | # define lockdep_hardirq_exit() \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 48 | do { \ |
| 49 | current->hardirq_context--; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 50 | } while (0) |
| 51 | # define lockdep_softirq_enter() \ |
| 52 | do { \ |
| 53 | current->softirq_context++; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 54 | } while (0) |
| 55 | # define lockdep_softirq_exit() \ |
| 56 | do { \ |
| 57 | current->softirq_context--; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 58 | } while (0) |
Sebastian Andrzej Siewior | 40db173 | 2020-03-21 12:26:02 +0100 | [diff] [blame] | 59 | |
| 60 | # define lockdep_hrtimer_enter(__hrtimer) \ |
Sebastian Andrzej Siewior | 73d2056 | 2020-03-31 22:18:49 +0200 | [diff] [blame] | 61 | ({ \ |
| 62 | bool __expires_hardirq = true; \ |
| 63 | \ |
| 64 | if (!__hrtimer->is_hard) { \ |
| 65 | current->irq_config = 1; \ |
| 66 | __expires_hardirq = false; \ |
| 67 | } \ |
| 68 | __expires_hardirq; \ |
| 69 | }) |
Sebastian Andrzej Siewior | 40db173 | 2020-03-21 12:26:02 +0100 | [diff] [blame] | 70 | |
Sebastian Andrzej Siewior | 73d2056 | 2020-03-31 22:18:49 +0200 | [diff] [blame] | 71 | # define lockdep_hrtimer_exit(__expires_hardirq) \ |
| 72 | do { \ |
| 73 | if (!__expires_hardirq) \ |
Sebastian Andrzej Siewior | 40db173 | 2020-03-21 12:26:02 +0100 | [diff] [blame] | 74 | current->irq_config = 0; \ |
Sebastian Andrzej Siewior | 73d2056 | 2020-03-31 22:18:49 +0200 | [diff] [blame] | 75 | } while (0) |
Sebastian Andrzej Siewior | 40db173 | 2020-03-21 12:26:02 +0100 | [diff] [blame] | 76 | |
Sebastian Andrzej Siewior | d53f2b6 | 2020-03-21 12:26:04 +0100 | [diff] [blame] | 77 | # define lockdep_posixtimer_enter() \ |
| 78 | do { \ |
| 79 | current->irq_config = 1; \ |
| 80 | } while (0) |
| 81 | |
| 82 | # define lockdep_posixtimer_exit() \ |
| 83 | do { \ |
| 84 | current->irq_config = 0; \ |
| 85 | } while (0) |
| 86 | |
Sebastian Andrzej Siewior | 49915ac | 2020-03-21 12:26:03 +0100 | [diff] [blame] | 87 | # define lockdep_irq_work_enter(__work) \ |
| 88 | do { \ |
| 89 | if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\ |
| 90 | current->irq_config = 1; \ |
| 91 | } while (0) |
| 92 | # define lockdep_irq_work_exit(__work) \ |
| 93 | do { \ |
| 94 | if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\ |
| 95 | current->irq_config = 0; \ |
| 96 | } while (0) |
| 97 | |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 98 | #else |
| 99 | # define trace_hardirqs_on() do { } while (0) |
| 100 | # define trace_hardirqs_off() do { } while (0) |
Peter Zijlstra | ef99691 | 2020-03-20 12:56:42 +0100 | [diff] [blame] | 101 | # define lockdep_hardirq_context(p) 0 |
| 102 | # define lockdep_softirq_context(p) 0 |
| 103 | # define lockdep_hardirqs_enabled(p) 0 |
| 104 | # define lockdep_softirqs_enabled(p) 0 |
Thomas Gleixner | 2502ec3 | 2020-03-20 12:56:40 +0100 | [diff] [blame] | 105 | # define lockdep_hardirq_enter() do { } while (0) |
Linus Torvalds | d5f744f | 2020-03-30 19:14:28 -0700 | [diff] [blame] | 106 | # define lockdep_hardirq_threaded() do { } while (0) |
Thomas Gleixner | 2502ec3 | 2020-03-20 12:56:40 +0100 | [diff] [blame] | 107 | # define lockdep_hardirq_exit() do { } while (0) |
Ingo Molnar | d820ac4 | 2009-03-13 01:30:40 +0100 | [diff] [blame] | 108 | # define lockdep_softirq_enter() do { } while (0) |
| 109 | # define lockdep_softirq_exit() do { } while (0) |
Sebastian Andrzej Siewior | 73d2056 | 2020-03-31 22:18:49 +0200 | [diff] [blame] | 110 | # define lockdep_hrtimer_enter(__hrtimer) false |
| 111 | # define lockdep_hrtimer_exit(__context) do { } while (0) |
Sebastian Andrzej Siewior | d53f2b6 | 2020-03-21 12:26:04 +0100 | [diff] [blame] | 112 | # define lockdep_posixtimer_enter() do { } while (0) |
| 113 | # define lockdep_posixtimer_exit() do { } while (0) |
Sebastian Andrzej Siewior | 49915ac | 2020-03-21 12:26:03 +0100 | [diff] [blame] | 114 | # define lockdep_irq_work_enter(__work) do { } while (0) |
| 115 | # define lockdep_irq_work_exit(__work) do { } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 116 | #endif |
| 117 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 118 | #if defined(CONFIG_IRQSOFF_TRACER) || \ |
| 119 | defined(CONFIG_PREEMPT_TRACER) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 120 | extern void stop_critical_timings(void); |
| 121 | extern void start_critical_timings(void); |
| 122 | #else |
| 123 | # define stop_critical_timings() do { } while (0) |
| 124 | # define start_critical_timings() do { } while (0) |
| 125 | #endif |
| 126 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 127 | /* |
| 128 | * Wrap the arch provided IRQ routines to provide appropriate checks. |
| 129 | */ |
| 130 | #define raw_local_irq_disable() arch_local_irq_disable() |
| 131 | #define raw_local_irq_enable() arch_local_irq_enable() |
| 132 | #define raw_local_irq_save(flags) \ |
| 133 | do { \ |
| 134 | typecheck(unsigned long, flags); \ |
| 135 | flags = arch_local_irq_save(); \ |
| 136 | } while (0) |
| 137 | #define raw_local_irq_restore(flags) \ |
| 138 | do { \ |
| 139 | typecheck(unsigned long, flags); \ |
| 140 | arch_local_irq_restore(flags); \ |
| 141 | } while (0) |
| 142 | #define raw_local_save_flags(flags) \ |
| 143 | do { \ |
| 144 | typecheck(unsigned long, flags); \ |
| 145 | flags = arch_local_save_flags(); \ |
| 146 | } while (0) |
| 147 | #define raw_irqs_disabled_flags(flags) \ |
| 148 | ({ \ |
| 149 | typecheck(unsigned long, flags); \ |
| 150 | arch_irqs_disabled_flags(flags); \ |
| 151 | }) |
| 152 | #define raw_irqs_disabled() (arch_irqs_disabled()) |
| 153 | #define raw_safe_halt() arch_safe_halt() |
| 154 | |
| 155 | /* |
| 156 | * The local_irq_*() APIs are equal to the raw_local_irq*() |
| 157 | * if !TRACE_IRQFLAGS. |
| 158 | */ |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 159 | #ifdef CONFIG_TRACE_IRQFLAGS |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 160 | #define local_irq_enable() \ |
| 161 | do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0) |
| 162 | #define local_irq_disable() \ |
| 163 | do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 164 | #define local_irq_save(flags) \ |
| 165 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 166 | raw_local_irq_save(flags); \ |
| 167 | trace_hardirqs_off(); \ |
| 168 | } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 169 | |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 170 | |
| 171 | #define local_irq_restore(flags) \ |
| 172 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 173 | if (raw_irqs_disabled_flags(flags)) { \ |
| 174 | raw_local_irq_restore(flags); \ |
| 175 | trace_hardirqs_off(); \ |
| 176 | } else { \ |
| 177 | trace_hardirqs_on(); \ |
| 178 | raw_local_irq_restore(flags); \ |
| 179 | } \ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 180 | } while (0) |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 181 | |
| 182 | #define safe_halt() \ |
| 183 | do { \ |
| 184 | trace_hardirqs_on(); \ |
| 185 | raw_safe_halt(); \ |
| 186 | } while (0) |
| 187 | |
| 188 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 189 | #else /* !CONFIG_TRACE_IRQFLAGS */ |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 190 | |
| 191 | #define local_irq_enable() do { raw_local_irq_enable(); } while (0) |
| 192 | #define local_irq_disable() do { raw_local_irq_disable(); } while (0) |
| 193 | #define local_irq_save(flags) \ |
| 194 | do { \ |
| 195 | raw_local_irq_save(flags); \ |
| 196 | } while (0) |
| 197 | #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0) |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 198 | #define safe_halt() do { raw_safe_halt(); } while (0) |
| 199 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 200 | #endif /* CONFIG_TRACE_IRQFLAGS */ |
| 201 | |
| 202 | #define local_save_flags(flags) raw_local_save_flags(flags) |
| 203 | |
| 204 | /* |
| 205 | * Some architectures don't define arch_irqs_disabled(), so even if either |
| 206 | * definition would be fine we need to use different ones for the time being |
| 207 | * to avoid build issues. |
| 208 | */ |
| 209 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
| 210 | #define irqs_disabled() \ |
| 211 | ({ \ |
| 212 | unsigned long _flags; \ |
| 213 | raw_local_save_flags(_flags); \ |
| 214 | raw_irqs_disabled_flags(_flags); \ |
| 215 | }) |
| 216 | #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
| 217 | #define irqs_disabled() raw_irqs_disabled() |
Michael Neuling | 40b1f4e | 2009-10-22 14:39:28 +1100 | [diff] [blame] | 218 | #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 219 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 220 | #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags) |
| 221 | |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 222 | #endif |