Subject: Re: [PATCH net-next] net/tls: Use RCU API to access tls_ctx->netdev

From: Jakub Kicinski <[email-masked]>
Date: Mon, 1 Aug 2022 12:42:39 -0700

On Mon, 1 Aug 2022 11:00:53 +0300 Maxim Mikityanskiy wrote:
> @@ -1329,7 +1345,11 @@ static int tls_device_down(struct net_device *netdev)
>  
>  	spin_lock_irqsave(&tls_device_lock, flags);
>  	list_for_each_entry_safe(ctx, tmp, &tls_device_list, list) {
> -		if (ctx->netdev != netdev ||
> +		struct net_device *ctx_netdev =
> +			rcu_dereference_protected(ctx->netdev,
> +						  lockdep_is_held(&device_offload_lock));
> +
> +		if (ctx_netdev != netdev ||
>  		    !refcount_inc_not_zero(&ctx->refcount))
>  			continue;

For cases like this where we don't actually hold onto the object, just
take a peek at the address of it we can save a handful of LoC by using
rcu_access_pointer().