Skip to content

Commit 5c4853b

Browse files
fweisbecingomolnar
authored andcommitted
lockdep: Simplify a bit hardirq <-> softirq transitions
Instead of saving the hardirq state on a per CPU variable, which require an explicit call before the softirq handling and some complication, just save and restore the hardirq tracing state through functions return values and parameters. It simplifies a bit the black magic that works around the fact that softirqs can be called from hardirqs while hardirqs can nest on softirqs but those two cases have very different semantics and only the latter case assume both states. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Link: http://lkml.kernel.org/r/1384906054-30676-1-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 7d5b158 commit 5c4853b

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

‎kernel/softirq.c‎

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,40 +213,35 @@ EXPORT_SYMBOL(local_bh_enable_ip);
213213

214214
#ifdef CONFIG_TRACE_IRQFLAGS
215215
/*
216-
* Convoluted means of passing __do_softirq() a message through the various
217-
* architecture execute_on_stack() bits.
218-
*
219216
* When we run softirqs from irq_exit() and thus on the hardirq stack we need
220217
* to keep the lockdep irq context tracking as tight as possible in order to
221218
* not miss-qualify lock contexts and miss possible deadlocks.
222219
*/
223-
static DEFINE_PER_CPU(int, softirq_from_hardirq);
224220

225-
static inline void lockdep_softirq_from_hardirq(void)
221+
static inline bool lockdep_softirq_start(void)
226222
{
227-
this_cpu_write(softirq_from_hardirq, 1);
228-
}
223+
bool in_hardirq = false;
229224

230-
static inline void lockdep_softirq_start(void)
231-
{
232-
if (this_cpu_read(softirq_from_hardirq))
225+
if (trace_hardirq_context(current)) {
226+
in_hardirq = true;
233227
trace_hardirq_exit();
228+
}
229+
234230
lockdep_softirq_enter();
231+
232+
return in_hardirq;
235233
}
236234

237-
static inline void lockdep_softirq_end(void)
235+
static inline void lockdep_softirq_end(bool in_hardirq)
238236
{
239237
lockdep_softirq_exit();
240-
if (this_cpu_read(softirq_from_hardirq)) {
241-
this_cpu_write(softirq_from_hardirq, 0);
238+
239+
if (in_hardirq)
242240
trace_hardirq_enter();
243-
}
244241
}
245-
246242
#else
247-
static inline void lockdep_softirq_from_hardirq(void) { }
248-
static inline void lockdep_softirq_start(void) { }
249-
static inline void lockdep_softirq_end(void) { }
243+
static inline bool lockdep_softirq_start(void) { return false; }
244+
static inline void lockdep_softirq_end(bool in_hardirq) { }
250245
#endif
251246

252247
asmlinkage void __do_softirq(void)
@@ -255,6 +250,7 @@ asmlinkage void __do_softirq(void)
255250
unsigned long old_flags = current->flags;
256251
int max_restart = MAX_SOFTIRQ_RESTART;
257252
struct softirq_action *h;
253+
bool in_hardirq;
258254
__u32 pending;
259255
int cpu;
260256

@@ -269,7 +265,7 @@ asmlinkage void __do_softirq(void)
269265
account_irq_enter_time(current);
270266

271267
__local_bh_disable(_RET_IP_, SOFTIRQ_OFFSET);
272-
lockdep_softirq_start();
268+
in_hardirq = lockdep_softirq_start();
273269

274270
cpu = smp_processor_id();
275271
restart:
@@ -316,7 +312,7 @@ asmlinkage void __do_softirq(void)
316312
wakeup_softirqd();
317313
}
318314

319-
lockdep_softirq_end();
315+
lockdep_softirq_end(in_hardirq);
320316
account_irq_exit_time(current);
321317
__local_bh_enable(SOFTIRQ_OFFSET);
322318
WARN_ON_ONCE(in_interrupt());
@@ -365,7 +361,6 @@ void irq_enter(void)
365361
static inline void invoke_softirq(void)
366362
{
367363
if (!force_irqthreads) {
368-
lockdep_softirq_from_hardirq();
369364
#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
370365
/*
371366
* We can safely execute softirq on the current stack if

0 commit comments

Comments
 (0)