net_sched: some cleanup and improvments
Subsystems (5)
v4 cover net_sched: some cleanup and improvments
Here are some cleanup and improvements for tc filters and tc actions.
v3 -> v4:
* fix tcf_exts_is_predicative()
* rename 'head' to 'actions'
* use spinlock instead of spinlock+RCU
* add two more patches
v2 -> v3:
* fix a typo introduced during rebase
v1 -> v2:
* fix a smatch warning and a checkpatch warning
* add a cover letter
* add a missing synchronize_rcu()
Cong Wang (8):
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 spinlock
net_sched: convert tc_action_ops to use struct list_head
net_sched: convert tcf_proto_ops to use struct list_head
include/net/act_api.h | 43 ++++++--- include/net/pkt_cls.h | 37 ++++---- include/net/sch_generic.h | 2 +- include/net/tc_act/tc_mirred.h | 4 +- net/sched/act_api.c | 198 +++++++++++++++++------------------------ 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 | 63 ++++++------- net/sched/act_simple.c | 20 +++-- net/sched/act_skbedit.c | 13 ++- net/sched/cls_api.c | 99 ++++++++++----------- 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 ++- 24 files changed, 320 insertions(+), 383 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v4 1/8 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
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 1/8] net_sched: remove get_stats from tc_action_ops
Quoted 5 lines · Cong Wang
It is not used.
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>
cheers,
jamal
Quoted 33 lines
--- 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 ||
PATCH v4 2/8 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 | 16 ++++++-- 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, 101 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 *actions,int bind); +int tcf_action_exec (struct sk_buff *skb,const struct list_head *actions,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 +12 -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 actions;#endif };
@@ -74,6 +75,13 @@ struct tcf_ext_map {int police; }; +static inline void tcf_exts_init (struct tcf_exts *exts) +{ +#ifdef CONFIG_NET_CLS_ACT +INIT_LIST_HEAD (&exts->actions); +#endif +} +/** * tcf_exts_is_predicative - check if a predicative extension is present * @exts: tc filter extensions handle
@@ -85,7 +93,7 @@ static inline int tcf_exts_is_predicative(struct tcf_exts *exts) {#ifdef CONFIG_NET_CLS_ACT -return !!exts->action; +return !list_empty (&exts->actions);#else return 0 ;#endif
@@ -120,8 +128,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->actions)) +return tcf_action_exec (skb, &exts->actions, 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
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 2/8] net_sched: act: use standard struct list_head
Quoted 9 lines · Cong Wang
Currently 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_headso that in the latter patch we can remove an action without finding its head.Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>
Look good, thanks.
cheers,
jamal
PATCH v4 3/8 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 dev 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
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 5 lines · Cong Wang
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Sorry - this one i have problems with.
actions may be referenced from multiple filters,
you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
[And when we delete actions we send netlink events to announce that]. The proper solution would require i.e tag it as to be deleted and implement some form of garbage collection. Do you mind leaving this one out for this series?
cheers,
jamal
Quoted 69 lines
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>--- 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); } }
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 8 lines · Jamal Hadi Salim
Quoted 6 lines · Cong Wang
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Quoted 5 lines
Sorry - this one i have problems with. actions may be referenced from multiple filters, you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
How? tcf_action_init() always allocates a new action, it doesn't even look for an existing one.
Quoted 3 lines
[And when we delete actions we send netlink events to announce that]. The proper solution would require i.e tag it as to be deleted and implement some form of garbage collection.
It doesn't worth to have a GC for this...
Even if what you said is true, we should just make a copy for each of the filters. I just tried to create two different filters with same and different mirred actions, my patch works perfectly.
David Miller
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
From: Cong Wang <[email protected]>
Date: Wed, 18 Dec 2013 10:36:06 -0800
Quoted 22 lines · Jamal Hadi Salim
Quoted 8 lines · Cong Wang
Quoted 6 lines
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Quoted 5 lines
Sorry - this one i have problems with. actions may be referenced from multiple filters, you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
How?
tcf_action_init()always allocates a new action, it doesn't even look for an existing one.Quoted 3 lines
[And when we delete actions we send netlink events to announce that]. The proper solution would require i.e tag it as to be deleted and implement some form of garbage collection.
Quoted 6 lines
It doesn't worth to have a GC for this...
Even if what you said is true, we should just make a copy for each of the filters. I just tried to create two different filters with same and different mirred actions, my patch works perfectly.
Indeed, I think Jamal is confusing how he intended the code to work vs. how it actually does :-)
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
In reply to Cong WangQuoted 9 lines · Cong Wang
Quoted 8 lines · Jamal Hadi Salim
Quoted 6 lines · Cong Wang
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Quoted 9 lines
Quoted 5 lines
Sorry - this one i have problems with. actions may be referenced from multiple filters, you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
How?
tcf_action_init()always allocates a new action, it doesn't even look for an existing one.
tc action blah index 123
tc action filter goo action blah index 123 tc action filter gah action blah index 123
Very useful for example for multiple flows to share the same policer.
Quoted 11 lines
Quoted 3 lines
[And when we delete actions we send netlink events to announce that]. The proper solution would require i.e tag it as to be deleted and implement some form of garbage collection.
It doesn't worth to have a GC for this...
Even if what you said is true, we should just make a copy for each of the filters. I just tried to create two different filters with same and different mirred actions, my patch works perfectly.
A copy wont work. We want sharing.
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 26 lines · Jamal Hadi Salim
Quoted 20 lines · Cong Wang
Quoted 10 lines · Jamal Hadi Salim
Quoted 7 lines · Cong Wang
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Quoted 5 lines
Sorry - this one i have problems with. actions may be referenced from multiple filters, you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
Quoted 3 lines
How?
tcf_action_init()always allocates a new action, it doesn't even look for an existing one.
Quoted 7 lines
tc action blah index 123
tc action filter goo action blah index 123 tc action filter gah action blah index 123Very useful for example for multiple flows to share the same policer.
Ah, I see. I will create a test case for this
and rework on the mirred patch.
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
I am sorry Cong - I will still object to this change. I dont want to even bother testing it.
You are making some serious policy decisions in the kernel. Such policy decisions should be made by user space not the kernel. Whoever made the idiotic decision of removing the device should modify or delete the flow rule - at minimal they
may deserve some warning. Deleting the action is wrong. It is simple graph theory.
Slightly related is this - look at the attached test (I went out of my way to annotate it) and imagine you have mirred where the policers are ....
cheers,
jamal
Quoted 31 lines · Cong Wang
Quoted 30 lines · Jamal Hadi Salim
Quoted 20 lines · Cong Wang
Quoted 10 lines · Jamal Hadi Salim
Quoted 7 lines · Cong Wang
When the target device is removed, the mirred action is still there but with the dev pointer setting to NULL. This makes the output from 'tc filter' ugly. There is no reason to keep it.
Quoted 5 lines
Sorry - this one i have problems with. actions may be referenced from multiple filters, you cant just delete it (that would leave other users pointing to it dangling). Destroying would eventually delete it when the refcount goes to 0.
Quoted 3 lines
How?
tcf_action_init()always allocates a new action, it doesn't even look for an existing one.tc action blah index 123
tc action filter goo action blah index 123 tc action filter gah action blah index 123
Quoted 7 lines
Quoted 3 lines
Very useful for example for multiple flows to share the same policer.
Ah, I see. I will create a test case for this
and rework on the mirred patch.
TC="/sbin/tc"
#
sudo ifconfig dummy0 up
sudo ifconfig dummy1 up
DEV1="eth0"
DEV2="eth1"
#
#
#
sudo $TC qdisc del dev $DEV1 ingress
sudo $TC qdisc add dev $DEV1 ingress
sudo $TC qdisc del dev $DEV2 ingress
sudo $TC qdisc add dev $DEV2 ingress
#Note - older tc did not pipe for skbedit (add "pipe" if this is rejected) sudo $TC filter add dev $DEV1 parent ffff: protocol ip pref 10 \
u32 match ip protocol 1 0xff flowid 1:10 \
action skbedit mark 11 \
action police rate 10kbit burst 10k pipe index 1 \
action skbedit mark 12 \
action police rate 20kbit burst 20k pipe index 2 \
action action mirred egress mirror dev dummy0
#note sharing of the two policers by two flows
#across multiple devices
sudo $TC filter add dev $DEV2 parent ffff: protocol ip pref 10 \
u32 match ip protocol 1 0xff flowid 1:10 \
action skbedit mark 21 \
action police rate 10kbit burst 10k pipe index 1 \
action skbedit mark 22 \
action police rate 20kbit burst 20k pipe index 2 \
action action mirred egress mirror dev dummy1
#
#
# now do a ping -f to somewhere, for more exciting results # do a -s 2048 or so # sudo ping -f 192.168.1.100 -c 10000 # sudo ping -f 127.0.0.1 -c 10000 # sudo tc -s filter ls dev $DEV1 parent ffff: protocol ip sudo tc -s filter ls dev $DEV2 parent ffff: protocol ip sudo tc -s actions ls action police sudo tc -s actions ls action skbedit
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 6 lines · Jamal Hadi Salim
I am sorry Cong - I will still object to this change. I dont want to even bother testing it.
You are making some serious policy decisions in the kernel. Such policy decisions should be made by user space not the kernel.
You know qdiscs and filters are removed too when the device is gone, right? So isn't that also a policy you are talking about?
This doesn't make any sense to me, if it did, you should remove all net device notifications in kernel, right?
Quoted 4 lines
Whoever made the idiotic decision of removing the device should modify or delete the flow rule - at minimal they
may deserve some warning. Deleting the action is wrong. It is simple graph theory.
Have you ever thought about how hard it is to remove a mirred action upon the device removal? Even with libnl, we still have to:
1) monitor the device removal notification
2) search the action cache to get the action matches the target device
3) search for the filters that contains such actions
4) remove the action by changing the filters it is attached
Try it and see how much more work you will do, compare it with this kernel patch. It would not be hard to conclude which is easier.
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 5 lines · Cong Wang
On Sun, Dec 22, 2013 at 8:15 AM, Jamal Hadi Salim <[email protected]> wrote:
You know qdiscs and filters are removed too when the device is gone, right? So isn't that also a policy you are talking about?
That is an easy optimization that made sense to make - we deleted the root of a graph. No need to spam the policy manager. What we are talking about is deleting a faulty node shared by multiple graphs and deleting the vertex but then leaving dangling edges around. Doesnt make sense.
No action that is shared between two flows or devices is EVER going to be removed because you deleted a qdisc or a netdev.
Quoted 3 lines
This doesn't make any sense to me, if it did, you should remove all net device notifications in kernel, right?
Refer to above.
Quoted 11 lines
Have you ever thought about how hard it is to remove a mirred action upon the device removal? Even with libnl, we still have to:
1) monitor the device removal notification
2) search the action cache to get the action matches the target device
3) search for the filters that contains such actions
4) remove the action by changing the filters it is attachedTry it and see how much more work you will do, compare it with this kernel patch. It would not be hard to conclude which is easier.
It is not about ease - it is about correctness.
You are making a macroscopic decision with a microscopic view. This is why we have control planes. It is like the legs making decisions on behalf of the brain.
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 10 lines · Jamal Hadi Salim
Quoted 8 lines · Cong Wang
On Sun, Dec 22, 2013 at 8:15 AM, Jamal Hadi Salim <[email protected]> wrote:
You know qdiscs and filters are removed too when the device is gone, right? So isn't that also a policy you are talking about?
Quoted 7 lines
That is an easy optimization that made sense to make - we deleted the root of a graph. No need to spam the policy manager. What we are talking about is deleting a faulty node shared by multiple graphs and deleting the vertex but then leaving dangling edges around. Doesnt make sense.
No action that is shared between two flows or devices is EVER going to be removed because you deleted a qdisc or a netdev.
NOTHING you talked about here is relevant to the policy or mechanism you talked previously. Just correctness.
If removing an shared action is impossible, what about non-shared ones? Actually for my _own_ use case, I even don't use nor care about shared one...
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 3 lines · Cong Wang
NOTHING you talked about here is relevant to the policy or mechanism you talked previously. Just correctness.
It is about _correct policy_
If you have a packets going:
->A-->B-->C-->D-->E
That is the policy (decided by someone/thing in user space). A to E are mechanisms.
If something goes wrong with mechanism D, you dont go deleting D because it is affecting other things in the graph. You have no clue what it would affect - and if you try to build that in it is not cheap for no good reason.
You let the thing/person who set it know and do the deletion.
You compared it to something going wrong with A(when A is netdev) and how we delete everything underneath. They are not the same, in that case, we know precisely that is the begining of the graph and we can unreference everything underneath.
Does that make more sense?
Quoted 4 lines
If removing an shared action is impossible, what about non-shared ones? Actually for my _own_ use case, I even don't use nor care about shared one...
Refer to above.
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 6 lines · Jamal Hadi Salim
Quoted 3 lines · Cong Wang
NOTHING you talked about here is relevant to the policy or mechanism you talked previously. Just correctness.
Quoted 6 lines
It is about
_correctpolicy_
If you have a packets going:
->A-->B-->C-->D-->EThat is the policy (decided by someone/thing in user space). A to E are mechanisms.
Apparently you have a different definition of "policy" and "mechanism" with me, probably with others too...
I assume you mean actions here, since we don't care about others in this thread.
Quoted 4 lines
If something goes wrong with mechanism D, you dont go deleting D because it is affecting other things in the graph. You have no clue what it would affect - and if you try to build that in it is not cheap for no good reason.
Since they are chained by a singly or doubly linked list in non-shared case, where are "other things in the graph"?
Please do explain how can they be in a graph in non-shared case, it is not obvious to me at all.
Quoted 6 lines
You let the thing/person who set it know and do the deletion.
You compared it to something going wrong with A(when A is netdev) and how we delete everything underneath. They are not the same, in that case, we know precisely that is the begining of the graph and we can unreference everything underneath.
Nope, I only want to remove A from the chain by list_del() for non-shared case.
Quoted 3 lines
Does that make more sense?
Nope, you continue to mention graph, but don't explain why there is a graph in non-shared case. Nor I think you use "policy" or "mechanism" correctly. :)
Jamal, please don't be abstract, just talk about actions. We DO NOT care about others in this thread.
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 7 lines · Cong Wang
Quoted 5 lines · Jamal Hadi Salim
It is about
_correctpolicy_
If you have a packets going:
->A-->B-->C-->D-->E
Quoted 6 lines
Quoted 2 lines
That is the policy (decided by someone/thing in user space). A to E are mechanisms.
Apparently you have a different definition of "policy" and "mechanism" with me, probably with others too...
I think only with you ;->
Quoted 3 lines
I assume you mean actions here, since we don't care about others in this thread.
[..]
Quoted 4 lines
Since they are chained by a singly or doubly linked list in non-shared case, where are "other things in the graph"?
Nothing to do with implementation - think conceptually.
Quoted 3 lines
Please do explain how can they be in a graph in non-shared case, it is not obvious to me at all.
[..]
Quoted 3 lines
Nope, I only want to remove A from the chain by
list_del()for non-shared case.
[..]
Quoted 8 lines
Nope, you continue to mention graph, but don't explain why there is a graph in non-shared case. Nor I think you use "policy" or "mechanism" correctly. :)
Jamal, please don't be abstract, just talk about actions. We DO NOT care about others in this thread.
It is not just actions that constitute the graph. It starts at netdev. Actions are more complex because you have a real DAG. i.e you can have branches etc.
So how best to explain this?
Ive gone the avenue of showing you shared actions and failed. So i am trying to simplify it to a single basic graph;->
I will try again to use the graph concept:
If i or some program decide that a packet coming on is going to traverse:
-->netdevX->qdiscA->classifierB->{ActionC->Action D->ActionE}
That is a policy. It tells different parts of the kernel(the mechanisms)
how to treat a packet that traverses them in order to create some
resultant service.
What i drew above is a graph (as noted above {} is more complex
because you could have branches etc, eg i could go on Action C to do
sometimes but skip to E other times based on state, actually you
could have that with classifiers - but lets ignore that for now).
Each of the things preceeded by "->" is a graph node, otherwise known as a vertex (eg netdevX). Each of the "->" is an known as a graph edge.
Each of the nodes in a graph is a mechanism.
If this still doesnt make sense to you, I can describe it differently
without using concept of graphs.
Now if you have such a graph:
User space can delete the node netdevX and then you (kernel)
can dereference all that is underneath it. That is a good optimization
since user just deleted the root; we can then notify user only about netdevX. It doesnt matter if Action D is shared; reference count will decrease and if it hits zero, real destroy will happen.
User can delete the qdiscA and then kernel can dereference everything
underneath. That is fair optimization as above.
User can delete the filter and kernel can dereference
everything underneath it. That is also fair optimization as above.
What you cannot do is, on your own as kernel, decide you want to delete
one action that is _bound_ to a filter because one of its attributes is
gone berserk. It doesnt matter whether such an action is mirred or foo
or whether D and E dont exist. You can put a big hole where the town
used to be and leave roads leading to the town.
It will still be referenced by things preeceding it (primarily the classifier which keeps an action chain intact), which is bad when the next packet arrives.
You let the user/control program which is monitoring things do that
and "reroute" around the problem. If you insist on putting a little part
of the medula oblangata in the stomach, then:
the only correct way to do it is delete the filter.
And you start doing that you are making some serious policy decisions
in the kernel and adding lots of complexity.
Ok, does it make sense now?;->
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 2 lines · Jamal Hadi Salim
Now if you have such a graph:
Making such an abstraction only helps misunderstanding, really...
Quoted 5 lines
What you cannot do is, on your own as kernel, decide you want to delete one action that is _bound_ to a filter because one of its attributes is gone berserk. It doesnt matter whether such an action is mirred or foo or whether D and E dont exist. You can put a big hole where the town used to be and leave roads leading to the town.
Again, since (non-shared) actions attached to a filter are chained by a doubly linked list, why not?
Quoted 3 lines
It will still be referenced by things preeceding it (primarily the classifier which keeps an action chain intact), which is bad when the next packet arrives.
You know, there is a head for such linked list for the filter to refer, so what's the problem with deleting a node from a linked list if we lock it properly? In non-shared case, no filter can refer to any action without the head of the chain, right? So what is the problem of "referenced by things preeceding it" when they are linked and locked properly?
Quoted 4 lines
You let the user/control program which is monitoring things do that and "reroute" around the problem. If you insist on putting a little part of the medula oblangata in the stomach, then:
the only correct way to do it is delete the filter.
Apparent not, different actions can attached to the same filter and only mirred action has a target dev.
Quoted 3 lines
And you start doing that you are making some serious policy decisions in the kernel and adding lots of complexity.
Why removing a filter when the netdev is removed is not policy? Actually it is, ONLY that it is not be able to shared with current implementation.
Since you love mechanism _so much_, why not make filters shared by other qdisc's and stop removing them when netdev is gone in kernel?
Be realistic, Jamal, user-space is hard, you can't simply let user-space decide everything, especially when you don't provide a simple way to do it. Netlink is already hard to use, even with libnl, since it enforces a cache layer. Sit down and spend some time to write some libnl code, compare it with this patch.
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 6 lines · Cong Wang
Quoted 2 lines · Jamal Hadi Salim
Now if you have such a graph:
Making such an abstraction only helps misunderstanding, really...
So I used a graph that maps to a netdevice, qdisc, filter and actions like you asked to - there is still a misunderstanding?
Quoted 13 lines
Quoted 5 lines
What you cannot do is, on your own as kernel, decide you want to delete one action that is _bound_ to a filter because one of its attributes is gone berserk. It doesnt matter whether such an action is mirred or foo or whether D and E dont exist. You can put a big hole where the town used to be and leave roads leading to the town.
Again, since (non-shared) actions attached to a filter are chained by a doubly linked list, why not?
Quoted 3 lines
It will still be referenced by things preeceding it (primarily the classifier which keeps an action chain intact), which is bad when the next packet arrives.
Quoted 7 lines
You know, there is a head for such linked list for the filter to refer, so what's the problem with deleting a node from a linked list if we lock it properly? In non-shared case, no filter can refer to any action without the head of the chain, right? So what is the problem of "referenced by things preeceding it" when they are linked and locked properly?
Huh? This has nothing to do with whether you are capable to remove a node from a list. It is about you making a decision that the node should be removed. You dont have sufficient information to make such a decision. Remember earlier i said you are making a macroscopic decision by looking at microscope? I just saw a white blood cell, let me chop that toe.
Quoted 8 lines
Quoted 4 lines
You let the user/control program which is monitoring things do that and "reroute" around the problem. If you insist on putting a little part of the medula oblangata in the stomach, then:
the only correct way to do it is delete the filter.Apparent not, different actions can attached to the same filter and only mirred action has a target dev.
Parse error.
Quoted 8 lines
Quoted 3 lines
And you start doing that you are making some serious policy decisions in the kernel and adding lots of complexity.
Why removing a filter when the netdev is removed is not policy? Actually it is, ONLY that it is not be able to shared with current implementation.
Of course it is. Since you understand that why do you think removing an action which is part of that policy is a good idea?
Quoted 9 lines
Since you love mechanism
_somuch_, why not make filters shared by other qdisc's and stop removing them when netdev is gone in kernel?Be realistic, Jamal, user-space is hard, you can't simply let user-space decide everything, especially when you don't provide a simple way to do it. Netlink is already hard to use, even with libnl, since it enforces a cache layer. Sit down and spend some time to write some libnl code, compare it with this patch.
You gotta be joking. I live through this every ither day. Frankly, I think i will have no progress if i tried to convince you the world is round. I am dropping from this discussion.
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 4 lines · Jamal Hadi Salim
Huh? This has nothing to do with whether you are capable to remove a node from a list. It is about you making a decision that the node should be removed. You dont have sufficient information to make such a decision.
Then which lacks?
Quoted 8 lines
Quoted 4 lines
Why removing a filter when the netdev is removed is not policy? Actually it is, ONLY that it is not be able to shared with current implementation.
Of course it is. Since you understand that why do you think removing an action which is part of that policy is a good idea?
Well, I think doing such policy decision for both filters and actions in kernel IS fine, simply because it is harder for user-space. We already have many of such policies, they fit well.
Quoted 12 lines
Quoted 11 lines
Since you love mechanism
_somuch_, why not make filters shared by other qdisc's and stop removing them when netdev is gone in kernel?Be realistic, Jamal, user-space is hard, you can't simply let user-space decide everything, especially when you don't provide a simple way to do it.
Netlink is already hard to use, even with libnl, since it enforces a cache layer. Sit down and spend some time to write some libnl code, compare it with this patch.
Quoted 1 line
You gotta be joking. I live through this every ither day.
Great! Then show me how to do remove a mirred action upon the target device is gone in user-space, please?
Quoted 3 lines
Frankly, I think i will have no progress if i tried to convince you the world is round. I am dropping from this discussion.
Your replies show you care about policy vs mechanism very much, but you even don't do any thing with either 1) try to show me how the user-space implements it or 2) go head to make same mechanism for filters (and qdisc) as well.
Do something to prove that you said. :) Otherwise, I think you are kidding me.
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
On 12/23/13 17:51, Cong Wang wrote:
[..]
Quoted 2 lines
Great! Then show me how to do remove a mirred action upon the target device is gone in user-space, please?
[..]
Quoted 8 lines
Your replies show you care about policy vs mechanism very much, but you even don't do any thing with either 1) try to show me how the user-space implements it or 2) go head to make same mechanism for filters (and qdisc) as well.
Do something to prove that you said. :) Otherwise, I think you are kidding me.
No disrespect intended Cong - but lets just end this discussion agreeing to disagree. On my side I violently disagree. I hope not to spend any more energy on this.
cheers,
jamal
Re: [PATCH net-next v4 3/8] net_sched: mirred: remove action when the target device is gone
Quoted 5 lines · Jamal Hadi Salim
No disrespect intended Cong - but lets just end this discussion agreeing to disagree. On my side I violently disagree. I hope not to spend any more energy on this.
Sorry, I think your argument on policy vs mechanism doesn't make any sense at all. Therefore I don't accept it.
PATCH v4 4/8 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 | 23 ++++++++++------------- net/sched/cls_api.c | 31 +++++++++++++------------------ 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, 69 insertions(+), 114 deletions(-)
include/net/pkt_cls.h +10 -13
@@ -65,21 +65,21 @@ struct tcf_exts {__u32 type;/* for backward compat(TCA_OLD_COMPAT) */ struct list_head actions;#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) +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->actions);#endif + exts->action = action; + exts->police = police; }/**
@@ -136,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 -18
@@ -507,18 +507,15 @@ 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->actions); -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 +523,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->actions); - }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->actions);if (err)
@@ -536,8 +533,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 +561,10 @@ EXPORT_SYMBOL(tcf_exts_change);#define tcf_exts_first_act (ext) \ list_first_entry(&(exts)->actions, 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->actions)) { +if (exts->action && !list_empty (&exts->actions)) {/* * again for backward compatible mode - we want * to work with both old and new modes of entering
@@ -576,15 +572,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->actions,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 +596,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
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 4/8] net_sched: cls: refactor out struct tcf_ext_map
Quoted 6 lines · Cong Wang
These information can be saved in
tcf_exts, and this will simplify the code.Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>
Looks good, thanks.
cheers,
jamal
PATCH v4 5/8 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
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 5/8] net_sched: init struct tcf_hashinfo at register time
Quoted 6 lines · Cong Wang
It looks weird to store the lock out of the struct but still points to a static variable. Just move them into the struct.
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>
Looks good - thanks.
cheers,
jamal
PATCH v4 6/8 net_sched: convert tcf_hashinfo to hlist and use spinlock
In reply to Cong WangSo that we don't need to play with singly linked list, and since the code is not on hot path, we can use spinlock instead of rwlock.
--- include/net/act_api.h | 16 +++++++----- net/sched/act_api.c | 69 ++++++++++++++++++++++---------------------------- net/sched/act_police.c | 45 +++++++++++++------------------- 3 files changed, 58 insertions(+), 72 deletions(-)
include/net/act_api.h +10 -6
@@ -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 *), + hf->htab =kzalloc ((mask +1 ) *sizeof (struct hlist_head ),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 +30 -39
132 lines not on this page · raw message
net/sched/act_police.c +18 -27
78 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 6/8] net_sched: convert tcf_hashinfo to hlist and use spinlock
Quoted 7 lines · Cong Wang
So that we don't need to play with singly linked list, and since the code is not on hot path, we can use spinlock instead of rwlock.
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>
nice.
cheers,
jamal
PATCH v4 7/8 net_sched: convert tc_action_ops to use struct list_head
In reply to Cong WangWe don't need to maintain our own singly linked list code.
--- include/net/act_api.h | 2 +- net/sched/act_api.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-)
include/net/act_api.h +1 -1
@@ -85,7 +85,7 @@ struct tc_action {#define TCA_CAP_NONE 0struct tc_action_ops { -struct tc_action_ops *next; +struct list_head head;struct tcf_hashinfo *hinfo;char kind[IFNAMSIZ ];__u32 type;/* TBD to match kind */
net/sched/act_api.c +9 -11
@@ -255,12 +255,12 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo) }EXPORT_SYMBOL (tcf_hash_insert); -static struct tc_action_ops *act_base =NULL ; +static LIST_HEAD (act_base);static DEFINE_RWLOCK (act_mod_lock);int tcf_register_action (struct tc_action_ops *act) { -struct tc_action_ops *a, **ap; +struct tc_action_ops *a;/* Must supply act, dump, cleanup and init */ if (!act->act || !act->dump || !act->cleanup || !act->init)
@@ -273,14 +273,13 @@ int tcf_register_action(struct tc_action_ops *act) act->walk = tcf_generic_walker;write_lock (&act_mod_lock); -for (ap = &act_base; (a = *ap) !=NULL ; ap = &a->next) { +list_for_each_entry (a, &act_base, head) {if (act->type == a->type || (strcmp (act->kind, a->kind) ==0 )) {write_unlock (&act_mod_lock);return -EEXIST ; } } - act->next =NULL ; - *ap = act; +list_add_tail (&act->head, &act_base);write_unlock (&act_mod_lock);return 0 ; }
@@ -288,16 +287,15 @@ EXPORT_SYMBOL(tcf_register_action);int tcf_unregister_action (struct tc_action_ops *act) { -struct tc_action_ops *a, **ap; +struct tc_action_ops *a;int err = -ENOENT ;write_lock (&act_mod_lock); -for (ap = &act_base; (a = *ap) !=NULL ; ap = &a->next) +list_for_each_entry (a, &act_base, head)if (a == act)break ;if (a) { - *ap = a->next; - a->next =NULL ; +list_del (&act->head); err =0 ; }write_unlock (&act_mod_lock);
@@ -312,7 +310,7 @@ static struct tc_action_ops *tc_lookup_action_n(char *kind)if (kind) {read_lock (&act_mod_lock); -for (a = act_base; a; a = a->next) { +list_for_each_entry (a, &act_base, head) {if (strcmp (kind, a->kind) ==0 ) {if (!try_module_get (a->owner)) {read_unlock (&act_mod_lock);
@@ -333,7 +331,7 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)if (kind) {read_lock (&act_mod_lock); -for (a = act_base; a; a = a->next) { +list_for_each_entry (a, &act_base, head) {if (nla_strcmp (kind, a->kind) ==0 ) {if (!try_module_get (a->owner)) {read_unlock (&act_mod_lock);
Signature · 1 line
1.8.1.4
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 7/8] net_sched: convert tc_action_ops to use struct list_head
Quoted 6 lines · Cong Wang
We don't need to maintain our own singly linked list code.
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>---
nice!
cheers,
jamal
PATCH v4 8/8 net_sched: convert tcf_proto_ops to use struct list_head
In reply to Cong WangWe don't need to maintain our own singly linked list code.
--- include/net/sch_generic.h | 2 +- net/sched/cls_api.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-)
include/net/sch_generic.h +1 -1
@@ -185,7 +185,7 @@ struct tcf_result { };struct tcf_proto_ops { -struct tcf_proto_ops *next; +struct list_head head;char kind[IFNAMSIZ ]; int (*classify)(struct sk_buff *,
net/sched/cls_api.c +8 -10
@@ -31,8 +31,7 @@#include <net/pkt_cls.h> /* The list of all installed classifier types */ - -static struct tcf_proto_ops *tcf_proto_base__read_mostly ; +static LIST_HEAD (tcf_proto_base);/* Protects list of registered TC modules. It is pure SMP lock. */ static DEFINE_RWLOCK (cls_mod_lock);
@@ -45,7 +44,7 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)if (kind) {read_lock (&cls_mod_lock); -for (t = tcf_proto_base; t; t = t->next) { +list_for_each_entry (t, &tcf_proto_base, head) {if (nla_strcmp (kind, t->kind) ==0 ) {if (!try_module_get (t->owner)) t =NULL ;
@@ -61,16 +60,15 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)int register_tcf_proto_ops (struct tcf_proto_ops *ops) { -struct tcf_proto_ops *t, **tp; +struct tcf_proto_ops *t;int rc = -EEXIST ;write_lock (&cls_mod_lock); -for (tp = &tcf_proto_base; (t = *tp) !=NULL ; tp = &t->next) +list_for_each_entry (t, &tcf_proto_base, head)if (!strcmp (ops->kind, t->kind)) goto out; - ops->next =NULL ; - *tp = ops; +list_add_tail (&ops->head, &tcf_proto_base); rc =0 ; out:write_unlock (&cls_mod_lock);
@@ -80,17 +78,17 @@ EXPORT_SYMBOL(register_tcf_proto_ops);int unregister_tcf_proto_ops (struct tcf_proto_ops *ops) { -struct tcf_proto_ops *t, **tp; +struct tcf_proto_ops *t;int rc = -ENOENT ;write_lock (&cls_mod_lock); -for (tp = &tcf_proto_base; (t = *tp) !=NULL ; tp = &t->next) +list_for_each_entry (t, &tcf_proto_base, head)if (t == ops)break ;if (!t) goto out; - *tp = t->next; +list_del (&t->head); rc =0 ; out:write_unlock (&cls_mod_lock);
Signature · 1 line
1.8.1.4
Jamal Hadi Salim
maintainerRe: [PATCH net-next v4 8/8] net_sched: convert tcf_proto_ops to use struct list_head
Quoted 10 lines · Cong Wang
We don't need to maintain our own singly linked list code.
Cc Jamal Hadi Salim <[email protected]>Cc David S. Miller <[email protected]>Signed-off-by Cong Wang <[email protected]>--- include/net/sch_generic.h | 2 +- net/sched/cls_api.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-)
And another nice improvement. Thanks Cong
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 3 lines · Cong Wang
Here are some cleanup and improvements for tc filters and tc actions.
Thanks.
I would like to run some tests I have and look closely - please give me some time; unfortunately I dont right away (yesterday was good for me); will do this week.
cheers,
jamal
David Miller
maintainerFrom: Jamal Hadi Salim <[email protected]>
Date: Mon, 16 Dec 2013 07:45:24 -0500
Quoted 3 lines
I would like to run some tests I have and look closely - please give me some time; unfortunately I dont right away (yesterday was good for me); will do this week.
Please do this at your earliest convenience so Cong's patches don't just rot in patchwork. When patches are held up like this it makes extra work for me as I analyze my patchwork todo list each and every day.
Thank you.
Jamal Hadi Salim
maintainerQuoted 4 lines · David Miller
Please do this at your earliest convenience so Cong's patches don't just rot in patchwork. When patches are held up like this it makes extra work for me as I analyze my patchwork todo list each and every day.
Will do. I was hoping for the weekend but the update didnt show up until yesterday.
In the minimal i will do the patch review today and if nothing stands out you can take in the patches.
For large changes like these Dave - you gotta let me do my testing. I am OCD. Maybe i will clean up the tests and make them available somewhere so i dont slow people down.
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 3 lines · Cong Wang
Here are some cleanup and improvements for tc filters and tc actions.
Hi Cong,
I think these patches are a long overdue useful improvement. Thanks for the effort. I will comment on each individually.
cheers,
jamal
PS: checkpatch was whining to me - but thats probably because of the way thunderbird saved things for me. Double check just in case.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Sun, 15 Dec 2013 20:15:03 -0800
Quoted 2 lines
Here are some cleanup and improvements for tc filters and tc actions.
All except the mirred patch applied to net-next, thanks.
Quoted 7 lines · David Miller
From: Cong Wang <[email protected]>
Date: Sun, 15 Dec 2013 20:15:03 -0800Quoted 2 lines
Here are some cleanup and improvements for tc filters and tc actions.
All except the mirred patch applied to net-next, thanks.
Thanks, then I will rework on the mirred patch.