aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2018-07-24 18:28:09 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2018-08-30 19:03:42 -0400
commit74de6960c99d8df0d09fb29a7b014cb9c5571e2b (patch)
tree2399404f1a3a043609c1f998c4c5f836e1100244
parent7e28c5af4ef6b539334aa5de40feca0c041c94df (diff)
rcu: Provide functions for determining if call_rcu() has been invoked
This commit adds rcu_head_init() and rcu_head_after_call_rcu() functions to help RCU users detect when another CPU has passed the specified rcu_head structure and function to call_rcu(). The rcu_head_init() should be invoked before making the structure visible to RCU readers, and then the rcu_head_after_call_rcu() may be invoked from within an RCU read-side critical section on an rcu_head structure that was obtained during a traversal of the data structure in question. The rcu_head_after_call_rcu() function will return true if the rcu_head structure has already been passed (with the specified function) to call_rcu(), otherwise it will return false. If rcu_head_init() has not been invoked on the rcu_head structure or if the rcu_head (AKA callback) has already been invoked, then rcu_head_after_call_rcu() will do WARN_ON_ONCE(). Reported-by: NeilBrown <neilb@suse.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> [ paulmck: Apply neilb naming feedback. ]
-rw-r--r--include/linux/rcupdate.h40
-rw-r--r--kernel/rcu/rcu.h5
2 files changed, 44 insertions, 1 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index e4f821165d0b..4db8bcacc51a 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -857,6 +857,46 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
857#endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ 857#endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */
858 858
859 859
860/* Has the specified rcu_head structure been handed to call_rcu()? */
861
862/*
863 * rcu_head_init - Initialize rcu_head for rcu_head_after_call_rcu()
864 * @rhp: The rcu_head structure to initialize.
865 *
866 * If you intend to invoke rcu_head_after_call_rcu() to test whether a
867 * given rcu_head structure has already been passed to call_rcu(), then
868 * you must also invoke this rcu_head_init() function on it just after
869 * allocating that structure. Calls to this function must not race with
870 * calls to call_rcu(), rcu_head_after_call_rcu(), or callback invocation.
871 */
872static inline void rcu_head_init(struct rcu_head *rhp)
873{
874 rhp->func = (rcu_callback_t)~0L;
875}
876
877/*
878 * rcu_head_after_call_rcu - Has this rcu_head been passed to call_rcu()?
879 * @rhp: The rcu_head structure to test.
880 * @func: The function passed to call_rcu() along with @rhp.
881 *
882 * Returns @true if the @rhp has been passed to call_rcu() with @func,
883 * and @false otherwise. Emits a warning in any other case, including
884 * the case where @rhp has already been invoked after a grace period.
885 * Calls to this function must not race with callback invocation. One way
886 * to avoid such races is to enclose the call to rcu_head_after_call_rcu()
887 * in an RCU read-side critical section that includes a read-side fetch
888 * of the pointer to the structure containing @rhp.
889 */
890static inline bool
891rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
892{
893 if (READ_ONCE(rhp->func) == f)
894 return true;
895 WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L);
896 return false;
897}
898
899
860/* Transitional pre-consolidation compatibility definitions. */ 900/* Transitional pre-consolidation compatibility definitions. */
861 901
862static inline void synchronize_rcu_bh(void) 902static inline void synchronize_rcu_bh(void)
diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h
index 5dec94509a7e..4c56c1d98fb3 100644
--- a/kernel/rcu/rcu.h
+++ b/kernel/rcu/rcu.h
@@ -224,6 +224,7 @@ void kfree(const void *);
224 */ 224 */
225static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) 225static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
226{ 226{
227 rcu_callback_t f;
227 unsigned long offset = (unsigned long)head->func; 228 unsigned long offset = (unsigned long)head->func;
228 229
229 rcu_lock_acquire(&rcu_callback_map); 230 rcu_lock_acquire(&rcu_callback_map);
@@ -234,7 +235,9 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
234 return true; 235 return true;
235 } else { 236 } else {
236 RCU_TRACE(trace_rcu_invoke_callback(rn, head);) 237 RCU_TRACE(trace_rcu_invoke_callback(rn, head);)
237 head->func(head); 238 f = head->func;
239 WRITE_ONCE(head->func, (rcu_callback_t)0L);
240 f(head);
238 rcu_lock_release(&rcu_callback_map); 241 rcu_lock_release(&rcu_callback_map);
239 return false; 242 return false;
240 } 243 }