devlink: move DEVLINK_ATTR_MAX-sized array off stack
Subsystems (4)
PATCH v2 1/1 devlink: move DEVLINK_ATTR_MAX-sized array off stack
From: Arnd Bergmann <[email protected]>
There are many possible devlink attributes, so having an array of them on the stack can cause a warning for 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=]
Change this to dynamic allocation instead.
---
I see that only two of the many array entries are actually used in this
function: DEVLINK_ATTR_RATE_TC_INDEX and DEVLINK_ATTR_RATE_TC_BW. If there is an interface to extract just a single entry, using that would be a little easier than the kcalloc().
v2: use __free() helper to simplify cleanup
--- net/devlink/rate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/devlink/rate.c +5 -1
@@ -346,10 +346,14 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw,unsigned long *bitmap, struct netlink_ext_ack *extack) { - struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr **tb __free(kfree) = NULL;u8 tc_index;int err; + tb =kcalloc (DEVLINK_ATTR_MAX +1 ,sizeof (struct nlattr *),GFP_KERNEL ); +if (!tb) +return -ENOMEM ; + err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , parent_nest, devlink_dl_rate_tc_bws_nl_policy, extack);if (err)
Signature · 1 line
2.39.5
Jakub Kicinski
maintainerReview
Quoted 2 lines · On Wed, 9 Jul 2025 16:59:00 +0200 Arnd Bergmann wrote:
(quoted diff) +1
-1- struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr **tb __free(kfree) = NULL;
Ugh, now you triggered me.
Review
Quoted 6 lines
(quoted diff) +3
-0u8 tc_index; int err; + tb = kcalloc(DEVLINK_ATTR_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL); + if (!tb) + return -ENOMEM;
Cramming all the attributes in a single space is silly, it's better for devlink to grow up :/ Carolina could you test this?
Documentation/netlink/specs/devlink.yaml +9 -13
@@ -853,18 +853,6 @@ doc: Partial family for Devlink. type: nest multi-attr: true nested-attributes: dl-rate-tc-bws - - - name: rate-tc-index - type: u8 - checks: - max: rate-tc-index-max - - - name: rate-tc-bw - type: u32 - doc: | - Specifies the bandwidth share assigned to the Traffic Class. - The bandwidth for the traffic class is determined - in proportion to the sum of the shares of all configured classes. - name: dl-dev-stats subset-of: devlink
@@ -1271,12 +1259,20 @@ doc: Partial family for Devlink. type: flag - name: dl-rate-tc-bws - subset-of: devlink + name-prefix: devlink-attr- attributes: - name: rate-tc-index + type: u8 + checks: + max: rate-tc-index-max - name: rate-tc-bw + type: u32 + doc: | + Specifies the bandwidth share assigned to the Traffic Class. + The bandwidth for the traffic class is determined + in proportion to the sum of the shares of all configured classes. operations: enum-model: directional
include/uapi/linux/devlink.h +8 -2
@@ -635,8 +635,6 @@ enum devlink_attr {DEVLINK_ATTR_REGION_DIRECT ,/* flag */ DEVLINK_ATTR_RATE_TC_BWS, /* nested */ -DEVLINK_ATTR_RATE_TC_INDEX ,/* u8 */ -DEVLINK_ATTR_RATE_TC_BW ,/* u32 */ /* Add new attributes above here, update the spec in * Documentation/netlink/specs/devlink.yaml and re-generate
@@ -647,6 +645,14 @@ enum devlink_attr { DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1 }; +enum { +DEVLINK_ATTR_RATE_TC_INDEX =1 ,/* u8 */ +DEVLINK_ATTR_RATE_TC_BW ,/* u32 */ + + __DEVLINK_ATTR_RATE_TC_MAX, +DEVLINK_ATTR_RATE_TC_MAX = __DEVLINK_ATTR_RATE_TC_MAX -1 +}; +/* Mapping between internal resource described by the field and system * structure */
net/devlink/rate.c +2 -2
@@ -346,11 +346,11 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw,unsigned long *bitmap, struct netlink_ext_ack *extack) { - struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr *tb[DEVLINK_ATTR_RATE_TC_MAX + 1];u8 tc_index;int err; - err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , parent_nest, + err =nla_parse_nested (tb,DEVLINK_ATTR_RATE_TC_MAX , parent_nest, devlink_dl_rate_tc_bws_nl_policy, extack);if (err)return err;
Quoted 9 lines · Jakub Kicinski
Review
Quoted 2 lines · On Wed, 9 Jul 2025 16:59:00 +0200 Arnd Bergmann wrote:
(quoted diff) +1
-1- struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr **tb __free(kfree) = NULL;Ugh, now you triggered me.
Quoted 3 lines
u8
tc_index;
int err;
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ tb = kcalloc(DEVLINK_ATTR_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL); + if (!tb) + return -ENOMEM;Cramming all the attributes in a single space is silly, it's better for devlink to grow up :/ Carolina could you test this?
Sure, testing it. Will update.
Thanks!
Quoted 91 lines
Documentation/netlink/specs/devlink.yaml +9
-13@@ -853,18 +853,6 @@ doc: Partial family for Devlink. type: nest multi-attr: true nested-attributes: dl-rate-tc-bws - - - name: rate-tc-index - type: u8 - checks: - max: rate-tc-index-max - - - name: rate-tc-bw - type: u32 - doc: | - Specifies the bandwidth share assigned to the Traffic Class. - The bandwidth for the traffic class is determined - in proportion to the sum of the shares of all configured classes. - name: dl-dev-stats subset-of: devlink@@ -1271,12 +1259,20 @@ doc: Partial family for Devlink. type: flag - name: dl-rate-tc-bws - subset-of: devlink + name-prefix: devlink-attr- attributes: - name: rate-tc-index + type: u8 + checks: + max: rate-tc-index-max - name: rate-tc-bw + type: u32 + doc: | + Specifies the bandwidth share assigned to the Traffic Class. + The bandwidth for the traffic class is determined + in proportion to the sum of the shares of all configured classes. operations: enum-model: directionalinclude/uapi/linux/devlink.h +8
-2@@ -635,8 +635,6 @@ enum devlink_attr {DEVLINK_ATTR_REGION_DIRECT ,/* flag */ DEVLINK_ATTR_RATE_TC_BWS, /* nested */ -DEVLINK_ATTR_RATE_TC_INDEX ,/* u8 */ -DEVLINK_ATTR_RATE_TC_BW ,/* u32 */ /* Add new attributes above here, update the spec in * Documentation/netlink/specs/devlink.yaml and re-generate @@ -647,6 +645,14 @@ enum devlink_attr { DEVLINK_ATTR_MAX = __DEVLINK_ATTR_MAX - 1 }; +enum { +DEVLINK_ATTR_RATE_TC_INDEX =1 ,/* u8 */ +DEVLINK_ATTR_RATE_TC_BW ,/* u32 */ + + __DEVLINK_ATTR_RATE_TC_MAX, +DEVLINK_ATTR_RATE_TC_MAX = __DEVLINK_ATTR_RATE_TC_MAX -1 +}; +/* Mapping between internal resource described by the field and system * structure */ net/devlink/rate.c +2
-2@@ -346,11 +346,11 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw,unsigned long *bitmap, struct netlink_ext_ack *extack) { - struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr *tb[DEVLINK_ATTR_RATE_TC_MAX + 1];u8 tc_index;int err; - err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , parent_nest, + err =nla_parse_nested (tb,DEVLINK_ATTR_RATE_TC_MAX , parent_nest, devlink_dl_rate_tc_bws_nl_policy, extack);if (err)return err;
Quoted 16 lines · Carolina Jubran
Quoted 13 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 9 Jul 2025 16:59:00 +0200 Arnd Bergmann wrote:
- struct nlattr *tb[DEVLINK_ATTR_MAX + 1];
+ struct nlattr **tb__free(kfree)= NULL;Ugh, now you triggered me.
Quoted 6 lines
u8
tc_index;
int err;
+ tb =kcalloc(DEVLINK_ATTR_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
+ if (!tb)
+ return-ENOMEM;
Quoted 7 lines
Quoted 3 lines
Cramming all the attributes in a single space is silly, it's better for devlink to grow up :/ Carolina could you test this?
Sure, testing it. Will update.
Thanks!
I have tested and it looks good. Thanks!
Quoted 23 lines
Quoted 23 lines
Documentation/netlink/specs/devlink.yaml +0
-0@@ -853,18 +853,6 @@ doc: Partial family for Devlink.type: nest
multi-attr: true
nested-attributes: dl-rate-tc-bws
- -
- name: rate-tc-index
- type: u8
- checks:
- max: rate-tc-index-max
- -
- name: rate-tc-bw
- type: u32
- doc: |
- Specifies the bandwidth share assigned to the Traffic Class.
- The bandwidth for the traffic class is determined - in proportion to the sum of the shares of all configured classes.
-
Quoted 8 lines
Quoted 8 lines
name: dl-dev-stats
subset-of: devlinkDocumentation/netlink/specs/devlink.yaml +0
-0@@ -1271,12 +1259,20 @@ doc: Partial family for Devlink.type: flag
-
name: dl-rate-tc-bws
- subset-of: devlink
+ name-prefix: devlink-attr-
Maybe use name-prefix: devlink-attr-rate-tc- instead?
Quoted 61 lines
Quoted 60 lines
attributes:
-
name: rate-tc-index
+ type: u8
+ checks:
+ max: rate-tc-index-max
-
name: rate-tc-bw
+ type: u32
+ doc: |
+ Specifies the bandwidth share assigned to the Traffic Class.
+ The bandwidth for the traffic class is determined + in proportion to the sum of the shares of all configured classes.
operations:
enum-model: directionalinclude/uapi/linux/devlink.h +0
-0@@ -635,8 +635,6 @@ enum devlink_attr {DEVLINK_ATTR_REGION_DIRECT, /* flag */ DEVLINK_ATTR_RATE_TC_BWS, /* nested */
- DEVLINK_ATTR_RATE_TC_INDEX, /* u8 */
- DEVLINK_ATTR_RATE_TC_BW, /* u32 */
/* Add new attributes above here, update the spec in
*Documentation/netlink/specs/devlink.yamland re-generateinclude/uapi/linux/devlink.h +0
-0@@ -647,6 +645,14 @@ enum devlink_attr {
DEVLINK_ATTR_MAX=__DEVLINK_ATTR_MAX- 1
};include/uapi/linux/devlink.h +8
-0+enum { + DEVLINK_ATTR_RATE_TC_INDEX = 1, /* u8 */ + DEVLINK_ATTR_RATE_TC_BW, /* u32 */ + + __DEVLINK_ATTR_RATE_TC_MAX, + DEVLINK_ATTR_RATE_TC_MAX = __DEVLINK_ATTR_RATE_TC_MAX - 1 +}; +/* Mapping between internal resource described by the field and system
* structure
*/net/devlink/rate.c +2
-2@@ -346,11 +346,11 @@ static int devlink_nl_rate_tc_bw_parse(struct nlattr *parent_nest, u32 *tc_bw, unsigned long *bitmap, struct netlink_ext_ack *extack) { - struct nlattr *tb[DEVLINK_ATTR_MAX + 1]; + struct nlattr *tb[DEVLINK_ATTR_RATE_TC_MAX + 1]; u8 tc_index; int err; - err = nla_parse_nested(tb, DEVLINK_ATTR_MAX, parent_nest, + err = nla_parse_nested(tb, DEVLINK_ATTR_RATE_TC_MAX, parent_nest, devlink_dl_rate_tc_bws_nl_policy, extack); if (err) return err;
Jakub Kicinski
maintainerQuoted 3 lines · On Sun, 13 Jul 2025 15:28:11 +0300 Carolina Jubran wrote:
Quoted 1 line
Sure, testing it. Will update.
I have tested and it looks good. Thanks!
Awesome, would you be willing to post the official patch? Add my as "suggested-by" and with my sign off. Most of the work here was the testing :)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/ renamed from Documentation/netlink/specs/devlink.yaml +0
-0
netlink/specs/devlink.yaml
index1c4bb0cbe5f0..3d75bc530b30100644Documentation/netlink/specs/devlink.yaml +0
-0
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Documentation/netlink/specs/devlink.yaml +0
-0@@ -1271,12 +1259,20 @@ doc: Partial family for Devlink.type: flag
-
name: dl-rate-tc-bws
- subset-of: devlink
+ name-prefix: devlink-attr-Maybe use name-prefix: devlink-attr-rate-tc- instead?
Sounds good!
Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Sun, 13 Jul 2025 15:28:11 +0300 Carolina Jubran wrote:
Quoted 1 line
Sure, testing it. Will update.
I have tested and it looks good. Thanks!
Awesome, would you be willing to post the official patch? Add my as "suggested-by" and with my sign off. Most of the work here was the testing :)
Sure, I will post it soon.
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/ renamed from Documentation/netlink/specs/devlink.yaml +0
-0
netlink/specs/devlink.yaml
index1c4bb0cbe5f0..3d75bc530b30100644Documentation/netlink/specs/devlink.yaml +0
-0Quoted 8 lines
Quoted 6 lines
Documentation/netlink/specs/devlink.yaml doc: Partial family for Devlink. · line 1262
Quoted 6 lines
Documentation/netlink/specs/devlink.yaml +1
-1@@ -1271,12 +1259,20 @@ doc: Partial family for Devlink. type: flag - name: dl-rate-tc-bws - subset-of: devlink + name-prefix: devlink-attr-Maybe use name-prefix: devlink-attr-rate-tc- instead?
Sounds good!