Skip to content

Commit

Permalink
lockdep: Make it RT aware
Browse files Browse the repository at this point in the history
There is not really a softirq context on PREEMPT_RT.
Softirqs on PREEMPT_RT are always invoked within the context of a threaded
interrupt handler or within ksoftirqd. The "in-softirq" context is preemptible
and is protected by a per-CPU lock to ensure mutual exclusion.

There is no difference on PREEMPT_RT between spin_lock_irq() and spin_lock()
because the former does not disable interrupts. Therefore if lock is used
in_softirq() and locked once with spin_lock_irq() then lockdep will report this
with "inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage".

Teach lockdep that we don't really do softirqs on -RT.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner authored and Sebastian Andrzej Siewior committed Sep 13, 2021
1 parent cdcac5f commit 842a333
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 15 additions & 8 deletions include/linux/irqflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ do { \
do { \
__this_cpu_dec(hardirq_context); \
} while (0)
# define lockdep_softirq_enter() \
do { \
current->softirq_context++; \
} while (0)
# define lockdep_softirq_exit() \
do { \
current->softirq_context--; \
} while (0)

# define lockdep_hrtimer_enter(__hrtimer) \
({ \
Expand Down Expand Up @@ -140,6 +132,21 @@ do { \
# define lockdep_irq_work_exit(__work) do { } while (0)
#endif

#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT)
# define lockdep_softirq_enter() \
do { \
current->softirq_context++; \
} while (0)
# define lockdep_softirq_exit() \
do { \
current->softirq_context--; \
} while (0)

#else
# define lockdep_softirq_enter() do { } while (0)
# define lockdep_softirq_exit() do { } while (0)
#endif

#if defined(CONFIG_IRQSOFF_TRACER) || \
defined(CONFIG_PREEMPT_TRACER)
extern void stop_critical_timings(void);
Expand Down
2 changes: 2 additions & 0 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -5473,6 +5473,7 @@ static noinstr void check_flags(unsigned long flags)
}
}

#ifndef CONFIG_PREEMPT_RT
/*
* We dont accurately track softirq state in e.g.
* hardirq contexts (such as on 4KSTACKS), so only
Expand All @@ -5487,6 +5488,7 @@ static noinstr void check_flags(unsigned long flags)
DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
}
}
#endif

if (!debug_locks)
print_irqtrace_events(current);
Expand Down

0 comments on commit 842a333

Please sign in to comment.