History

devlink: Fix excessive stack usage in rate TC bandwidth parsing

The devlink_nl_rate_tc_bw_parse function uses a large stack array for devlink attributes, which triggers a warning about excessive stack usage: net/devlink/rate.c: In function 'devlink_nl_rate_tc_bw_parse': net/devlink/rate.c:382:1: error: the frame size of 1648 bytes is larger than 1536 bytes [-Werror=frame-larger-than=] Introduce a separate attribute set specifically for rate TC bandwidth parsing that only contains the two attributes actually used: index and bandwidth. This reduces the stack array from DEVLINK_ATTR_MAX entries to just 2 entries, solving the stack usage issue. Update devlink selftest to use the new 'index' and 'bw' attribute names consistent with the YAML spec. Example usage with ynl with the new spec: ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \ --do rate-set --json '{ "bus-name": "pci", "dev-name": "0000:08:00.0", "port-index": 1, "rate-tc-bws": [ {"index": 0, "bw": 50}, {"index": 1, "bw": 50}, {"index": 2, "bw": 0}, {"index": 3, "bw": 0}, {"index": 4, "bw": 0}, {"index": 5, "bw": 0}, {"index": 6, "bw": 0}, {"index": 7, "bw": 0} ] }' ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \ --do rate-get --json '{ "bus-name": "pci", "dev-name": "0000:08:00.0", "port-index": 1 }' output for rate-get: {'bus-name': 'pci', 'dev-name': '0000:08:00.0', 'port-index': 1, 'rate-tc-bws': [{'bw': 50, 'index': 0}, {'bw': 50, 'index': 1}, {'bw': 0, 'index': 2}, {'bw': 0, 'index': 3}, {'bw': 0, 'index': 4}, {'bw': 0, 'index': 5}, {'bw': 0, 'index': 6}, {'bw': 0, 'index': 7}], 'rate-tx-max': 0, 'rate-tx-priority': 0, 'rate-tx-share': 0, 'rate-tx-weight': 0, 'rate-type': 'leaf'}

Carolina Jubran committed 1 year ago

Commit 1bbdb811 parent 56613006 files · +42 −39Browse files

Showing the changes to include/uapi (1 of 6 files). Show all

Unified · Split

include/uapi/linux/devlink.h+9−2
@@ -635,8 +635,6 @@ enum devlink_attr { · 634 unmodified lines
635 DEVLINK_ATTR_REGION_DIRECT, /* flag */635 DEVLINK_ATTR_REGION_DIRECT, /* flag */
636 636
637 DEVLINK_ATTR_RATE_TC_BWS, /* nested */637 DEVLINK_ATTR_RATE_TC_BWS, /* nested */
638 DEVLINK_ATTR_RATE_TC_INDEX, /* u8 */
639 DEVLINK_ATTR_RATE_TC_BW, /* u32 */
640 638
641 /* Add new attributes above here, update the spec in639 /* Add new attributes above here, update the spec in
642 * Documentation/netlink/specs/devlink.yaml and re-generate640 * Documentation/netlink/specs/devlink.yaml and re-generate
@@ -647,6 +645,15 @@ enum devlink_attr { · 4 unmodified lines
647 DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1645 DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1
648};646};
649 647
648enum devlink_rate_tc_attr {
649 DEVLINK_RATE_TC_ATTR_UNSPEC,
650 DEVLINK_RATE_TC_ATTR_INDEX, /* u8 */
651 DEVLINK_RATE_TC_ATTR_BW, /* u32 */
652
653 __DEVLINK_RATE_TC_ATTR_MAX,
654 DEVLINK_RATE_TC_ATTR_MAX = __DEVLINK_RATE_TC_ATTR_MAX - 1
655};
656
650/* Mapping between internal resource described by the field and system657/* Mapping between internal resource described by the field and system
651 * structure658 * structure
652 */659 */