blob: 61a9ced3aa50d3de714d5e0f5dff2eb4c87972a9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnarde30a2b2006-07-03 00:24:42 -07002/*
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 Rostedt3f3078912008-07-25 01:45:25 -070015#include <linux/typecheck.h>
David Howellsdf9ee292010-10-07 14:08:55 +010016#include <asm/irqflags.h>
Steven Rostedt3f3078912008-07-25 01:45:25 -070017
Peter Zijlstra0d384532020-03-20 12:56:41 +010018/* Currently lockdep_softirqs_on/off is used only by lockdep */
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070019#ifdef CONFIG_PROVE_LOCKING
Peter Zijlstra0d384532020-03-20 12:56:41 +010020 extern void lockdep_softirqs_on(unsigned long ip);
21 extern void lockdep_softirqs_off(unsigned long ip);
Steven Rostedt (VMware)bff1b202018-08-06 15:50:58 -040022 extern void lockdep_hardirqs_on(unsigned long ip);
23 extern void lockdep_hardirqs_off(unsigned long ip);
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070024#else
Peter Zijlstra0d384532020-03-20 12:56:41 +010025 static inline void lockdep_softirqs_on(unsigned long ip) { }
26 static inline void lockdep_softirqs_off(unsigned long ip) { }
Steven Rostedt (VMware)bff1b202018-08-06 15:50:58 -040027 static inline void lockdep_hardirqs_on(unsigned long ip) { }
28 static inline void lockdep_hardirqs_off(unsigned long ip) { }
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070029#endif
30
31#ifdef CONFIG_TRACE_IRQFLAGS
Steven Rostedt81d68a92008-05-12 21:20:42 +020032 extern void trace_hardirqs_on(void);
33 extern void trace_hardirqs_off(void);
Peter Zijlstraef996912020-03-20 12:56:42 +010034# 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 Gleixner2502ec32020-03-20 12:56:40 +010038# define lockdep_hardirq_enter() \
Byungchul Parkb09be672017-08-07 16:12:52 +090039do { \
Peter Zijlstrade8f5e42020-03-21 12:26:01 +010040 if (!current->hardirq_context++) \
41 current->hardirq_threaded = 0; \
42} while (0)
Linus Torvaldsd5f744f2020-03-30 19:14:28 -070043# define lockdep_hardirq_threaded() \
Peter Zijlstrade8f5e42020-03-21 12:26:01 +010044do { \
45 current->hardirq_threaded = 1; \
Byungchul Parkb09be672017-08-07 16:12:52 +090046} while (0)
Thomas Gleixner2502ec32020-03-20 12:56:40 +010047# define lockdep_hardirq_exit() \
Byungchul Parkb09be672017-08-07 16:12:52 +090048do { \
49 current->hardirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090050} while (0)
51# define lockdep_softirq_enter() \
52do { \
53 current->softirq_context++; \
Byungchul Parkb09be672017-08-07 16:12:52 +090054} while (0)
55# define lockdep_softirq_exit() \
56do { \
57 current->softirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090058} while (0)
Sebastian Andrzej Siewior40db1732020-03-21 12:26:02 +010059
60# define lockdep_hrtimer_enter(__hrtimer) \
Sebastian Andrzej Siewior73d20562020-03-31 22:18:49 +020061({ \
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 Siewior40db1732020-03-21 12:26:02 +010070
Sebastian Andrzej Siewior73d20562020-03-31 22:18:49 +020071# define lockdep_hrtimer_exit(__expires_hardirq) \
72 do { \
73 if (!__expires_hardirq) \
Sebastian Andrzej Siewior40db1732020-03-21 12:26:02 +010074 current->irq_config = 0; \
Sebastian Andrzej Siewior73d20562020-03-31 22:18:49 +020075 } while (0)
Sebastian Andrzej Siewior40db1732020-03-21 12:26:02 +010076
Sebastian Andrzej Siewiord53f2b62020-03-21 12:26:04 +010077# 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 Siewior49915ac2020-03-21 12:26:03 +010087# 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 Molnarde30a2b2006-07-03 00:24:42 -070098#else
99# define trace_hardirqs_on() do { } while (0)
100# define trace_hardirqs_off() do { } while (0)
Peter Zijlstraef996912020-03-20 12:56:42 +0100101# 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 Gleixner2502ec32020-03-20 12:56:40 +0100105# define lockdep_hardirq_enter() do { } while (0)
Linus Torvaldsd5f744f2020-03-30 19:14:28 -0700106# define lockdep_hardirq_threaded() do { } while (0)
Thomas Gleixner2502ec32020-03-20 12:56:40 +0100107# define lockdep_hardirq_exit() do { } while (0)
Ingo Molnard820ac42009-03-13 01:30:40 +0100108# define lockdep_softirq_enter() do { } while (0)
109# define lockdep_softirq_exit() do { } while (0)
Sebastian Andrzej Siewior73d20562020-03-31 22:18:49 +0200110# define lockdep_hrtimer_enter(__hrtimer) false
111# define lockdep_hrtimer_exit(__context) do { } while (0)
Sebastian Andrzej Siewiord53f2b62020-03-21 12:26:04 +0100112# define lockdep_posixtimer_enter() do { } while (0)
113# define lockdep_posixtimer_exit() do { } while (0)
Sebastian Andrzej Siewior49915ac2020-03-21 12:26:03 +0100114# define lockdep_irq_work_enter(__work) do { } while (0)
115# define lockdep_irq_work_exit(__work) do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700116#endif
117
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200118#if defined(CONFIG_IRQSOFF_TRACER) || \
119 defined(CONFIG_PREEMPT_TRACER)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200120 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 Howellsdf9ee292010-10-07 14:08:55 +0100127/*
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 Beulichdb2dcb42015-01-20 13:00:46 +0000159#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700160#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 Rostedt3f3078912008-07-25 01:45:25 -0700164#define local_irq_save(flags) \
165 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700166 raw_local_irq_save(flags); \
167 trace_hardirqs_off(); \
168 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700169
Steven Rostedt3f3078912008-07-25 01:45:25 -0700170
171#define local_irq_restore(flags) \
172 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700173 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 Molnarde30a2b2006-07-03 00:24:42 -0700180 } while (0)
David Howellsdf9ee292010-10-07 14:08:55 +0100181
182#define safe_halt() \
183 do { \
184 trace_hardirqs_on(); \
185 raw_safe_halt(); \
186 } while (0)
187
188
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000189#else /* !CONFIG_TRACE_IRQFLAGS */
David Howellsdf9ee292010-10-07 14:08:55 +0100190
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 Howellsdf9ee292010-10-07 14:08:55 +0100198#define safe_halt() do { raw_safe_halt(); } while (0)
199
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000200#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 Neuling40b1f4e2009-10-22 14:39:28 +1100218#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700219
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000220#define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
221
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700222#endif