locking/lockdep: Add IRQs disabled/enabled assertion APIs: lockdep_assert_irqs_enabled()/disabled() [Linux 3.16.72]

This Linux kernel change "locking/lockdep: Add IRQs disabled/enabled assertion APIs: lockdep_assert_irqs_enabled()/disabled()" is included in the Linux 3.16.72 release. This change is authored by Frederic Weisbecker <frederic [at] kernel.org> on Mon Nov 6 16:01:17 2017 +0100. The commit for this change in Linux stable tree is 399df2d (patch) which is from upstream commit f54bb2e. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream f54bb2e.

locking/lockdep: Add IRQs disabled/enabled assertion APIs: lockdep_assert_irqs_enabled()/disabled()

commit f54bb2ec02c839f6bfe3e8d438cd93d30b4809dd upstream.

Checking whether IRQs are enabled or disabled is a very common sanity
check, however not free of overhead especially on fastpath where such
assertion is very common.

Lockdep is a good host for such concurrency correctness check and it
even already tracks down IRQs disablement state. Just reuse its
machinery. This will allow us to get rid of the flags pop and check
overhead from fast path when kernel is built for production.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David S . Miller <davem@davemloft.net>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/1509980490-4285-2-git-send-email-frederic@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

There are 15 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 include/linux/lockdep.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 64c7425..f2bca5a 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -525,9 +525,24 @@ static inline void print_irqtrace_events(struct task_struct *curr)
    lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_);    \
    lock_release(&(lock)->dep_map, 0, _THIS_IP_);           \
 } while (0)
+
+#define lockdep_assert_irqs_enabled()  do {                \
+       WARN_ONCE(debug_locks && !current->lockdep_recursion && \
+             !current->hardirqs_enabled,           \
+             "IRQs not enabled as expected\n");        \
+   } while (0)
+
+#define lockdep_assert_irqs_disabled() do {                \
+       WARN_ONCE(debug_locks && !current->lockdep_recursion && \
+             current->hardirqs_enabled,            \
+             "IRQs not disabled as expected\n");       \
+   } while (0)
+
 #else
 # define might_lock(lock) do { } while (0)
 # define might_lock_read(lock) do { } while (0)
+# define lockdep_assert_irqs_enabled() do { } while (0)
+# define lockdep_assert_irqs_disabled() do { } while (0)
 #endif

 #ifdef CONFIG_PROVE_RCU

Leave a Reply

Your email address will not be published. Required fields are marked *