From: Tariq Toukan <tariqt@nvidia.com>
To: Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>
Cc: Donald Hunter <donald.hunter@gmail.com>,
Jiri Pirko <jiri@resnulli.us>, Jonathan Corbet <corbet@lwn.net>,
Saeed Mahameed <saeedm@nvidia.com>,
"Leon Romanovsky" <leon@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Shuah Khan <shuah@kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
Gal Pressman <gal@nvidia.com>,
Dragos Tatulea <dtatulea@nvidia.com>,
Shay Drory <shayd@nvidia.com>, Jiri Pirko <jiri@nvidia.com>,
Moshe Shemesh <moshe@nvidia.com>,
Or Har-Toov <ohartoov@nvidia.com>
Subject: [PATCH net-next V3 01/10] devlink: Add dump support for device-level resources
Date: Fri, 27 Feb 2026 00:19:07 +0200 [thread overview]
Message-ID: <20260226221916.1800227-2-tariqt@nvidia.com> (raw)
In-Reply-To: <20260226221916.1800227-1-tariqt@nvidia.com>
From: Or Har-Toov <ohartoov@nvidia.com>
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
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
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(-)
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 837112da6738..ee679ac14261 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -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
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index f4c61c2b4f22..d6667a3f87a0 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c
@@ -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,
diff --git a/net/devlink/netlink_gen.h b/net/devlink/netlink_gen.h
index 2817d53a0eba..d79f6a0888f6 100644
--- a/net/devlink/netlink_gen.h
+++ b/net/devlink/netlink_gen.h
@@ -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,
diff --git a/net/devlink/resource.c b/net/devlink/resource.c
index 2d6324f3d91f..5131875482ec 100644
--- a/net/devlink/resource.c
+++ b/net/devlink/resource.c
@@ -213,21 +213,43 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
return -EMSGSIZE;
}
+static int devlink_resource_list_fill(struct sk_buff *skb,
+ struct devlink *devlink,
+ int *idx)
+{
+ struct devlink_resource *resource;
+ int i = 0;
+ int err;
+
+ list_for_each_entry(resource, &devlink->resource_list, list) {
+ if (i < *idx) {
+ i++;
+ continue;
+ }
+ err = devlink_resource_put(devlink, skb, resource);
+ if (err) {
+ *idx = i;
+ return err;
+ }
+ i++;
+ }
+ *idx = 0;
+ return 0;
+}
+
static int devlink_resource_fill(struct genl_info *info,
enum devlink_command cmd, int flags)
{
struct devlink *devlink = info->user_ptr[0];
- struct devlink_resource *resource;
struct nlattr *resources_attr;
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh;
bool incomplete;
+ int start_idx;
void *hdr;
- int i;
+ int i = 0;
int err;
- resource = list_first_entry(&devlink->resource_list,
- struct devlink_resource, list);
start_again:
err = devlink_nl_msg_reply_and_new(&skb, info);
if (err)
@@ -249,16 +271,12 @@ static int devlink_resource_fill(struct genl_info *info,
goto nla_put_failure;
incomplete = false;
- i = 0;
- list_for_each_entry_from(resource, &devlink->resource_list, list) {
- err = devlink_resource_put(devlink, skb, resource);
- if (err) {
- if (!i)
- goto err_resource_put;
- incomplete = true;
- break;
- }
- i++;
+ start_idx = i;
+ err = devlink_resource_list_fill(skb, devlink, &i);
+ if (err) {
+ if (i == start_idx)
+ goto err_resource_put;
+ incomplete = true;
}
nla_nest_end(skb, resources_attr);
genlmsg_end(skb, hdr);
@@ -292,6 +310,59 @@ int devlink_nl_resource_dump_doit(struct sk_buff *skb, struct genl_info *info)
return devlink_resource_fill(info, DEVLINK_CMD_RESOURCE_DUMP, 0);
}
+static int
+devlink_nl_resource_dump_one(struct sk_buff *skb, struct devlink *devlink,
+ struct netlink_callback *cb, int flags)
+{
+ struct devlink_nl_dump_state *state = devlink_dump_state(cb);
+ struct nlattr *resources_attr;
+ int start_idx = state->idx;
+ void *hdr;
+ int err;
+
+ if (list_empty(&devlink->resource_list))
+ return 0;
+
+ hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
+ &devlink_nl_family, flags, DEVLINK_CMD_RESOURCE_DUMP);
+ if (!hdr)
+ return -EMSGSIZE;
+
+ err = devlink_nl_put_handle(skb, devlink);
+ if (err)
+ goto nla_put_failure;
+
+ resources_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_RESOURCE_LIST);
+ if (!resources_attr) {
+ err = -EMSGSIZE;
+ goto nla_put_failure;
+ }
+
+ err = devlink_resource_list_fill(skb, devlink, &state->idx);
+ if (err) {
+ if (state->idx == start_idx)
+ goto nla_put_failure_unwind;
+ nla_nest_end(skb, resources_attr);
+ genlmsg_end(skb, hdr);
+ return err;
+ }
+ nla_nest_end(skb, resources_attr);
+ genlmsg_end(skb, hdr);
+ return 0;
+
+nla_put_failure_unwind:
+ nla_nest_cancel(skb, resources_attr);
+nla_put_failure:
+ genlmsg_cancel(skb, hdr);
+ return err;
+}
+
+int devlink_nl_resource_dump_dumpit(struct sk_buff *skb,
+ struct netlink_callback *cb)
+{
+ return devlink_nl_dumpit(skb, cb, devlink_nl_resource_dump_one);
+}
+
int devlink_resources_validate(struct devlink *devlink,
struct devlink_resource *resource,
struct genl_info *info)
--
2.44.0
next prev parent reply other threads:[~2026-02-26 22:20 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 22:19 [PATCH net-next V3 00/10] devlink: add per-port resource support Tariq Toukan
2026-02-26 22:19 ` Tariq Toukan [this message]
2026-02-26 22:19 ` [PATCH net-next V3 02/10] selftest: netdevsim: Add resource dump test Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 03/10] devlink: Add dump to resource documentation Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 04/10] devlink: Refactor resource functions to be generic Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 05/10] devlink: Add port-level resource registration infrastructure Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 06/10] devlink: Add port resource netlink command Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 07/10] net/mlx5: Register SF resource on PF port representor Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 08/10] netdevsim: Add devlink port resource registration Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 09/10] selftest: netdevsim: Add devlink port resource test Tariq Toukan
2026-02-26 22:19 ` [PATCH net-next V3 10/10] devlink: Document port-level resources Tariq Toukan
2026-03-03 3:14 ` Jakub Kicinski
2026-03-04 10:06 ` Jiri Pirko
2026-03-03 3:26 ` [PATCH net-next V3 00/10] devlink: add per-port resource support Jakub Kicinski
2026-03-04 10:05 ` Jiri Pirko
2026-03-04 10:34 ` Jiri Pirko
2026-03-04 18:15 ` Jakub Kicinski
2026-03-05 7:56 ` Jiri Pirko
2026-03-05 14:37 ` Jakub Kicinski
2026-03-06 12:13 ` Jiri Pirko
2026-03-06 20:03 ` Jakub Kicinski
2026-03-08 16:03 ` Or Har-Toov
2026-03-09 20:33 ` Jakub Kicinski
2026-03-11 18:24 ` Or Har-Toov
2026-03-11 21:51 ` Jakub Kicinski
2026-03-12 8:34 ` Jiri Pirko
2026-03-12 14:19 ` Jakub Kicinski
2026-03-12 14:29 ` Jiri Pirko
2026-03-12 14:36 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260226221916.1800227-2-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=jiri@nvidia.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=moshe@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=ohartoov@nvidia.com \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=shayd@nvidia.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox