Skip to contentSkip to conversation

devlink: small port_new/del() cleanup

PATCH Applied Jiri Pirko 4 participants 9 messages May 23, 2023 – May 24, 2023

Subsystems (4)
lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

cover devlink: small port_new/del() cleanup

From: Jiri Pirko <[email protected]>

This patchset cleans up couple of leftovers after recent devlink locking changes. Previously, both port_new/dev() commands were called without holding instance lock. Currently all devlink commands are called with instance lock held.

The first patch just removes redundant port notification. The second one removes couple of outdated comments.
The last patch changes port_dev() to have devlink_port pointer as an arg instead of port_index, which makes it similar to the rest of port related ops.

Jiri Pirko (3):
devlink: remove duplicate port notification
devlink: remove no longer true locking comment from port_new/del()
devlink: pass devlink_port pointer to ops->port_del() instead of index

 .../ethernet/mellanox/mlx5/core/sf/devlink.c  | 14 ++---
 .../net/ethernet/mellanox/mlx5/core/sf/sf.h   |  6 +-
 include/net/devlink.h                         | 12 +---
 net/devlink/leftover.c                        | 56 ++-----------------
 4 files changed, 16 insertions(+), 72 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/3 devlink: remove duplicate port notification

From: Jiri Pirko <[email protected]>

The notification about created port is send from devl_port_register() function called from ops->port_new(). No need to send it again here, so remove the call and the helper function.

---
 .../ethernet/mellanox/mlx5/core/sf/devlink.c  |  9 ++--
 .../net/ethernet/mellanox/mlx5/core/sf/sf.h   |  3 +-
 include/net/devlink.h                         |  4 +-
 net/devlink/leftover.c                        | 45 +------------------
 4 files changed, 6 insertions(+), 55 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +3 -6
index 7d955a4d9f14..de15b9c85e1b 100644
@@ -282,8 +282,7 @@ int mlx5_devlink_sf_port_fn_state_set(struct devlink_port *dl_port,
 
 static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
 		       const struct devlink_port_new_attrs *new_attr,
-		       struct netlink_ext_ack *extack,
-		       unsigned int *new_port_index)
+		       struct netlink_ext_ack *extack)
 {
 	struct mlx5_eswitch *esw = dev->priv.eswitch;
 	struct mlx5_sf *sf;
@@ -297,7 +296,6 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
 						new_attr->controller, new_attr->sfnum);
 	if (err)
 		goto esw_err;
-	*new_port_index = sf->port_index;
 	trace_mlx5_sf_add(dev, sf->port_index, sf->controller, sf->hw_fn_id, new_attr->sfnum);
 	return 0;
 
@@ -338,8 +336,7 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_
 
 int mlx5_devlink_sf_port_new(struct devlink *devlink,
 			     const struct devlink_port_new_attrs *new_attr,
-			     struct netlink_ext_ack *extack,
-			     unsigned int *new_port_index)
+			     struct netlink_ext_ack *extack)
 {
 	struct mlx5_core_dev *dev = devlink_priv(devlink);
 	struct mlx5_sf_table *table;
@@ -355,7 +352,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;
 	}
-	err = mlx5_sf_add(dev, table, new_attr, extack, new_port_index);
+	err = mlx5_sf_add(dev, table, new_attr, extack);
 	mlx5_sf_table_put(table);
 	return err;
 }
drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h +1 -2
index 3a480e06ecc0..1f7d8cbd72e8 100644
@@ -20,8 +20,7 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev);
 
 int mlx5_devlink_sf_port_new(struct devlink *devlink,
 			     const struct devlink_port_new_attrs *add_attr,
-			     struct netlink_ext_ack *extack,
-			     unsigned int *new_port_index);
+			     struct netlink_ext_ack *extack);
 int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
 			     struct netlink_ext_ack *extack);
 int mlx5_devlink_sf_port_fn_state_get(struct devlink_port *dl_port,
include/net/devlink.h +1 -3
index 6a942e70e451..ccea6e079777 100644
@@ -1500,7 +1500,6 @@ struct devlink_ops {
 	 * @devlink: Devlink instance
 	 * @attrs: attributes of the new port
 	 * @extack: extack for reporting error messages
-	 * @new_port_index: index of the new port
 	 *
 	 * Devlink core will call this device driver function upon user request
 	 * to create a new port function of a specified flavor and optional
@@ -1515,8 +1514,7 @@ struct devlink_ops {
 	 */
 	int (*port_new)(struct devlink *devlink,
 			const struct devlink_port_new_attrs *attrs,
-			struct netlink_ext_ack *extack,
-			unsigned int *new_port_index);
+			struct netlink_ext_ack *extack);
 	/**
 	 * port_del() - Delete a port function
 	 * @devlink: Devlink instance
net/devlink/leftover.c +1 -44

63 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 2/3 devlink: remove no longer true locking comment from port_new/del()

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

All commands are called holding instance lock. Remove the outdated comment that says otherwise.

---
 include/net/devlink.h | 4 ----
 1 file changed, 4 deletions(-)
include/net/devlink.h +0 -4
index ccea6e079777..24a48f3d4c35 100644
@@ -1506,8 +1506,6 @@ struct devlink_ops {
 	 * attributes
 	 *
 	 * Notes:
-	 *	- Called without devlink instance lock being held. Drivers must
-	 *	  implement own means of synchronization
 	 *	- On success, drivers must register a port with devlink core
 	 *
 	 * Return: 0 on success, negative value otherwise.
@@ -1525,8 +1523,6 @@ struct devlink_ops {
 	 * to delete a previously created port function
 	 *
 	 * Notes:
-	 *	- Called without devlink instance lock being held. Drivers must
-	 *	  implement own means of synchronization
 	 *	- On success, drivers must unregister the corresponding devlink
 	 *	  port
 	 *
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 3/3 devlink: pass devlink_port pointer to ops->port_del() instead of index

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Historically there was a reason why port_dev() along with for example port_split() did get port_index instead of the devlink_port pointer. With the locking changes that were done which ensured devlink instance mutex is hold for every command, the port ops could get devlink_port pointer directly. Change the forgotten port_dev() op to be as others and pass devlink_port pointer instead of port_index.

---
 drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c |  5 +++--
 drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h      |  3 ++-
 include/net/devlink.h                                |  4 ++--
 net/devlink/leftover.c                               | 11 +++--------
 4 files changed, 10 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +3 -2
index de15b9c85e1b..c7d4691cb65a 100644
@@ -376,7 +376,8 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)
 	}
 }
 
-int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
+int mlx5_devlink_sf_port_del(struct devlink *devlink,
+			     struct devlink_port *dl_port,
 			     struct netlink_ext_ack *extack)
 {
 	struct mlx5_core_dev *dev = devlink_priv(devlink);
@@ -391,7 +392,7 @@ int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
 				   "Port del is only supported in eswitch switchdev mode or SF ports are disabled.");
 		return -EOPNOTSUPP;
 	}
-	sf = mlx5_sf_lookup_by_index(table, port_index);
+	sf = mlx5_sf_lookup_by_index(table, dl_port->index);
 	if (!sf) {
 		err = -ENODEV;
 		goto sf_err;
drivers/net/ethernet/mellanox/mlx5/core/sf/sf.h +2 -1
index 1f7d8cbd72e8..c5430b8dcdf6 100644
@@ -21,7 +21,8 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev);
 int mlx5_devlink_sf_port_new(struct devlink *devlink,
 			     const struct devlink_port_new_attrs *add_attr,
 			     struct netlink_ext_ack *extack);
-int mlx5_devlink_sf_port_del(struct devlink *devlink, unsigned int port_index,
+int mlx5_devlink_sf_port_del(struct devlink *devlink,
+			     struct devlink_port *dl_port,
 			     struct netlink_ext_ack *extack);
 int mlx5_devlink_sf_port_fn_state_get(struct devlink_port *dl_port,
 				      enum devlink_port_fn_state *state,
include/net/devlink.h +2 -2
index 24a48f3d4c35..1bd56c8d6f3c 100644
@@ -1516,7 +1516,7 @@ struct devlink_ops {
 	/**
 	 * port_del() - Delete a port function
 	 * @devlink: Devlink instance
-	 * @port_index: port function index to delete
+	 * @port: The devlink port
 	 * @extack: extack for reporting error messages
 	 *
 	 * Devlink core will call this device driver function upon user request
@@ -1528,7 +1528,7 @@ struct devlink_ops {
 	 *
 	 * Return: 0 on success, negative value otherwise.
 	 */
-	int (*port_del)(struct devlink *devlink, unsigned int port_index,
+	int (*port_del)(struct devlink *devlink, struct devlink_port *port,
 			struct netlink_ext_ack *extack);
 	/**
 	 * port_fn_state_get() - Get the state of a port function
net/devlink/leftover.c +3 -8
index cb60e42b2761..0410137a4a31 100644
@@ -1396,20 +1396,14 @@ static int devlink_nl_cmd_port_new_doit(struct sk_buff *skb,
 static int devlink_nl_cmd_port_del_doit(struct sk_buff *skb,
 					struct genl_info *info)
 {
+	struct devlink_port *devlink_port = info->user_ptr[1];
 	struct netlink_ext_ack *extack = info->extack;
 	struct devlink *devlink = info->user_ptr[0];
-	unsigned int port_index;
 
 	if (!devlink->ops->port_del)
 		return -EOPNOTSUPP;
 
-	if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PORT_INDEX)) {
-		NL_SET_ERR_MSG(extack, "Port index is not specified");
-		return -EINVAL;
-	}
-	port_index = nla_get_u32(info->attrs[DEVLINK_ATTR_PORT_INDEX]);
-
-	return devlink->ops->port_del(devlink, port_index, extack);
+	return devlink->ops->port_del(devlink, devlink_port, extack);
 }
 
 static int
@@ -6341,6 +6335,7 @@ const struct genl_small_ops devlink_nl_ops[56] = {
 		.cmd = DEVLINK_CMD_PORT_DEL,
 		.doit = devlink_nl_cmd_port_del_doit,
 		.flags = GENL_ADMIN_PERM,
+		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
 	},
 	{
 		.cmd = DEVLINK_CMD_LINECARD_GET,
Signature · 1 line
2.39.2
Reviewed-by on v1 3/3
#6 lore raw

Re: [patch net-next 3/3] devlink: pass devlink_port pointer to ops->port_del() instead of index

Quoted 10 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

Historically there was a reason why port_dev() along with for example port_split() did get port_index instead of the devlink_port pointer. With the locking changes that were done which ensured devlink instance mutex is hold for every command, the port ops could get devlink_port pointer directly. Change the forgotten port_dev() op to be as others and pass devlink_port pointer instead of port_index.

maintainer Reviewed-by on the v1 series
#7 lore raw
In reply to Jiri Pirko
Quoted 10 lines · On Tue, 23 May 2023 14:37:58 +0200 Jiri Pirko wrote:

This patchset cleans up couple of leftovers after recent devlink locking changes. Previously, both port_new/dev() commands were called without holding instance lock. Currently all devlink commands are called with instance lock held.

The first patch just removes redundant port notification. The second one removes couple of outdated comments.
The last patch changes port_dev() to have devlink_port pointer as an arg instead of port_index, which makes it similar to the rest of port related ops.

#8 lore raw
In reply to Jiri Pirko
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 8 lines · On Tue, 23 May 2023 14:37:58 +0200 you wrote:

From: Jiri Pirko <[email protected]>

This patchset cleans up couple of leftovers after recent devlink locking changes. Previously, both port_new/dev() commands were called without holding instance lock. Currently all devlink commands are called with instance lock held.

[...]

Here is the summary with links:
- [net-next,1/3] devlink: remove duplicate port notification

    https://git.kernel.org/netdev/net-next/c/c496daeb8630
  - [net-next,2/3] devlink: remove no longer true locking comment from port_new/del()
    https://git.kernel.org/netdev/net-next/c/1bb1b5789850
  - [net-next,3/3] devlink: pass devlink_port pointer to ops->port_del() instead of index
    https://git.kernel.org/netdev/net-next/c/9277649c66fe

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html