Skip to content

Commit 1bbdb81

Browse files
cjubrankuba-moo
authored andcommitted
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'} Fixes: 566e8f1 ("devlink: Extend devlink rate API with traffic classes bandwidth management") Reported-by: Arnd Bergmann <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Carolina Jubran <[email protected]> Tested-by: Carolina Jubran <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5661300 commit 1bbdb81

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

Documentation/netlink/specs/devlink.yaml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -853,18 +853,6 @@ attribute-sets:
853853
type: nest
854854
multi-attr: true
855855
nested-attributes: dl-rate-tc-bws
856-
-
857-
name: rate-tc-index
858-
type: u8
859-
checks:
860-
max: rate-tc-index-max
861-
-
862-
name: rate-tc-bw
863-
type: u32
864-
doc: |
865-
Specifies the bandwidth share assigned to the Traffic Class.
866-
The bandwidth for the traffic class is determined
867-
in proportion to the sum of the shares of all configured classes.
868856
-
869857
name: dl-dev-stats
870858
subset-of: devlink
@@ -1271,12 +1259,20 @@ attribute-sets:
12711259
type: flag
12721260
-
12731261
name: dl-rate-tc-bws
1274-
subset-of: devlink
1262+
name-prefix: devlink-rate-tc-attr-
12751263
attributes:
12761264
-
1277-
name: rate-tc-index
1265+
name: index
1266+
type: u8
1267+
checks:
1268+
max: rate-tc-index-max
12781269
-
1279-
name: rate-tc-bw
1270+
name: bw
1271+
type: u32
1272+
doc: |
1273+
Specifies the bandwidth share assigned to the Traffic Class.
1274+
The bandwidth for the traffic class is determined
1275+
in proportion to the sum of the shares of all configured classes.
12801276
12811277
operations:
12821278
enum-model: directional

include/uapi/linux/devlink.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ enum devlink_attr {
635635
DEVLINK_ATTR_REGION_DIRECT, /* flag */
636636

637637
DEVLINK_ATTR_RATE_TC_BWS, /* nested */
638-
DEVLINK_ATTR_RATE_TC_INDEX, /* u8 */
639-
DEVLINK_ATTR_RATE_TC_BW, /* u32 */
640638

641639
/* Add new attributes above here, update the spec in
642640
* Documentation/netlink/specs/devlink.yaml and re-generate
@@ -647,6 +645,15 @@ enum devlink_attr {
647645
DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1
648646
};
649647

648+
enum 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+
650657
/* Mapping between internal resource described by the field and system
651658
* structure
652659
*/

net/devlink/netlink_gen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_
4545
[DEVLINK_PORT_FN_ATTR_CAPS] = NLA_POLICY_BITFIELD32(15),
4646
};
4747

48-
const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_ATTR_RATE_TC_BW + 1] = {
49-
[DEVLINK_ATTR_RATE_TC_INDEX] = NLA_POLICY_MAX(NLA_U8, DEVLINK_RATE_TC_INDEX_MAX),
50-
[DEVLINK_ATTR_RATE_TC_BW] = { .type = NLA_U32, },
48+
const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_ATTR_BW + 1] = {
49+
[DEVLINK_RATE_TC_ATTR_INDEX] = NLA_POLICY_MAX(NLA_U8, DEVLINK_RATE_TC_INDEX_MAX),
50+
[DEVLINK_RATE_TC_ATTR_BW] = { .type = NLA_U32, },
5151
};
5252

5353
const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1] = {

net/devlink/netlink_gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/* Common nested types */
1515
extern const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_CAPS + 1];
16-
extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_ATTR_RATE_TC_BW + 1];
16+
extern const struct nla_policy devlink_dl_rate_tc_bws_nl_policy[DEVLINK_RATE_TC_ATTR_BW + 1];
1717
extern const struct nla_policy devlink_dl_selftest_id_nl_policy[DEVLINK_ATTR_SELFTEST_ID_FLASH + 1];
1818

1919
/* Ops table for devlink */

net/devlink/rate.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ static int devlink_rate_put_tc_bws(struct sk_buff *msg, u32 *tc_bw)
9090
if (!nla_tc_bw)
9191
return -EMSGSIZE;
9292

93-
if (nla_put_u8(msg, DEVLINK_ATTR_RATE_TC_INDEX, i) ||
94-
nla_put_u32(msg, DEVLINK_ATTR_RATE_TC_BW, tc_bw[i]))
93+
if (nla_put_u8(msg, DEVLINK_RATE_TC_ATTR_INDEX, i) ||
94+
nla_put_u32(msg, DEVLINK_RATE_TC_ATTR_BW, tc_bw[i]))
9595
goto nla_put_failure;
9696

9797
nla_nest_end(msg, nla_tc_bw);
@@ -346,26 +346,26 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw,
346346
unsigned long *bitmap,
347347
struct netlink_ext_ack *extack)
348348
{
349-
struct nlattr *tb[DEVLINK_ATTR_MAX + 1];
349+
struct nlattr *tb[DEVLINK_RATE_TC_ATTR_MAX + 1];
350350
u8 tc_index;
351351
int err;
352352

353-
err = nla_parse_nested(tb, DEVLINK_ATTR_MAX, parent_nest,
353+
err = nla_parse_nested(tb, DEVLINK_RATE_TC_ATTR_MAX, parent_nest,
354354
devlink_dl_rate_tc_bws_nl_policy, extack);
355355
if (err)
356356
return err;
357357

358-
if (!tb[DEVLINK_ATTR_RATE_TC_INDEX]) {
358+
if (!tb[DEVLINK_RATE_TC_ATTR_INDEX]) {
359359
NL_SET_ERR_ATTR_MISS(extack, parent_nest,
360-
DEVLINK_ATTR_RATE_TC_INDEX);
360+
DEVLINK_RATE_TC_ATTR_INDEX);
361361
return -EINVAL;
362362
}
363363

364-
tc_index = nla_get_u8(tb[DEVLINK_ATTR_RATE_TC_INDEX]);
364+
tc_index = nla_get_u8(tb[DEVLINK_RATE_TC_ATTR_INDEX]);
365365

366-
if (!tb[DEVLINK_ATTR_RATE_TC_BW]) {
366+
if (!tb[DEVLINK_RATE_TC_ATTR_BW]) {
367367
NL_SET_ERR_ATTR_MISS(extack, parent_nest,
368-
DEVLINK_ATTR_RATE_TC_BW);
368+
DEVLINK_RATE_TC_ATTR_BW);
369369
return -EINVAL;
370370
}
371371

@@ -376,7 +376,7 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw,
376376
return -EINVAL;
377377
}
378378

379-
tc_bw[tc_index] = nla_get_u32(tb[DEVLINK_ATTR_RATE_TC_BW]);
379+
tc_bw[tc_index] = nla_get_u32(tb[DEVLINK_RATE_TC_ATTR_BW]);
380380

381381
return 0;
382382
}

tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ def setup_devlink_rate(cfg):
208208
"port-index": port_index,
209209
"rate-tx-max": 125000000,
210210
"rate-tc-bws": [
211-
{"rate-tc-index": 0, "rate-tc-bw": 0},
212-
{"rate-tc-index": 1, "rate-tc-bw": 0},
213-
{"rate-tc-index": 2, "rate-tc-bw": 0},
214-
{"rate-tc-index": 3, "rate-tc-bw": 20},
215-
{"rate-tc-index": 4, "rate-tc-bw": 80},
216-
{"rate-tc-index": 5, "rate-tc-bw": 0},
217-
{"rate-tc-index": 6, "rate-tc-bw": 0},
218-
{"rate-tc-index": 7, "rate-tc-bw": 0},
211+
{"index": 0, "bw": 0},
212+
{"index": 1, "bw": 0},
213+
{"index": 2, "bw": 0},
214+
{"index": 3, "bw": 20},
215+
{"index": 4, "bw": 80},
216+
{"index": 5, "bw": 0},
217+
{"index": 6, "bw": 0},
218+
{"index": 7, "bw": 0},
219219
]
220220
})
221221
except NlError as exc:

0 commit comments

Comments
 (0)