[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <380eb27278e581012524cdc16f99e1872cee9be0.camel@nvidia.com>
Date: Tue, 2 Aug 2022 12:03:32 +0000
From: Maxim Mikityanskiy <maximmi@...dia.com>
To: "kuba@...nel.org" <kuba@...nel.org>
CC: "davem@...emloft.net" <davem@...emloft.net>,
Tariq Toukan <tariqt@...dia.com>,
Gal Pressman <gal@...dia.com>,
"john.fastabend@...il.com" <john.fastabend@...il.com>,
"pabeni@...hat.com" <pabeni@...hat.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"edumazet@...gle.com" <edumazet@...gle.com>,
Saeed Mahameed <saeedm@...dia.com>,
Boris Pismenny <borisp@...dia.com>
Subject: Re: [PATCH net-next] net/tls: Use RCU API to access tls_ctx->netdev
On Mon, 2022-08-01 at 12:42 -0700, Jakub Kicinski wrote:
> 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().
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.
--cut--
Though, I can change the read side to use rcu_access_pointer, wherever
the pointer is not dereferenced. But it won't save lines of code :)
Powered by blists - more mailing lists