Subject: Re: [PATCH v2 net-next 01/14] rtnetlink: prepare nla_put_iflink() to run under RCU

From: Donald Hunter <[email-masked]>
Date: Fri, 23 Feb 2024 13:29:58 +0000

Eric Dumazet <[email-masked]> writes:

> We want to be able to run rtnl_fill_ifinfo() under RCU protection
> instead of RTNL in the future.
>
> This patch prepares dev_get_iflink() and nla_put_iflink()
> to run either with RTNL or RCU held.
>
> Signed-off-by: Eric Dumazet <[email-masked]>

I notice that several of the *_get_iflink() implementations are wrapped
with rcu_read_lock()/unlock() and many are not. Shouldn't this be done
consistently for all?

e.g.

> diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
> index 7a5be705d71830d5bb3aa26a96a4463df03883a4..6f2a688fccbfb02ae7bdf3d55cca0e77fa9b56b4 100644
> --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
> +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
> @@ -1272,10 +1272,10 @@ static int ipoib_get_iflink(const struct net_device *dev)
>  
>  	/* parent interface */
>  	if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags))
> -		return dev->ifindex;
> +		return READ_ONCE(dev->ifindex);
>  
>  	/* child/vlan interface */
> -	return priv->parent->ifindex;
> +	return READ_ONCE(priv->parent->ifindex);
>  }
>  
>  static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr)
> diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
> index 98c669ad5141479b509ee924ddba3da6bca554cd..f7fabba707ea640cab8863e63bb19294e333ba2c 100644
> --- a/drivers/net/can/vxcan.c
> +++ b/drivers/net/can/vxcan.c
> @@ -119,7 +119,7 @@ static int vxcan_get_iflink(const struct net_device *dev)
>  
>  	rcu_read_lock();
>  	peer = rcu_dereference(priv->peer);
> -	iflink = peer ? peer->ifindex : 0;
> +	iflink = peer ? READ_ONCE(peer->ifindex) : 0;
>  	rcu_read_unlock();
>  
>  	return iflink;