Skip to content

Commit c3ac7cf

Browse files
committed
rcu: Add rcu_pointer_handoff()
This commit adds an rcu_pointer_handoff() that is intended to mark situations where a structure's protection transitions from RCU to some other mechanism (locking, reference counting, whatever). These markings should allow external tools to more easily spot bugs involving leaking pointers out of RCU read-side critical sections. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent c34d2f4 commit c3ac7cf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/linux/rcupdate.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,28 @@ static inline void rcu_preempt_sleep_check(void)
812812
*/
813813
#define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
814814

815+
/**
816+
* rcu_pointer_handoff() - Hand off a pointer from RCU to other mechanism
817+
* @p: The pointer to hand off
818+
*
819+
* This is simply an identity function, but it documents where a pointer
820+
* is handed off from RCU to some other synchronization mechanism, for
821+
* example, reference counting or locking. In C11, it would map to
822+
* kill_dependency(). It could be used as follows:
823+
*
824+
* rcu_read_lock();
825+
* p = rcu_dereference(gp);
826+
* long_lived = is_long_lived(p);
827+
* if (long_lived) {
828+
* if (!atomic_inc_not_zero(p->refcnt))
829+
* long_lived = false;
830+
* else
831+
* p = rcu_pointer_handoff(p);
832+
* }
833+
* rcu_read_unlock();
834+
*/
835+
#define rcu_pointer_handoff(p) (p)
836+
815837
/**
816838
* rcu_read_lock() - mark the beginning of an RCU read-side critical section
817839
*

0 commit comments

Comments
 (0)