History

lockdep: Add preemption enabled/disabled assertion APIs

Asserting that preemption is enabled or disabled is a critical sanity check. Developers are usually reluctant to add such a check in a fastpath as reading the preemption count can be costly. Extend the lockdep API with macros asserting that preemption is disabled or enabled. If lockdep is disabled, or if the underlying architecture does not support kernel preemption, this assert has no runtime overhead.

Ahmed S. Darwish committed 6 years ago

Commit 8fd8ad51 parent 932e4632 files · +20 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/lockdep.h+19−0
@@ -549,6 +549,22 @@ do { \ · 548 unmodified lines
549 WARN_ON_ONCE(debug_locks && !this_cpu_read(hardirq_context)); \549 WARN_ON_ONCE(debug_locks && !this_cpu_read(hardirq_context)); \
550} while (0)550} while (0)
551 551
552#define lockdep_assert_preemption_enabled() \
553do { \
554 WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
555 debug_locks && \
556 (preempt_count() != 0 || \
557 !this_cpu_read(hardirqs_enabled))); \
558} while (0)
559
560#define lockdep_assert_preemption_disabled() \
561do { \
562 WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
563 debug_locks && \
564 (preempt_count() == 0 && \
565 this_cpu_read(hardirqs_enabled))); \
566} while (0)
567
552#else568#else
553# define might_lock(lock) do { } while (0)569# define might_lock(lock) do { } while (0)
554# define might_lock_read(lock) do { } while (0)570# define might_lock_read(lock) do { } while (0)
@@ -557,6 +573,9 @@ do { \ · 2 unmodified lines
557# define lockdep_assert_irqs_enabled() do { } while (0)573# define lockdep_assert_irqs_enabled() do { } while (0)
558# define lockdep_assert_irqs_disabled() do { } while (0)574# define lockdep_assert_irqs_disabled() do { } while (0)
559# define lockdep_assert_in_irq() do { } while (0)575# define lockdep_assert_in_irq() do { } while (0)
576
577# define lockdep_assert_preemption_enabled() do { } while (0)
578# define lockdep_assert_preemption_disabled() do { } while (0)
560#endif579#endif
561 580
562#ifdef CONFIG_PROVE_RAW_LOCK_NESTING581#ifdef CONFIG_PROVE_RAW_LOCK_NESTING