devlink: Hold the instance lock in port_new / port_del callbacks
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 11 Jul 2022 08:14:08 +0000 (01:14 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 12 Jul 2022 08:26:23 +0000 (10:26 +0200)
Let the core take the devlink instance lock around port_new and port_del
callbacks and remove the now redundant locking in the only driver that
currently use them.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
net/core/devlink.c

index 2068c22..7d955a4 100644 (file)
@@ -355,9 +355,7 @@ int mlx5_devlink_sf_port_new(struct devlink *devlink,
                                   "Port add is only supported in eswitch switchdev mode or SF ports are disabled.");
                return -EOPNOTSUPP;
        }
-       devl_lock(devlink);
        err = mlx5_sf_add(dev, table, new_attr, extack, new_port_index);
-       devl_unlock(devlink);
        mlx5_sf_table_put(table);
        return err;
 }
@@ -402,9 +400,7 @@ int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
                goto sf_err;
        }
 
-       devl_lock(devlink);
        mlx5_esw_offloads_sf_vport_disable(esw, sf->hw_fn_id);
-       devl_unlock(devlink);
        mlx5_sf_id_erase(table, sf);
 
        mutex_lock(&table->sf_state_lock);
index 970e5c2..e206cc9 100644 (file)
@@ -1712,7 +1712,7 @@ static int devlink_port_new_notifiy(struct devlink *devlink,
        if (!msg)
                return -ENOMEM;
 
-       mutex_lock(&devlink->lock);
+       lockdep_assert_held(&devlink->lock);
        devlink_port = devlink_port_get_by_index(devlink, port_index);
        if (!devlink_port) {
                err = -ENODEV;
@@ -1725,11 +1725,9 @@ static int devlink_port_new_notifiy(struct devlink *devlink,
                goto out;
 
        err = genlmsg_reply(msg, info);
-       mutex_unlock(&devlink->lock);
        return err;
 
 out:
-       mutex_unlock(&devlink->lock);
        nlmsg_free(msg);
        return err;
 }
@@ -9067,13 +9065,11 @@ static const struct genl_small_ops devlink_nl_ops[] = {
                .cmd = DEVLINK_CMD_PORT_NEW,
                .doit = devlink_nl_cmd_port_new_doit,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
        },
        {
                .cmd = DEVLINK_CMD_PORT_DEL,
                .doit = devlink_nl_cmd_port_del_doit,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
        },
        {
                .cmd = DEVLINK_CMD_LINECARD_GET,