* [PATCH iproute2-next 1/7] devlink: Split dpipe tables output to a separate function
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 2/7] devlink: Move dpipe tables query to resources show callback Tariq Toukan
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Ido Schimmel <idosch@nvidia.com>
As part of showing device resources, devlink also iterates over
available dpipe tables and shows the associated tables, if any.
A subsequent patch will show the device resources even if we failed to
retrieve the dpipe tables. In preparation for this change, split the
functionality of showing the associated dpipe tables into a separate
function.
No functional changes intended.
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
devlink/devlink.c | 54 +++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 23 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index b4deba30c538..d998520cfd88 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -8811,34 +8811,13 @@ static const char *resource_unit_str_get(enum devlink_resource_unit unit)
}
}
-static void resource_show(struct resource *resource,
- struct resource_ctx *ctx)
+static void resource_dpipe_tables_show(const struct resource *resource,
+ const struct resource_ctx *ctx)
{
- struct resource *child_resource;
struct dpipe_table *table;
struct dl *dl = ctx->dl;
bool array = false;
- check_indent_newline(dl);
- print_string(PRINT_ANY, "name", "name %s", resource->name);
- if (dl->verbose)
- resource_path_print(dl, ctx->resources, resource->id);
- pr_out_u64(dl, "size", resource->size);
- if (resource->size != resource->size_new)
- pr_out_u64(dl, "size_new", resource->size_new);
- if (resource->occ_valid)
- print_uint(PRINT_ANY, "occ", " occ %u", resource->size_occ);
- print_string(PRINT_ANY, "unit", " unit %s",
- resource_unit_str_get(resource->unit));
-
- if (resource->size_min != resource->size_max) {
- print_uint(PRINT_ANY, "size_min", " size_min %u",
- resource->size_min);
- pr_out_u64(dl, "size_max", resource->size_max);
- print_uint(PRINT_ANY, "size_gran", " size_gran %u",
- resource->size_gran);
- }
-
list_for_each_entry(table, &ctx->tables->table_list, list)
if (table->resource_id == resource->id &&
table->resource_valid)
@@ -8862,6 +8841,35 @@ static void resource_show(struct resource *resource,
}
if (array)
pr_out_array_end(dl);
+}
+
+static void resource_show(struct resource *resource,
+ struct resource_ctx *ctx)
+{
+ struct resource *child_resource;
+ struct dl *dl = ctx->dl;
+
+ check_indent_newline(dl);
+ print_string(PRINT_ANY, "name", "name %s", resource->name);
+ if (dl->verbose)
+ resource_path_print(dl, ctx->resources, resource->id);
+ pr_out_u64(dl, "size", resource->size);
+ if (resource->size != resource->size_new)
+ pr_out_u64(dl, "size_new", resource->size_new);
+ if (resource->occ_valid)
+ print_uint(PRINT_ANY, "occ", " occ %u", resource->size_occ);
+ print_string(PRINT_ANY, "unit", " unit %s",
+ resource_unit_str_get(resource->unit));
+
+ if (resource->size_min != resource->size_max) {
+ print_uint(PRINT_ANY, "size_min", " size_min %u",
+ resource->size_min);
+ pr_out_u64(dl, "size_max", resource->size_max);
+ print_uint(PRINT_ANY, "size_gran", " size_gran %u",
+ resource->size_gran);
+ }
+
+ resource_dpipe_tables_show(resource, ctx);
if (list_empty(&resource->resource_list))
return;
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 2/7] devlink: Move dpipe tables query to resources show callback
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 1/7] devlink: Split dpipe tables output to a separate function Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 3/7] devlink: fix memory leak in resource_ctx_fini Tariq Toukan
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Ido Schimmel <idosch@nvidia.com>
As previously explained, as part of showing device resources, devlink
queries the device's dpipe tables so that it will be able to show the
association between resources and dpipe tables.
Currently, the dpipe tables are queried before the device resources.
This will become a problem when devlink is extended to support dumping
the resources of all available devices.
Therefore, in preparation for resource dump support, move the querying
of the device's dpipe tables to the resources show callback which is
invoked per-device.
There is no difference in the output of the resource show command, but
one functional difference is that errors in dpipe tables query are not
considered fatal. This seems reasonable given that errors are unlikely
and that displaying the dpipe tables is secondary to showing the device
resources.
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
devlink/devlink.c | 82 +++++++++++++++++++++++++++++++++++------------
1 file changed, 62 insertions(+), 20 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index d998520cfd88..7a8be3ad9b6a 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -8818,6 +8818,9 @@ static void resource_dpipe_tables_show(const struct resource *resource,
struct dl *dl = ctx->dl;
bool array = false;
+ if (!ctx->tables)
+ return;
+
list_for_each_entry(table, &ctx->tables->table_list, list)
if (table->resource_id == resource->id &&
table->resource_valid)
@@ -8888,17 +8891,75 @@ static void resource_show(struct resource *resource,
pr_out_array_end(dl);
}
+static void resources_dpipe_tables_init(struct dpipe_ctx *dpipe_ctx,
+ struct resource_ctx *resource_ctx,
+ struct nlattr **tb)
+{
+ const char *bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
+ const char *dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
+ struct mnlu_gen_socket nlg_dpipe;
+ struct dl *dl = resource_ctx->dl;
+ struct nlmsghdr *nlh;
+ int err;
+
+ err = dpipe_ctx_init(dpipe_ctx, dl);
+ if (err)
+ return;
+
+ err = mnlu_gen_socket_open(&nlg_dpipe, DEVLINK_GENL_NAME,
+ DEVLINK_GENL_VERSION);
+ if (err)
+ goto ctx_fini;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&nlg_dpipe,
+ DEVLINK_CMD_DPIPE_TABLE_GET,
+ NLM_F_REQUEST);
+
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
+
+ err = mnlu_gen_socket_sndrcv(&nlg_dpipe, nlh, cmd_dpipe_table_show_cb,
+ dpipe_ctx);
+ if (err)
+ goto socket_close;
+
+ resource_ctx->tables = dpipe_ctx->tables;
+ mnlu_gen_socket_close(&nlg_dpipe);
+
+ return;
+
+socket_close:
+ mnlu_gen_socket_close(&nlg_dpipe);
+ctx_fini:
+ dpipe_ctx_fini(dpipe_ctx);
+}
+
+static void resources_dpipe_tables_fini(struct dpipe_ctx *dpipe_ctx,
+ struct resource_ctx *resource_ctx)
+{
+ if (!resource_ctx->tables)
+ return;
+
+ resource_ctx->tables = NULL;
+ dpipe_ctx_fini(dpipe_ctx);
+}
+
static void
resources_show(struct resource_ctx *ctx, struct nlattr **tb)
{
struct resources *resources = ctx->resources;
+ struct dpipe_ctx dpipe_ctx = {};
struct resource *resource;
+ resources_dpipe_tables_init(&dpipe_ctx, ctx, tb);
+
list_for_each_entry(resource, &resources->resource_list, list) {
pr_out_handle_start_arr(ctx->dl, tb);
resource_show(resource, ctx);
pr_out_handle_end(ctx->dl);
}
+
+ resources_dpipe_tables_fini(&dpipe_ctx, ctx);
}
static int resources_get(struct resource_ctx *ctx, struct nlattr **tb)
@@ -8933,7 +8994,6 @@ static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)
static int cmd_resource_show(struct dl *dl)
{
struct nlmsghdr *nlh;
- struct dpipe_ctx dpipe_ctx = {};
struct resource_ctx resource_ctx = {};
int err;
@@ -8941,27 +9001,11 @@ static int cmd_resource_show(struct dl *dl)
if (err)
return err;
- nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET,
- NLM_F_REQUEST);
- dl_opts_put(nlh, dl);
-
- err = dpipe_ctx_init(&dpipe_ctx, dl);
- if (err)
- return err;
-
- err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dpipe_table_show_cb,
- &dpipe_ctx);
- if (err) {
- pr_err("error get tables %s\n", strerror(dpipe_ctx.err));
- goto out;
- }
-
err = resource_ctx_init(&resource_ctx, dl);
if (err)
- goto out;
+ return err;
resource_ctx.print_resources = true;
- resource_ctx.tables = dpipe_ctx.tables;
nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
NLM_F_REQUEST | NLM_F_ACK);
dl_opts_put(nlh, dl);
@@ -8970,8 +9014,6 @@ static int cmd_resource_show(struct dl *dl)
&resource_ctx);
pr_out_section_end(dl);
resource_ctx_fini(&resource_ctx);
-out:
- dpipe_ctx_fini(&dpipe_ctx);
return err;
}
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 3/7] devlink: fix memory leak in resource_ctx_fini
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 1/7] devlink: Split dpipe tables output to a separate function Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 2/7] devlink: Move dpipe tables query to resources show callback Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 4/7] devlink: add dump support for resource show Tariq Toukan
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Or Har-Toov <ohartoov@nvidia.com>
resource_ctx_init() allocates ctx->resources via resources_alloc()
which calls calloc(). resource_ctx_fini() calls resources_free() to
free the list items inside the struct, but never frees the struct
itself.
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
devlink/devlink.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 7a8be3ad9b6a..ba14c0056b1c 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -7441,6 +7441,7 @@ static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)
static void resource_ctx_fini(struct resource_ctx *ctx)
{
resources_free(ctx->resources);
+ free(ctx->resources);
}
struct dpipe_ctx {
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 4/7] devlink: add dump support for resource show
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
` (2 preceding siblings ...)
2026-06-09 5:39 ` [PATCH iproute2-next 3/7] devlink: fix memory leak in resource_ctx_fini Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 5/7] devlink: show port resources in resource dump Tariq Toukan
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Or Har-Toov <ohartoov@nvidia.com>
Allow 'devlink resource show' without specifying a device to dump
resources from all devlink devices.
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
devlink/devlink.c | 18 ++++++++++++++----
man/man8/devlink-resource.8 | 10 ++++++++--
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index ba14c0056b1c..0962ffd861ad 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -7429,6 +7429,12 @@ static void resources_free(struct resources *resources)
resource_free(resource);
}
+static void resources_reset(struct resources *resources)
+{
+ resources_free(resources);
+ INIT_LIST_HEAD(&resources->resource_list);
+}
+
static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)
{
ctx->resources = resources_alloc();
@@ -8986,19 +8992,23 @@ static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)
return MNL_CB_ERROR;
}
- if (ctx->print_resources)
+ if (ctx->print_resources) {
resources_show(ctx, tb);
+ resources_reset(ctx->resources);
+ }
return MNL_CB_OK;
}
static int cmd_resource_show(struct dl *dl)
{
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
struct nlmsghdr *nlh;
struct resource_ctx resource_ctx = {};
int err;
- err = dl_argv_parse(dl, DL_OPT_HANDLE, 0);
+ err = dl_argv_parse_with_selector(dl, &flags, DEVLINK_CMD_RESOURCE_DUMP,
+ DL_OPT_HANDLE, 0, 0, 0);
if (err)
return err;
@@ -9008,7 +9018,7 @@ static int cmd_resource_show(struct dl *dl)
resource_ctx.print_resources = true;
nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
- NLM_F_REQUEST | NLM_F_ACK);
+ flags);
dl_opts_put(nlh, dl);
pr_out_section_start(dl, "resources");
err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb,
@@ -9020,7 +9030,7 @@ static int cmd_resource_show(struct dl *dl)
static void cmd_resource_help(void)
{
- pr_err("Usage: devlink resource show DEV\n"
+ pr_err("Usage: devlink resource show [ DEV ]\n"
" devlink resource set DEV path PATH size SIZE\n");
}
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
index c4f6918c9b03..b55138d950c7 100644
--- a/man/man8/devlink-resource.8
+++ b/man/man8/devlink-resource.8
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration
.ti -8
.B devlink resource show
-.IR DEV
+.RI "[ " DEV " ]"
.ti -8
.B devlink resource help
@@ -31,11 +31,12 @@ devlink-resource \- devlink device resource configuration
.BI size " RESOURCE_SIZE"
.SH "DESCRIPTION"
-.SS devlink resource show - display devlink device's resosources
+.SS devlink resource show - display devlink device resources
.PP
.I "DEV"
- specifies the devlink device to show.
+If omitted, all devices are listed.
.in +4
Format is:
@@ -58,6 +59,11 @@ The new resource's size.
.SH "EXAMPLES"
.PP
+devlink resource show
+.RS 4
+Shows resources for all devlink devices.
+.RE
+.PP
devlink resource show pci/0000:01:00.0
.RS 4
Shows the resources of the specified devlink device.
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 5/7] devlink: show port resources in resource dump
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
` (3 preceding siblings ...)
2026-06-09 5:39 ` [PATCH iproute2-next 4/7] devlink: add dump support for resource show Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 6/7] devlink: add per-port resource show support Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 7/7] devlink: add scope filter to resource show Tariq Toukan
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Or Har-Toov <ohartoov@nvidia.com>
When the kernel returns port-level resource messages during a
DEVLINK_CMD_RESOURCE_DUMP, display them alongside device-level
resources.
For example:
$ devlink resource show
pci/0000:03:00.0:
name max_local_SFs size 32 unit entry dpipe_tables none
name max_external_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.0/196608:
name max_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.1:
name max_local_SFs size 32 unit entry dpipe_tables none
name max_external_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.1/262144:
name max_SFs size 32 unit entry dpipe_tables none
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
devlink/devlink.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 0962ffd861ad..737cfc7437f9 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -8954,18 +8954,23 @@ static void resources_dpipe_tables_fini(struct dpipe_ctx *dpipe_ctx,
static void
resources_show(struct resource_ctx *ctx, struct nlattr **tb)
{
- struct resources *resources = ctx->resources;
+ bool is_port = !!tb[DEVLINK_ATTR_PORT_INDEX];
struct dpipe_ctx dpipe_ctx = {};
struct resource *resource;
+ struct dl *dl = ctx->dl;
resources_dpipe_tables_init(&dpipe_ctx, ctx, tb);
-
- list_for_each_entry(resource, &resources->resource_list, list) {
- pr_out_handle_start_arr(ctx->dl, tb);
+ list_for_each_entry(resource, &ctx->resources->resource_list, list) {
+ if (is_port)
+ pr_out_port_handle_start_arr(dl, tb, false);
+ else
+ pr_out_handle_start_arr(dl, tb);
resource_show(resource, ctx);
- pr_out_handle_end(ctx->dl);
+ if (is_port)
+ pr_out_port_handle_end(dl);
+ else
+ pr_out_handle_end(dl);
}
-
resources_dpipe_tables_fini(&dpipe_ctx, ctx);
}
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 6/7] devlink: add per-port resource show support
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
` (4 preceding siblings ...)
2026-06-09 5:39 ` [PATCH iproute2-next 5/7] devlink: show port resources in resource dump Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
2026-06-09 5:39 ` [PATCH iproute2-next 7/7] devlink: add scope filter to resource show Tariq Toukan
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Or Har-Toov <ohartoov@nvidia.com>
Extend 'devlink resource show' to accept DEV/PORT_INDEX, sending
DEVLINK_ATTR_PORT_INDEX to the kernel so it returns only that port's
resources directly.
For example:
$ devlink resource show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608:
name max_SFs size 128 unit entry dpipe_tables none
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
bash-completion/devlink | 1 +
devlink/devlink.c | 5 +++--
man/man8/devlink-resource.8 | 17 ++++++++++++++++-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/bash-completion/devlink b/bash-completion/devlink
index 7ec6a7cb6abd..3d8452a8869e 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -704,6 +704,7 @@ _devlink_resource()
show)
if [[ $cword -eq 3 ]]; then
_devlink_direct_complete "dev"
+ _devlink_direct_complete "port"
fi
return
;;
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 737cfc7437f9..4224b7fa6792 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -9013,7 +9013,8 @@ static int cmd_resource_show(struct dl *dl)
int err;
err = dl_argv_parse_with_selector(dl, &flags, DEVLINK_CMD_RESOURCE_DUMP,
- DL_OPT_HANDLE, 0, 0, 0);
+ DL_OPT_HANDLE | DL_OPT_HANDLEP,
+ 0, 0, 0);
if (err)
return err;
@@ -9035,7 +9036,7 @@ static int cmd_resource_show(struct dl *dl)
static void cmd_resource_help(void)
{
- pr_err("Usage: devlink resource show [ DEV ]\n"
+ pr_err("Usage: devlink resource show [ DEV[/PORT_INDEX] ]\n"
" devlink resource set DEV path PATH size SIZE\n");
}
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
index b55138d950c7..1e7d96126ce5 100644
--- a/man/man8/devlink-resource.8
+++ b/man/man8/devlink-resource.8
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration
.ti -8
.B devlink resource show
-.RI "[ " DEV " ]"
+.RI "[ " DEV "[/" PORT_INDEX "] ]"
.ti -8
.B devlink resource help
@@ -43,6 +43,16 @@ Format is:
.in +2
BUS_NAME/BUS_ADDRESS
+.PP
+.I "PORT_INDEX"
+- specifies the port to show resources for.
+When given, only port-level resources for that port are shown.
+
+.in +4
+Format is:
+.in +2
+BUS_NAME/BUS_ADDRESS/PORT_INDEX
+
.SS devlink resource set - sets resource size of specific resource
.PP
@@ -69,6 +79,11 @@ devlink resource show pci/0000:01:00.0
Shows the resources of the specified devlink device.
.RE
.PP
+devlink resource show pci/0000:01:00.0/1
+.RS 4
+Shows port-level resources for port 1 of the specified devlink device.
+.RE
+.PP
devlink resource set pci/0000:01:00.0 path /kvd/linear size 98304
.RS 4
Sets the size of the specified resource for the specified devlink device.
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH iproute2-next 7/7] devlink: add scope filter to resource show
2026-06-09 5:39 [PATCH iproute2-next 0/7] devlink: add per-port resource support Tariq Toukan
` (5 preceding siblings ...)
2026-06-09 5:39 ` [PATCH iproute2-next 6/7] devlink: add per-port resource show support Tariq Toukan
@ 2026-06-09 5:39 ` Tariq Toukan
6 siblings, 0 replies; 8+ messages in thread
From: Tariq Toukan @ 2026-06-09 5:39 UTC (permalink / raw)
To: Stephen Hemminger, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, David S. Miller
Cc: David Ahern, Donald Hunter, Simon Horman, Jiri Pirko,
Jonathan Corbet, Shuah Khan, Saeed Mahameed, Leon Romanovsky,
Tariq Toukan, Mark Bloch, Shuah Khan, Matthieu Baerts (NGI0),
Chuck Lever, Or Har-Toov, Carolina Jubran, Moshe Shemesh,
Shay Drori, Dragos Tatulea, Daniel Zahka, Shahar Shitrit,
Jacob Keller, Cosmin Ratiu, Parav Pandit, Kees Cook,
Adithya Jayachandran, Daniel Jurgens, netdev, linux-kernel,
linux-doc, linux-rdma, linux-kselftest, Gal Pressman,
Ido Schimmel, Jiri Pirko, Petr Machata
From: Or Har-Toov <ohartoov@nvidia.com>
Add optional 'scope { dev | port }' argument to 'devlink resource show'
without a device handle to filter the full dump to device-level or
port-level resources only.
Example - dump only device-level resources:
$ devlink resource show scope dev
pci/0000:03:00.0:
name max_local_SFs size 128 unit entry dpipe_tables none
name max_external_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1:
name max_local_SFs size 128 unit entry dpipe_tables none
name max_external_SFs size 128 unit entry dpipe_tables none
Example - dump only port-level resources:
$ devlink resource show scope port
pci/0000:03:00.0/196608:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.0/196609:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1/196708:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1/196709:
name max_SFs size 128 unit entry dpipe_tables none
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
bash-completion/devlink | 7 ++++++
devlink/devlink.c | 47 ++++++++++++++++++++++++++++++++-----
man/man8/devlink-resource.8 | 11 ++++++++-
3 files changed, 58 insertions(+), 7 deletions(-)
diff --git a/bash-completion/devlink b/bash-completion/devlink
index 3d8452a8869e..bfc0083f647b 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -702,9 +702,16 @@ _devlink_resource()
{
case $command in
show)
+ case $prev in
+ scope)
+ COMPREPLY=( $( compgen -W "dev port" -- "$cur" ) )
+ return
+ ;;
+ esac
if [[ $cword -eq 3 ]]; then
_devlink_direct_complete "dev"
_devlink_direct_complete "port"
+ COMPREPLY+=( $( compgen -W "scope" -- "$cur" ) )
fi
return
;;
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 4224b7fa6792..1a94b6413048 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -314,6 +314,7 @@ static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
#define DL_OPT_PORT_FN_RATE_TC_BWS BIT(59)
#define DL_OPT_HEALTH_REPORTER_BURST_PERIOD BIT(60)
#define DL_OPT_PARAM_SET_DEFAULT BIT(61)
+#define DL_OPT_RESOURCE_SCOPE BIT(62)
struct dl_opts {
uint64_t present; /* flags of present items */
@@ -382,6 +383,7 @@ struct dl_opts {
bool selftests_opt[DEVLINK_ATTR_SELFTEST_ID_MAX + 1];
struct nla_bitfield32 port_fn_caps;
uint32_t port_fn_max_io_eqs;
+ uint32_t resource_scope_mask;
};
struct dl {
@@ -1467,6 +1469,19 @@ static int flash_overwrite_section_get(const char *sectionstr, uint32_t *mask)
return 0;
}
+static int resource_scope_get(const char *scopestr, uint32_t *scope)
+{
+ if (strcmp(scopestr, "dev") == 0) {
+ *scope = DEVLINK_RESOURCE_SCOPE_DEV;
+ } else if (strcmp(scopestr, "port") == 0) {
+ *scope = DEVLINK_RESOURCE_SCOPE_PORT;
+ } else {
+ pr_err("Unknown resource scope \"%s\"\n", scopestr);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int param_cmode_get(const char *cmodestr,
enum devlink_param_cmode *cmode)
{
@@ -1647,6 +1662,7 @@ static const struct dl_args_metadata dl_args_required[] = {
{DL_OPT_ESWITCH_ENCAP_MODE, "E-Switch encapsulation option expected."},
{DL_OPT_RESOURCE_PATH, "Resource path expected."},
{DL_OPT_RESOURCE_SIZE, "Resource size expected."},
+ {DL_OPT_RESOURCE_SCOPE, "Resource scope expected."},
{DL_OPT_PARAM_NAME, "Parameter name expected."},
{DL_OPT_PARAM_VALUE, "Value to set expected."},
{DL_OPT_PARAM_CMODE, "Configuration mode expected."},
@@ -2662,6 +2678,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
if (opts->present & DL_OPT_RESOURCE_SIZE)
mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_SIZE,
opts->resource_size);
+ if (opts->present & DL_OPT_RESOURCE_SCOPE)
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_RESOURCE_SCOPE_MASK,
+ opts->resource_scope_mask);
if (opts->present & DL_OPT_PARAM_NAME)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME,
opts->param_name);
@@ -9010,13 +9029,29 @@ static int cmd_resource_show(struct dl *dl)
uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
struct nlmsghdr *nlh;
struct resource_ctx resource_ctx = {};
+ struct dl_opts *opts = &dl->opts;
int err;
- err = dl_argv_parse_with_selector(dl, &flags, DEVLINK_CMD_RESOURCE_DUMP,
- DL_OPT_HANDLE | DL_OPT_HANDLEP,
- 0, 0, 0);
- if (err)
- return err;
+ if (dl_argv_match(dl, "scope")) {
+ const char *scopestr;
+
+ dl_arg_inc(dl);
+ err = dl_argv_str(dl, &scopestr);
+ if (err)
+ return err;
+ err = resource_scope_get(scopestr, &opts->resource_scope_mask);
+ if (err)
+ return err;
+ opts->present |= DL_OPT_RESOURCE_SCOPE;
+ flags |= NLM_F_DUMP;
+ } else {
+ err = dl_argv_parse_with_selector(dl, &flags,
+ DEVLINK_CMD_RESOURCE_DUMP,
+ DL_OPT_HANDLE | DL_OPT_HANDLEP,
+ 0, 0, 0);
+ if (err)
+ return err;
+ }
err = resource_ctx_init(&resource_ctx, dl);
if (err)
@@ -9036,7 +9071,7 @@ static int cmd_resource_show(struct dl *dl)
static void cmd_resource_help(void)
{
- pr_err("Usage: devlink resource show [ DEV[/PORT_INDEX] ]\n"
+ pr_err("Usage: devlink resource show [ DEV[/PORT_INDEX] | scope { dev | port } ]\n"
" devlink resource set DEV path PATH size SIZE\n");
}
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
index 1e7d96126ce5..04cde2bf8958 100644
--- a/man/man8/devlink-resource.8
+++ b/man/man8/devlink-resource.8
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration
.ti -8
.B devlink resource show
-.RI "[ " DEV "[/" PORT_INDEX "] ]"
+.RI "[ " DEV "[/" PORT_INDEX "] | " scope " { " dev " | " port " } ]"
.ti -8
.B devlink resource help
@@ -53,6 +53,15 @@ Format is:
.in +2
BUS_NAME/BUS_ADDRESS/PORT_INDEX
+.TP
+.BI scope " { dev | port }"
+Filter resources by scope.
+.B dev
+shows only device-level resources.
+.B port
+shows only port-level resources.
+When omitted, resources of both scopes are shown.
+
.SS devlink resource set - sets resource size of specific resource
.PP
--
2.44.0
^ permalink raw reply related [flat|nested] 8+ messages in thread