forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/net/sched/cls_u32.c
....@@ -1,10 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/sched/cls_u32.c Ugly (or Universal) 32bit key Packet Classifier.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version
7
- * 2 of the License, or (at your option) any later version.
84 *
95 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
106 *
....@@ -23,9 +19,6 @@
2319 * It is especially useful for link sharing combined with QoS;
2420 * pure RSVP doesn't need such a general approach and can use
2521 * much simpler (and faster) schemes, sort of cls_rsvp.c.
26
- *
27
- * JHS: We should remove the CONFIG_NET_CLS_IND from here
28
- * eventually when the meta match extension is made available
2922 *
3023 * nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
3124 */
....@@ -52,9 +45,7 @@
5245 u32 handle;
5346 struct tc_u_hnode __rcu *ht_up;
5447 struct tcf_exts exts;
55
-#ifdef CONFIG_NET_CLS_IND
5648 int ifindex;
57
-#endif
5849 u8 fshift;
5950 struct tcf_result res;
6051 struct tc_u_hnode __rcu *ht_down;
....@@ -68,7 +59,6 @@
6859 u32 mask;
6960 u32 __percpu *pcpu_success;
7061 #endif
71
- struct tcf_proto *tp;
7262 struct rcu_work rwork;
7363 /* The 'sel' field MUST be the last field in structure to allow for
7464 * tc_u32_keys allocated at end of structure.
....@@ -80,16 +70,16 @@
8070 struct tc_u_hnode __rcu *next;
8171 u32 handle;
8272 u32 prio;
83
- struct tc_u_common *tp_c;
8473 int refcnt;
8574 unsigned int divisor;
8675 struct idr handle_idr;
76
+ bool is_root;
8777 struct rcu_head rcu;
8878 u32 flags;
8979 /* The 'ht' field MUST be the last field in structure to allow for
9080 * more entries allocated at end of structure.
9181 */
92
- struct tc_u_knode __rcu *ht[1];
82
+ struct tc_u_knode __rcu *ht[];
9383 };
9484
9585 struct tc_u_common {
....@@ -98,7 +88,7 @@
9888 int refcnt;
9989 struct idr handle_idr;
10090 struct hlist_node hnode;
101
- struct rcu_head rcu;
91
+ long knodes;
10292 };
10393
10494 static inline unsigned int u32_hash_fold(__be32 key,
....@@ -181,12 +171,10 @@
181171 if (n->sel.flags & TC_U32_TERMINAL) {
182172
183173 *res = n->res;
184
-#ifdef CONFIG_NET_CLS_IND
185174 if (!tcf_match_indev(skb, n->ifindex)) {
186175 n = rcu_dereference_bh(n->next);
187176 goto next_knode;
188177 }
189
-#endif
190178 #ifdef CONFIG_CLS_U32_PERF
191179 __this_cpu_inc(n->pf->rhit);
192180 #endif
....@@ -344,19 +332,16 @@
344332 return block->q;
345333 }
346334
347
-static unsigned int tc_u_hash(const struct tcf_proto *tp)
335
+static struct hlist_head *tc_u_hash(void *key)
348336 {
349
- return hash_ptr(tc_u_common_ptr(tp), U32_HASH_SHIFT);
337
+ return tc_u_common_hash + hash_ptr(key, U32_HASH_SHIFT);
350338 }
351339
352
-static struct tc_u_common *tc_u_common_find(const struct tcf_proto *tp)
340
+static struct tc_u_common *tc_u_common_find(void *key)
353341 {
354342 struct tc_u_common *tc;
355
- unsigned int h;
356
-
357
- h = tc_u_hash(tp);
358
- hlist_for_each_entry(tc, &tc_u_common_hash[h], hnode) {
359
- if (tc->ptr == tc_u_common_ptr(tp))
343
+ hlist_for_each_entry(tc, tc_u_hash(key), hnode) {
344
+ if (tc->ptr == key)
360345 return tc;
361346 }
362347 return NULL;
....@@ -365,38 +350,35 @@
365350 static int u32_init(struct tcf_proto *tp)
366351 {
367352 struct tc_u_hnode *root_ht;
368
- struct tc_u_common *tp_c;
369
- unsigned int h;
353
+ void *key = tc_u_common_ptr(tp);
354
+ struct tc_u_common *tp_c = tc_u_common_find(key);
370355
371
- tp_c = tc_u_common_find(tp);
372
-
373
- root_ht = kzalloc(sizeof(*root_ht), GFP_KERNEL);
356
+ root_ht = kzalloc(struct_size(root_ht, ht, 1), GFP_KERNEL);
374357 if (root_ht == NULL)
375358 return -ENOBUFS;
376359
377360 root_ht->refcnt++;
378361 root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : 0x80000000;
379362 root_ht->prio = tp->prio;
363
+ root_ht->is_root = true;
380364 idr_init(&root_ht->handle_idr);
381365
382366 if (tp_c == NULL) {
383
- tp_c = kzalloc(sizeof(*tp_c), GFP_KERNEL);
367
+ tp_c = kzalloc(struct_size(tp_c, hlist->ht, 1), GFP_KERNEL);
384368 if (tp_c == NULL) {
385369 kfree(root_ht);
386370 return -ENOBUFS;
387371 }
388
- tp_c->ptr = tc_u_common_ptr(tp);
372
+ tp_c->ptr = key;
389373 INIT_HLIST_NODE(&tp_c->hnode);
390374 idr_init(&tp_c->handle_idr);
391375
392
- h = tc_u_hash(tp);
393
- hlist_add_head(&tp_c->hnode, &tc_u_common_hash[h]);
376
+ hlist_add_head(&tp_c->hnode, tc_u_hash(key));
394377 }
395378
396379 tp_c->refcnt++;
397380 RCU_INIT_POINTER(root_ht->next, tp_c->hlist);
398381 rcu_assign_pointer(tp_c->hlist, root_ht);
399
- root_ht->tp_c = tp_c;
400382
401383 root_ht->refcnt++;
402384 rcu_assign_pointer(tp->root, root_ht);
....@@ -404,15 +386,19 @@
404386 return 0;
405387 }
406388
407
-static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n,
408
- bool free_pf)
389
+static void __u32_destroy_key(struct tc_u_knode *n)
409390 {
410391 struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
411392
412393 tcf_exts_destroy(&n->exts);
413
- tcf_exts_put_net(&n->exts);
414394 if (ht && --ht->refcnt == 0)
415395 kfree(ht);
396
+ kfree(n);
397
+}
398
+
399
+static void u32_destroy_key(struct tc_u_knode *n, bool free_pf)
400
+{
401
+ tcf_exts_put_net(&n->exts);
416402 #ifdef CONFIG_CLS_U32_PERF
417403 if (free_pf)
418404 free_percpu(n->pf);
....@@ -421,8 +407,7 @@
421407 if (free_pf)
422408 free_percpu(n->pcpu_success);
423409 #endif
424
- kfree(n);
425
- return 0;
410
+ __u32_destroy_key(n);
426411 }
427412
428413 /* u32_delete_key_rcu should be called when free'ing a copied
....@@ -439,7 +424,7 @@
439424 struct tc_u_knode,
440425 rwork);
441426 rtnl_lock();
442
- u32_destroy_key(key->tp, key, false);
427
+ u32_destroy_key(key, false);
443428 rtnl_unlock();
444429 }
445430
....@@ -456,12 +441,13 @@
456441 struct tc_u_knode,
457442 rwork);
458443 rtnl_lock();
459
- u32_destroy_key(key->tp, key, true);
444
+ u32_destroy_key(key, true);
460445 rtnl_unlock();
461446 }
462447
463448 static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)
464449 {
450
+ struct tc_u_common *tp_c = tp->data;
465451 struct tc_u_knode __rcu **kp;
466452 struct tc_u_knode *pkp;
467453 struct tc_u_hnode *ht = rtnl_dereference(key->ht_up);
....@@ -472,6 +458,7 @@
472458 kp = &pkp->next, pkp = rtnl_dereference(*kp)) {
473459 if (pkp == key) {
474460 RCU_INIT_POINTER(*kp, key->next);
461
+ tp_c->knodes--;
475462
476463 tcf_unbind_filter(tp, &key->res);
477464 idr_remove(&ht->handle_idr, key->handle);
....@@ -497,7 +484,7 @@
497484 cls_u32.hnode.handle = h->handle;
498485 cls_u32.hnode.prio = h->prio;
499486
500
- tc_setup_cb_call(block, NULL, TC_SETUP_CLSU32, &cls_u32, false);
487
+ tc_setup_cb_call(block, TC_SETUP_CLSU32, &cls_u32, false, true);
501488 }
502489
503490 static int u32_replace_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h,
....@@ -515,7 +502,7 @@
515502 cls_u32.hnode.handle = h->handle;
516503 cls_u32.hnode.prio = h->prio;
517504
518
- err = tc_setup_cb_call(block, NULL, TC_SETUP_CLSU32, &cls_u32, skip_sw);
505
+ err = tc_setup_cb_call(block, TC_SETUP_CLSU32, &cls_u32, skip_sw, true);
519506 if (err < 0) {
520507 u32_clear_hw_hnode(tp, h, NULL);
521508 return err;
....@@ -539,8 +526,8 @@
539526 cls_u32.command = TC_CLSU32_DELETE_KNODE;
540527 cls_u32.knode.handle = n->handle;
541528
542
- tc_setup_cb_call(block, NULL, TC_SETUP_CLSU32, &cls_u32, false);
543
- tcf_block_offload_dec(block, &n->flags);
529
+ tc_setup_cb_destroy(block, tp, TC_SETUP_CLSU32, &cls_u32, false,
530
+ &n->flags, &n->in_hw_count, true);
544531 }
545532
546533 static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
....@@ -564,17 +551,16 @@
564551 cls_u32.knode.mask = 0;
565552 #endif
566553 cls_u32.knode.sel = &n->sel;
554
+ cls_u32.knode.res = &n->res;
567555 cls_u32.knode.exts = &n->exts;
568556 if (n->ht_down)
569557 cls_u32.knode.link_handle = ht->handle;
570558
571
- err = tc_setup_cb_call(block, NULL, TC_SETUP_CLSU32, &cls_u32, skip_sw);
572
- if (err < 0) {
559
+ err = tc_setup_cb_add(block, tp, TC_SETUP_CLSU32, &cls_u32, skip_sw,
560
+ &n->flags, &n->in_hw_count, true);
561
+ if (err) {
573562 u32_remove_hw_knode(tp, n, NULL);
574563 return err;
575
- } else if (err > 0) {
576
- n->in_hw_count = err;
577
- tcf_block_offload_inc(block, &n->flags);
578564 }
579565
580566 if (skip_sw && !(n->flags & TCA_CLS_FLAGS_IN_HW))
....@@ -586,6 +572,7 @@
586572 static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht,
587573 struct netlink_ext_ack *extack)
588574 {
575
+ struct tc_u_common *tp_c = tp->data;
589576 struct tc_u_knode *n;
590577 unsigned int h;
591578
....@@ -593,13 +580,14 @@
593580 while ((n = rtnl_dereference(ht->ht[h])) != NULL) {
594581 RCU_INIT_POINTER(ht->ht[h],
595582 rtnl_dereference(n->next));
583
+ tp_c->knodes--;
596584 tcf_unbind_filter(tp, &n->res);
597585 u32_remove_hw_knode(tp, n, extack);
598586 idr_remove(&ht->handle_idr, n->handle);
599587 if (tcf_exts_get_net(&n->exts))
600588 tcf_queue_work(&n->rwork, u32_delete_key_freepf_work);
601589 else
602
- u32_destroy_key(n->tp, n, true);
590
+ u32_destroy_key(n, true);
603591 }
604592 }
605593 }
....@@ -632,18 +620,8 @@
632620 return -ENOENT;
633621 }
634622
635
-static bool ht_empty(struct tc_u_hnode *ht)
636
-{
637
- unsigned int h;
638
-
639
- for (h = 0; h <= ht->divisor; h++)
640
- if (rcu_access_pointer(ht->ht[h]))
641
- return false;
642
-
643
- return true;
644
-}
645
-
646
-static void u32_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack)
623
+static void u32_destroy(struct tcf_proto *tp, bool rtnl_held,
624
+ struct netlink_ext_ack *extack)
647625 {
648626 struct tc_u_common *tp_c = tp->data;
649627 struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
....@@ -677,15 +655,11 @@
677655 }
678656
679657 static int u32_delete(struct tcf_proto *tp, void *arg, bool *last,
680
- struct netlink_ext_ack *extack)
658
+ bool rtnl_held, struct netlink_ext_ack *extack)
681659 {
682660 struct tc_u_hnode *ht = arg;
683
- struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
684661 struct tc_u_common *tp_c = tp->data;
685662 int ret = 0;
686
-
687
- if (ht == NULL)
688
- goto out;
689663
690664 if (TC_U32_KEY(ht->handle)) {
691665 u32_remove_hw_knode(tp, (struct tc_u_knode *)ht, extack);
....@@ -693,7 +667,7 @@
693667 goto out;
694668 }
695669
696
- if (root_ht == ht) {
670
+ if (ht->is_root) {
697671 NL_SET_ERR_MSG_MOD(extack, "Not allowed to delete root node");
698672 return -EINVAL;
699673 }
....@@ -706,38 +680,7 @@
706680 }
707681
708682 out:
709
- *last = true;
710
- if (root_ht) {
711
- if (root_ht->refcnt > 2) {
712
- *last = false;
713
- goto ret;
714
- }
715
- if (root_ht->refcnt == 2) {
716
- if (!ht_empty(root_ht)) {
717
- *last = false;
718
- goto ret;
719
- }
720
- }
721
- }
722
-
723
- if (tp_c->refcnt > 1) {
724
- *last = false;
725
- goto ret;
726
- }
727
-
728
- if (tp_c->refcnt == 1) {
729
- struct tc_u_hnode *ht;
730
-
731
- for (ht = rtnl_dereference(tp_c->hlist);
732
- ht;
733
- ht = rtnl_dereference(ht->next))
734
- if (!ht_empty(ht)) {
735
- *last = false;
736
- break;
737
- }
738
- }
739
-
740
-ret:
683
+ *last = tp_c->refcnt == 1 && tp_c->knodes == 0;
741684 return ret;
742685 }
743686
....@@ -768,14 +711,14 @@
768711 };
769712
770713 static int u32_set_parms(struct net *net, struct tcf_proto *tp,
771
- unsigned long base, struct tc_u_hnode *ht,
714
+ unsigned long base,
772715 struct tc_u_knode *n, struct nlattr **tb,
773716 struct nlattr *est, bool ovr,
774717 struct netlink_ext_ack *extack)
775718 {
776719 int err;
777720
778
- err = tcf_exts_validate(net, tp, tb, est, &n->exts, ovr, extack);
721
+ err = tcf_exts_validate(net, tp, tb, est, &n->exts, ovr, true, extack);
779722 if (err < 0)
780723 return err;
781724
....@@ -789,10 +732,14 @@
789732 }
790733
791734 if (handle) {
792
- ht_down = u32_lookup_ht(ht->tp_c, handle);
735
+ ht_down = u32_lookup_ht(tp->data, handle);
793736
794737 if (!ht_down) {
795738 NL_SET_ERR_MSG_MOD(extack, "Link hash table not found");
739
+ return -EINVAL;
740
+ }
741
+ if (ht_down->is_root) {
742
+ NL_SET_ERR_MSG_MOD(extack, "Not linking to root node");
796743 return -EINVAL;
797744 }
798745 ht_down->refcnt++;
....@@ -809,7 +756,6 @@
809756 tcf_bind_filter(tp, &n->res, base);
810757 }
811758
812
-#ifdef CONFIG_NET_CLS_IND
813759 if (tb[TCA_U32_INDEV]) {
814760 int ret;
815761 ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
....@@ -817,7 +763,6 @@
817763 return -EINVAL;
818764 n->ifindex = ret;
819765 }
820
-#endif
821766 return 0;
822767 }
823768
....@@ -848,16 +793,14 @@
848793 rcu_assign_pointer(*ins, n);
849794 }
850795
851
-static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
796
+static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
852797 struct tc_u_knode *n)
853798 {
854799 struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
855800 struct tc_u32_sel *s = &n->sel;
856801 struct tc_u_knode *new;
857802
858
- new = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key),
859
- GFP_KERNEL);
860
-
803
+ new = kzalloc(struct_size(new, sel.keys, s->nkeys), GFP_KERNEL);
861804 if (!new)
862805 return NULL;
863806
....@@ -865,17 +808,11 @@
865808 new->handle = n->handle;
866809 RCU_INIT_POINTER(new->ht_up, n->ht_up);
867810
868
-#ifdef CONFIG_NET_CLS_IND
869811 new->ifindex = n->ifindex;
870
-#endif
871812 new->fshift = n->fshift;
872813 new->res = n->res;
873814 new->flags = n->flags;
874815 RCU_INIT_POINTER(new->ht_down, ht);
875
-
876
- /* bump reference count as long as we hold pointer to structure */
877
- if (ht)
878
- ht->refcnt++;
879816
880817 #ifdef CONFIG_CLS_U32_PERF
881818 /* Statistics may be incremented by readers during update
....@@ -891,20 +828,23 @@
891828 /* Similarly success statistics must be moved as pointers */
892829 new->pcpu_success = n->pcpu_success;
893830 #endif
894
- new->tp = tp;
895
- memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
831
+ memcpy(&new->sel, s, struct_size(s, keys, s->nkeys));
896832
897
- if (tcf_exts_init(&new->exts, TCA_U32_ACT, TCA_U32_POLICE)) {
833
+ if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
898834 kfree(new);
899835 return NULL;
900836 }
837
+
838
+ /* bump reference count as long as we hold pointer to structure */
839
+ if (ht)
840
+ ht->refcnt++;
901841
902842 return new;
903843 }
904844
905845 static int u32_change(struct net *net, struct sk_buff *in_skb,
906846 struct tcf_proto *tp, unsigned long base, u32 handle,
907
- struct nlattr **tca, void **arg, bool ovr,
847
+ struct nlattr **tca, void **arg, bool ovr, bool rtnl_held,
908848 struct netlink_ext_ack *extack)
909849 {
910850 struct tc_u_common *tp_c = tp->data;
....@@ -916,9 +856,6 @@
916856 u32 htid, flags = 0;
917857 size_t sel_size;
918858 int err;
919
-#ifdef CONFIG_CLS_U32_PERF
920
- size_t size;
921
-#endif
922859
923860 if (!opt) {
924861 if (handle) {
....@@ -929,7 +866,8 @@
929866 }
930867 }
931868
932
- err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, extack);
869
+ err = nla_parse_nested_deprecated(tb, TCA_U32_MAX, opt, u32_policy,
870
+ extack);
933871 if (err < 0)
934872 return err;
935873
....@@ -956,22 +894,21 @@
956894 return -EINVAL;
957895 }
958896
959
- new = u32_init_knode(tp, n);
897
+ new = u32_init_knode(net, tp, n);
960898 if (!new)
961899 return -ENOMEM;
962900
963
- err = u32_set_parms(net, tp, base,
964
- rtnl_dereference(n->ht_up), new, tb,
901
+ err = u32_set_parms(net, tp, base, new, tb,
965902 tca[TCA_RATE], ovr, extack);
966903
967904 if (err) {
968
- u32_destroy_key(tp, new, false);
905
+ __u32_destroy_key(new);
969906 return err;
970907 }
971908
972909 err = u32_replace_hw_knode(tp, new, flags, extack);
973910 if (err) {
974
- u32_destroy_key(tp, new, false);
911
+ __u32_destroy_key(new);
975912 return err;
976913 }
977914
....@@ -988,7 +925,11 @@
988925 if (tb[TCA_U32_DIVISOR]) {
989926 unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);
990927
991
- if (--divisor > 0x100) {
928
+ if (!is_power_of_2(divisor)) {
929
+ NL_SET_ERR_MSG_MOD(extack, "Divisor is not a power of 2");
930
+ return -EINVAL;
931
+ }
932
+ if (divisor-- > 0x100) {
992933 NL_SET_ERR_MSG_MOD(extack, "Exceeded maximum 256 hash buckets");
993934 return -EINVAL;
994935 }
....@@ -996,7 +937,7 @@
996937 NL_SET_ERR_MSG_MOD(extack, "Divisor can only be used on a hash table");
997938 return -EINVAL;
998939 }
999
- ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);
940
+ ht = kzalloc(struct_size(ht, ht, divisor + 1), GFP_KERNEL);
1000941 if (ht == NULL)
1001942 return -ENOBUFS;
1002943 if (handle == 0) {
....@@ -1013,7 +954,6 @@
1013954 return err;
1014955 }
1015956 }
1016
- ht->tp_c = tp_c;
1017957 ht->refcnt = 1;
1018958 ht->divisor = divisor;
1019959 ht->handle = handle;
....@@ -1083,15 +1023,15 @@
10831023 goto erridr;
10841024 }
10851025
1086
- n = kzalloc(offsetof(typeof(*n), sel) + sel_size, GFP_KERNEL);
1026
+ n = kzalloc(struct_size(n, sel.keys, s->nkeys), GFP_KERNEL);
10871027 if (n == NULL) {
10881028 err = -ENOBUFS;
10891029 goto erridr;
10901030 }
10911031
10921032 #ifdef CONFIG_CLS_U32_PERF
1093
- size = sizeof(struct tc_u32_pcnt) + s->nkeys * sizeof(u64);
1094
- n->pf = __alloc_percpu(size, __alignof__(struct tc_u32_pcnt));
1033
+ n->pf = __alloc_percpu(struct_size(n->pf, kcnts, s->nkeys),
1034
+ __alignof__(struct tc_u32_pcnt));
10951035 if (!n->pf) {
10961036 err = -ENOBUFS;
10971037 goto errfree;
....@@ -1103,9 +1043,8 @@
11031043 n->handle = handle;
11041044 n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
11051045 n->flags = flags;
1106
- n->tp = tp;
11071046
1108
- err = tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE);
1047
+ err = tcf_exts_init(&n->exts, net, TCA_U32_ACT, TCA_U32_POLICE);
11091048 if (err < 0)
11101049 goto errout;
11111050
....@@ -1125,7 +1064,7 @@
11251064 }
11261065 #endif
11271066
1128
- err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr,
1067
+ err = u32_set_parms(net, tp, base, n, tb, tca[TCA_RATE], ovr,
11291068 extack);
11301069 if (err == 0) {
11311070 struct tc_u_knode __rcu **ins;
....@@ -1146,6 +1085,7 @@
11461085
11471086 RCU_INIT_POINTER(n->next, pins);
11481087 rcu_assign_pointer(*ins, n);
1088
+ tp_c->knodes++;
11491089 *arg = n;
11501090 return 0;
11511091 }
....@@ -1167,7 +1107,8 @@
11671107 return err;
11681108 }
11691109
1170
-static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
1110
+static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg,
1111
+ bool rtnl_held)
11711112 {
11721113 struct tc_u_common *tp_c = tp->data;
11731114 struct tc_u_hnode *ht;
....@@ -1208,7 +1149,7 @@
12081149 }
12091150
12101151 static int u32_reoffload_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht,
1211
- bool add, tc_setup_cb_t *cb, void *cb_priv,
1152
+ bool add, flow_setup_cb_t *cb, void *cb_priv,
12121153 struct netlink_ext_ack *extack)
12131154 {
12141155 struct tc_cls_u32_offload cls_u32 = {};
....@@ -1228,7 +1169,7 @@
12281169 }
12291170
12301171 static int u32_reoffload_knode(struct tcf_proto *tp, struct tc_u_knode *n,
1231
- bool add, tc_setup_cb_t *cb, void *cb_priv,
1172
+ bool add, flow_setup_cb_t *cb, void *cb_priv,
12321173 struct netlink_ext_ack *extack)
12331174 {
12341175 struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
....@@ -1251,24 +1192,22 @@
12511192 cls_u32.knode.mask = 0;
12521193 #endif
12531194 cls_u32.knode.sel = &n->sel;
1195
+ cls_u32.knode.res = &n->res;
12541196 cls_u32.knode.exts = &n->exts;
12551197 if (n->ht_down)
12561198 cls_u32.knode.link_handle = ht->handle;
12571199 }
12581200
1259
- err = cb(TC_SETUP_CLSU32, &cls_u32, cb_priv);
1260
- if (err) {
1261
- if (add && tc_skip_sw(n->flags))
1262
- return err;
1263
- return 0;
1264
- }
1265
-
1266
- tc_cls_offload_cnt_update(block, &n->in_hw_count, &n->flags, add);
1201
+ err = tc_setup_cb_reoffload(block, tp, add, cb, TC_SETUP_CLSU32,
1202
+ &cls_u32, cb_priv, &n->flags,
1203
+ &n->in_hw_count);
1204
+ if (err)
1205
+ return err;
12671206
12681207 return 0;
12691208 }
12701209
1271
-static int u32_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
1210
+static int u32_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb,
12721211 void *cb_priv, struct netlink_ext_ack *extack)
12731212 {
12741213 struct tc_u_common *tp_c = tp->data;
....@@ -1329,7 +1268,7 @@
13291268 }
13301269
13311270 static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
1332
- struct sk_buff *skb, struct tcmsg *t)
1271
+ struct sk_buff *skb, struct tcmsg *t, bool rtnl_held)
13331272 {
13341273 struct tc_u_knode *n = fh;
13351274 struct tc_u_hnode *ht_up, *ht_down;
....@@ -1340,7 +1279,7 @@
13401279
13411280 t->tcm_handle = n->handle;
13421281
1343
- nest = nla_nest_start(skb, TCA_OPTIONS);
1282
+ nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
13441283 if (nest == NULL)
13451284 goto nla_put_failure;
13461285
....@@ -1356,8 +1295,7 @@
13561295 int cpu;
13571296 #endif
13581297
1359
- if (nla_put(skb, TCA_U32_SEL,
1360
- sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key),
1298
+ if (nla_put(skb, TCA_U32_SEL, struct_size(&n->sel, keys, n->sel.nkeys),
13611299 &n->sel))
13621300 goto nla_put_failure;
13631301
....@@ -1400,18 +1338,14 @@
14001338 if (tcf_exts_dump(skb, &n->exts) < 0)
14011339 goto nla_put_failure;
14021340
1403
-#ifdef CONFIG_NET_CLS_IND
14041341 if (n->ifindex) {
14051342 struct net_device *dev;
14061343 dev = __dev_get_by_index(net, n->ifindex);
14071344 if (dev && nla_put_string(skb, TCA_U32_INDEV, dev->name))
14081345 goto nla_put_failure;
14091346 }
1410
-#endif
14111347 #ifdef CONFIG_CLS_U32_PERF
1412
- gpf = kzalloc(sizeof(struct tc_u32_pcnt) +
1413
- n->sel.nkeys * sizeof(u64),
1414
- GFP_KERNEL);
1348
+ gpf = kzalloc(struct_size(gpf, kcnts, n->sel.nkeys), GFP_KERNEL);
14151349 if (!gpf)
14161350 goto nla_put_failure;
14171351
....@@ -1425,9 +1359,7 @@
14251359 gpf->kcnts[i] += pf->kcnts[i];
14261360 }
14271361
1428
- if (nla_put_64bit(skb, TCA_U32_PCNT,
1429
- sizeof(struct tc_u32_pcnt) +
1430
- n->sel.nkeys * sizeof(u64),
1362
+ if (nla_put_64bit(skb, TCA_U32_PCNT, struct_size(gpf, kcnts, n->sel.nkeys),
14311363 gpf, TCA_U32_PAD)) {
14321364 kfree(gpf);
14331365 goto nla_put_failure;
....@@ -1471,9 +1403,7 @@
14711403 #ifdef CONFIG_CLS_U32_PERF
14721404 pr_info(" Performance counters on\n");
14731405 #endif
1474
-#ifdef CONFIG_NET_CLS_IND
14751406 pr_info(" input device check on\n");
1476
-#endif
14771407 #ifdef CONFIG_NET_CLS_ACT
14781408 pr_info(" Actions configured\n");
14791409 #endif