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

From: Jakub Kicinski <[email-masked]>
Date: Tue, 2 Aug 2022 08:37:31 -0700

On Tue, 2 Aug 2022 12:03:32 +0000 Maxim Mikityanskiy wrote:
> > 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().   
> 
> The documentation of rcu_access_pointer says it shouldn't be used on
> the update side, because we lose lockdep protection:
> 
> --cut--
> 
> Although rcu_access_pointer() may also be used in cases
> where update-side locks prevent the value of the pointer from changing,
> you should instead use rcu_dereference_protected() for this use case.

I think what this is trying to say is to not use the
rcu_access_pointer() as a hack against lockdep:

	lock(writer_lock);
	/* no need for rcu_dereference() because we have writer lock */
	ptr = rcu_access_pointer(obj->ptr);
	ptr->something = 1;
	unlock(writer_lock);

It's still perfectly fine to use access_pointer as intended on 
the write side, which is just checking the value of the pointer, 
not deferencing it:

	lock(writer_lock);
	if (rcu_access_pointer(obj->ptr) == target)
		so_something(obj);
	unlock(writer_lock);