Subject: Re: [PATCH net-next] vrf: vrf_master_ifindex_rcu is not always called with rcu read lock

From: David Ahern <[email-masked]>
Date: Tue, 18 Aug 2015 13:45:20 -0600

On 8/18/15 10:17 AM, Nikolay Aleksandrov wrote:
> diff --git a/include/net/vrf.h b/include/net/vrf.h
> index 40e3793c7a05..22dfe2195092 100644
> --- a/include/net/vrf.h
> +++ b/include/net/vrf.h
> @@ -35,7 +35,6 @@ struct net_vrf {
>
>
>   #if IS_ENABLED(CONFIG_NET_VRF)
> -/* called with rcu_read_lock() */
>   static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
>   {
>   	struct net_vrf_dev *vrf_ptr;
> @@ -44,12 +43,14 @@ static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
>   	if (!dev)
>   		return 0;
>
> -	if (netif_is_vrf(dev))
> +	if (netif_is_vrf(dev)) {
>   		ifindex = dev->ifindex;
> -	else {
> +	} else {
> +		rcu_read_lock();
>   		vrf_ptr = rcu_dereference(dev->vrf_ptr);
>   		if (vrf_ptr)
>   			ifindex = vrf_ptr->ifindex;
> +		rcu_read_unlock();
>   	}
>
>   	return ifindex;
>

The intent of the _rcu in the name is to mean it is called with 
rcu_read_lock held which is the case for __fib_validate_source and 
ip_route_input_slow. It looks like the icmp callers (icmp_reply and 
icmp_route_lookup) are the exceptions. For those create a

static inline int vrf_master_ifindex(const struct net_device *dev)
{

}

that does the rcu lock/unlock and calls vrf_master_ifindex_rcu in between.