Commit 2cddd20147826aef283115abb00012d4dafe3cdb

Authored by Ivan Vecera
Committed by David S. Miller
1 parent 3f1bb6abdf

net/sched: cls_flower: allocate mask dynamically in fl_change()

Recent changes (especially 05cd271fd61a ("cls_flower: Support multiple
masks per priority")) in the fl_flow_mask structure grow it and its
current size e.g. on x86_64 with defconfig is 760 bytes and more than
1024 bytes with some debug options enabled. Prior the mentioned commit
its size was 176 bytes (using defconfig on x86_64).
With regard to this fact it's reasonable to allocate this structure
dynamically in fl_change() to reduce its stack size.

v2:
- use kzalloc() instead of kcalloc()

Fixes: 05cd271fd61a ("cls_flower: Support multiple masks per priority")
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: Paul Blakey <paulb@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 14 additions and 5 deletions Side-by-side Diff

net/sched/cls_flower.c
... ... @@ -1290,17 +1290,23 @@
1290 1290 struct cls_fl_head *head = rtnl_dereference(tp->root);
1291 1291 struct cls_fl_filter *fold = *arg;
1292 1292 struct cls_fl_filter *fnew;
  1293 + struct fl_flow_mask *mask;
1293 1294 struct nlattr **tb;
1294   - struct fl_flow_mask mask = {};
1295 1295 int err;
1296 1296  
1297 1297 if (!tca[TCA_OPTIONS])
1298 1298 return -EINVAL;
1299 1299  
1300   - tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
1301   - if (!tb)
  1300 + mask = kzalloc(sizeof(struct fl_flow_mask), GFP_KERNEL);
  1301 + if (!mask)
1302 1302 return -ENOBUFS;
1303 1303  
  1304 + tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
  1305 + if (!tb) {
  1306 + err = -ENOBUFS;
  1307 + goto errout_mask_alloc;
  1308 + }
  1309 +
1304 1310 err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS],
1305 1311 fl_policy, NULL);
1306 1312 if (err < 0)
1307 1313  
... ... @@ -1343,12 +1349,12 @@
1343 1349 }
1344 1350 }
1345 1351  
1346   - err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr,
  1352 + err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], ovr,
1347 1353 tp->chain->tmplt_priv, extack);
1348 1354 if (err)
1349 1355 goto errout_idr;
1350 1356  
1351   - err = fl_check_assign_mask(head, fnew, fold, &mask);
  1357 + err = fl_check_assign_mask(head, fnew, fold, mask);
1352 1358 if (err)
1353 1359 goto errout_idr;
1354 1360  
... ... @@ -1392,6 +1398,7 @@
1392 1398 }
1393 1399  
1394 1400 kfree(tb);
  1401 + kfree(mask);
1395 1402 return 0;
1396 1403  
1397 1404 errout_mask:
... ... @@ -1405,6 +1412,8 @@
1405 1412 kfree(fnew);
1406 1413 errout_tb:
1407 1414 kfree(tb);
  1415 +errout_mask_alloc:
  1416 + kfree(mask);
1408 1417 return err;
1409 1418 }
1410 1419