Subject: Re: What protects rcu_dereference() in __in6_dev_get()?

From: "Paul E. McKenney" <[email-masked]>
Date: Fri, 15 Jan 2010 07:53:09 -0800

On Fri, Jan 15, 2010 at 04:29:14PM +0100, Eric Dumazet wrote:
> Le 15/01/2010 16:15, Paul E. McKenney a écrit :
> > On Fri, Jan 15, 2010 at 06:50:15AM +0100, Eric Dumazet wrote:
> >> __in6_dev_get() is called either with rcu_read_lock()/rcu_read_unlock() protection,
> >> or with the RTNL mutex held.
> > 
> > Very good!  So I make a lockdep_rtnl_is_held() in net/core/rtnetlink.c:
> > 
> > 	#ifdef CONFIG_PROVE_LOCKING
> > 	int lockdep_rtnl_is_held(void)
> > 	{
> > 		return lockdep_is_held(&rtnl_mutex);
> > 	}
> > 	EXPORT_SYMBOL(lockdep_rtnl_is_held);
> > 	#endif /* #ifdef CONFIG_PROVE_LOCKING */
> > 
> > Then I make __in6_dev_get() look as follows:
> > 
> > 	static inline struct inet6_dev *
> > 	__in6_dev_get(struct net_device *dev)
> > 	{
> > 		return rcu_dereference_check(dev->ip6_ptr,
> > 					     rcu_read_lock_held() ||
> > 					     lockdep_rtnl_is_held());
> > 	}
> > 
> > Seem reasonable?
> 
> I guess so, but is lockdep_is_held(&mutex) actually cheking this mutex is owned by us ?

Indeed it does!  But only if lockdep is enabled.  When lockdep is -not-
enabled, rcu_dereference_check() ignores its second argument.

> If another thread is the owner, we could miss a bug.

That s why I created a new lockdep_rtnl_is_held() rather than using the
existing rtnl_is_locked().

							Thanx, Paul