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

From: Eric Dumazet <[email-masked]>
Date: Fri, 15 Jan 2010 16:29:14 +0100

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 ?

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