Re: [PATCH net-next v2 2/3] net: add granular lock for the netdev netlink socket

From: Mina Almasry
Date: Tue Mar 11 2025 - 19:43:53 EST


On Tue, Mar 11, 2025 at 1:03 PM Stanislav Fomichev <stfomichev@xxxxxxxxx> wrote:
>
> On 03/11, Mina Almasry wrote:
> > On Tue, Mar 11, 2025 at 7:40 AM Stanislav Fomichev <sdf@xxxxxxxxxxx> wrote:
> > >
> > > As we move away from rtnl_lock for queue ops, introduce
> > > per-netdev_nl_sock lock.
> > >
> > > Cc: Mina Almasry <almasrymina@xxxxxxxxxx>
> > > Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxxx>
> > > ---
> > > include/net/netdev_netlink.h | 1 +
> > > net/core/netdev-genl.c | 6 ++++++
> > > 2 files changed, 7 insertions(+)
> > >
> > > diff --git a/include/net/netdev_netlink.h b/include/net/netdev_netlink.h
> > > index 1599573d35c9..075962dbe743 100644
> > > --- a/include/net/netdev_netlink.h
> > > +++ b/include/net/netdev_netlink.h
> > > @@ -5,6 +5,7 @@
> > > #include <linux/list.h>
> > >
> > > struct netdev_nl_sock {
> > > + struct mutex lock;
> > > struct list_head bindings;
> > > };
> > >
> > > diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> > > index a219be90c739..63e10717efc5 100644
> > > --- a/net/core/netdev-genl.c
> > > +++ b/net/core/netdev-genl.c
> > > @@ -859,6 +859,7 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
> > > goto err_genlmsg_free;
> > > }
> > >
> > > + mutex_lock(&priv->lock);
> >
> > You do not need to acquire this lock so early, no? AFAICT you only
> > need to lock around:
> >
> > list_add(&binding->list, sock_binding_list);
> >
> > Or is this to establish a locking order (sock_binding_list lock before
> > the netdev lock)?
>
> Right, if I acquire it later, I'd have to do the same order
> in netdev_nl_sock_priv_destroy and it seems to be a bit more complicated
> to do (since we go over the list of bindings over there).

Thanks,

Reviewed-by: Mina Almasry <almasrymina@xxxxxxxxxx>


--
Thanks,
Mina