Re: [PATCH net-next v2] net: hold netdev reference during qdisc_create request_module
From: Stanislav Fomichev
Date: Mon Mar 24 2025 - 18:22:30 EST
On 03/24, Jakub Kicinski wrote:
> On Thu, 20 Mar 2025 09:51:03 -0700 Stanislav Fomichev wrote:
> > rtnl_lock();
> > netdev_lock_ops(dev);
> > + dev_put(dev);
> > ops = qdisc_lookup_ops(kind);
>
> I'm not sure if this is a correct sequence. Do we guarantee that locks
> will be taken before device is freed? I mean we do:
>
> dev = netdev_wait_allrefs_any()
> free_netdev(dev)
> mutex_destroy(dev->lock)
>
> without explicitly taking rtnl_lock() or netdev_lock(), so the moment
> that dev_put() is called the device may get freed from another thread
> - while its locked here.
>
> My mental model is that taking the instance lock on a dev for which we
> only have a ref requires a dance implemented in __netdev_put_lock().
Good point, didn't think about it. In this case, I think I need to
get back to exposing locked/unlocked signal back to the callers.
Even with __netdev_put_lock, there is a case where the netdev is
dead and can't be relocked. Will add some new 'bool *locked' argument
and reset it here; the caller will skip unlock when 'locked == false'.
LMK if you have better ideas, otherwise will post something tomorrow.