Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

devlink: Include port resources in resource dump dumpit

Allow querying devlink resources per-port via the resource-dump dumpit
handler. Both device-level and all ports resources are included in the
reply.

For example:

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

Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260407194107.148063-7-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Or Har-Toov and committed by
Jakub Kicinski
810b7639 11636b55

+58 -8
+5
net/devlink/devl_internal.h
··· 164 164 struct { 165 165 u64 dump_ts; 166 166 }; 167 + /* DEVLINK_CMD_RESOURCE_DUMP */ 168 + struct { 169 + u32 index; 170 + bool index_valid; 171 + } port_ctx; 167 172 }; 168 173 }; 169 174
+2
net/devlink/netlink.c
··· 370 370 371 371 /* restart sub-object walk for the next instance */ 372 372 state->idx = 0; 373 + state->port_ctx.index = 0; 374 + state->port_ctx.index_valid = false; 373 375 } 374 376 375 377 if (err != -EMSGSIZE)
+51 -8
net/devlink/resource.c
··· 328 328 } 329 329 330 330 static int 331 - devlink_nl_resource_dump_one(struct sk_buff *skb, struct devlink *devlink, 332 - struct netlink_callback *cb, int flags) 331 + devlink_resource_dump_fill_one(struct sk_buff *skb, struct devlink *devlink, 332 + struct devlink_port *devlink_port, 333 + struct netlink_callback *cb, int flags, int *idx) 333 334 { 334 - struct devlink_nl_dump_state *state = devlink_dump_state(cb); 335 + struct list_head *resource_list; 335 336 struct nlattr *resources_attr; 336 - int start_idx = state->idx; 337 + int start_idx = *idx; 337 338 void *hdr; 338 339 int err; 339 340 340 - if (list_empty(&devlink->resource_list)) 341 + resource_list = devlink_port ? 342 + &devlink_port->resource_list : &devlink->resource_list; 343 + 344 + if (list_empty(resource_list)) 341 345 return 0; 342 346 343 347 err = -EMSGSIZE; ··· 352 348 353 349 if (devlink_nl_put_handle(skb, devlink)) 354 350 goto nla_put_failure; 351 + if (devlink_port && 352 + nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX, devlink_port->index)) 353 + goto nla_put_failure; 355 354 356 355 resources_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_RESOURCE_LIST); 357 356 if (!resources_attr) 358 357 goto nla_put_failure; 359 358 360 - err = devlink_resource_list_fill(skb, devlink, 361 - &devlink->resource_list, &state->idx); 359 + err = devlink_resource_list_fill(skb, devlink, resource_list, idx); 362 360 if (err) { 363 - if (state->idx == start_idx) 361 + if (*idx == start_idx) 364 362 goto resource_list_cancel; 365 363 nla_nest_end(skb, resources_attr); 366 364 genlmsg_end(skb, hdr); ··· 377 371 nla_put_failure: 378 372 genlmsg_cancel(skb, hdr); 379 373 return err; 374 + } 375 + 376 + static int 377 + devlink_nl_resource_dump_one(struct sk_buff *skb, struct devlink *devlink, 378 + struct netlink_callback *cb, int flags) 379 + { 380 + struct devlink_nl_dump_state *state = devlink_dump_state(cb); 381 + struct devlink_port *devlink_port; 382 + unsigned long port_idx; 383 + int err; 384 + 385 + if (!state->port_ctx.index_valid) { 386 + err = devlink_resource_dump_fill_one(skb, devlink, NULL, 387 + cb, flags, &state->idx); 388 + if (err) 389 + return err; 390 + state->idx = 0; 391 + } 392 + 393 + /* Check in case port was removed between dump callbacks. */ 394 + if (state->port_ctx.index_valid && 395 + !xa_load(&devlink->ports, state->port_ctx.index)) 396 + state->idx = 0; 397 + state->port_ctx.index_valid = true; 398 + xa_for_each_start(&devlink->ports, port_idx, devlink_port, 399 + state->port_ctx.index) { 400 + err = devlink_resource_dump_fill_one(skb, devlink, devlink_port, 401 + cb, flags, &state->idx); 402 + if (err) { 403 + state->port_ctx.index = port_idx; 404 + return err; 405 + } 406 + state->idx = 0; 407 + } 408 + state->port_ctx.index_valid = false; 409 + state->port_ctx.index = 0; 410 + return 0; 380 411 } 381 412 382 413 int devlink_nl_resource_dump_dumpit(struct sk_buff *skb,