Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rcu: Improve diagnostics for blocked critical sections in irq

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 <paulmck@linux.vnet.ibm.com>

+14 -3
+6 -1
include/linux/lockdep.h
··· 531 531 # define might_lock_read(lock) do { } while (0) 532 532 #endif 533 533 534 - #ifdef CONFIG_PROVE_RCU 534 + #ifdef CONFIG_LOCKDEP 535 535 void lockdep_rcu_suspicious(const char *file, const int line, const char *s); 536 + #else 537 + static inline void 538 + lockdep_rcu_suspicious(const char *file, const int line, const char *s) 539 + { 540 + } 536 541 #endif 537 542 538 543 #endif /* __LINUX_LOCKDEP_H */
+1 -1
include/linux/rcupdate.h
··· 942 942 { 943 943 rcu_lockdep_assert(rcu_is_watching(), 944 944 "rcu_read_unlock() used illegally while idle"); 945 - rcu_lock_release(&rcu_lock_map); 946 945 __release(RCU); 947 946 __rcu_read_unlock(); 947 + rcu_lock_release(&rcu_lock_map); /* Keep acq info for rls diags. */ 948 948 } 949 949 950 950 /**
+7 -1
kernel/rcu/tree_plugin.h
··· 334 334 } 335 335 336 336 /* Hardware IRQ handlers cannot block, complain if they get here. */ 337 - if (WARN_ON_ONCE(in_irq() || in_serving_softirq())) { 337 + if (in_irq() || in_serving_softirq()) { 338 + lockdep_rcu_suspicious(__FILE__, __LINE__, 339 + "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n"); 340 + pr_alert("->rcu_read_unlock_special: %#x (b: %d, nq: %d)\n", 341 + t->rcu_read_unlock_special.s, 342 + t->rcu_read_unlock_special.b.blocked, 343 + t->rcu_read_unlock_special.b.need_qs); 338 344 local_irq_restore(flags); 339 345 return; 340 346 }