net_sched: some cleanup and improvments
Subsystems (5)
v2 cover net_sched: some cleanup and improvments
Here are some cleanup and improvements for tc filters and tc actions.
v1 -> v2:
* fix a smatch warning and a checkpatch warning
* add a cover letter
* add a missing synchronize_rcu()
Cong Wang (6):
net_sched: remove get_stats from tc_action_ops
net_sched: act: use standard struct list_head
net_sched: mirred: remove action when the target device is gone
net_sched: cls: refactor out struct tcf_ext_map
net_sched: init struct tcf_hashinfo at register time
net_sched: convert tcf_hashinfo to hlist and use rcu
include/net/act_api.h | 41 +++++++--- include/net/pkt_cls.h | 37 +++++---- include/net/tc_act/tc_mirred.h | 4 +- net/sched/act_api.c | 180 ++++++++++++++++++----------------------- net/sched/act_csum.c | 13 ++- net/sched/act_gact.c | 13 ++- net/sched/act_ipt.c | 21 +++-- net/sched/act_mirred.c | 31 ++++--- net/sched/act_nat.c | 12 ++- net/sched/act_pedit.c | 12 ++- net/sched/act_police.c | 65 +++++++-------- net/sched/act_simple.c | 20 ++--- net/sched/act_skbedit.c | 13 ++- net/sched/cls_api.c | 80 +++++++++--------- net/sched/cls_basic.c | 13 ++- net/sched/cls_bpf.c | 13 ++- net/sched/cls_cgroup.c | 14 ++-- net/sched/cls_flow.c | 13 ++- net/sched/cls_fw.c | 13 ++- net/sched/cls_route.c | 13 ++- net/sched/cls_rsvp.h | 13 ++- net/sched/cls_tcindex.c | 17 ++-- net/sched/cls_u32.c | 13 ++- 23 files changed, 304 insertions(+), 360 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/6 net_sched: remove get_stats from tc_action_ops
It is not used.
--- include/net/act_api.h | 1 - net/sched/act_api.c | 4 ---- 2 files changed, 5 deletions(-)
include/net/act_api.h +0 -1
@@ -72,7 +72,6 @@ struct tc_action_ops {__u32 capab;/* capabilities includes 4 bit version */ struct module *owner;int (*act)(struct sk_buff *,const struct tc_action *,struct tcf_result *); -int (*get_stats)(struct sk_buff *,struct tc_action *);int (*dump)(struct sk_buff *,struct tc_action *,int ,int );int (*cleanup)(struct tc_action *,int bind);int (*lookup)(struct tc_action *,u32 );
net/sched/act_api.c +0 -4
@@ -637,10 +637,6 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,if (err <0 ) goto errout; -if (a->ops !=NULL && a->ops->get_stats !=NULL ) -if (a->ops->get_stats (skb, a) <0 ) - goto errout; - if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 || gnet_stats_copy_rate_est(&d, &h->tcf_bstats, &h->tcf_rate_est) < 0 ||
Signature · 1 line
1.8.1.4
PATCH v2 2/6 net_sched: act: use standard struct list_head
In reply to Cong WangCurrently actions are chained by a singly linked list, therefore it is a bit hard to add and remove a specific entry. Convert it to struct list_head so that in the latter patch we can remove an action without finding its head.
--- include/net/act_api.h | 12 +++--- include/net/pkt_cls.h | 15 +++++-- net/sched/act_api.c | 105 +++++++++++++++++++++--------------------------- net/sched/cls_api.c | 54 ++++++++++++------------- net/sched/cls_basic.c | 1 + net/sched/cls_bpf.c | 1 + net/sched/cls_cgroup.c | 1 + net/sched/cls_flow.c | 1 + net/sched/cls_fw.c | 1 + net/sched/cls_route.c | 1 + net/sched/cls_rsvp.h | 1 + net/sched/cls_tcindex.c | 5 ++- net/sched/cls_u32.c | 1 + 13 files changed, 100 insertions(+), 99 deletions(-)
include/net/act_api.h +6 -6
@@ -60,7 +60,7 @@ struct tc_action {const struct tc_action_ops *ops;__u32 type;/* for backward compat(TCA_OLD_COMPAT) */ __u32 order; -struct tc_action *next; +struct list_head list; };#define TCA_CAP_NONE 0
@@ -99,16 +99,16 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo);int tcf_register_action (struct tc_action_ops *a);int tcf_unregister_action (struct tc_action_ops *a); -void tcf_action_destroy (struct tc_action *a,int bind); -int tcf_action_exec (struct sk_buff *skb,const struct tc_action *a, +void tcf_action_destroy (struct list_head *head,int bind); +int tcf_action_exec (struct sk_buff *skb,const struct list_head *head,struct tcf_result *res); -struct tc_action *tcf_action_init (struct net *net,struct nlattr *nla, +int tcf_action_init (struct net *net,struct nlattr *nla,struct nlattr *est,char *n,int ovr, -int bind); +int bind,struct list_head *);struct tc_action *tcf_action_init_1 (struct net *net,struct nlattr *nla,struct nlattr *est,char *n,int ovr,int bind); -int tcf_action_dump (struct sk_buff *skb,struct tc_action *a,int ,int ); +int tcf_action_dump (struct sk_buff *skb,struct list_head *,int ,int );int tcf_action_dump_old (struct sk_buff *skb,struct tc_action *a,int ,int );int tcf_action_dump_1 (struct sk_buff *skb,struct tc_action *a,int ,int );int tcf_action_copy_stats (struct sk_buff *,struct tc_action *,int );
include/net/pkt_cls.h +11 -4
@@ -62,7 +62,8 @@ tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)struct tcf_exts {#ifdef CONFIG_NET_CLS_ACT -struct tc_action *action; +__u32 type;/* for backward compat(TCA_OLD_COMPAT) */ +struct list_head head;#endif };
@@ -85,12 +86,18 @@ static inline int tcf_exts_is_predicative(struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT -return !!exts->action; +return list_empty (&exts->head);#else return 0 ;#endif } +static inline void tcf_exts_init (struct tcf_exts *exts) +{ +#ifdef CONFIG_NET_CLS_ACT +INIT_LIST_HEAD (&exts->head); +#endif +}/** * tcf_exts_is_available - check if at least one extension is present * @exts: tc filter extensions handle
@@ -120,8 +127,8 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, struct tcf_result *res) {#ifdef CONFIG_NET_CLS_ACT -if (exts->action) -return tcf_action_exec (skb, exts->action, res); +if (!list_empty (&exts->head)) +return tcf_action_exec (skb, &exts->head, res);#endif return 0 ; }
net/sched/act_api.c +45 -60
276 lines not on this page · raw message
net/sched/cls_api.c +26 -28
114 lines not on this page · raw message
net/sched/cls_basic.c +1 -0
@@ -191,6 +191,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout; +tcf_exts_init (&f->exts); err = -EINVAL ;if (handle) f->handle = handle;
net/sched/cls_bpf.c +1 -0
@@ -271,6 +271,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,if (prog ==NULL )return -ENOBUFS ; +tcf_exts_init (&prog->exts);if (handle ==0 ) prog->handle =cls_bpf_grab_new_handle (tp, head);else
net/sched/cls_cgroup.c +1 -0
@@ -203,6 +203,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (head ==NULL )return -ENOBUFS ; +tcf_exts_init (&head->exts); head->handle = handle;tcf_tree_lock (tp);
net/sched/cls_flow.c +1 -0
@@ -455,6 +455,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, f->handle = handle; f->mask = ~0U ; +tcf_exts_init (&f->exts);get_random_bytes (&f->hashrnd,4 ); f->perturb_timer.function = flow_perturbation;
net/sched/cls_fw.c +1 -0
@@ -280,6 +280,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL )return -ENOBUFS ; +tcf_exts_init (&f->exts); f->id = handle; err =fw_change_attrs (net, tp, f, tb, tca, base);
net/sched/cls_route.c +1 -0
@@ -481,6 +481,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout; +tcf_exts_init (&f->exts); err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );if (err <0 )
net/sched/cls_rsvp.h +1 -0
@@ -471,6 +471,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout2; +tcf_exts_init (&f->exts); h2 =16 ;if (tb[TCA_RSVP_SRC ]) {memcpy (f->src,nla_data (tb[TCA_RSVP_SRC ]),sizeof (f->src));
net/sched/cls_tcindex.c +4 -1
@@ -215,11 +215,14 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,memcpy (&cp, p,sizeof (cp));memset (&new_filter_result,0 ,sizeof (new_filter_result)); +tcf_exts_init (&new_filter_result.exts);if (old_r)memcpy (&cr, r,sizeof (cr)); -else +else {memset (&cr,0 ,sizeof (cr)); +tcf_exts_init (&cr.exts); + }if (tb[TCA_TCINDEX_HASH ]) cp.hash =nla_get_u32 (tb[TCA_TCINDEX_HASH ]);
net/sched/cls_u32.c +1 -0
@@ -646,6 +646,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, n->ht_up = ht; n->handle = handle; n->fshift = s->hmask ?ffs (ntohl (s->hmask)) -1 :0 ; +tcf_exts_init (&n->exts);#ifdef CONFIG_CLS_U32_MARK if (tb[TCA_U32_MARK ]) {
Signature · 1 line
1.8.1.4
PATCH v2 3/6 net_sched: mirred: remove action when the target device is gone
In reply to Cong WangWhen the target device is removed, the mirred action is still there but with the pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
--- include/net/tc_act/tc_mirred.h | 4 +++- net/sched/act_mirred.c | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
include/net/tc_act/tc_mirred.h +3 -1
@@ -7,9 +7,11 @@ struct tcf_mirred {struct tcf_common common;int tcfm_eaction;int tcfm_ifindex; -int tcfm_ok_push; + unsigned int tcfm_ok_push:1; + unsigned int tcfm_bind:1;struct net_device *tcfm_dev;struct list_head tcfm_list; +struct tc_action *tcfm_act; };#define to_mirred (pc) \ container_of(pc, struct tcf_mirred, common)
net/sched/act_mirred.c +7 -8
@@ -136,6 +136,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,dev_hold (dev); m->tcfm_dev = dev; m->tcfm_ok_push = ok_push; + m->tcfm_bind = bind; + m->tcfm_act = a; }spin_unlock_bh (&m->tcf_lock);if (ret ==ACT_P_CREATED ) {
@@ -169,10 +171,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,bstats_update (&m->tcf_bstats, skb); dev = m->tcfm_dev; -if (!dev) { -printk_once (KERN_NOTICE "tc mirred: target device is gone\n" ); - goto out; - }if (!(dev->flags &IFF_UP )) { net_notice_ratelimited("tc mirred to Houston: device %s is down\n",
@@ -244,13 +242,14 @@ static int mirred_device_event(struct notifier_block *unused, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); -struct tcf_mirred *m; +struct tcf_mirred *m, *tmp;if (event ==NETDEV_UNREGISTER ) -list_for_each_entry (m, &mirred_list, tcfm_list) { +list_for_each_entry_safe (m, tmp, &mirred_list, tcfm_list) {if (m->tcfm_dev == dev) { -dev_put (dev); - m->tcfm_dev =NULL ; +list_del (&m->tcfm_act->list); +tcf_mirred_cleanup (m->tcfm_act, m->tcfm_bind); +kfree (m->tcfm_act); } }
Signature · 1 line
1.8.1.4
PATCH v2 4/6 net_sched: cls: refactor out struct tcf_ext_map
In reply to Cong WangThese information can be saved in tcf_exts, and this will simplify the code.
--- include/net/pkt_cls.h | 34 ++++++++++++++++------------------ net/sched/cls_api.c | 32 +++++++++++++------------------- net/sched/cls_basic.c | 14 +++++--------- net/sched/cls_bpf.c | 14 +++++--------- net/sched/cls_cgroup.c | 15 +++++---------- net/sched/cls_flow.c | 14 +++++--------- net/sched/cls_fw.c | 14 +++++--------- net/sched/cls_route.c | 14 +++++--------- net/sched/cls_rsvp.h | 14 +++++--------- net/sched/cls_tcindex.c | 16 ++++++---------- net/sched/cls_u32.c | 14 +++++--------- 11 files changed, 75 insertions(+), 120 deletions(-)
include/net/pkt_cls.h +16 -18
@@ -65,16 +65,23 @@ struct tcf_exts {__u32 type;/* for backward compat(TCA_OLD_COMPAT) */ struct list_head head;#endif -}; - -/* Map to export classifier specific extension TLV types to the -* generic extensions API. Unsupported extensions must be set to 0. -*/ -struct tcf_ext_map { +/* Map to export classifier specific extension TLV types to the +* generic extensions API. Unsupported extensions must be set to 0. +*/ int action;int police; }; +static inline void tcf_exts_init (struct tcf_exts *exts,int action,int police) +{ +#ifdef CONFIG_NET_CLS_ACT + exts->type =0 ; +INIT_LIST_HEAD (&exts->head); +#endif + exts->action = action; + exts->police = police; +} +/** * tcf_exts_is_predicative - check if a predicative extension is present * @exts: tc filter extensions handle
@@ -92,12 +99,6 @@ tcf_exts_is_predicative(struct tcf_exts *exts)#endif } -static inline void tcf_exts_init (struct tcf_exts *exts) -{ -#ifdef CONFIG_NET_CLS_ACT -INIT_LIST_HEAD (&exts->head); -#endif -}/** * tcf_exts_is_available - check if at least one extension is present * @exts: tc filter extensions handle
@@ -135,15 +136,12 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,int tcf_exts_validate (struct net *net,struct tcf_proto *tp,struct nlattr **tb,struct nlattr *rate_tlv, -struct tcf_exts *exts, -const struct tcf_ext_map *map); +struct tcf_exts *exts);void tcf_exts_destroy (struct tcf_proto *tp,struct tcf_exts *exts);void tcf_exts_change (struct tcf_proto *tp,struct tcf_exts *dst,struct tcf_exts *src); -int tcf_exts_dump (struct sk_buff *skb,struct tcf_exts *exts, -const struct tcf_ext_map *map); -int tcf_exts_dump_stats (struct sk_buff *skb,struct tcf_exts *exts, -const struct tcf_ext_map *map); +int tcf_exts_dump (struct sk_buff *skb,struct tcf_exts *exts); +int tcf_exts_dump_stats (struct sk_buff *skb,struct tcf_exts *exts);/** * struct tcf_pkt_info - packet information
net/sched/cls_api.c +13 -19
@@ -507,18 +507,14 @@ void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts)EXPORT_SYMBOL (tcf_exts_destroy);int tcf_exts_validate (struct net *net,struct tcf_proto *tp,struct nlattr **tb, -struct nlattr *rate_tlv,struct tcf_exts *exts, -const struct tcf_ext_map *map) +struct nlattr *rate_tlv,struct tcf_exts *exts) { -memset (exts,0 ,sizeof (*exts)); -#ifdef CONFIG_NET_CLS_ACT {struct tc_action *act; -INIT_LIST_HEAD (&exts->head); -if (map->police && tb[map->police]) { - act =tcf_action_init_1 (net, tb[map->police], rate_tlv, +if (exts->police && tb[exts->police]) { + act =tcf_action_init_1 (net, tb[exts->police], rate_tlv,"police" ,TCA_ACT_NOREPLACE ,TCA_ACT_BIND );if (IS_ERR (act))
@@ -526,9 +522,9 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, act->type = exts->type =TCA_OLD_COMPAT ;list_add (&act->list, &exts->head); - }else if (map->action && tb[map->action]) { + }else if (exts->action && tb[exts->action]) {int err; - err =tcf_action_init (net, tb[map->action], rate_tlv, + err =tcf_action_init (net, tb[exts->action], rate_tlv,NULL ,TCA_ACT_NOREPLACE ,TCA_ACT_BIND , &exts->head);if (err)
@@ -536,8 +532,8 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, } }#else -if ((map->action && tb[map->action]) || - (map->police && tb[map->police])) +if ((exts->action && tb[exts->action]) || + (exts->police && tb[exts->police]))return -EOPNOTSUPP ;#endif
@@ -564,11 +560,10 @@ EXPORT_SYMBOL(tcf_exts_change);#define tcf_exts_first_act (ext) \ list_first_entry(&(exts)->head, struct tc_action, list) -int tcf_exts_dump (struct sk_buff *skb,struct tcf_exts *exts, -const struct tcf_ext_map *map) +int tcf_exts_dump (struct sk_buff *skb,struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT -if (map->action && !list_empty (&exts->head)) { +if (exts->action && !list_empty (&exts->head)) {/* * again for backward compatible mode - we want * to work with both old and new modes of entering
@@ -576,15 +571,15 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,*/ struct nlattr *nest;if (exts->type !=TCA_OLD_COMPAT ) { - nest =nla_nest_start (skb, map->action); + nest =nla_nest_start (skb, exts->action);if (nest ==NULL ) goto nla_put_failure;if (tcf_action_dump (skb, &exts->head,0 ,0 ) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); - }else if (map->police) { + }else if (exts->police) {struct tc_action *act =tcf_exts_first_act (exts); - nest =nla_nest_start (skb, map->police); + nest =nla_nest_start (skb, exts->police);if (nest ==NULL ) goto nla_put_failure;if (tcf_action_dump_old (skb, act,0 ,0 ) <0 )
@@ -600,8 +595,7 @@ nla_put_failure: __attribute__ ((unused))EXPORT_SYMBOL (tcf_exts_dump); -int tcf_exts_dump_stats (struct sk_buff *skb,struct tcf_exts *exts, -const struct tcf_ext_map *map) +int tcf_exts_dump_stats (struct sk_buff *skb,struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT struct tc_action *a =tcf_exts_first_act (exts);
net/sched/cls_basic.c +5 -9
@@ -34,11 +34,6 @@ struct basic_filter {struct list_head link; }; -static const struct tcf_ext_map basic_ext_map = { - .action =TCA_BASIC_ACT , - .police =TCA_BASIC_POLICE -}; -static int basic_classify (struct sk_buff *skb,const struct tcf_proto *tp,struct tcf_result *res) {
@@ -141,7 +136,8 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,struct tcf_exts e;struct tcf_ematch_tree t; - err =tcf_exts_validate (net, tp, tb, est, &e, &basic_ext_map); +tcf_exts_init (&e,TCA_BASIC_ACT ,TCA_BASIC_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &e);if (err <0 )return err;
@@ -191,7 +187,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout; -tcf_exts_init (&f->exts); +tcf_exts_init (&f->exts,TCA_BASIC_ACT ,TCA_BASIC_POLICE ); err = -EINVAL ;if (handle) f->handle = handle;
@@ -264,13 +260,13 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh, nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid)) goto nla_put_failure; -if (tcf_exts_dump (skb, &f->exts, &basic_ext_map) <0 || +if (tcf_exts_dump (skb, &f->exts) <0 ||tcf_em_tree_dump (skb, &f->ematches,TCA_BASIC_EMATCHES ) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &f->exts, &basic_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &f->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_bpf.c +5 -9
@@ -46,11 +46,6 @@ static const struct nla_policy bpf_policy[TCA_BPF_MAX + 1] = { .len = sizeof(struct sock_filter) * BPF_MAXINSNS }, }; -static const struct tcf_ext_map bpf_ext_map = { - .action =TCA_BPF_ACT , - .police =TCA_BPF_POLICE , -}; -static int cls_bpf_classify (struct sk_buff *skb,const struct tcf_proto *tp,struct tcf_result *res) {
@@ -174,7 +169,8 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,if (!tb[TCA_BPF_OPS_LEN ] || !tb[TCA_BPF_OPS ] || !tb[TCA_BPF_CLASSID ])return -EINVAL ; - ret =tcf_exts_validate (net, tp, tb, est, &exts, &bpf_ext_map); +tcf_exts_init (&exts,TCA_BPF_ACT ,TCA_BPF_POLICE ); + ret =tcf_exts_validate (net, tp, tb, est, &exts);if (ret <0 )return ret;
@@ -271,7 +267,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,if (prog ==NULL )return -ENOBUFS ; -tcf_exts_init (&prog->exts); +tcf_exts_init (&prog->exts,TCA_BPF_ACT ,TCA_BPF_POLICE );if (handle ==0 ) prog->handle =cls_bpf_grab_new_handle (tp, head);else
@@ -326,12 +322,12 @@ static int cls_bpf_dump(struct tcf_proto *tp, unsigned long fh,memcpy (nla_data (nla), prog->bpf_ops,nla_len (nla)); -if (tcf_exts_dump (skb, &prog->exts, &bpf_ext_map) <0 ) +if (tcf_exts_dump (skb, &prog->exts) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &prog->exts, &bpf_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &prog->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_cgroup.c +5 -10
@@ -172,11 +172,6 @@ static int cls_cgroup_init(struct tcf_proto *tp)return 0 ; } -static const struct tcf_ext_map cgroup_ext_map = { - .action =TCA_CGROUP_ACT , - .police =TCA_CGROUP_POLICE , -}; -static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX +1 ] = { [TCA_CGROUP_EMATCHES ] = { .type =NLA_NESTED }, };
@@ -203,7 +198,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (head ==NULL )return -ENOBUFS ; -tcf_exts_init (&head->exts); +tcf_exts_init (&head->exts,TCA_CGROUP_ACT ,TCA_CGROUP_POLICE ); head->handle = handle;tcf_tree_lock (tp);
@@ -219,8 +214,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, - &cgroup_ext_map); +tcf_exts_init (&e,TCA_CGROUP_ACT ,TCA_CGROUP_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e);if (err <0 )return err;
@@ -278,13 +273,13 @@ static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,if (nest ==NULL ) goto nla_put_failure; -if (tcf_exts_dump (skb, &head->exts, &cgroup_ext_map) <0 || +if (tcf_exts_dump (skb, &head->exts) <0 ||tcf_em_tree_dump (skb, &head->ematches,TCA_CGROUP_EMATCHES ) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &head->exts, &cgroup_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &head->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_flow.c +5 -9
@@ -56,11 +56,6 @@ struct flow_filter {u32 hashrnd; }; -static const struct tcf_ext_map flow_ext_map = { - .action =TCA_FLOW_ACT , - .police =TCA_FLOW_POLICE , -}; -static inline u32 addr_fold (void *addr) {unsigned long a = (unsigned long )addr;
@@ -397,7 +392,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,return -EOPNOTSUPP ; } - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, &flow_ext_map); +tcf_exts_init (&e,TCA_FLOW_ACT ,TCA_FLOW_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e);if (err <0 )return err;
@@ -455,7 +451,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, f->handle = handle; f->mask = ~0U ; -tcf_exts_init (&f->exts); +tcf_exts_init (&f->exts,TCA_FLOW_ACT ,TCA_FLOW_POLICE );get_random_bytes (&f->hashrnd,4 ); f->perturb_timer.function = flow_perturbation;
@@ -609,7 +605,7 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh, nla_put_u32(skb, TCA_FLOW_PERTURB, f->perturb_period / HZ)) goto nla_put_failure; -if (tcf_exts_dump (skb, &f->exts, &flow_ext_map) <0 ) +if (tcf_exts_dump (skb, &f->exts) <0 ) goto nla_put_failure;#ifdef CONFIG_NET_EMATCH if (f->ematches.hdr.nmatches &&
@@ -618,7 +614,7 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,#endif nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &f->exts, &flow_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &f->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_fw.c +5 -9
@@ -46,11 +46,6 @@ struct fw_filter {struct tcf_exts exts; }; -static const struct tcf_ext_map fw_ext_map = { - .action =TCA_FW_ACT , - .police =TCA_FW_POLICE -}; -static inline int fw_hash (u32 handle) {if (HTSIZE ==4096 )
@@ -200,7 +195,8 @@ fw_change_attrs(struct net *net, struct tcf_proto *tp, struct fw_filter *f,u32 mask;int err; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, &fw_ext_map); +tcf_exts_init (&e,TCA_FW_ACT ,TCA_FW_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e);if (err <0 )return err;
@@ -280,7 +276,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL )return -ENOBUFS ; -tcf_exts_init (&f->exts); +tcf_exts_init (&f->exts,TCA_FW_ACT ,TCA_FW_POLICE ); f->id = handle; err =fw_change_attrs (net, tp, f, tb, tca, base);
@@ -360,12 +356,12 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh, nla_put_u32(skb, TCA_FW_MASK, head->mask)) goto nla_put_failure; -if (tcf_exts_dump (skb, &f->exts, &fw_ext_map) <0 ) +if (tcf_exts_dump (skb, &f->exts) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &f->exts, &fw_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &f->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_route.c +5 -9
@@ -59,11 +59,6 @@ struct route4_filter {#define ROUTE4_FAILURE ((struct route4_filter *)(-1L)) -static const struct tcf_ext_map route_ext_map = { - .police =TCA_ROUTE4_POLICE , - .action =TCA_ROUTE4_ACT -}; -static inline int route4_fastmap_hash (u32 id,int iif) {return id &0xF ;
@@ -347,7 +342,8 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,struct route4_bucket *b;struct tcf_exts e; - err =tcf_exts_validate (net, tp, tb, est, &e, &route_ext_map); +tcf_exts_init (&e,TCA_ROUTE4_ACT ,TCA_ROUTE4_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &e);if (err <0 )return err;
@@ -481,7 +477,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout; -tcf_exts_init (&f->exts); +tcf_exts_init (&f->exts,TCA_ROUTE4_ACT ,TCA_ROUTE4_POLICE ); err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );if (err <0 )
@@ -590,12 +586,12 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh, nla_put_u32(skb, TCA_ROUTE4_CLASSID, f->res.classid)) goto nla_put_failure; -if (tcf_exts_dump (skb, &f->exts, &route_ext_map) <0 ) +if (tcf_exts_dump (skb, &f->exts) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &f->exts, &route_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &f->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_rsvp.h +5 -9
@@ -116,11 +116,6 @@ static inline unsigned int hash_src(__be32 *src)return h &0xF ; } -static struct tcf_ext_map rsvp_ext_map = { - .police =TCA_RSVP_POLICE , - .action =TCA_RSVP_ACT -}; -#define RSVP_APPLY_RESULT () \ { \ int r = tcf_exts_exec(skb, &f->exts, res); \
@@ -440,7 +435,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, &rsvp_ext_map); +tcf_exts_init (&e,TCA_RSVP_ACT ,TCA_RSVP_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e);if (err <0 )return err;
@@ -471,7 +467,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,if (f ==NULL ) goto errout2; -tcf_exts_init (&f->exts); +tcf_exts_init (&f->exts,TCA_RSVP_ACT ,TCA_RSVP_POLICE ); h2 =16 ;if (tb[TCA_RSVP_SRC ]) {memcpy (f->src,nla_data (tb[TCA_RSVP_SRC ]),sizeof (f->src));
@@ -634,12 +630,12 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh, nla_put(skb, TCA_RSVP_SRC, sizeof(f->src), f->src)) goto nla_put_failure; -if (tcf_exts_dump (skb, &f->exts, &rsvp_ext_map) <0 ) +if (tcf_exts_dump (skb, &f->exts) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &f->exts, &rsvp_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &f->exts) <0 ) goto nla_put_failure;return skb->len;
net/sched/cls_tcindex.c +6 -10
@@ -50,11 +50,6 @@ struct tcindex_data {int fall_through;/* 0: only classify if explicit match */ }; -static const struct tcf_ext_map tcindex_ext_map = { - .police =TCA_TCINDEX_POLICE , - .action =TCA_TCINDEX_ACT -}; -static inline int tcindex_filter_is_set (struct tcindex_filter_result *r) {
@@ -209,19 +204,20 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,struct tcindex_filter *f =NULL ;/* make gcc behave */ struct tcf_exts e; - err =tcf_exts_validate (net, tp, tb, est, &e, &tcindex_ext_map); +tcf_exts_init (&e,TCA_TCINDEX_ACT ,TCA_TCINDEX_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &e);if (err <0 )return err;memcpy (&cp, p,sizeof (cp));memset (&new_filter_result,0 ,sizeof (new_filter_result)); -tcf_exts_init (&new_filter_result.exts); +tcf_exts_init (&new_filter_result.exts,TCA_TCINDEX_ACT ,TCA_TCINDEX_POLICE );if (old_r)memcpy (&cr, r,sizeof (cr));else {memset (&cr,0 ,sizeof (cr)); -tcf_exts_init (&cr.exts); +tcf_exts_init (&cr.exts,TCA_TCINDEX_ACT ,TCA_TCINDEX_POLICE ); }if (tb[TCA_TCINDEX_HASH ])
@@ -471,11 +467,11 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh, nla_put_u32(skb, TCA_TCINDEX_CLASSID, r->res.classid)) goto nla_put_failure; -if (tcf_exts_dump (skb, &r->exts, &tcindex_ext_map) <0 ) +if (tcf_exts_dump (skb, &r->exts) <0 ) goto nla_put_failure;nla_nest_end (skb, nest); -if (tcf_exts_dump_stats (skb, &r->exts, &tcindex_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &r->exts) <0 ) goto nla_put_failure; }
net/sched/cls_u32.c +5 -9
@@ -79,11 +79,6 @@ struct tc_u_common {u32 hgenerator; }; -static const struct tcf_ext_map u32_ext_map = { - .action =TCA_U32_ACT , - .police =TCA_U32_POLICE -}; -static inline unsigned int u32_hash_fold (__be32 key,const struct tc_u32_sel *sel,u8 fshift)
@@ -496,7 +491,8 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,int err;struct tcf_exts e; - err =tcf_exts_validate (net, tp, tb, est, &e, &u32_ext_map); +tcf_exts_init (&e,TCA_U32_ACT ,TCA_U32_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &e);if (err <0 )return err;
@@ -646,7 +642,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, n->ht_up = ht; n->handle = handle; n->fshift = s->hmask ?ffs (ntohl (s->hmask)) -1 :0 ; -tcf_exts_init (&n->exts); +tcf_exts_init (&n->exts,TCA_U32_ACT ,TCA_U32_POLICE );#ifdef CONFIG_CLS_U32_MARK if (tb[TCA_U32_MARK ]) {
@@ -760,7 +756,7 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh, goto nla_put_failure;#endif -if (tcf_exts_dump (skb, &n->exts, &u32_ext_map) <0 ) +if (tcf_exts_dump (skb, &n->exts) <0 ) goto nla_put_failure;#ifdef CONFIG_NET_CLS_IND
@@ -779,7 +775,7 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,nla_nest_end (skb, nest);if (TC_U32_KEY (n->handle)) -if (tcf_exts_dump_stats (skb, &n->exts, &u32_ext_map) <0 ) +if (tcf_exts_dump_stats (skb, &n->exts) <0 ) goto nla_put_failure;return skb->len;
Signature · 1 line
1.8.1.4
PATCH v2 5/6 net_sched: init struct tcf_hashinfo at register time
In reply to Cong WangIt looks weird to store the lock out of the struct but still points to a static variable. Just move them into the struct.
--- include/net/act_api.h | 18 +++++++++++++++++- net/sched/act_api.c | 16 ++++++++-------- net/sched/act_csum.c | 13 +++++-------- net/sched/act_gact.c | 13 +++++-------- net/sched/act_ipt.c | 21 ++++++++++----------- net/sched/act_mirred.c | 16 +++++++--------- net/sched/act_nat.c | 12 +++++------- net/sched/act_pedit.c | 12 +++++------- net/sched/act_police.c | 38 +++++++++++++++++++------------------- net/sched/act_simple.c | 20 +++++++++++--------- net/sched/act_skbedit.c | 13 +++++-------- 11 files changed, 97 insertions(+), 95 deletions(-)
include/net/act_api.h +17 -1
@@ -38,7 +38,7 @@ struct tcf_common {struct tcf_hashinfo {struct tcf_common **htab;unsigned int hmask; -rwlock_t *lock; +rwlock_t lock; };static inline unsigned int tcf_hash (u32 index,unsigned int hmask)
@@ -46,6 +46,22 @@ static inline unsigned int tcf_hash(u32 index, unsigned int hmask)return index & hmask; } +static inline int tcf_hashinfo_init (struct tcf_hashinfo *hf,unsigned int mask) +{ +rwlock_init (&hf->lock); + hf->hmask = mask; + hf->htab =kzalloc ((mask +1 ) *sizeof (struct tcf_common *), +GFP_KERNEL ); +if (!hf->htab) +return -ENOMEM ; +return 0 ; +} + +static inline void tcf_hashinfo_destroy (struct tcf_hashinfo *hf) +{ +kfree (hf->htab); +} +#ifdef CONFIG_NET_CLS_ACT #define ACT_P_CREATED 1
net/sched/act_api.c +8 -8
@@ -34,9 +34,9 @@ void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) {if (*p1p == p) { -write_lock_bh (hinfo->lock); +write_lock_bh (&hinfo->lock); *p1p = p->tcfc_next; -write_unlock_bh (hinfo->lock); +write_unlock_bh (&hinfo->lock);gen_kill_estimator (&p->tcfc_bstats, &p->tcfc_rate_est);/*
@@ -77,7 +77,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,int err =0 , index =-1 , i =0 , s_i =0 , n_i =0 ;struct nlattr *nest; -read_lock_bh (hinfo->lock); +read_lock_bh (&hinfo->lock); s_i = cb->args[0 ];
@@ -107,7 +107,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb, } } done: -read_unlock_bh (hinfo->lock); +read_unlock_bh (&hinfo->lock);if (n_i) cb->args[0 ] += n_i;return n_i;
@@ -170,13 +170,13 @@ struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo) {struct tcf_common *p; -read_lock_bh (hinfo->lock); +read_lock_bh (&hinfo->lock);for (p = hinfo->htab[tcf_hash (index, hinfo->hmask)]; p; p = p->tcfc_next) {if (p->tcfc_index == index)break ; } -read_unlock_bh (hinfo->lock); +read_unlock_bh (&hinfo->lock);return p; }
@@ -257,10 +257,10 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo) {unsigned int h =tcf_hash (p->tcfc_index, hinfo->hmask); -write_lock_bh (hinfo->lock); +write_lock_bh (&hinfo->lock); p->tcfc_next = hinfo->htab[h]; hinfo->htab[h] = p; -write_unlock_bh (hinfo->lock); +write_unlock_bh (&hinfo->lock); }EXPORT_SYMBOL (tcf_hash_insert);
net/sched/act_csum.c +5 -8
@@ -37,15 +37,8 @@#include <net/tc_act/tc_csum.h> #define CSUM_TAB_MASK 15 -static struct tcf_common *tcf_csum_ht[CSUM_TAB_MASK +1 ];static u32 csum_idx_gen; -static DEFINE_RWLOCK (csum_lock); - -static struct tcf_hashinfo csum_hash_info = { - .htab = tcf_csum_ht, - .hmask =CSUM_TAB_MASK , - .lock = &csum_lock, -}; +static struct tcf_hashinfo csum_hash_info;static const struct nla_policy csum_policy[TCA_CSUM_MAX +1 ] = { [TCA_CSUM_PARMS ] = { .len =sizeof (struct tc_csum ), },
@@ -593,6 +586,10 @@ MODULE_LICENSE("GPL");static int __init csum_init_module (void ) { +int err =tcf_hashinfo_init (&csum_hash_info,CSUM_TAB_MASK +1 ); +if (err) +return err; +return tcf_register_action (&act_csum_ops); }
net/sched/act_gact.c +5 -8
@@ -24,15 +24,8 @@#include <net/tc_act/tc_gact.h> #define GACT_TAB_MASK 15 -static struct tcf_common *tcf_gact_ht[GACT_TAB_MASK +1 ];static u32 gact_idx_gen; -static DEFINE_RWLOCK (gact_lock); - -static struct tcf_hashinfo gact_hash_info = { - .htab = tcf_gact_ht, - .hmask =GACT_TAB_MASK , - .lock = &gact_lock, -}; +static struct tcf_hashinfo gact_hash_info;#ifdef CONFIG_GACT_PROB static int gact_net_rand (struct tcf_gact *gact)
@@ -215,6 +208,9 @@ MODULE_LICENSE("GPL");static int __init gact_init_module (void ) { +int err =tcf_hashinfo_init (&gact_hash_info,GACT_TAB_MASK +1 ); +if (err) +return err;#ifdef CONFIG_GACT_PROB pr_info ("GACT probability on\n" );#else
@@ -226,6 +222,7 @@ static int __init gact_init_module(void) static void __exit gact_cleanup_module(void) {tcf_unregister_action (&act_gact_ops); +tcf_hashinfo_destroy (&gact_hash_info); }module_init (gact_init_module);
net/sched/act_ipt.c +10 -11
@@ -29,15 +29,8 @@#define IPT_TAB_MASK 15 -static struct tcf_common *tcf_ipt_ht[IPT_TAB_MASK +1 ];static u32 ipt_idx_gen; -static DEFINE_RWLOCK (ipt_lock); - -static struct tcf_hashinfo ipt_hash_info = { - .htab = tcf_ipt_ht, - .hmask =IPT_TAB_MASK , - .lock = &ipt_lock, -}; +static struct tcf_hashinfo ipt_hash_info;static int ipt_init_target (struct xt_entry_target *t,char *table,unsigned int hook) {
@@ -320,7 +313,11 @@ MODULE_ALIAS("act_xt");static int __init ipt_init_module (void ) { -int ret1, ret2; +int ret1, ret2, err; + err =tcf_hashinfo_init (&ipt_hash_info,IPT_TAB_MASK +1 ); +if (err) +return err; + ret1 =tcf_register_action (&act_xt_ops);if (ret1 <0 )printk ("Failed to load xt action\n" );
@@ -328,9 +325,10 @@ static int __init ipt_init_module(void)if (ret2 <0 )printk ("Failed to load ipt action\n" ); -if (ret1 <0 && ret2 <0 ) +if (ret1 <0 && ret2 <0 ) { +tcf_hashinfo_destroy (&ipt_hash_info);return ret1; -else + }else return 0 ; }
@@ -338,6 +336,7 @@ static void __exit ipt_cleanup_module(void) {tcf_unregister_action (&act_xt_ops);tcf_unregister_action (&act_ipt_ops); +tcf_hashinfo_destroy (&ipt_hash_info); }module_init (ipt_init_module);
net/sched/act_mirred.c +7 -9
@@ -30,16 +30,9 @@#include <linux/if_arp.h> #define MIRRED_TAB_MASK 7 -static struct tcf_common *tcf_mirred_ht[MIRRED_TAB_MASK +1 ];static u32 mirred_idx_gen; -static DEFINE_RWLOCK (mirred_lock);static LIST_HEAD (mirred_list); - -static struct tcf_hashinfo mirred_hash_info = { - .htab = tcf_mirred_ht, - .hmask =MIRRED_TAB_MASK , - .lock = &mirred_lock, -}; +static struct tcf_hashinfo mirred_hash_info;static int tcf_mirred_release (struct tcf_mirred *m,int bind) {
@@ -260,7 +253,6 @@ static struct notifier_block mirred_device_notifier = { .notifier_call = mirred_device_event, }; -static struct tc_action_ops act_mirred_ops = { .kind ="mirred" , .hinfo = &mirred_hash_info,
@@ -283,6 +275,11 @@ static int __init mirred_init_module(void)if (err)return err; + err =tcf_hashinfo_init (&mirred_hash_info,MIRRED_TAB_MASK +1 ); +if (err) { +unregister_netdevice_notifier (&mirred_device_notifier); +return err; + }pr_info ("Mirror/redirect action on\n" );return tcf_register_action (&act_mirred_ops); }
@@ -290,6 +287,7 @@ static int __init mirred_init_module(void) static void __exit mirred_cleanup_module(void) {unregister_netdevice_notifier (&mirred_device_notifier); +tcf_hashinfo_destroy (&mirred_hash_info);tcf_unregister_action (&act_mirred_ops); }
net/sched/act_nat.c +5 -7
@@ -30,15 +30,9 @@#define NAT_TAB_MASK 15 -static struct tcf_common *tcf_nat_ht[NAT_TAB_MASK +1 ];static u32 nat_idx_gen; -static DEFINE_RWLOCK (nat_lock); -static struct tcf_hashinfo nat_hash_info = { - .htab = tcf_nat_ht, - .hmask =NAT_TAB_MASK , - .lock = &nat_lock, -}; +static struct tcf_hashinfo nat_hash_info;static const struct nla_policy nat_policy[TCA_NAT_MAX +1 ] = { [TCA_NAT_PARMS ] = { .len =sizeof (struct tc_nat ) },
@@ -316,12 +310,16 @@ MODULE_LICENSE("GPL");static int __init nat_init_module (void ) { +int err =tcf_hashinfo_init (&nat_hash_info,NAT_TAB_MASK +1 ); +if (err) +return err;return tcf_register_action (&act_nat_ops); } static void __exit nat_cleanup_module(void) {tcf_unregister_action (&act_nat_ops); +tcf_hashinfo_destroy (&nat_hash_info); }module_init (nat_init_module);
net/sched/act_pedit.c +5 -7
@@ -24,15 +24,9 @@#include <net/tc_act/tc_pedit.h> #define PEDIT_TAB_MASK 15 -static struct tcf_common *tcf_pedit_ht[PEDIT_TAB_MASK +1 ];static u32 pedit_idx_gen; -static DEFINE_RWLOCK (pedit_lock); -static struct tcf_hashinfo pedit_hash_info = { - .htab = tcf_pedit_ht, - .hmask =PEDIT_TAB_MASK , - .lock = &pedit_lock, -}; +static struct tcf_hashinfo pedit_hash_info;static const struct nla_policy pedit_policy[TCA_PEDIT_MAX +1 ] = { [TCA_PEDIT_PARMS ] = { .len =sizeof (struct tc_pedit ) },
@@ -252,11 +246,15 @@ MODULE_LICENSE("GPL");static int __init pedit_init_module (void ) { +int err =tcf_hashinfo_init (&pedit_hash_info,PEDIT_TAB_MASK +1 ); +if (err) +return err;return tcf_register_action (&act_pedit_ops); } static void __exit pedit_cleanup_module(void) { +tcf_hashinfo_destroy (&pedit_hash_info);tcf_unregister_action (&act_pedit_ops); }
net/sched/act_police.c +19 -19
@@ -41,15 +41,8 @@ struct tcf_police { container_of(pc, struct tcf_police, common)#define POL_TAB_MASK 15 -static struct tcf_common *tcf_police_ht[POL_TAB_MASK +1 ];static u32 police_idx_gen; -static DEFINE_RWLOCK (police_lock); - -static struct tcf_hashinfo police_hash_info = { - .htab = tcf_police_ht, - .hmask =POL_TAB_MASK , - .lock = &police_lock, -}; +static struct tcf_hashinfo police_hash_info;/* old policer structure from before tc actions */ struct tc_police_compat {
@@ -71,12 +64,12 @@ static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cint err =0 , index =-1 , i =0 , s_i =0 , n_i =0 ;struct nlattr *nest; -read_lock_bh (&police_lock); +read_lock_bh (&police_hash_info.lock); s_i = cb->args[0 ];for (i =0 ; i < (POL_TAB_MASK +1 ); i++) { - p = tcf_police_ht[tcf_hash (i,POL_TAB_MASK )]; + p = police_hash_info.htab[tcf_hash (i,POL_TAB_MASK )];for (; p; p = p->tcfc_next) { index++;
@@ -101,7 +94,7 @@ static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *c } } done: -read_unlock_bh (&police_lock); +read_unlock_bh (&police_hash_info.lock);if (n_i) cb->args[0 ] += n_i;return n_i;
@@ -116,11 +109,11 @@ static void tcf_police_destroy(struct tcf_police *p)unsigned int h =tcf_hash (p->tcf_index,POL_TAB_MASK );struct tcf_common **p1p; -for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) { +for (p1p = &police_hash_info.htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) {if (*p1p == &p->common) { -write_lock_bh (&police_lock); +write_lock_bh (&police_hash_info.lock); *p1p = p->tcf_next; -write_unlock_bh (&police_lock); +write_unlock_bh (&police_hash_info.lock);gen_kill_estimator (&p->tcf_bstats, &p->tcf_rate_est);/*
@@ -266,10 +259,10 @@ override: police->tcf_index = parm->index ? parm->index :tcf_hash_new_index (&police_idx_gen, &police_hash_info); h =tcf_hash (police->tcf_index,POL_TAB_MASK ); -write_lock_bh (&police_lock); - police->tcf_next = tcf_police_ht[h]; - tcf_police_ht[h] = &police->common; -write_unlock_bh (&police_lock); +write_lock_bh (&police_hash_info.lock); + police->tcf_next = police_hash_info.htab[h]; + police_hash_info.htab[h] = &police->common; +write_unlock_bh (&police_hash_info.lock); a->priv = police;return ret;
@@ -414,12 +407,19 @@ static struct tc_action_ops act_police_ops = {static int __init police_init_module (void ) { -return tcf_register_action (&act_police_ops); +int err =tcf_hashinfo_init (&police_hash_info,POL_TAB_MASK +1 ); +if (err) +return err; + err =tcf_register_action (&act_police_ops); +if (err) +tcf_hashinfo_destroy (&police_hash_info); +return err; } static void __exitpolice_cleanup_module (void ) { +tcf_hashinfo_destroy (&police_hash_info);tcf_unregister_action (&act_police_ops); }
net/sched/act_simple.c +11 -9
@@ -25,15 +25,8 @@#include <net/tc_act/tc_defact.h> #define SIMP_TAB_MASK 7 -static struct tcf_common *tcf_simp_ht[SIMP_TAB_MASK +1 ];static u32 simp_idx_gen; -static DEFINE_RWLOCK (simp_lock); - -static struct tcf_hashinfo simp_hash_info = { - .htab = tcf_simp_ht, - .hmask =SIMP_TAB_MASK , - .lock = &simp_lock, -}; +static struct tcf_hashinfo simp_hash_info;#define SIMP_MAX_DATA 32 static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
@@ -209,14 +202,23 @@ MODULE_LICENSE("GPL");static int __init simp_init_module (void ) { -int ret =tcf_register_action (&act_simp_ops); +int err, ret; + err =tcf_hashinfo_init (&simp_hash_info,SIMP_TAB_MASK +1 ); +if (err) +return err; + + ret =tcf_register_action (&act_simp_ops);if (!ret)pr_info ("Simple TC action Loaded\n" ); +else +tcf_hashinfo_destroy (&simp_hash_info); +return ret; } static void __exit simp_cleanup_module(void) { +tcf_hashinfo_destroy (&simp_hash_info);tcf_unregister_action (&act_simp_ops); }
net/sched/act_skbedit.c +5 -8
@@ -28,15 +28,8 @@#include <net/tc_act/tc_skbedit.h> #define SKBEDIT_TAB_MASK 15 -static struct tcf_common *tcf_skbedit_ht[SKBEDIT_TAB_MASK +1 ];static u32 skbedit_idx_gen; -static DEFINE_RWLOCK (skbedit_lock); - -static struct tcf_hashinfo skbedit_hash_info = { - .htab = tcf_skbedit_ht, - .hmask =SKBEDIT_TAB_MASK , - .lock = &skbedit_lock, -}; +static struct tcf_hashinfo skbedit_hash_info;static int tcf_skbedit (struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res)
@@ -210,11 +203,15 @@ MODULE_LICENSE("GPL");static int __init skbedit_init_module (void ) { +int err =tcf_hashinfo_init (&skbedit_hash_info,SKBEDIT_TAB_MASK +1 ); +if (err) +return err;return tcf_register_action (&act_skbedit_ops); } static void __exit skbedit_cleanup_module(void) { +tcf_hashinfo_destroy (&skbedit_hash_info);tcf_unregister_action (&act_skbedit_ops); }
Signature · 1 line
1.8.1.4
PATCH v2 6/6 net_sched: convert tcf_hashinfo to hlist and use rcu
In reply to Cong WangSo that we don't need to play with singly linked list and of course we can use RCU+spinlock instead of rwlock now.
--- include/net/act_api.h | 14 ++++++---- net/sched/act_api.c | 71 +++++++++++++++++++++++--------------------------- net/sched/act_police.c | 47 ++++++++++++++------------------- 3 files changed, 61 insertions(+), 71 deletions(-)
include/net/act_api.h +9 -5
@@ -9,7 +9,7 @@#include <net/pkt_sched.h> struct tcf_common { -struct tcf_common *tcfc_next; +struct hlist_node tcfc_head;u32 tcfc_index;int tcfc_refcnt;int tcfc_bindcnt;
@@ -22,7 +22,7 @@ struct tcf_common {spinlock_t tcfc_lock;struct rcu_head tcfc_rcu; }; -#define tcf_next common.tcfc_next +#define tcf_head common.tcfc_head#define tcf_index common.tcfc_index#define tcf_refcnt common.tcfc_refcnt#define tcf_bindcnt common.tcfc_bindcnt
@@ -36,9 +36,9 @@ struct tcf_common {#define tcf_rcu common.tcfc_rcustruct tcf_hashinfo { -struct tcf_common **htab; +struct hlist_head *htab;unsigned int hmask; -rwlock_t lock; +spinlock_t lock; };static inline unsigned int tcf_hash (u32 index,unsigned int hmask)
@@ -48,12 +48,16 @@ static inline unsigned int tcf_hash(u32 index, unsigned int hmask)static inline int tcf_hashinfo_init (struct tcf_hashinfo *hf,unsigned int mask) { -rwlock_init (&hf->lock); +int i; + +spin_lock_init (&hf->lock); hf->hmask = mask; hf->htab =kzalloc ((mask +1 ) *sizeof (struct tcf_common *),GFP_KERNEL );if (!hf->htab)return -ENOMEM ; +for (i =0 ; i < mask +1 ; i++) +INIT_HLIST_HEAD (&hf->htab[i]);return 0 ; }
net/sched/act_api.c +32 -39
134 lines not on this page · raw message
net/sched/act_police.c +20 -27
80 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Re: [PATCH net-next v2 6/6] net_sched: convert tcf_hashinfo to hlist and use rcu
include/net/act_api.h static inline unsigned int tcf_hash(u32 index, unsigned int hmask) · line 61
Quoted 13 lines · Cong Wang
{
include/net/act_api.h +5
-1-rwlock_init (&hf->lock); +int i; + +spin_lock_init (&hf->lock); hf->hmask = mask; hf->htab =kzalloc ((mask +1 ) *sizeof (struct tcf_common *),GFP_KERNEL );if (!hf->htab)return -ENOMEM ; +for (i =0 ; i < mask +1 ; i++) +INIT_HLIST_HEAD (&hf->htab[i]);return 0 ;
Oops, a new bug was introduced during my rebase...
Re: [PATCH net-next v2 2/6] net_sched: act: use standard struct list_head
In reply to Cong Wanginclude/net/pkt_cls.h static inline int · line 94
Quoted 12 lines · Cong Wang
include/net/pkt_cls.h +1
-1@@ -85,12 +86,18 @@ static inline int tcf_exts_is_predicative(struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT -return !!exts->action; +return list_empty (&exts->head);#else return 0 ;#endif }
You missed a "!".
Thanks.
Signature · 2 lines
Regards, Changli Gao([email protected])
Re: [PATCH net-next v2 2/6] net_sched: act: use standard struct list_head
Quoted 16 lines · Changli Gao
include/net/pkt_cls.h static inline int · line 94
Quoted 12 lines · Cong Wang
include/net/pkt_cls.h +1
-1@@ -85,12 +86,18 @@ static inline int tcf_exts_is_predicative(struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT -return !!exts->action; +return list_empty (&exts->head);#else return 0 ;#endif }You missed a "!".
Fixed.
Thanks.