devlink: hold the instance lock in port_split / port_unsplit callbacks

Let the core take the devlink instance lock around port splitting
and remove the now redundant locking in the drivers.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2022-03-14 23:00:08 -07:00
parent 5e8930aa86
commit 49e83bbe8c
3 changed files with 8 additions and 33 deletions

View File

@ -2025,7 +2025,6 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
struct mlxsw_sp_port_mapping port_mapping; struct mlxsw_sp_port_mapping port_mapping;
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
enum mlxsw_reg_pmtdb_status status; enum mlxsw_reg_pmtdb_status status;
@ -2063,7 +2062,6 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
port_mapping = mlxsw_sp_port->mapping; port_mapping = mlxsw_sp_port->mapping;
devl_lock(devlink);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
u16 s_local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i); u16 s_local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i);
@ -2077,13 +2075,11 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
dev_err(mlxsw_sp->bus_info->dev, "Failed to create split ports\n"); dev_err(mlxsw_sp->bus_info->dev, "Failed to create split ports\n");
goto err_port_split_create; goto err_port_split_create;
} }
devl_unlock(devlink);
return 0; return 0;
err_port_split_create: err_port_split_create:
mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl); mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl);
devl_unlock(devlink);
return err; return err;
} }
@ -2091,7 +2087,6 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
char pmtdb_pl[MLXSW_REG_PMTDB_LEN]; char pmtdb_pl[MLXSW_REG_PMTDB_LEN];
unsigned int count; unsigned int count;
@ -2123,7 +2118,6 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port,
return err; return err;
} }
devl_lock(devlink);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
u16 s_local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i); u16 s_local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i);
@ -2132,7 +2126,6 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port,
} }
mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl); mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl);
devl_unlock(devlink);
return 0; return 0;
} }

View File

@ -70,29 +70,21 @@ nfp_devlink_port_split(struct devlink *devlink, unsigned int port_index,
unsigned int lanes; unsigned int lanes;
int ret; int ret;
devl_lock(devlink);
rtnl_lock(); rtnl_lock();
ret = nfp_devlink_fill_eth_port_from_id(pf, port_index, &eth_port); ret = nfp_devlink_fill_eth_port_from_id(pf, port_index, &eth_port);
rtnl_unlock(); rtnl_unlock();
if (ret) if (ret)
goto out; return ret;
if (eth_port.port_lanes % count) { if (eth_port.port_lanes % count)
ret = -EINVAL; return -EINVAL;
goto out;
}
/* Special case the 100G CXP -> 2x40G split */ /* Special case the 100G CXP -> 2x40G split */
lanes = eth_port.port_lanes / count; lanes = eth_port.port_lanes / count;
if (eth_port.lanes == 10 && count == 2) if (eth_port.lanes == 10 && count == 2)
lanes = 8 / count; lanes = 8 / count;
ret = nfp_devlink_set_lanes(pf, eth_port.index, lanes); return nfp_devlink_set_lanes(pf, eth_port.index, lanes);
out:
devl_unlock(devlink);
return ret;
} }
static int static int
@ -104,29 +96,21 @@ nfp_devlink_port_unsplit(struct devlink *devlink, unsigned int port_index,
unsigned int lanes; unsigned int lanes;
int ret; int ret;
devl_lock(devlink);
rtnl_lock(); rtnl_lock();
ret = nfp_devlink_fill_eth_port_from_id(pf, port_index, &eth_port); ret = nfp_devlink_fill_eth_port_from_id(pf, port_index, &eth_port);
rtnl_unlock(); rtnl_unlock();
if (ret) if (ret)
goto out; return ret;
if (!eth_port.is_split) { if (!eth_port.is_split)
ret = -EINVAL; return -EINVAL;
goto out;
}
/* Special case the 100G CXP -> 2x40G unsplit */ /* Special case the 100G CXP -> 2x40G unsplit */
lanes = eth_port.port_lanes; lanes = eth_port.port_lanes;
if (eth_port.port_lanes == 8) if (eth_port.port_lanes == 8)
lanes = 10; lanes = 10;
ret = nfp_devlink_set_lanes(pf, eth_port.index, lanes); return nfp_devlink_set_lanes(pf, eth_port.index, lanes);
out:
devl_unlock(devlink);
return ret;
} }
static int static int

View File

@ -8672,14 +8672,12 @@ static const struct genl_small_ops devlink_nl_ops[] = {
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
.doit = devlink_nl_cmd_port_split_doit, .doit = devlink_nl_cmd_port_split_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
}, },
{ {
.cmd = DEVLINK_CMD_PORT_UNSPLIT, .cmd = DEVLINK_CMD_PORT_UNSPLIT,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
.doit = devlink_nl_cmd_port_unsplit_doit, .doit = devlink_nl_cmd_port_unsplit_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
}, },
{ {
.cmd = DEVLINK_CMD_PORT_NEW, .cmd = DEVLINK_CMD_PORT_NEW,