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: Add resource scope filtering to resource dump

Allow filtering the resource dump to device-level or port-level
resources using the 'scope' option.

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>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260407194107.148063-11-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Or Har-Toov and committed by
Jakub Kicinski
1bc45341 170e160a

+55 -4
+23 -1
Documentation/netlink/specs/devlink.yaml
··· 159 159 name: entry 160 160 - 161 161 type: enum 162 + name: resource-scope 163 + entries: 164 + - 165 + name: dev 166 + - 167 + name: port 168 + - 169 + type: enum 162 170 name: reload-action 163 171 entries: 164 172 - ··· 881 873 doc: Unique devlink instance index. 882 874 checks: 883 875 max: u32-max 876 + - 877 + name: resource-scope-mask 878 + type: u32 879 + enum: resource-scope 880 + enum-as-flags: true 881 + doc: | 882 + Bitmask selecting which resource classes to include in a 883 + resource-dump response. Bit 0 (dev) selects device-level 884 + resources; bit 1 (port) selects port-level resources. 885 + When absent all classes are returned. 884 886 - 885 887 name: dl-dev-stats 886 888 subset-of: devlink ··· 1793 1775 - resource-list 1794 1776 dump: 1795 1777 request: 1796 - attributes: *dev-id-attrs 1778 + attributes: 1779 + - bus-name 1780 + - dev-name 1781 + - index 1782 + - resource-scope-mask 1797 1783 reply: *resource-dump-reply 1798 1784 1799 1785 -
+11
include/uapi/linux/devlink.h
··· 645 645 DEVLINK_ATTR_PARAM_RESET_DEFAULT, /* flag */ 646 646 647 647 DEVLINK_ATTR_INDEX, /* uint */ 648 + DEVLINK_ATTR_RESOURCE_SCOPE_MASK, /* u32 */ 648 649 649 650 /* Add new attributes above here, update the spec in 650 651 * Documentation/netlink/specs/devlink.yaml and re-generate ··· 704 703 enum devlink_resource_unit { 705 704 DEVLINK_RESOURCE_UNIT_ENTRY, 706 705 }; 706 + 707 + enum devlink_resource_scope { 708 + DEVLINK_RESOURCE_SCOPE_DEV_BIT, 709 + DEVLINK_RESOURCE_SCOPE_PORT_BIT, 710 + }; 711 + 712 + #define DEVLINK_RESOURCE_SCOPE_DEV \ 713 + _BITUL(DEVLINK_RESOURCE_SCOPE_DEV_BIT) 714 + #define DEVLINK_RESOURCE_SCOPE_PORT \ 715 + _BITUL(DEVLINK_RESOURCE_SCOPE_PORT_BIT) 707 716 708 717 enum devlink_port_fn_attr_cap { 709 718 DEVLINK_PORT_FN_ATTR_CAP_ROCE_BIT,
+18 -1
net/devlink/resource.c
··· 398 398 struct netlink_callback *cb, int flags) 399 399 { 400 400 struct devlink_nl_dump_state *state = devlink_dump_state(cb); 401 + const struct genl_info *info = genl_info_dump(cb); 401 402 struct devlink_port *devlink_port; 403 + struct nlattr *scope_attr = NULL; 402 404 unsigned long port_idx; 405 + u32 scope = 0; 403 406 int err; 404 407 405 - if (!state->port_ctx.index_valid) { 408 + if (info->attrs && info->attrs[DEVLINK_ATTR_RESOURCE_SCOPE_MASK]) { 409 + scope_attr = info->attrs[DEVLINK_ATTR_RESOURCE_SCOPE_MASK]; 410 + scope = nla_get_u32(scope_attr); 411 + if (!scope) { 412 + NL_SET_ERR_MSG_ATTR(info->extack, scope_attr, 413 + "empty resource scope selection"); 414 + return -EINVAL; 415 + } 416 + } 417 + 418 + if (!state->port_ctx.index_valid && 419 + (!scope || (scope & DEVLINK_RESOURCE_SCOPE_DEV))) { 406 420 err = devlink_resource_dump_fill_one(skb, devlink, NULL, 407 421 cb, flags, &state->idx); 408 422 if (err) ··· 424 410 state->idx = 0; 425 411 } 426 412 413 + if (scope && !(scope & DEVLINK_RESOURCE_SCOPE_PORT)) 414 + goto out; 427 415 /* Check in case port was removed between dump callbacks. */ 428 416 if (state->port_ctx.index_valid && 429 417 !xa_load(&devlink->ports, state->port_ctx.index)) ··· 441 425 } 442 426 state->idx = 0; 443 427 } 428 + out: 444 429 state->port_ctx.index_valid = false; 445 430 state->port_ctx.index = 0; 446 431 return 0;