From: "Paul E. McKenney" <paul...@linux.vnet.ibm.com>

If an RCU read-side critical section occurs within an interrupt handler
or a softirq handler, it cannot have been preempted.  Therefore, there is
a check in rcu_read_unlock_special() checking for this error.  However,
when this check triggers, it lacks diagnostic information.  This commit
therefore moves rcu_read_unlock()'s lockdep annotation to follow the
call to __rcu_read_unlock() and changes rcu_read_unlock_special()'s
WARN_ON_ONCE() to an lockdep_rcu_suspicious() in order to locate where
the offending RCU read-side critical section began.  In addition, the
value of the ->rcu_read_unlock_special field is printed.

Signed-off-by: Paul E. McKenney <paul...@linux.vnet.ibm.com>
---
 include/linux/lockdep.h  | 7 ++++++-
 include/linux/rcupdate.h | 2 +-
 kernel/rcu/tree_plugin.h | 8 +++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 74ab23176e9b..066ba4157541 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -531,8 +531,13 @@ do {                                                       
                \
 # define might_lock_read(lock) do { } while (0)
 #endif
 
-#ifdef CONFIG_PROVE_RCU
+#ifdef CONFIG_LOCKDEP
 void lockdep_rcu_suspicious(const char *file, const int line, const char *s);
+#else
+static inline void
+lockdep_rcu_suspicious(const char *file, const int line, const char *s)
+{
+}
 #endif
 
 #endif /* __LINUX_LOCKDEP_H */
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 3e6afed51051..70b896e16f19 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -942,9 +942,9 @@ static inline void rcu_read_unlock(void)
 {
        rcu_lockdep_assert(rcu_is_watching(),
                           "rcu_read_unlock() used illegally while idle");
-       rcu_lock_release(&rcu_lock_map);
        __release(RCU);
        __rcu_read_unlock();
+       rcu_lock_release(&rcu_lock_map); /* Keep acq info for rls diags. */
 }
 
 /**
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 93eeefeacc02..fec7034d41db 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -334,7 +334,13 @@ void rcu_read_unlock_special(struct task_struct *t)
        }
 
        /* Hardware IRQ handlers cannot block, complain if they get here. */
-       if (WARN_ON_ONCE(in_irq() || in_serving_softirq())) {
+       if (in_irq() || in_serving_softirq()) {
+               lockdep_rcu_suspicious(__FILE__, __LINE__,
+                                      "rcu_read_unlock() from irq or softirq 
with blocking in critical section!!!\n");
+               pr_alert("->rcu_read_unlock_special: %#x (b: %d, nq: %d)\n",
+                        t->rcu_read_unlock_special.s,
+                        t->rcu_read_unlock_special.b.blocked,
+                        t->rcu_read_unlock_special.b.need_qs);
                local_irq_restore(flags);
                return;
        }
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to