Skip to contentSkip to conversation

devlink: Add shared descriptor eswitch attr

RFC PATCH Superseded William Tu 3 participants 5 messages Feb 28, 2024 – Feb 29, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

William Tu

author
#0 lore raw

RFC PATCH 1/2 devlink: Add shared descriptor eswitch attr

Add two eswitch attrs: shrdesc_mode and shrdesc_count.

1. shrdesc_mode: to enable a sharing memory buffer for representor's rx buffer, and 2. shrdesc_count: to control the number of buffers in this shared memory pool.

When using switchdev mode, the representor ports handles the slow path traffic, the traffic that can't be offloaded will be redirected to the representor port for processing. Memory consumption of the representor port's rx buffer can grow to several GB when scaling to 1k VFs reps. For example, in mlx5 driver, each RQ, with a typical 1K descriptors, consumes 3MB of DMA memory for packet buffer in WQEs, and with four channels, it consumes 4 * 3MB * 1024 = 12GB of memory. And since rep ports are for slow path traffic, most of these rx DMA memory are idle.

Add shrdesc_mode configuration, allowing multiple representors to share a rx memory buffer pool. When enabled, individual representor doesn't need to allocate its dedicated rx buffer, but just pointing its rq to the memory pool. This could make the memory being better utilized. The shrdesc_count represents the number of rx ring entries, e.g., same meaning as ethtool -g, that's shared across other representors. Users adjust it based on how many reps, total system memory, or performance expectation.

The two params are also useful for other vendors such as Intel ICE drivers and Broadcom's driver, which also have representor ports for slow path traffic.

An example use case:

$ devlink dev eswitch show pci/0000:08:00.0
  pci/0000:08:00.0: mode legacy inline-mode none encap-mode basic \
  shrdesc-mode none shrdesc-count 0
$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev \
  shrdesc-mode basic shrdesc-count 1024
$ devlink dev eswitch show pci/0000:08:00.0
  pci/0000:08:00.0: mode switchdev inline-mode none encap-mode basic \
  shrdesc-mode basic shrdesc-count 1024

Note that new configurations are set at legacy mode, and enabled at switchdev mode.

---
previous devlink-sd discussion
https://lore.kernel.org/netdev/[email protected]/

---
 include/net/devlink.h        |  8 +++++++
 include/uapi/linux/devlink.h |  7 ++++++
 net/devlink/dev.c            | 43 ++++++++++++++++++++++++++++++++++++
 net/devlink/netlink_gen.c    |  6 +++--
 4 files changed, 62 insertions(+), 2 deletions(-)
include/net/devlink.h +8 -0
index 9ac394bdfbe4..aca25183e72a 100644
@@ -1327,6 +1327,14 @@ struct devlink_ops {
 	int (*eswitch_encap_mode_set)(struct devlink *devlink,
 				      enum devlink_eswitch_encap_mode encap_mode,
 				      struct netlink_ext_ack *extack);
+	int (*eswitch_shrdesc_mode_get)(struct devlink *devlink,
+				        enum devlink_eswitch_shrdesc_mode *p_shrdesc_mode);
+	int (*eswitch_shrdesc_mode_set)(struct devlink *devlink,
+				        enum devlink_eswitch_shrdesc_mode shrdesc_mode,
+				        struct netlink_ext_ack *extack);
+	int (*eswitch_shrdesc_count_get)(struct devlink *devlink, int *count);
+	int (*eswitch_shrdesc_count_set)(struct devlink *devlink, int count,
+				        struct netlink_ext_ack *extack);
 	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
 			struct netlink_ext_ack *extack);
 	/**
include/uapi/linux/devlink.h +7 -0
index 130cae0d3e20..31323c481614 100644
@@ -195,6 +195,11 @@ enum devlink_eswitch_encap_mode {
 	DEVLINK_ESWITCH_ENCAP_MODE_BASIC,
 };
 
+enum devlink_eswitch_shrdesc_mode {
+	DEVLINK_ESWITCH_SHRDESC_MODE_NONE,
+	DEVLINK_ESWITCH_SHRDESC_MODE_BASIC,
+};
+
 enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_PHYSICAL, /* Any kind of a port physically
 					* facing the user.
@@ -614,6 +619,8 @@ enum devlink_attr {
 
 	DEVLINK_ATTR_REGION_DIRECT,		/* flag */
 
+	DEVLINK_ATTR_ESWITCH_SHRDESC_MODE,	/* u8 */
+	DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT,	/* u32 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
net/devlink/dev.c +43 -0

72 lines not on this page · raw message

net/devlink/netlink_gen.c +4 -2
index c81cf2dd154f..ac8b0c7105dd 100644
@@ -194,12 +194,14 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
 };
 
 /* DEVLINK_CMD_ESWITCH_SET - do */
-static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
+static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT + 1] = {
 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U16, 3),
 	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT] = NLA_POLICY_MAX(NLA_U32, 65535),
 };
 
 /* DEVLINK_CMD_DPIPE_TABLE_GET - do */
@@ -787,7 +789,7 @@ const struct genl_split_ops devlink_nl_ops[74] = {
 		.doit		= devlink_nl_eswitch_set_doit,
 		.post_doit	= devlink_nl_post_doit,
 		.policy		= devlink_eswitch_set_nl_policy,
-		.maxattr	= DEVLINK_ATTR_ESWITCH_ENCAP_MODE,
+		.maxattr	= DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT,
 		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
 	},
 	{
Signature · 1 line
2.38.1
author
#1 lore raw

RFC PATCH 2/2 net/mlx5e: Add eswitch shared descriptor devlink

Add devlink support for ewsitch shared descriptor
implementation for mlx5 driver.

---
 .../net/ethernet/mellanox/mlx5/core/devlink.c |  4 +
 .../net/ethernet/mellanox/mlx5/core/eswitch.h | 10 +++
 .../mellanox/mlx5/core/eswitch_offloads.c     | 80 +++++++++++++++++++
 3 files changed, 94 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/devlink.c +4 -0
index 3e064234f6fe..24eb03763b60 100644
@@ -312,6 +312,10 @@ static const struct devlink_ops mlx5_devlink_ops = {
 	.eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get,
 	.eswitch_encap_mode_set = mlx5_devlink_eswitch_encap_mode_set,
 	.eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get,
+	.eswitch_shrdesc_mode_set = mlx5_devlink_eswitch_shrdesc_mode_set,
+	.eswitch_shrdesc_mode_get = mlx5_devlink_eswitch_shrdesc_mode_get,
+	.eswitch_shrdesc_count_set = mlx5_devlink_eswitch_shrdesc_count_set,
+	.eswitch_shrdesc_count_get = mlx5_devlink_eswitch_shrdesc_count_get,
 	.rate_leaf_tx_share_set = mlx5_esw_devlink_rate_leaf_tx_share_set,
 	.rate_leaf_tx_max_set = mlx5_esw_devlink_rate_leaf_tx_max_set,
 	.rate_node_tx_share_set = mlx5_esw_devlink_rate_node_tx_share_set,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +10 -0
index 349e28a6dd8d..f678bcb98e1f 100644
@@ -378,6 +378,8 @@ struct mlx5_eswitch {
 	struct mlx5_esw_functions esw_funcs;
 	struct {
 		u32             large_group_num;
+		u32             shared_rx_ring_counts;
+		bool            enable_shared_rx_ring;
 	}  params;
 	struct blocking_notifier_head n_head;
 	struct xarray paired;
@@ -549,6 +551,14 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
 					struct netlink_ext_ack *extack);
 int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
 					enum devlink_eswitch_encap_mode *encap);
+int mlx5_devlink_eswitch_shrdesc_mode_set(struct devlink *devlink,
+					  enum devlink_eswitch_shrdesc_mode mode,
+					  struct netlink_ext_ack *extack);
+int mlx5_devlink_eswitch_shrdesc_mode_get(struct devlink *devlink,
+					  enum devlink_eswitch_shrdesc_mode *mode);
+int mlx5_devlink_eswitch_shrdesc_count_set(struct devlink *devlink, int count,
+					   struct netlink_ext_ack *extack);
+int mlx5_devlink_eswitch_shrdesc_count_get(struct devlink *devlink, int *count);
 int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
 				     u8 *hw_addr, int *hw_addr_len,
 				     struct netlink_ext_ack *extack);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +80 -0

86 lines not on this page · raw message

Signature · 1 line
2.38.1
reviewer
#2 lore raw
In reply to William Tu

On Wed, Feb 28, 2024 at 03:59:53AM +0200, William Tu wrote:

...

Quoted 8 lines
net/devlink/netlink_gen.c +0 -0
index c81cf2dd154f..ac8b0c7105dd 100644
@@ -194,12 +194,14 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
 };
 
 /* DEVLINK_CMD_ESWITCH_SET - do */

net/devlink/netlink_gen.c static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA · line 205

Quoted 10 lines
net/devlink/netlink_gen.c +3 -1
-static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
+static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT + 1] = {
 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U16, 3),
 	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT] = NLA_POLICY_MAX(NLA_U32, 65535),
 };

Hi William,

I realise this is probably not central to your purpose in sending an RFC, but my understanding is that the max value set using NLA_POLICY_MAX is of type s16, and thus 65535 is too large - it becomes -1.

Flagged by W=1 build with clang-17.

Quoted 2 lines
net/devlink/netlink_gen.c +0 -0
 /* DEVLINK_CMD_DPIPE_TABLE_GET - do */

...

maintainer
#3 lore raw
Quoted 25 lines · Wed, Feb 28, 2024 at 02:12:49PM CET, [email protected] wrote:

On Wed, Feb 28, 2024 at 03:59:53AM +0200, William Tu wrote:

...

Quoted 8 lines
net/devlink/netlink_gen.c +0 -0
index c81cf2dd154f..ac8b0c7105dd 100644
@@ -194,12 +194,14 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
 };
 
 /* DEVLINK_CMD_ESWITCH_SET - do */

net/devlink/netlink_gen.c static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA · line 205

Quoted 10 lines
net/devlink/netlink_gen.c +3 -1
-static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
+static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT + 1] = {
 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U16, 3),
 	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+	[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT] = NLA_POLICY_MAX(NLA_U32, 65535),
 };

Hi William,

Quoted 5 lines

I realise this is probably not central to your purpose in sending an RFC, but my understanding is that the max value set using NLA_POLICY_MAX is of type s16, and thus 65535 is too large - it becomes -1.

Flagged by W=1 build with clang-17.

First of all:
/* Do not edit directly, auto-generated from: */
/* Documentation/netlink/specs/devlink.yaml */

Quoted 6 lines
Quoted 3 lines
net/devlink/netlink_gen.c +0 -0
 /* DEVLINK_CMD_DPIPE_TABLE_GET - do */

...

author
#4 lore raw
Quoted 28 lines · Jiri Pirko

External email: Use caution opening links or attachments

Quoted 24 lines · Wed, Feb 28, 2024 at 02:12:49PM CET, [email protected] wrote:

On Wed, Feb 28, 2024 at 03:59:53AM +0200, William Tu wrote:

...

Quoted 8 lines
net/devlink/netlink_gen.c +0 -0
index c81cf2dd154f..ac8b0c7105dd 100644
@@ -194,12 +194,14 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
  };
 
  /* DEVLINK_CMD_ESWITCH_SET - do */

net/devlink/netlink_gen.c static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA · line 205

Quoted 10 lines
net/devlink/netlink_gen.c +3 -1
-static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
+static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT + 1] = {
      [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
      [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
      [DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
      [DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U16, 3),
      [DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+    [DEVLINK_ATTR_ESWITCH_SHRDESC_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
+    [DEVLINK_ATTR_ESWITCH_SHRDESC_COUNT] = NLA_POLICY_MAX(NLA_U32, 65535),
  };

Hi William,

Quoted 11 lines
Quoted 5 lines

I realise this is probably not central to your purpose in sending an RFC, but my understanding is that the max value set using NLA_POLICY_MAX is of type s16, and thus 65535 is too large - it becomes -1.

Flagged by W=1 build with clang-17.

First of all:
/* Do not edit directly, auto-generated from: */
/* Documentation/netlink/specs/devlink.yaml */

Hi Jiri and Simon,
Thanks for the feedback. Will fix it.
William