Skip to contentSkip to conversation

devlink: add per-port resource support

PATCH Superseded Tariq Toukan 4 participants 29 messages Feb 26 – Mar 12

Subsystems (9)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

v3 cover devlink: add per-port resource support

Hi,

This series adds devlink per-port resource support. See detailed description by Or below [1].

Regards,
Tariq

[1]
Currently, devlink resources are only available at the device level. However, some resources are inherently per-port, such as the maximum number of subfunctions (SFs) that can be created on a specific PF port. This limitation prevents user space from obtaining accurate per-port capacity information.
This series adds infrastructure for per-port resources in devlink core and implements it in the mlx5 driver to expose the max_SFs resource on PF devlink ports.

Patch #1  adds dump support for device-level resources
Patch #2  adds selftest for resource dump
Patch #3  adds dump to resource documentation
Patch #4  refactors resource functions to be generic
Patch #5  adds port-level resource registration infrastructure
Patch #6  adds port resource netlink command
Patch #7  registers SF resource on PF port representor in mlx5
Patch #8  adds devlink port resource registration to netdevsim for testing
Patch #9  adds selftest for devlink port resources

Patch #10 documents port-level resources

With this series, users can query per-port resources:

$ devlink port resource show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
$ devlink port resource show
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
pci/0000:03:00.1/262144:
  name max_SFs size 20 unit entry

Userspace patches for iproute2:
https://github.com/ohartoov/iproute2/tree/port_resource

V3:
- Add dump command for device-level resources.
- Fix selftest to expect the "test_resource" registered by netdevsim instead of max_SFs.
- Use a single netlink fill function for both device-level and port-level resources.
- Fix documentation to refer to the GET command (kernel/netlink perspective) instead of show.
- Link to V2: https://lore.kernel.org/all/[email protected]/

Or Har-Toov (10):
devlink: Add dump support for device-level resources
selftest: netdevsim: Add resource dump test
devlink: Add dump to resource documentation
devlink: Refactor resource functions to be generic
devlink: Add port-level resource registration infrastructure
devlink: Add port resource netlink command net/mlx5: Register SF resource on PF port representor
netdevsim: Add devlink port resource registration
selftest: netdevsim: Add devlink port resource test
devlink: Document port-level resources

 Documentation/netlink/specs/devlink.yaml      |  29 +-
 .../networking/devlink/devlink-resource.rst   |  60 ++-
 .../net/ethernet/mellanox/mlx5/core/devlink.h |   4 +
 .../mellanox/mlx5/core/esw/devlink_port.c     |  37 ++
 drivers/net/netdevsim/dev.c                   |  23 +-
 drivers/net/netdevsim/netdevsim.h             |   4 +
 include/net/devlink.h                         |  10 +-
 include/uapi/linux/devlink.h                  |   3 +
 net/devlink/devl_internal.h                   |   4 +
 net/devlink/netlink.c                         |   2 +-
 net/devlink/netlink_gen.c                     |  49 ++-
 net/devlink/netlink_gen.h                     |   8 +-
 net/devlink/port.c                            |   3 +
 net/devlink/resource.c                        | 366 +++++++++++++++---
 .../drivers/net/netdevsim/devlink.sh          |  53 ++-
 15 files changed, 581 insertions(+), 74 deletions(-)

base-commit: 90fcb0f3bc5ab67773b35030af68ed8c6bd83e1c

Signature · 1 line
2.44.0
author maintainer
#1 lore raw

PATCH v3 1/10 devlink: Add dump support for device-level resources

From: Or Har-Toov <[email protected]>

Add dumpit handler for resource-dump command to iterate over all devlink devices and show their resources. This aligns the device-level resource command with the port-level resource command that will be added in next patches.

  $ devlink resource show
  pci/0000:08:00.0:
    name local_max_SFs size 508 unit entry
    name external_max_SFs size 508 unit entry
  pci/0000:08:00.1:
    name local_max_SFs size 508 unit entry
    name external_max_SFs size 508 unit entry
---
 Documentation/netlink/specs/devlink.yaml |  6 +-
 net/devlink/netlink_gen.c                | 19 ++++-
 net/devlink/netlink_gen.h                |  4 +-
 net/devlink/resource.c                   | 99 ++++++++++++++++++++----
 4 files changed, 109 insertions(+), 19 deletions(-)
Documentation/netlink/specs/devlink.yaml +5 -1
index 837112da6738..ee679ac14261 100644
@@ -1733,12 +1733,16 @@ operations:
           attributes:
             - bus-name
             - dev-name
-        reply:
+        reply: &resource-dump-reply
           value: 36
           attributes:
             - bus-name
             - dev-name
             - resource-list
+      dump:
+        request:
+          attributes: *dev-id-attrs
+        reply: *resource-dump-reply
 
     -
       name: reload
net/devlink/netlink_gen.c +16 -3
index f4c61c2b4f22..d6667a3f87a0 100644
@@ -272,7 +272,13 @@ static const struct nla_policy devlink_resource_set_nl_policy[DEVLINK_ATTR_RESOU
 };
 
 /* DEVLINK_CMD_RESOURCE_DUMP - do */
-static const struct nla_policy devlink_resource_dump_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
+static const struct nla_policy devlink_resource_dump_do_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
+	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+};
+
+/* DEVLINK_CMD_RESOURCE_DUMP - dump */
+static const struct nla_policy devlink_resource_dump_dump_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
 };
@@ -605,7 +611,7 @@ static const struct nla_policy devlink_notify_filter_set_nl_policy[DEVLINK_ATTR_
 };
 
 /* Ops table for devlink */
-const struct genl_split_ops devlink_nl_ops[74] = {
+const struct genl_split_ops devlink_nl_ops[75] = {
 	{
 		.cmd		= DEVLINK_CMD_GET,
 		.validate	= GENL_DONT_VALIDATE_STRICT,
@@ -883,10 +889,17 @@ const struct genl_split_ops devlink_nl_ops[74] = {
 		.pre_doit	= devlink_nl_pre_doit,
 		.doit		= devlink_nl_resource_dump_doit,
 		.post_doit	= devlink_nl_post_doit,
-		.policy		= devlink_resource_dump_nl_policy,
+		.policy		= devlink_resource_dump_do_nl_policy,
 		.maxattr	= DEVLINK_ATTR_DEV_NAME,
 		.flags		= GENL_CMD_CAP_DO,
 	},
+	{
+		.cmd		= DEVLINK_CMD_RESOURCE_DUMP,
+		.dumpit		= devlink_nl_resource_dump_dumpit,
+		.policy		= devlink_resource_dump_dump_nl_policy,
+		.maxattr	= DEVLINK_ATTR_DEV_NAME,
+		.flags		= GENL_CMD_CAP_DUMP,
+	},
 	{
 		.cmd		= DEVLINK_CMD_RELOAD,
 		.validate	= GENL_DONT_VALIDATE_STRICT,
net/devlink/netlink_gen.h +3 -1
index 2817d53a0eba..d79f6a0888f6 100644
@@ -18,7 +18,7 @@ extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_
 extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1];
 
 /* Ops table for devlink */
-extern const struct genl_split_ops devlink_nl_ops[74];
+extern const struct genl_split_ops devlink_nl_ops[75];
 
 int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
 			struct genl_info *info);
@@ -80,6 +80,8 @@ int devlink_nl_dpipe_table_counters_set_doit(struct sk_buff *skb,
 					     struct genl_info *info);
 int devlink_nl_resource_set_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_resource_dump_doit(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_resource_dump_dumpit(struct sk_buff *skb,
+				    struct netlink_callback *cb);
 int devlink_nl_reload_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_param_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_param_get_dumpit(struct sk_buff *skb,
net/devlink/resource.c +85 -14

128 lines not on this page · raw message

Signature · 1 line
2.44.0
author maintainer
#2 lore raw

PATCH v3 2/10 selftest: netdevsim: Add resource dump test

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Add test for devlink resource dump command which verifies dumping resources for all devices.

---
 .../selftests/drivers/net/netdevsim/devlink.sh  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +16 -1
index 1b529ccaf050..9efd20d0241c 100755
@@ -5,7 +5,7 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 
 ALL_TESTS="fw_flash_test params_test  \
 	   params_default_test regions_test reload_test \
-	   netns_reload_test resource_test dev_info_test \
+	   netns_reload_test resource_test resource_dump_test dev_info_test \
 	   empty_reporter_test dummy_reporter_test rate_test"
 NUM_NETIFS=0
 source $lib_dir/lib.sh
@@ -482,6 +482,21 @@ resource_test()
 	log_test "resource test"
 }
 
+resource_dump_test()
+{
+	RET=0
+
+	if ! devlink resource show > /dev/null 2>&1; then
+		echo "SKIP: devlink resource dump not supported"
+		return
+	fi
+
+	devlink resource show > /dev/null 2>&1
+	check_err $? "Failed to dump all resources"
+
+	log_test "resource dump test"
+}
+
 info_get()
 {
 	local name=$1
Signature · 1 line
2.44.0
author maintainer
#3 lore raw

PATCH v3 3/10 devlink: Add dump to resource documentation

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Add dump documentation for resource command. Resource dump command allow viewing resources for all devices as a list.

---
 .../networking/devlink/devlink-resource.rst   | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
Documentation/networking/devlink/devlink-resource.rst +22 -2
index 3d5ae51e65a2..b4203c498bf2 100644
@@ -40,11 +40,31 @@ device drivers and their description must be added to the following table:
 example usage
 -------------
 
-The resources exposed by the driver can be observed, for example:
+The resources exposed by the driver can be observed.
+
+To list resources for all devlink devices that have resources registered:
 
 .. code:: shell
 
-    $devlink resource show pci/0000:03:00.0
+    $ devlink resource show
+    pci/0000:03:00.0:
+      name kvd size 245760 unit entry
+        resources:
+          name linear size 98304 occ 0 unit entry size_min 0 size_max 147456 size_gran 128
+          name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128
+          name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128
+    pci/0000:04:00.0:
+      name kvd size 245760 unit entry
+        resources:
+          name linear size 98304 occ 0 unit entry size_min 0 size_max 147456 size_gran 128
+          name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128
+          name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128
+
+To show resources for a specific device:
+
+.. code:: shell
+
+    $ devlink resource show pci/0000:03:00.0
     pci/0000:03:00.0:
       name kvd size 245760 unit entry
         resources:
Signature · 1 line
2.44.0
author maintainer
#4 lore raw

PATCH v3 4/10 devlink: Refactor resource functions to be generic

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Currently the resource functions take devlink pointer as parameter and take the resource list from there.
Allow resource functions to work with other resource lists that will be added in next patches and not only with the devlink's resource list.

---
 include/net/devlink.h  |   2 +-
 net/devlink/resource.c | 140 ++++++++++++++++++++++++++---------------
 2 files changed, 91 insertions(+), 51 deletions(-)
include/net/devlink.h +1 -1
index cb839e0435a1..48e1ad067836 100644
@@ -1875,7 +1875,7 @@ int devl_resource_register(struct devlink *devlink,
 			   u64 resource_size,
 			   u64 resource_id,
 			   u64 parent_resource_id,
-			   const struct devlink_resource_size_params *size_params);
+			   const struct devlink_resource_size_params *params);
 void devl_resources_unregister(struct devlink *devlink);
 void devlink_resources_unregister(struct devlink *devlink);
 int devl_resource_size_get(struct devlink *devlink,
net/devlink/resource.c +90 -50

264 lines not on this page · raw message

Signature · 1 line
2.44.0
author maintainer
#5 lore raw

PATCH v3 5/10 devlink: Add port-level resource registration infrastructure

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

The current devlink resource infrastructure supports only device-level resources. Some hardware resources are associated with specific ports rather than the entire device, and today we have no way to show resource per-port.

Add support for registering resources at the port level.

---
 include/net/devlink.h  |  8 ++++++++
 net/devlink/port.c     |  3 +++
 net/devlink/resource.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
include/net/devlink.h +8 -0
index 48e1ad067836..1ba12ab51e66 100644
@@ -129,6 +129,7 @@ struct devlink_rate {
 struct devlink_port {
 	struct list_head list;
 	struct list_head region_list;
+	struct list_head resource_list;
 	struct devlink *devlink;
 	const struct devlink_port_ops *ops;
 	unsigned int index;
@@ -1881,6 +1882,13 @@ void devlink_resources_unregister(struct devlink *devlink);
 int devl_resource_size_get(struct devlink *devlink,
 			   u64 resource_id,
 			   u64 *p_resource_size);
+int
+devl_port_resource_register(struct devlink_port *devlink_port,
+			    const char *resource_name,
+			    u64 resource_size, u64 resource_id,
+			    u64 parent_resource_id,
+			    const struct devlink_resource_size_params *params);
+void devl_port_resources_unregister(struct devlink_port *devlink_port);
 int devl_dpipe_table_resource_set(struct devlink *devlink,
 				  const char *table_name, u64 resource_id,
 				  u64 resource_units);
net/devlink/port.c +3 -0
index 93d8a25bb920..10d0d88894a3 100644
@@ -1024,6 +1024,7 @@ void devlink_port_init(struct devlink *devlink,
 		return;
 	devlink_port->devlink = devlink;
 	INIT_LIST_HEAD(&devlink_port->region_list);
+	INIT_LIST_HEAD(&devlink_port->resource_list);
 	devlink_port->initialized = true;
 }
 EXPORT_SYMBOL_GPL(devlink_port_init);
@@ -1041,6 +1042,7 @@ EXPORT_SYMBOL_GPL(devlink_port_init);
 void devlink_port_fini(struct devlink_port *devlink_port)
 {
 	WARN_ON(!list_empty(&devlink_port->region_list));
+	WARN_ON(!list_empty(&devlink_port->resource_list));
 }
 EXPORT_SYMBOL_GPL(devlink_port_fini);
 
@@ -1135,6 +1137,7 @@ void devl_port_unregister(struct devlink_port *devlink_port)
 	devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL);
 	xa_erase(&devlink_port->devlink->ports, devlink_port->index);
 	WARN_ON(!list_empty(&devlink_port->reporter_list));
+	devlink_port_fini(devlink_port);
 	devlink_port->registered = false;
 }
 EXPORT_SYMBOL_GPL(devl_port_unregister);
net/devlink/resource.c +43 -0

46 lines not on this page · raw message

Signature · 1 line
2.44.0
author maintainer
#6 lore raw

PATCH v3 6/10 devlink: Add port resource netlink command

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Add support for userspace to query resources registered on devlink ports, allowing drivers to expose per-port resource limits and usage.

Example output:

  $ devlink port resource show
  pci/0000:03:00.0/196608:
    name max_SFs size 20 unit entry
  pci/0000:03:00.1/262144:
    name max_SFs size 20 unit entry
  $ devlink port resource show pci/0000:03:00.0/196608
  pci/0000:03:00.0/196608:
    name max_SFs size 20 unit entry
---
 Documentation/netlink/specs/devlink.yaml | 23 ++++++
 include/uapi/linux/devlink.h             |  3 +
 net/devlink/devl_internal.h              |  4 ++
 net/devlink/netlink.c                    |  2 +-
 net/devlink/netlink_gen.c                | 32 ++++++++-
 net/devlink/netlink_gen.h                |  6 +-
 net/devlink/resource.c                   | 90 +++++++++++++++++++++++-
 7 files changed, 155 insertions(+), 5 deletions(-)
Documentation/netlink/specs/devlink.yaml +23 -0
index ee679ac14261..9b813f5fc51c 100644
@@ -2340,3 +2340,26 @@ operations:
             - bus-name
             - dev-name
             - port-index
+
+    -
+      name: port-resource-get
+      doc: Get port resources.
+      attribute-set: devlink
+      dont-validate: [strict]
+      do:
+        pre: devlink-nl-pre-doit-port
+        post: devlink-nl-post-doit
+        request:
+          value: 85
+          attributes: *port-id-attrs
+        reply: &port-resource-get-reply
+          value: 85
+          attributes:
+            - bus-name
+            - dev-name
+            - port-index
+            - resource-list
+      dump:
+        request:
+          attributes: *dev-id-attrs
+        reply: *port-resource-get-reply
include/uapi/linux/devlink.h +3 -0
index e7d6b6d13470..1cabd1f6cba0 100644
@@ -141,6 +141,9 @@ enum devlink_command {
 
 	DEVLINK_CMD_NOTIFY_FILTER_SET,
 
+	DEVLINK_CMD_PORT_RESOURCE_GET,	/* can dump */
+	DEVLINK_CMD_PORT_RESOURCE_SET,
+
 	/* add new commands above here */
 	__DEVLINK_CMD_MAX,
 	DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
net/devlink/devl_internal.h +4 -0
index 1377864383bc..ddf855bc893f 100644
@@ -148,6 +148,10 @@ struct devlink_nl_dump_state {
 		struct {
 			u64 dump_ts;
 		};
+		/* DEVLINK_CMD_PORT_RESOURCE_GET - dump */
+		struct {
+			unsigned long port_index;
+		};
 	};
 };
 
net/devlink/netlink.c +1 -1
index 593605c1b1ef..c78c31779622 100644
@@ -367,7 +367,7 @@ struct genl_family devlink_nl_family __ro_after_init = {
 	.module		= THIS_MODULE,
 	.split_ops	= devlink_nl_ops,
 	.n_split_ops	= ARRAY_SIZE(devlink_nl_ops),
-	.resv_start_op	= DEVLINK_CMD_SELFTESTS_RUN + 1,
+	.resv_start_op	= DEVLINK_CMD_PORT_RESOURCE_GET + 1,
 	.mcgrps		= devlink_nl_mcgrps,
 	.n_mcgrps	= ARRAY_SIZE(devlink_nl_mcgrps),
 	.sock_priv_size		= sizeof(struct devlink_nl_sock_priv),
net/devlink/netlink_gen.c +31 -1
index d6667a3f87a0..a235748d0688 100644
@@ -610,8 +610,21 @@ static const struct nla_policy devlink_notify_filter_set_nl_policy[DEVLINK_ATTR_
 	[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, },
 };
 
+/* DEVLINK_CMD_PORT_RESOURCE_GET - do */
+static const struct nla_policy devlink_port_resource_get_do_nl_policy[DEVLINK_ATTR_PORT_INDEX + 1] = {
+	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+	[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, },
+};
+
+/* DEVLINK_CMD_PORT_RESOURCE_GET - dump */
+static const struct nla_policy devlink_port_resource_get_dump_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
+	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+};
+
 /* Ops table for devlink */
-const struct genl_split_ops devlink_nl_ops[75] = {
+const struct genl_split_ops devlink_nl_ops[77] = {
 	{
 		.cmd		= DEVLINK_CMD_GET,
 		.validate	= GENL_DONT_VALIDATE_STRICT,
@@ -1297,4 +1310,21 @@ const struct genl_split_ops devlink_nl_ops[75] = {
 		.maxattr	= DEVLINK_ATTR_PORT_INDEX,
 		.flags		= GENL_CMD_CAP_DO,
 	},
+	{
+		.cmd		= DEVLINK_CMD_PORT_RESOURCE_GET,
+		.validate	= GENL_DONT_VALIDATE_STRICT,
+		.pre_doit	= devlink_nl_pre_doit_port,
+		.doit		= devlink_nl_port_resource_get_doit,
+		.post_doit	= devlink_nl_post_doit,
+		.policy		= devlink_port_resource_get_do_nl_policy,
+		.maxattr	= DEVLINK_ATTR_PORT_INDEX,
+		.flags		= GENL_CMD_CAP_DO,
+	},
+	{
+		.cmd		= DEVLINK_CMD_PORT_RESOURCE_GET,
+		.dumpit		= devlink_nl_port_resource_get_dumpit,
+		.policy		= devlink_port_resource_get_dump_nl_policy,
+		.maxattr	= DEVLINK_ATTR_DEV_NAME,
+		.flags		= GENL_CMD_CAP_DUMP,
+	},
 };
net/devlink/netlink_gen.h +5 -1
index d79f6a0888f6..cab9d30e913a 100644
@@ -18,7 +18,7 @@ extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_
 extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1];
 
 /* Ops table for devlink */
-extern const struct genl_split_ops devlink_nl_ops[75];
+extern const struct genl_split_ops devlink_nl_ops[77];
 
 int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
 			struct genl_info *info);
@@ -148,5 +148,9 @@ int devlink_nl_selftests_get_dumpit(struct sk_buff *skb,
 int devlink_nl_selftests_run_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_notify_filter_set_doit(struct sk_buff *skb,
 				      struct genl_info *info);
+int devlink_nl_port_resource_get_doit(struct sk_buff *skb,
+				      struct genl_info *info);
+int devlink_nl_port_resource_get_dumpit(struct sk_buff *skb,
+					struct netlink_callback *cb);
 
 #endif /* _LINUX_DEVLINK_GEN_H */
net/devlink/resource.c +88 -2

106 lines not on this page · raw message

Signature · 1 line
2.44.0
author maintainer
#7 lore raw

PATCH v3 7/10 net/mlx5: Register SF resource on PF port representor

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

The device-level "resource show" displays max_local_SFs and max_external_SFs without indicating which port each resource belongs to. Users cannot determine the controller number and pfnum associated with each SF pool.

Register max_SFs resource on the Host PF representor port to expose per-port SF limits. Users can correlate the port resource with the controller number and pfnum shown in 'devlink port show'.

Future patches will introduce an ECPF that manages multiple PFs, where each PF has its own SF pool.

Example usage:

  $ devlink port resource show
  pci/0000:03:00.0/196608:
    name max_SFs size 20 unit entry
  pci/0000:03:00.1/262144:
    name max_SFs size 20 unit entry
  $ devlink port resource show pci/0000:03:00.0/196608
  pci/0000:03:00.0/196608:
    name max_SFs size 20 unit entry
  $ devlink port show pci/0000:03:00.0/196608
  pci/0000:03:00.0/196608: type eth netdev pf0hpf flavour pcipf
    controller 1 pfnum 0 external true splittable false
    function:
      hw_addr b8:3f:d2:e1:8f:dc roce enable max_io_eqs 120

We can create up to 20 SFs over devlink port pci/0000:03:00.0/196608, with pfnum 0 and controller 1.

---
 .../net/ethernet/mellanox/mlx5/core/devlink.h |  4 ++
 .../mellanox/mlx5/core/esw/devlink_port.c     | 37 +++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/devlink.h +4 -0
index 43b9bf8829cf..4fbb3926a3e5 100644
@@ -14,6 +14,10 @@ enum mlx5_devlink_resource_id {
 	MLX5_ID_RES_MAX = __MLX5_ID_RES_MAX - 1,
 };
 
+enum mlx5_devlink_port_resource_id {
+	MLX5_DL_PORT_RES_MAX_SFS = 1,
+};
+
 enum mlx5_devlink_param_id {
 	MLX5_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
 	MLX5_DEVLINK_PARAM_ID_FLOW_STEERING_MODE,
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +37 -0
index cd60bc500ec5..9601eaace168 100644
@@ -3,6 +3,7 @@
 
 #include <linux/mlx5/driver.h>
 #include "eswitch.h"
+#include "devlink.h"
 
 static void
 mlx5_esw_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_item_id *ppid)
@@ -158,6 +159,32 @@ static const struct devlink_port_ops mlx5_esw_dl_sf_port_ops = {
 	.port_fn_max_io_eqs_set = mlx5_devlink_port_fn_max_io_eqs_set,
 };
 
+static int mlx5_esw_devlink_port_res_register(struct mlx5_eswitch *esw,
+					      struct devlink_port *dl_port)
+{
+	struct devlink_resource_size_params size_params;
+	struct mlx5_core_dev *dev = esw->dev;
+	u16 max_sfs, sf_base_id;
+	int err;
+
+	err = mlx5_esw_sf_max_hpf_functions(dev, &max_sfs, &sf_base_id);
+	if (err)
+		return err;
+
+	devlink_resource_size_params_init(&size_params, max_sfs, max_sfs, 1,
+					  DEVLINK_RESOURCE_UNIT_ENTRY);
+
+	return devl_port_resource_register(dl_port, "max_SFs", max_sfs,
+					   MLX5_DL_PORT_RES_MAX_SFS,
+					   DEVLINK_RESOURCE_ID_PARENT_TOP,
+					   &size_params);
+}
+
+static void mlx5_esw_devlink_port_res_unregister(struct devlink_port *dl_port)
+{
+	devl_port_resources_unregister(dl_port);
+}
+
 int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
 {
 	struct mlx5_core_dev *dev = esw->dev;
@@ -189,6 +216,15 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlx
 	if (err)
 		goto rate_err;
 
+	if (vport_num == MLX5_VPORT_PF) {
+		err = mlx5_esw_devlink_port_res_register(esw,
+							 &dl_port->dl_port);
+		if (err)
+			mlx5_core_dbg(dev,
+				      "Failed to register port resources: %d\n",
+				       err);
+	}
+
 	return 0;
 
 rate_err:
@@ -203,6 +239,7 @@ void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_vport *vport)
 	if (!vport->dl_port)
 		return;
 	dl_port = vport->dl_port;
+	mlx5_esw_devlink_port_res_unregister(&dl_port->dl_port);
 
 	mlx5_esw_qos_vport_update_parent(vport, NULL, NULL);
 	devl_rate_leaf_destroy(&dl_port->dl_port);
Signature · 1 line
2.44.0
author maintainer
#8 lore raw

PATCH v3 8/10 netdevsim: Add devlink port resource registration

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Register port-level resources for netdevsim ports to enable testing of the port resource infrastructure.

---
 drivers/net/netdevsim/dev.c       | 23 ++++++++++++++++++++++-
 drivers/net/netdevsim/netdevsim.h |  4 ++++
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/net/netdevsim/dev.c +22 -1
index f7b32446d3b8..80df3ffd1bc7 100644
@@ -1487,9 +1487,25 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ
 	if (err)
 		goto err_port_free;
 
+	if (nsim_dev_port_is_pf(nsim_dev_port)) {
+		u64 parent_id = DEVLINK_RESOURCE_ID_PARENT_TOP;
+		struct devlink_resource_size_params params = {
+			.size_max = 100,
+			.size_granularity = 1,
+			.unit = DEVLINK_RESOURCE_UNIT_ENTRY
+		};
+
+		err = devl_port_resource_register(devlink_port,
+						  "test_resource", 20,
+						  NSIM_PORT_RESOURCE_TEST,
+						  parent_id, &params);
+		if (err)
+			goto err_dl_port_unregister;
+	}
+
 	err = nsim_dev_port_debugfs_init(nsim_dev, nsim_dev_port);
 	if (err)
-		goto err_dl_port_unregister;
+		goto err_port_resource_unregister;
 
 	nsim_dev_port->ns = nsim_create(nsim_dev, nsim_dev_port, perm_addr);
 	if (IS_ERR(nsim_dev_port->ns)) {
@@ -1512,6 +1528,9 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ
 	nsim_destroy(nsim_dev_port->ns);
 err_port_debugfs_exit:
 	nsim_dev_port_debugfs_exit(nsim_dev_port);
+err_port_resource_unregister:
+	if (nsim_dev_port_is_pf(nsim_dev_port))
+		devl_port_resources_unregister(devlink_port);
 err_dl_port_unregister:
 	devl_port_unregister(devlink_port);
 err_port_free:
@@ -1528,6 +1547,8 @@ static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port)
 		devl_rate_leaf_destroy(&nsim_dev_port->devlink_port);
 	nsim_destroy(nsim_dev_port->ns);
 	nsim_dev_port_debugfs_exit(nsim_dev_port);
+	if (nsim_dev_port_is_pf(nsim_dev_port))
+		devl_port_resources_unregister(devlink_port);
 	devl_port_unregister(devlink_port);
 	kfree(nsim_dev_port);
 }
drivers/net/netdevsim/netdevsim.h +4 -0
index f767fc8a7505..985530486184 100644
@@ -224,6 +224,10 @@ enum nsim_resource_id {
 	NSIM_RESOURCE_NEXTHOPS,
 };
 
+enum nsim_port_resource_id {
+	NSIM_PORT_RESOURCE_TEST = 1,
+};
+
 struct nsim_dev_health {
 	struct devlink_health_reporter *empty_reporter;
 	struct devlink_health_reporter *dummy_reporter;
Signature · 1 line
2.44.0
author maintainer
#9 lore raw

PATCH v3 9/10 selftest: netdevsim: Add devlink port resource test

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Add selftest to verify port-level resource functionality using netdevsim.

---
 .../drivers/net/netdevsim/devlink.sh          | 38 ++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +37 -1
index 9efd20d0241c..93f6ef3cd700 100755
@@ -5,7 +5,8 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 
 ALL_TESTS="fw_flash_test params_test  \
 	   params_default_test regions_test reload_test \
-	   netns_reload_test resource_test resource_dump_test dev_info_test \
+	   netns_reload_test resource_test resource_dump_test \
+	   port_resource_test dev_info_test \
 	   empty_reporter_test dummy_reporter_test rate_test"
 NUM_NETIFS=0
 source $lib_dir/lib.sh
@@ -871,6 +872,41 @@ rate_test()
 	log_test "rate test"
 }
 
+port_resource_test()
+{
+	RET=0
+
+	if ! devlink port help 2>&1 | grep -q resource; then
+		echo "SKIP: missing devlink port resource support"
+		return
+	fi
+
+	local first_port="${DL_HANDLE}/0"
+	local name
+	local size
+
+	devlink port resource show "$first_port" > /dev/null 2>&1
+	check_err $? "Failed to show port resource for $first_port"
+
+	name=$(cmd_jq "devlink port resource show $first_port -j" \
+		      ".[][][].name")
+	[ "$name" == "test_resource" ]
+	check_err $? "Unexpected resource name $name (expected test_resource)"
+
+	size=$(cmd_jq "devlink port resource show $first_port -j" \
+		      ".[][][].size")
+	[ "$size" == "20" ]
+	check_err $? "Unexpected resource size $size (expected 20)"
+
+	devlink port resource show "$DL_HANDLE" > /dev/null 2>&1
+	check_err $? "Failed to show port resources for $DL_HANDLE"
+
+	devlink port resource show > /dev/null 2>&1
+	check_err $? "Failed to dump all port resources"
+
+	log_test "port resource test"
+}
+
 setup_prepare()
 {
 	modprobe netdevsim
Signature · 1 line
2.44.0
author maintainer
#10 lore raw

PATCH v3 10/10 devlink: Document port-level resources

In reply to Tariq Toukan

From: Or Har-Toov <[email protected]>

Add documentation for the port-level resource feature to devlink-resource.rst. Port-level resources allow viewing resources associated with specific devlink ports.

Currently, port-level resources only support the get command for viewing resource information.

---
 .../networking/devlink/devlink-resource.rst   | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
Documentation/networking/devlink/devlink-resource.rst +36 -0
index b4203c498bf2..1d6d8bfa1692 100644
@@ -94,3 +94,39 @@ attribute, which represents the pending change in size. For example:
 
 Note that changes in resource size may require a device reload to properly
 take effect.
+
+Port-level Resources
+====================
+
+In addition to device-level resources, ``devlink`` also supports port-level
+resources. These resources are associated with a specific devlink port rather
+than the device as a whole.
+
+Currently, port-level resources only support the ``GET`` command for viewing
+resource information.
+
+Port-level resources can be viewed for a specific port:
+
+.. code:: shell
+
+    $devlink port resource show pci/0000:03:00.0/196608
+    pci/0000:03:00.0/196608:
+      name max_SFs size 20 unit entry
+
+Or for ports of a specific device:
+
+.. code:: shell
+
+    $devlink port resource show pci/0000:03:00.0
+    pci/0000:03:00.0/196608:
+      name max_SFs size 20 unit entry
+
+Or for all ports across all devices:
+
+.. code:: shell
+
+    $devlink port resource show
+    pci/0000:03:00.0/196608:
+      name max_SFs size 20 unit entry
+    pci/0000:03:00.1/262144:
+      name max_SFs size 20 unit entry
Signature · 1 line
2.44.0
maintainer
#11 lore raw

Re: [PATCH net-next V3 10/10] devlink: Document port-level resources

Documentation/networking/devlink/devlink-resource.rst attribute, which represents the pending change in size. For example: · line 106

Quoted 2 lines · On Fri, 27 Feb 2026 00:19:16 +0200 Tariq Toukan wrote:
Documentation/networking/devlink/devlink-resource.rst +2 -0
+Currently, port-level resources only support the ``GET`` command for viewing
+resource information.

In case there is v4, AI says:

Quoted 1 line

+Currently, port-level resources only support the ``GET`` command for viewing

                                                         ^^^^^

This isn't a bug, but the terminology here appears inconsistent with the rest of the documentation. The document uses user-facing command names elsewhere (like "devlink port resource show"), but this line uses "GET command" which seems to reference the internal DEVLINK_CMD_PORT_RESOURCE_GET netlink command.

Should this be reworded to match the user-facing terminology used throughout the rest of the document, perhaps "only support the show command" or "only support viewing"?

maintainer
#12 lore raw

Re: [PATCH net-next V3 10/10] devlink: Document port-level resources

Quoted 15 lines · Tue, Mar 03, 2026 at 04:14:48AM +0100, [email protected] wrote:

Documentation/networking/devlink/devlink-resource.rst attribute, which represents the pending change in size. For example: · line 106

Quoted 2 lines · On Fri, 27 Feb 2026 00:19:16 +0200 Tariq Toukan wrote:
Documentation/networking/devlink/devlink-resource.rst +2 -0
+Currently, port-level resources only support the ``GET`` command for viewing
+resource information.

In case there is v4, AI says:

Quoted 1 line

+Currently, port-level resources only support the ``GET`` command for viewing

                                                        ^^^^^

This isn't a bug, but the terminology here appears inconsistent with the rest of the documentation. The document uses user-facing command names elsewhere (like "devlink port resource show"), but this line uses "GET command" which seems to reference the internal DEVLINK_CMD_PORT_RESOURCE_GET netlink command.

Quoted 3 lines

Should this be reworded to match the user-facing terminology used throughout the rest of the document, perhaps "only support the show command" or "only support viewing"?

AI does not see the context here. This is in-line with the rest of the get commands.

maintainer
#13 lore raw
In reply to Tariq Toukan
Quoted 11 lines · On Fri, 27 Feb 2026 00:19:06 +0200 Tariq Toukan wrote:

With this series, users can query per-port resources:

$ devlink port resource show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
$ devlink port resource show
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
pci/0000:03:00.1/262144:
  name max_SFs size 20 unit entry

Code LGTM, I have a question about having a new cmd, tho.

Does it matter to the user how the resource is scoped? Whether the resource is at the instance level or at the port level?

I worry we are mechanically following the design of other commands. Since the dump handler is new we could just dump resources with port-id there. No existing user space may be using it. Alternatively we could add a new attribute to select a bitmask of which scope user wants to dump.

I have a strong suspicion that the user will want to access all resources of a device. devlink resource show [$dev] should dump all resources devlink knows about, including port ones.

What's the reason for the new command?

maintainer
#14 lore raw
Quoted 15 lines · Tue, Mar 03, 2026 at 04:26:40AM +0100, [email protected] wrote:
Quoted 11 lines · On Fri, 27 Feb 2026 00:19:06 +0200 Tariq Toukan wrote:

With this series, users can query per-port resources:

$ devlink port resource show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
$ devlink port resource show
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
pci/0000:03:00.1/262144:
  name max_SFs size 20 unit entry

Code LGTM, I have a question about having a new cmd, tho.

Quoted 8 lines

Does it matter to the user how the resource is scoped? Whether the resource is at the instance level or at the port level?

I worry we are mechanically following the design of other commands. Since the dump handler is new we could just dump resources with port-id there. No existing user space may be using it. Alternatively we could add a new attribute to select a bitmask of which scope user wants to dump.

You can specify what you want to dump with dump selectors. For example, if you are interensted only in port of specific devlink. That should be enough for most of the cases, no?

Quoted 6 lines

I have a strong suspicion that the user will want to access all resources of a device. devlink resource show [$dev] should dump all resources devlink knows about, including port ones.

What's the reason for the new command?

You are right, one cmd would do. Good thing someone forgot to implement dump for it :)

maintainer
#15 lore raw
Quoted 30 lines · Wed, Mar 04, 2026 at 11:05:06AM +0100, [email protected] wrote:
Quoted 15 lines · Tue, Mar 03, 2026 at 04:26:40AM +0100, [email protected] wrote:
Quoted 11 lines · On Fri, 27 Feb 2026 00:19:06 +0200 Tariq Toukan wrote:

With this series, users can query per-port resources:

$ devlink port resource show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
$ devlink port resource show
pci/0000:03:00.0/196608:
  name max_SFs size 20 unit entry
pci/0000:03:00.1/262144:
  name max_SFs size 20 unit entry

Code LGTM, I have a question about having a new cmd, tho.

Quoted 8 lines

Does it matter to the user how the resource is scoped? Whether the resource is at the instance level or at the port level?

I worry we are mechanically following the design of other commands. Since the dump handler is new we could just dump resources with port-id there. No existing user space may be using it. Alternatively we could add a new attribute to select a bitmask of which scope user wants to dump.

You can specify what you want to dump with dump selectors. For example, if you are interensted only in port of specific devlink. That should be enough for most of the cases, no?

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

I have a strong suspicion that the user will want to access all resources of a device. devlink resource show [$dev] should dump all resources devlink knows about, including port ones.

What's the reason for the new command?

You are right, one cmd would do. Good thing someone forgot to implement dump for it :)

On a second thought, if we merge multiple objects into one dump, how does this extend? I mean, the userspace has to check there are no extra attributes, as they may be used as a handle to another new object introduced in the future... Idk, it's a bit odd.

maintainer
#16 lore raw
Quoted 6 lines · On Wed, 4 Mar 2026 11:34:13 +0100 Jiri Pirko wrote:
Quoted 6 lines
Quoted 5 lines

I have a strong suspicion that the user will want to access all resources of a device. devlink resource show [$dev] should dump all resources devlink knows about, including port ones.

What's the reason for the new command?

Quoted 7 lines
Quoted 2 lines

You are right, one cmd would do. Good thing someone forgot to implement dump for it :)

On a second thought, if we merge multiple objects into one dump, how does this extend? I mean, the userspace has to check there are no extra attributes, as they may be used as a handle to another new object introduced in the future... Idk, it's a bit odd.

That's true, the user space must be able to interpret the object identifier. So if we extend the command to add more identifiers we will have to add the bitmask to the dump request, and have the user space tell the kernel which objects it can recognize. I was just saying that we don't have to add such attribute now, maybe leave a comment in a strategic place for our future selves?

maintainer
#17 lore raw
Quoted 15 lines · Wed, Mar 04, 2026 at 07:15:22PM +0100, [email protected] wrote:
Quoted 6 lines · On Wed, 4 Mar 2026 11:34:13 +0100 Jiri Pirko wrote:
Quoted 6 lines
Quoted 5 lines

I have a strong suspicion that the user will want to access all resources of a device. devlink resource show [$dev] should dump all resources devlink knows about, including port ones.

What's the reason for the new command?

Quoted 7 lines
Quoted 2 lines

You are right, one cmd would do. Good thing someone forgot to implement dump for it :)

On a second thought, if we merge multiple objects into one dump, how does this extend? I mean, the userspace has to check there are no extra attributes, as they may be used as a handle to another new object introduced in the future... Idk, it's a bit odd.

Quoted 6 lines

That's true, the user space must be able to interpret the object identifier. So if we extend the command to add more identifiers we will have to add the bitmask to the dump request, and have the user space tell the kernel which objects it can recognize. I was just saying that we don't have to add such attribute now, maybe leave a comment in a strategic place for our future selves?

Or, alternatively, we can have per-object dumps as we have for all objects and command right now and leave things simple and straightforward? I mean, I don't really see a benefit of a single dump for more objects :/

maintainer
#18 lore raw
Quoted 14 lines · On Thu, 5 Mar 2026 08:56:42 +0100 Jiri Pirko wrote:
Quoted 6 lines · Wed, Mar 04, 2026 at 07:15:22PM +0100, [email protected] wrote:
Quoted 4 lines · On Wed, 4 Mar 2026 11:34:13 +0100 Jiri Pirko wrote:

On a second thought, if we merge multiple objects into one dump, how does this extend? I mean, the userspace has to check there are no extra attributes, as they may be used as a handle to another new object introduced in the future... Idk, it's a bit odd.

Quoted 6 lines

That's true, the user space must be able to interpret the object identifier. So if we extend the command to add more identifiers we will have to add the bitmask to the dump request, and have the user space tell the kernel which objects it can recognize. I was just saying that we don't have to add such attribute now, maybe leave a comment in a strategic place for our future selves?

Quoted 4 lines

Or, alternatively, we can have per-object dumps as we have for all objects and command right now and leave things simple and straightforward? I mean, I don't really see a benefit of a single dump for more objects :/

What do you mean by straightforward, exactly?

User will most likely want to see all resources of a device in a single dump / command.

The objects themselves are identical, they only differ by the handle, and yet we'd have two separate commands to access them.

It's as if we had separate GETLINK commands in rtnetlink for devices on the PCIe bus vs connected via USB.

maintainer
#19 lore raw
Quoted 20 lines · Thu, Mar 05, 2026 at 03:37:29PM +0100, [email protected] wrote:
Quoted 14 lines · On Thu, 5 Mar 2026 08:56:42 +0100 Jiri Pirko wrote:
Quoted 6 lines · Wed, Mar 04, 2026 at 07:15:22PM +0100, [email protected] wrote:
Quoted 4 lines · On Wed, 4 Mar 2026 11:34:13 +0100 Jiri Pirko wrote:

On a second thought, if we merge multiple objects into one dump, how does this extend? I mean, the userspace has to check there are no extra attributes, as they may be used as a handle to another new object introduced in the future... Idk, it's a bit odd.

Quoted 6 lines

That's true, the user space must be able to interpret the object identifier. So if we extend the command to add more identifiers we will have to add the bitmask to the dump request, and have the user space tell the kernel which objects it can recognize. I was just saying that we don't have to add such attribute now, maybe leave a comment in a strategic place for our future selves?

Quoted 4 lines

Or, alternatively, we can have per-object dumps as we have for all objects and command right now and leave things simple and straightforward? I mean, I don't really see a benefit of a single dump for more objects :/

Quoted 4 lines

What do you mean by straightforward, exactly?

User will most likely want to see all resources of a device in a single dump / command.

Hmm. We actually already have this for region and health reporter dumps. Only for params we have that separate.
So let's do it for resource too.

Thanks!

Quoted 6 lines

The objects themselves are identical, they only differ by the handle, and yet we'd have two separate commands to access them.

It's as if we had separate GETLINK commands in rtnetlink for devices on the PCIe bus vs connected via USB.

maintainer
#20 lore raw
Quoted 7 lines · On Fri, 6 Mar 2026 13:13:26 +0100 Jiri Pirko wrote:
Quoted 6 lines · Thu, Mar 05, 2026 at 03:37:29PM +0100, [email protected] wrote:
Quoted 4 lines · On Thu, 5 Mar 2026 08:56:42 +0100 Jiri Pirko wrote:

Or, alternatively, we can have per-object dumps as we have for all objects and command right now and leave things simple and straightforward? I mean, I don't really see a benefit of a single dump for more objects :/

Quoted 8 lines
Quoted 4 lines

What do you mean by straightforward, exactly?

User will most likely want to see all resources of a device in a single dump / command.

Hmm. We actually already have this for region and health reporter dumps. Only for params we have that separate.
So let's do it for resource too.

That's not a good argument, as I said in my first response to the thread:

I worry we are mechanically following the design of other commands.

https://lore.kernel.org/all/[email protected]/

#21 lore raw
Quoted 20 lines · Jakub Kicinski

External email: Use caution opening links or attachments

Quoted 7 lines · On Fri, 6 Mar 2026 13:13:26 +0100 Jiri Pirko wrote:
Quoted 6 lines · Thu, Mar 05, 2026 at 03:37:29PM +0100, [email protected] wrote:
Quoted 4 lines · On Thu, 5 Mar 2026 08:56:42 +0100 Jiri Pirko wrote:

Or, alternatively, we can have per-object dumps as we have for all objects and command right now and leave things simple and straightforward? I mean, I don't really see a benefit of a single dump for more objects :/

Quoted 8 lines
Quoted 4 lines

What do you mean by straightforward, exactly?

User will most likely want to see all resources of a device in a single dump / command.

Hmm. We actually already have this for region and health reporter dumps. Only for params we have that separate.
So let's do it for resource too.

Quoted 7 lines

That's not a good argument, as I said in my first response to the thread:

I worry we are mechanically following the design of other commands.

https://lore.kernel.org/all/[email protected]/

Hi,

Do you mean that we will register resources per port, but not show with new devlink port resource show. Instead, the current devlink resource show dev command will also display the ports of that device?

For example:

$ devlink resource show pci/0000:03:00.0
  pci/0000:03:00.0:
    name local_max_SFs size 40 unit entry
  pci/0000:03:00.0/196608:
     name max_SFs size 20 unit entry
  pci/0000:03:00.0/196609:
     name max_SFs size 20 unit entry

Or should we keep the current behavior where devlink resource show dev displays only device-level resources, and only the full dump shows both devices and their ports?

For example:

$ devlink resource show
  pci/0000:03:00.0:
    name local_max_SFs size 40 unit entry
  pci/0000:03:00.0/196608:
     name max_SFs size 20 unit entry
  pci/0000:03:00.0/196609:
     name max_SFs size 20 unit entry
  pci/0000:03:00.1:
    name local_max_SFs size 40 unit entry
  pci/0000:03:00.1/196608:
     name max_SFs size 20 unit entry
  pci/0000:03:00.1/196609:
     name max_SFs size 20 unit entry

Want to confirm which behavior you meant.

Thanks.

maintainer
#22 lore raw
Quoted 35 lines · On Sun, 8 Mar 2026 18:03:11 +0200 Or Har-Toov wrote:

Do you mean that we will register resources per port, but not show with new devlink port resource show.
Instead, the current devlink resource show dev command will also display the ports of that device?

For example:

$ devlink resource show pci/0000:03:00.0
   pci/0000:03:00.0:
     name local_max_SFs size 40 unit entry
   pci/0000:03:00.0/196608:
      name max_SFs size 20 unit entry
   pci/0000:03:00.0/196609:
      name max_SFs size 20 unit entry

Or should we keep the current behavior where devlink resource show dev displays only device-level resources, and only the full dump shows both devices and their ports?

For example:

$ devlink resource show
   pci/0000:03:00.0:
     name local_max_SFs size 40 unit entry
   pci/0000:03:00.0/196608:
      name max_SFs size 20 unit entry
   pci/0000:03:00.0/196609:
      name max_SFs size 20 unit entry
   pci/0000:03:00.1:
     name local_max_SFs size 40 unit entry
   pci/0000:03:00.1/196608:
      name max_SFs size 20 unit entry
   pci/0000:03:00.1/196609:
      name max_SFs size 20 unit entry
Quoted 1 line

Want to confirm which behavior you meant.

No strong preference on the CLI. For the kernel I think specifying the device should not exclude the port resources. Whether port resources are shown or not should be entirely up to the mask attribute.

Thinking about this some more after my last reply to Jiri I think we should add that mask attribute to let user decide whether they want only the device resources, port resources or both. This will retain the exact functionality of the series.

On the CLI "devlink resource show" should show all resources in the system IMO. How we define the CLI arguments to scope things down I don't have a strong opinion on.

#23 lore raw
Quoted 44 lines · Jakub Kicinski
Quoted 35 lines · On Sun, 8 Mar 2026 18:03:11 +0200 Or Har-Toov wrote:

Do you mean that we will register resources per port, but not show with new devlink port resource show.
Instead, the current devlink resource show dev command will also display the ports of that device?

For example:

$ devlink resource show pci/0000:03:00.0
    pci/0000:03:00.0:
      name local_max_SFs size 40 unit entry
    pci/0000:03:00.0/196608:
       name max_SFs size 20 unit entry
    pci/0000:03:00.0/196609:
       name max_SFs size 20 unit entry

Or should we keep the current behavior where devlink resource show dev displays only device-level resources, and only the full dump shows both devices and their ports?

For example:

$ devlink resource show
    pci/0000:03:00.0:
      name local_max_SFs size 40 unit entry
    pci/0000:03:00.0/196608:
       name max_SFs size 20 unit entry
    pci/0000:03:00.0/196609:
       name max_SFs size 20 unit entry
    pci/0000:03:00.1:
      name local_max_SFs size 40 unit entry
    pci/0000:03:00.1/196608:
       name max_SFs size 20 unit entry
    pci/0000:03:00.1/196609:
       name max_SFs size 20 unit entry
Quoted 1 line

Want to confirm which behavior you meant.

No strong preference on the CLI. For the kernel I think specifying the device should not exclude the port resources. Whether port resources are shown or not should be entirely up to the mask attribute.

Quoted 8 lines

Thinking about this some more after my last reply to Jiri I think we should add that mask attribute to let user decide whether they want only the device resources, port resources or both. This will retain the exact functionality of the series.

On the CLI "devlink resource show" should show all resources in the system IMO. How we define the CLI arguments to scope things down I don't have a strong opinion on.

So for the dump of all resources it is clear. But I want to make sure I understood the scope/mask part:

For the dump-it command:
devlink resource show
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1:
<resource>
pci/0000:03:00.1/262144:
<port-resource>

devlink resource show scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1/262144:
<port-resource>

devlink resource show scope dev
pci/0000:03:00.0:
<resource>
pci/0000:03:00.1:
<resource>

For the do-it command:
devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope dev
pci/0000:03:00.0:
<resource>

The way to get the dev or port scope will be by bitmask in the netlink message of the dump/doit command. Thank you

maintainer
#24 lore raw
Quoted 21 lines · On Wed, 11 Mar 2026 20:24:08 +0200 Or Har-Toov wrote:

For the dump-it command:
devlink resource show
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1:
<resource>
pci/0000:03:00.1/262144:
<port-resource>

devlink resource show scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1/262144:
<port-resource>

Quoted 5 lines

devlink resource show scope dev
pci/0000:03:00.0:
<resource>
pci/0000:03:00.1:
<resource>

LGTM

Quoted 15 lines

For the do-it command:
devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

Quoted 3 lines

devlink resource show pci/0000:03:00.0 scope dev
pci/0000:03:00.0:
<resource>

Do we have to touch doit? Maybe we should let doit be what it is now and consider it legacy going forward? doit which is in fact a filtered dump is a bit of a mistake in the first place, from Netlink's perspective.

maintainer
#25 lore raw
Quoted 22 lines · Wed, Mar 11, 2026 at 10:51:26PM +0100, [email protected] wrote:
Quoted 21 lines · On Wed, 11 Mar 2026 20:24:08 +0200 Or Har-Toov wrote:

For the dump-it command:
devlink resource show
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1:
<resource>
pci/0000:03:00.1/262144:
<port-resource>

devlink resource show scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>
pci/0000:03:00.1/262144:
<port-resource>

Quoted 7 lines
Quoted 5 lines

devlink resource show scope dev
pci/0000:03:00.0:
<resource>
pci/0000:03:00.1:
<resource>

LGTM

I don't see the benefit of exposing the scope to the user to be honest. I mean, dump would show all, dump with "dev" handle would be used as a selector to dump only things related to "dev". What is the use case of this "scope" granularity?

Quoted 16 lines
Quoted 16 lines

For the do-it command:
devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

Quoted 8 lines
Quoted 3 lines

devlink resource show pci/0000:03:00.0 scope dev
pci/0000:03:00.0:
<resource>

Do we have to touch doit? Maybe we should let doit be what it is now and consider it legacy going forward? doit which is in fact a filtered dump is a bit of a mistake in the first place, from Netlink's perspective.

I don't think we should. If user wants doit, he is going to specify the object (dev/port). If user is interested only in things related to single device, he should do dump with selector (dev).

Let's make this simple.

maintainer
#26 lore raw
Quoted 6 lines · On Thu, 12 Mar 2026 09:34:52 +0100 Jiri Pirko wrote:
Quoted 6 lines
Quoted 5 lines

devlink resource show scope dev
pci/0000:03:00.0:
<resource>
pci/0000:03:00.1:
<resource>

Quoted 6 lines
Quoted 1 line

LGTM

I don't see the benefit of exposing the scope to the user to be honest. I mean, dump would show all, dump with "dev" handle would be used as a selector to dump only things related to "dev". What is the use case of this "scope" granularity?

If we follow the logic that dump should show the user relevant resources, no matter which sub-object they are attached to - having a dev specified should only filter the objects to match the dev, including resources which are on ports of that dev.

IDK if there's a strong use case for allowing the user to set scope on CLI but also - I don't see why not?

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

For the do-it command:
devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope dev
pci/0000:03:00.0:
<resource>

Quoted 8 lines
Quoted 4 lines

Do we have to touch doit? Maybe we should let doit be what it is now and consider it legacy going forward? doit which is in fact a filtered dump is a bit of a mistake in the first place, from Netlink's perspective.

I don't think we should. If user wants doit, he is going to specify the object (dev/port). If user is interested only in things related to single device, he should do dump with selector (dev).

Could you confirm that you're agreeing that we should leave doit as is? I'm not 100% sure after reading this twice :)

maintainer
#27 lore raw
Quoted 14 lines · Thu, Mar 12, 2026 at 03:19:16PM +0100, [email protected] wrote:
Quoted 6 lines · On Thu, 12 Mar 2026 09:34:52 +0100 Jiri Pirko wrote:
Quoted 6 lines
Quoted 5 lines

devlink resource show scope dev
pci/0000:03:00.0:
<resource>
pci/0000:03:00.1:
<resource>

Quoted 6 lines
Quoted 1 line

LGTM

I don't see the benefit of exposing the scope to the user to be honest. I mean, dump would show all, dump with "dev" handle would be used as a selector to dump only things related to "dev". What is the use case of this "scope" granularity?

Quoted 7 lines

If we follow the logic that dump should show the user relevant resources, no matter which sub-object they are attached to - having a dev specified should only filter the objects to match the dev, including resources which are on ports of that dev.

IDK if there's a strong use case for allowing the user to set scope on CLI but also - I don't see why not?

At least some small sense of consistency with other dumps? Health reporter and region does not have scope and output mixture of dev-based and port-based objects. Why to confuse user?

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 16 lines

For the do-it command:
devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
<resource>
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

devlink resource show pci/0000:03:00.0 scope port
pci/0000:03:00.0/196608:
<port-resource>
pci/0000:03:00.0/196609:
<port-resource>

Quoted 3 lines

devlink resource show pci/0000:03:00.0 scope dev
pci/0000:03:00.0:
<resource>

Do we have to touch doit? Maybe we should let doit be what it is now and consider it legacy going forward? doit which is in fact a filtered dump is a bit of a mistake in the first place, from Netlink's perspective.

Quoted 6 lines
Quoted 3 lines

I don't think we should. If user wants doit, he is going to specify the object (dev/port). If user is interested only in things related to single device, he should do dump with selector (dev).

Could you confirm that you're agreeing that we should leave doit as is? I'm not 100% sure after reading this twice :)

Yes.

maintainer
#28 lore raw
Quoted 10 lines · On Thu, 12 Mar 2026 15:29:53 +0100 Jiri Pirko wrote:
Quoted 10 lines
Quoted 4 lines

I don't see the benefit of exposing the scope to the user to be honest. I mean, dump would show all, dump with "dev" handle would be used as a selector to dump only things related to "dev". What is the use case of this "scope" granularity?

If we follow the logic that dump should show the user relevant resources, no matter which sub-object they are attached to - having a dev specified should only filter the objects to match the dev, including resources which are on ports of that dev.

Quoted 6 lines
Quoted 2 lines

IDK if there's a strong use case for allowing the user to set scope on CLI but also - I don't see why not?

At least some small sense of consistency with other dumps? Health reporter and region does not have scope and output mixture of dev-based and port-based objects. Why to confuse user?

That's a judgment call - either we confuse users but two commands behaving differently, or we confuse users with devlink $thing not dumping all instances of the $thing.

Especially that drivers often retroactively move $things from device scope to port scope :(