net: sched: summer cleanup part 1, mainly in exts area
Subsystems (13)
Jiri Pirko
maintainerv2 cover net: sched: summer cleanup part 1, mainly in exts area
From: Jiri Pirko <[email protected]>
This patchset is one of the couple cleanup patchsets I have in queue. The motivation aside the obvious need to "make things nicer" is also to prepare for shared filter blocks introduction. That requires tp->q removal, and therefore removal of all tp->q users.
Patch 1 is just some small thing I spotted on the way Patch 2 removes one user of tp->q, namely tcf_em_tree_change Patches 3-8 do preparations for exts->nr_actions removal Patches 9-10 do simple renames of functions in cls* Patches 11-19 remove unnecessary calls of tcf_exts_change helper The last patch changes tcf_exts_change to don't take lock
Tested by tools/testing/selftests/tc-testing
v1->v2:
- removed conversion of action array to list as noted by Cong
- added the past patch instead
- small rebases of patches 11-19
Jiri Pirko (20):
net: sched: sch_atm: use Qdisc_class_common structure
net: sched: remove unneeded tcf_em_tree_change
net: sched: change names of action number helpers to be aligned with
the rest
net: sched: use tcf_exts_has_actions in tcf_exts_exec
net: sched: remove redundant helpers tcf_exts_is_predicative and
tcf_exts_is_available
net: sched: fix return value of tcf_exts_exec
net: sched: remove check for number of actions in tcf_exts_exec
net: sched: use tcf_exts_has_actions instead of exts->nr_actions
net: sched: cls_bpf: rename cls_bpf_modify_existing function
net: sched: cls_fw: rename fw_change_attrs function
net: sched: cls_flower: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_fw: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_matchall: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_basic: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_bpf: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_cgroup: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_flow: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_route: no need to call tcf_exts_change for newly
allocated struct
net: sched: cls_u32: no need to call tcf_exts_change for newly
allocated struct
net: sched: avoid atomic swap in tcf_exts_change
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 2 +- drivers/net/ethernet/netronome/nfp/bpf/offload.c | 4 +- include/net/pkt_cls.h | 106 +++++++-------------- net/dsa/slave.c | 2 +- net/sched/act_api.c | 3 +- net/sched/cls_api.c | 14 +-- net/sched/cls_basic.c | 17 +--- net/sched/cls_bpf.c | 35 ++----- net/sched/cls_cgroup.c | 18 +--- net/sched/cls_flow.c | 47 ++++----- net/sched/cls_flower.c | 13 +-- net/sched/cls_fw.c | 34 +++---- net/sched/cls_matchall.c | 14 +-- net/sched/cls_route.c | 32 ++----- net/sched/cls_rsvp.h | 4 +- net/sched/cls_tcindex.c | 8 +- net/sched/cls_u32.c | 18 +--- net/sched/sch_atm.c | 12 +-- 22 files changed, 125 insertions(+), 268 deletions(-)
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 1/20 net: sched: sch_atm: use Qdisc_class_common structure
From: Jiri Pirko <[email protected]>
Even if it is only for classid now, use this common struct a be aligned with the rest of the classful qdiscs.
--- net/sched/sch_atm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/sched/sch_atm.c +6 -6
@@ -41,6 +41,7 @@#define VCC2FLOW (vcc) ((struct atm_flow_data *) ((vcc)->user_back))struct atm_flow_data { +struct Qdisc_class_common common;struct Qdisc *q;/* FIFO, TBF, etc. */ struct tcf_proto __rcu *filter_list;struct tcf_block *block;
@@ -49,7 +50,6 @@ struct atm_flow_data { struct sk_buff *skb); /* chaining */struct atm_qdisc_data *parent;/* parent qdisc */ struct socket *sock;/* for closing */ -u32 classid;/* x:y type ID */ int ref;/* reference count */ struct gnet_stats_basic_packed bstats;struct gnet_stats_queue qstats;
@@ -75,7 +75,7 @@ static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)struct atm_flow_data *flow;list_for_each_entry (flow, &p->flows, list) { -if (flow->classid == classid) +if (flow->common.classid == classid)return flow; }return NULL ;
@@ -293,7 +293,7 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, flow->old_pop = flow->vcc->pop; flow->parent = p; flow->vcc->pop = sch_atm_pop; - flow->classid = classid; + flow->common.classid = classid; flow->ref =1 ; flow->excess = excess;list_add (&flow->list, &p->link.list);
@@ -549,7 +549,7 @@ static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt) p->link.vcc =NULL ; p->link.sock =NULL ; - p->link.classid = sch->handle; + p->link.common.classid = sch->handle; p->link.ref =1 ;tasklet_init (&p->task, sch_atm_dequeue, (unsigned long )sch);return 0 ;
@@ -594,7 +594,7 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, sch, p, flow, skb, tcm);if (list_empty (&flow->list))return -EINVAL ; - tcm->tcm_handle = flow->classid; + tcm->tcm_handle = flow->common.classid; tcm->tcm_info = flow->q->handle; nest =nla_nest_start (skb,TCA_OPTIONS );
@@ -619,7 +619,7 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, goto nla_put_failure; }if (flow->excess) { -if (nla_put_u32 (skb,TCA_ATM_EXCESS , flow->classid)) +if (nla_put_u32 (skb,TCA_ATM_EXCESS , flow->common.classid)) goto nla_put_failure; }else {if (nla_put_u32 (skb,TCA_ATM_EXCESS ,0 ))
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 2/20 net: sched: remove unneeded tcf_em_tree_change
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Since tcf_em_tree_validate could be always called on a newly created filter, there is no need for this change function.
--- include/net/pkt_cls.h | 21 --------------------- net/sched/cls_basic.c | 4 +--- net/sched/cls_cgroup.c | 4 +--- net/sched/cls_flow.c | 12 +++++------- 4 files changed, 7 insertions(+), 34 deletions(-)
include/net/pkt_cls.h +0 -21
@@ -333,26 +333,6 @@ int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *, struct tcf_pkt_info *);/** -* tcf_em_tree_change - replace ematch tree of a running classifier -* -* @tp: classifier kind handle -* @dst: destination ematch tree variable -* @src: source ematch tree (temporary tree from tcf_em_tree_validate) -* -* This functions replaces the ematch tree in @dst with the ematch -* tree in @src. The classifier in charge of the ematch tree may be -* running. -*/ -static inline void tcf_em_tree_change (struct tcf_proto *tp, -struct tcf_ematch_tree *dst, -struct tcf_ematch_tree *src) -{ -tcf_tree_lock (tp); -memcpy (dst, src,sizeof (*dst)); -tcf_tree_unlock (tp); -} - -/** * tcf_em_tree_match - evaulate an ematch tree * * @skb: socket buffer of the packet in question
@@ -386,7 +366,6 @@ struct tcf_ematch_tree {#define tcf_em_tree_validate (tp, tb, t) ((void)(t), 0)#define tcf_em_tree_destroy (t) do { (void)(t); } while(0)#define tcf_em_tree_dump (skb, t, tlv) (0) -#define tcf_em_tree_change (tp, dst, src) do { } while(0)#define tcf_em_tree_match (skb, t, info) ((void)(info), 1)#endif /* CONFIG_NET_EMATCH */
net/sched/cls_basic.c +1 -3
@@ -130,7 +130,6 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp, {int err;struct tcf_exts e; -struct tcf_ematch_tree t; err =tcf_exts_init (&e,TCA_BASIC_ACT ,TCA_BASIC_POLICE );if (err <0 )
@@ -139,7 +138,7 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,if (err <0 ) goto errout; - err =tcf_em_tree_validate (tp, tb[TCA_BASIC_EMATCHES ], &t); + err =tcf_em_tree_validate (tp, tb[TCA_BASIC_EMATCHES ], &f->ematches);if (err <0 ) goto errout;
@@ -149,7 +148,6 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp, }tcf_exts_change (tp, &f->exts, &e); -tcf_em_tree_change (tp, &f->ematches, &t); f->tp = tp;return 0 ;
net/sched/cls_cgroup.c +1 -3
@@ -76,7 +76,6 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,struct nlattr *tb[TCA_CGROUP_MAX +1 ];struct cls_cgroup_head *head =rtnl_dereference (tp->root);struct cls_cgroup_head *new; -struct tcf_ematch_tree t;struct tcf_exts e;int err;
@@ -112,14 +111,13 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb, goto errout; } - err =tcf_em_tree_validate (tp, tb[TCA_CGROUP_EMATCHES ], &t); + err =tcf_em_tree_validate (tp, tb[TCA_CGROUP_EMATCHES ], &new->ematches);if (err <0 ) {tcf_exts_destroy (&e); goto errout; }tcf_exts_change (tp, &new->exts, &e); -tcf_em_tree_change (tp, &new->ematches, &t);rcu_assign_pointer (tp->root, new);if (head)
net/sched/cls_flow.c +5 -7
@@ -389,7 +389,6 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,struct nlattr *opt = tca[TCA_OPTIONS ];struct nlattr *tb[TCA_FLOW_MAX +1 ];struct tcf_exts e; -struct tcf_ematch_tree t;unsigned int nkeys =0 ;unsigned int perturb_period =0 ;u32 baseclass =0 ;
@@ -432,13 +431,13 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,if (err <0 ) goto err1; - err =tcf_em_tree_validate (tp, tb[TCA_FLOW_EMATCHES ], &t); -if (err <0 ) - goto err1; - err = -ENOBUFS ; fnew =kzalloc (sizeof (*fnew),GFP_KERNEL );if (!fnew) + goto err1; + + err =tcf_em_tree_validate (tp, tb[TCA_FLOW_EMATCHES ], &fnew->ematches); +if (err <0 ) goto err2; err =tcf_exts_init (&fnew->exts,TCA_FLOW_ACT ,TCA_FLOW_POLICE );
@@ -512,7 +511,6 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, (unsigned long)fnew);tcf_exts_change (tp, &fnew->exts, &e); -tcf_em_tree_change (tp, &fnew->ematches, &t);netif_keep_dst (qdisc_dev (tp->q));
@@ -554,8 +552,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, err3:tcf_exts_destroy (&fnew->exts); +tcf_em_tree_destroy (&fnew->ematches); err2: -tcf_em_tree_destroy (&t);kfree (fnew); err1:tcf_exts_destroy (&e);
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 3/20 net: sched: change names of action number helpers to be aligned with the rest
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
The rest of the helpers are named tcf_exts_*, so change the name of the action number helpers to be aligned. While at it, change to inline functions.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 4 +-- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 2 +- drivers/net/ethernet/netronome/nfp/bpf/offload.c | 4 +-- include/net/pkt_cls.h | 36 ++++++++++++++++------ net/dsa/slave.c | 2 +- net/sched/cls_api.c | 2 +- 9 files changed, 37 insertions(+), 19 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c +1 -1
@@ -96,7 +96,7 @@ static int fill_action_fields(struct adapter *adap,LIST_HEAD (actions); exts = cls->knode.exts; -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return -EINVAL ;tcf_exts_to_list (exts, &actions);
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -1
@@ -8953,7 +8953,7 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter,LIST_HEAD (actions);int err; -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return -EINVAL ;tcf_exts_to_list (exts, &actions);
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -2
@@ -1326,7 +1326,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,LIST_HEAD (actions);int err; -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return -EINVAL ; attr->flow_tag =MLX5_FS_DEFAULT_FLOW_TAG ;
@@ -1839,7 +1839,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,bool encap = false;int err =0 ; -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return -EINVAL ;memset (attr,0 ,sizeof (*attr));
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +1 -1
@@ -1626,7 +1626,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,LIST_HEAD (actions);int err; -if (!tc_single_action (cls->exts)) { +if (!tcf_exts_has_one_action (cls->exts)) {netdev_err (mlxsw_sp_port->dev,"only singular actions are supported\n" );return -EOPNOTSUPP ; }
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +1 -1
@@ -53,7 +53,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,LIST_HEAD (actions);int err; -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return 0 ;/* Count action is inserted first */
drivers/net/ethernet/netronome/nfp/bpf/offload.c +2 -2
@@ -115,14 +115,14 @@ nfp_net_bpf_get_act(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf)/* TC direct action */ if (cls_bpf->exts_integrated) { -if (tc_no_actions (cls_bpf->exts)) +if (!tcf_exts_has_actions (cls_bpf->exts))return NN_ACT_DIRECT ;return -EOPNOTSUPP ; }/* TC legacy mode */ -if (!tc_single_action (cls_bpf->exts)) +if (!tcf_exts_has_one_action (cls_bpf->exts))return -EOPNOTSUPP ;tcf_exts_to_list (cls_bpf->exts, &actions);
include/net/pkt_cls.h +27 -9
@@ -199,17 +199,35 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,return 0 ; } +/** +* tcf_exts_has_actions - check if at least one action is present +* @exts: tc filter extensions handle +* +* Returns true if at least one action is present. +*/ +static inline bool tcf_exts_has_actions (struct tcf_exts *exts) +{#ifdef CONFIG_NET_CLS_ACT +return exts->nr_actions; +#else +return false; +#endif +} -#define tc_no_actions (_exts) ((_exts)->nr_actions == 0) -#define tc_single_action (_exts) ((_exts)->nr_actions == 1) - -#else /* CONFIG_NET_CLS_ACT */ - -#define tc_no_actions (_exts) true -#define tc_single_action (_exts) false - -#endif /* CONFIG_NET_CLS_ACT */ +/** +* tcf_exts_has_one_action - check if exactly one action is present +* @exts: tc filter extensions handle +* +* Returns true if exactly one action is present. +*/ +static inline bool tcf_exts_has_one_action (struct tcf_exts *exts) +{ +#ifdef CONFIG_NET_CLS_ACT +return exts->nr_actions ==1 ; +#else +return false; +#endif +} int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, struct nlattr *rate_tlv,
net/dsa/slave.c +1 -1
@@ -779,7 +779,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,if (!ds->ops->port_mirror_add)return err; -if (!tc_single_action (cls->exts)) +if (!tcf_exts_has_one_action (cls->exts))return err;tcf_exts_to_list (cls->exts, &actions);
net/sched/cls_api.c +1 -1
@@ -972,7 +972,7 @@ int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,const struct tc_action *a;LIST_HEAD (actions); -if (tc_no_actions (exts)) +if (!tcf_exts_has_actions (exts))return -EINVAL ;tcf_exts_to_list (exts, &actions);
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 4/20 net: sched: use tcf_exts_has_actions in tcf_exts_exec
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Use the tcf_exts_has_actions helper instead or directly testing exts->nr_actions in tcf_exts_exec.
--- include/net/pkt_cls.h | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
include/net/pkt_cls.h +23 -23
@@ -177,29 +177,6 @@ tcf_exts_stats_update(const struct tcf_exts *exts, }/** -* tcf_exts_exec - execute tc filter extensions -* @skb: socket buffer -* @exts: tc filter extensions handle -* @res: desired result -* -* Executes all configured extensions. Returns 0 on a normal execution, -* a negative number if the filter must be considered unmatched or -* a positive action code (TC_ACT_*) which must be returned to the -* underlying layer. -*/ -static inline int -tcf_exts_exec (struct sk_buff *skb,struct tcf_exts *exts, -struct tcf_result *res) -{ -#ifdef CONFIG_NET_CLS_ACT -if (exts->nr_actions) -return tcf_action_exec (skb, exts->actions, exts->nr_actions, - res); -#endif -return 0 ; -} - -/** * tcf_exts_has_actions - check if at least one action is present * @exts: tc filter extensions handle *
@@ -229,6 +206,29 @@ static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)#endif } +/** +* tcf_exts_exec - execute tc filter extensions +* @skb: socket buffer +* @exts: tc filter extensions handle +* @res: desired result +* +* Executes all configured extensions. Returns 0 on a normal execution, +* a negative number if the filter must be considered unmatched or +* a positive action code (TC_ACT_*) which must be returned to the +* underlying layer. +*/ +static inline int +tcf_exts_exec (struct sk_buff *skb,struct tcf_exts *exts, +struct tcf_result *res) +{ +#ifdef CONFIG_NET_CLS_ACT +if (tcf_exts_has_actions (exts)) +return tcf_action_exec (skb, exts->actions, exts->nr_actions, + res); +#endif +return 0 ; +} +int tcf_exts_validate (struct net *net,struct tcf_proto *tp,struct nlattr **tb,struct nlattr *rate_tlv,struct tcf_exts *exts,bool ovr);
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 5/20 net: sched: remove redundant helpers tcf_exts_is_predicative and tcf_exts_is_available
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
These two helpers are doing the same as tcf_exts_has_actions, so remove them and use tcf_exts_has_actions instead.
--- include/net/pkt_cls.h | 30 ------------------------------ net/sched/cls_fw.c | 2 +- net/sched/cls_route.c | 2 +- net/sched/cls_tcindex.c | 2 +- 4 files changed, 3 insertions(+), 33 deletions(-)
include/net/pkt_cls.h +0 -30
@@ -113,36 +113,6 @@ static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police)return 0 ; } -/** -* tcf_exts_is_predicative - check if a predicative extension is present -* @exts: tc filter extensions handle -* -* Returns 1 if a predicative extension is present, i.e. an extension which -* might cause further actions and thus overrule the regular tcf_result. -*/ -static inline int -tcf_exts_is_predicative (struct tcf_exts *exts) -{ -#ifdef CONFIG_NET_CLS_ACT -return exts->nr_actions; -#else -return 0 ; -#endif -} - -/** -* tcf_exts_is_available - check if at least one extension is present -* @exts: tc filter extensions handle -* -* Returns 1 if at least one extension is present. -*/ -static inline int -tcf_exts_is_available (struct tcf_exts *exts) -{ -/* All non-predicative extensions must be added here. */ -return tcf_exts_is_predicative (exts); -} -static inline void tcf_exts_to_list (const struct tcf_exts *exts,struct list_head *actions) {
net/sched/cls_fw.c +1 -1
@@ -387,7 +387,7 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, unsigned long fh, t->tcm_handle = f->id; -if (!f->res.classid && !tcf_exts_is_available (&f->exts)) +if (!f->res.classid && !tcf_exts_has_actions (&f->exts))return skb->len; nest =nla_nest_start (skb,TCA_OPTIONS );
net/sched/cls_route.c +1 -1
@@ -113,7 +113,7 @@ static inline int route4_hash_wild(void)#define ROUTE4_APPLY_RESULT () \ { \ *res = f->res; \ - if (tcf_exts_is_available(&f->exts)) { \ + if (tcf_exts_has_actions(&f->exts)) { \ int r = tcf_exts_exec(skb, &f->exts, res); \ if (r < 0) { \ dont_cache = 1; \
net/sched/cls_tcindex.c +1 -1
@@ -52,7 +52,7 @@ struct tcindex_data {static inline int tcindex_filter_is_set (struct tcindex_filter_result *r) { -return tcf_exts_is_predicative (&r->exts) || r->res.classid; +return tcf_exts_has_actions (&r->exts) || r->res.classid; } static struct tcindex_filter_result *tcindex_lookup(struct tcindex_data *p,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 6/20 net: sched: fix return value of tcf_exts_exec
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Return the defined TC_ACT_OK instead of 0.
--- include/net/pkt_cls.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/pkt_cls.h +2 -2
@@ -182,7 +182,7 @@ static inline bool tcf_exts_has_one_action(struct tcf_exts *exts)* @exts: tc filter extensions handle * @res: desired result * -* Executes all configured extensions. Returns 0 on a normal execution, +* Executes all configured extensions. Returns TC_ACT_OK on a normal execution, * a negative number if the filter must be considered unmatched or * a positive action code (TC_ACT_*) which must be returned to the * underlying layer.
@@ -196,7 +196,7 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,return tcf_action_exec (skb, exts->actions, exts->nr_actions, res);#endif -return 0 ; +return TC_ACT_OK ; } int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 7/20 net: sched: remove check for number of actions in tcf_exts_exec
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Leave it to tcf_action_exec to return TC_ACT_OK in case there is no action present.
--- include/net/pkt_cls.h | 4 +--- net/sched/act_api.c | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-)
include/net/pkt_cls.h +1 -3
@@ -192,9 +192,7 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, struct tcf_result *res) {#ifdef CONFIG_NET_CLS_ACT -if (tcf_exts_has_actions (exts)) -return tcf_action_exec (skb, exts->actions, exts->nr_actions, - res); +return tcf_action_exec (skb, exts->actions, exts->nr_actions, res);#endif return TC_ACT_OK ; }
net/sched/act_api.c +2 -1
@@ -473,9 +473,10 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)int tcf_action_exec (struct sk_buff *skb,struct tc_action **actions,int nr_actions,struct tcf_result *res) { -int ret =-1 , i;u32 jmp_prgcnt =0 ;u32 jmp_ttl =TCA_ACT_MAX_PRIO ;/*matches actions per filter */ +int i; +int ret =TC_ACT_OK ;if (skb_skip_tc_classify (skb))return TC_ACT_OK ;
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 8/20 net: sched: use tcf_exts_has_actions instead of exts->nr_actions
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
For check in tcf_exts_dump use tcf_exts_has_actions helper instead of exts->nr_actions for checking if there are any actions present.
--- net/sched/cls_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_api.c +1 -1
@@ -915,7 +915,7 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)#ifdef CONFIG_NET_CLS_ACT struct nlattr *nest; -if (exts->action && exts->nr_actions) { +if (exts->action &&tcf_exts_has_actions (exts)) {/* * again for backward compatible mode - we want * to work with both old and new modes of entering
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 9/20 net: sched: cls_bpf: rename cls_bpf_modify_existing function
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
The name cls_bpf_modify_existing is highly misleading, as it indeed does not modify anything existing. It does not modify at all.
--- net/sched/cls_bpf.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/sched/cls_bpf.c +4 -6
@@ -382,10 +382,9 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,return 0 ; } -static int cls_bpf_modify_existing (struct net *net,struct tcf_proto *tp, -struct cls_bpf_prog *prog, -unsigned long base,struct nlattr **tb, -struct nlattr *est,bool ovr) +static int cls_bpf_set_parms (struct net *net,struct tcf_proto *tp, +struct cls_bpf_prog *prog,unsigned long base, +struct nlattr **tb,struct nlattr *est,bool ovr) {bool is_bpf, is_ebpf, have_exts = false;struct tcf_exts exts;
@@ -508,8 +507,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, goto errout; } - ret =cls_bpf_modify_existing (net, tp, prog, base, tb, tca[TCA_RATE ], - ovr); + ret =cls_bpf_set_parms (net, tp, prog, base, tb, tca[TCA_RATE ], ovr);if (ret <0 ) goto errout;
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 10/20 net: sched: cls_fw: rename fw_change_attrs function
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Since the function name is misleading since it is not changing anything, name it similarly to other cls.
--- net/sched/cls_fw.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/sched/cls_fw.c +5 -6
@@ -190,10 +190,9 @@ static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = { [TCA_FW_MASK] = { .type = NLA_U32 }, }; -static int -fw_change_attrs (struct net *net,struct tcf_proto *tp,struct fw_filter *f, -struct nlattr **tb,struct nlattr **tca,unsigned long base, -bool ovr) +static int fw_set_parms (struct net *net,struct tcf_proto *tp, +struct fw_filter *f,struct nlattr **tb, +struct nlattr **tca,unsigned long base,bool ovr) {struct fw_head *head =rtnl_dereference (tp->root);struct tcf_exts e;
@@ -282,7 +281,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,return err; } - err =fw_change_attrs (net, tp, fnew, tb, tca, base, ovr); + err =fw_set_parms (net, tp, fnew, tb, tca, base, ovr);if (err <0 ) {tcf_exts_destroy (&fnew->exts);kfree (fnew);
@@ -330,7 +329,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, f->id = handle; f->tp = tp; - err =fw_change_attrs (net, tp, f, tb, tca, base, ovr); + err =fw_set_parms (net, tp, f, tb, tca, base, ovr);if (err <0 ) goto errout;
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 11/20 net: sched: cls_flower: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the f struct was allocated right before fl_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_flower.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
net/sched/cls_flower.c +2 -11
@@ -852,15 +852,11 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct nlattr **tb, struct nlattr *est, bool ovr) { - struct tcf_exts e; int err; - err =tcf_exts_init (&e,TCA_FLOWER_ACT ,0 ); + err =tcf_exts_validate (net, tp, tb, est, &f->exts, ovr);if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, est, &e, ovr); -if (err <0 ) - goto errout;if (tb[TCA_FLOWER_CLASSID ]) { f->res.classid =nla_get_u32 (tb[TCA_FLOWER_CLASSID ]);
@@ -869,17 +865,12 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, err =fl_set_key (net, tb, &f->key, &mask->key);if (err) - goto errout; +return err;fl_mask_update_range (mask);fl_set_masked_key (&f->mkey, &f->key, mask); -tcf_exts_change (tp, &f->exts, &e); -return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static u32 fl_grab_new_handle(struct tcf_proto *tp,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 12/20 net: sched: cls_fw: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the f struct was allocated right before fw_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_fw.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
net/sched/cls_fw.c +5 -16
@@ -195,16 +195,12 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp, struct nlattr **tca, unsigned long base, bool ovr) { struct fw_head *head = rtnl_dereference(tp->root); -struct tcf_exts e;u32 mask;int err; - err =tcf_exts_init (&e,TCA_FW_ACT ,TCA_FW_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &f->exts, ovr);if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, ovr); -if (err <0 ) - goto errout;if (tb[TCA_FW_CLASSID ]) { f->res.classid =nla_get_u32 (tb[TCA_FW_CLASSID ]);
@@ -215,10 +211,8 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,if (tb[TCA_FW_INDEV ]) {int ret; ret =tcf_change_indev (net, tb[TCA_FW_INDEV ]); -if (ret <0 ) { - err = ret; - goto errout; - } +if (ret <0 ) +return ret; f->ifindex = ret; }#endif /* CONFIG_NET_CLS_IND */
@@ -227,16 +221,11 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,if (tb[TCA_FW_MASK ]) { mask =nla_get_u32 (tb[TCA_FW_MASK ]);if (mask != head->mask) - goto errout; +return err; }else if (head->mask !=0xFFFFFFFF ) - goto errout; - -tcf_exts_change (tp, &f->exts, &e); +return err;return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static int fw_change(struct net *net, struct sk_buff *in_skb,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 13/20 net: sched: cls_matchall: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the head struct was allocated right before mall_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_matchall.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
net/sched/cls_matchall.c +2 -12
@@ -120,27 +120,17 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct nlattr **tb, struct nlattr *est, bool ovr) { - struct tcf_exts e; int err; - err =tcf_exts_init (&e,TCA_MATCHALL_ACT ,0 ); -if (err) -return err; - err =tcf_exts_validate (net, tp, tb, est, &e, ovr); + err =tcf_exts_validate (net, tp, tb, est, &head->exts, ovr);if (err <0 ) - goto errout; +return err;if (tb[TCA_MATCHALL_CLASSID ]) { head->res.classid =nla_get_u32 (tb[TCA_MATCHALL_CLASSID ]);tcf_bind_filter (tp, &head->res, base); } - -tcf_exts_change (tp, &head->exts, &e); -return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static int mall_change(struct net *net, struct sk_buff *in_skb,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 14/20 net: sched: cls_basic: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the f struct was allocated right before basic_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_basic.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
net/sched/cls_basic.c +2 -11
@@ -129,31 +129,22 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp, struct nlattr *est, bool ovr) { int err; -struct tcf_exts e; - err =tcf_exts_init (&e,TCA_BASIC_ACT ,TCA_BASIC_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &f->exts, ovr);if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, est, &e, ovr); -if (err <0 ) - goto errout; err =tcf_em_tree_validate (tp, tb[TCA_BASIC_EMATCHES ], &f->ematches);if (err <0 ) - goto errout; +return err;if (tb[TCA_BASIC_CLASSID ]) { f->res.classid =nla_get_u32 (tb[TCA_BASIC_CLASSID ]);tcf_bind_filter (tp, &f->res, base); } -tcf_exts_change (tp, &f->exts, &e); f->tp = tp; -return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static int basic_change(struct net *net, struct sk_buff *in_skb,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 15/20 net: sched: cls_bpf: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the prog struct was allocated right before cls_bpf_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_bpf.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
net/sched/cls_bpf.c +6 -19
@@ -387,7 +387,6 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, struct nlattr **tb, struct nlattr *est, bool ovr) { bool is_bpf, is_ebpf, have_exts = false; -struct tcf_exts exts;u32 gen_flags =0 ;int ret;
@@ -396,30 +395,23 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))return -EINVAL ; - ret =tcf_exts_init (&exts,TCA_BPF_ACT ,TCA_BPF_POLICE ); + ret =tcf_exts_validate (net, tp, tb, est, &prog->exts, ovr);if (ret <0 )return ret; - ret =tcf_exts_validate (net, tp, tb, est, &exts, ovr); -if (ret <0 ) - goto errout;if (tb[TCA_BPF_FLAGS ]) {u32 bpf_flags =nla_get_u32 (tb[TCA_BPF_FLAGS ]); -if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT ) { - ret = -EINVAL ; - goto errout; - } +if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT ) +return -EINVAL ; have_exts = bpf_flags &TCA_BPF_FLAG_ACT_DIRECT ; }if (tb[TCA_BPF_FLAGS_GEN ]) { gen_flags =nla_get_u32 (tb[TCA_BPF_FLAGS_GEN ]);if (gen_flags & ~CLS_BPF_SUPPORTED_GEN_FLAGS || - !tc_flags_valid (gen_flags)) { - ret = -EINVAL ; - goto errout; - } + !tc_flags_valid (gen_flags)) +return -EINVAL ; } prog->exts_integrated = have_exts;
@@ -428,19 +420,14 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, ret = is_bpf ?cls_bpf_prog_from_ops (tb, prog) :cls_bpf_prog_from_efd (tb, prog, tp);if (ret <0 ) - goto errout; +return ret;if (tb[TCA_BPF_CLASSID ]) { prog->res.classid =nla_get_u32 (tb[TCA_BPF_CLASSID ]);tcf_bind_filter (tp, &prog->res, base); } -tcf_exts_change (tp, &prog->exts, &exts);return 0 ; - -errout: -tcf_exts_destroy (&exts); -return ret; } static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 16/20 net: sched: cls_cgroup: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the new struct just was allocated, so no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_cgroup.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
net/sched/cls_cgroup.c +2 -12
@@ -76,7 +76,6 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,struct nlattr *tb[TCA_CGROUP_MAX +1 ];struct cls_cgroup_head *head =rtnl_dereference (tp->root);struct cls_cgroup_head *new; -struct tcf_exts e;int err;if (!tca[TCA_OPTIONS ])
@@ -102,22 +101,13 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (err <0 ) goto errout; - err =tcf_exts_init (&e,TCA_CGROUP_ACT ,TCA_CGROUP_POLICE ); + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &new->exts, ovr);if (err <0 ) goto errout; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, ovr); -if (err <0 ) { -tcf_exts_destroy (&e); - goto errout; - } err =tcf_em_tree_validate (tp, tb[TCA_CGROUP_EMATCHES ], &new->ematches); -if (err <0 ) { -tcf_exts_destroy (&e); +if (err <0 ) goto errout; - } - -tcf_exts_change (tp, &new->exts, &e);rcu_assign_pointer (tp->root, new);if (head)
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 17/20 net: sched: cls_flow: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the fnew struct just was allocated, so no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_flow.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-)
net/sched/cls_flow.c +16 -25
@@ -388,7 +388,6 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,struct flow_filter *fold, *fnew;struct nlattr *opt = tca[TCA_OPTIONS ];struct nlattr *tb[TCA_FLOW_MAX +1 ]; -struct tcf_exts e;unsigned int nkeys =0 ;unsigned int perturb_period =0 ;u32 baseclass =0 ;
@@ -424,31 +423,27 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,return -EOPNOTSUPP ; } - err =tcf_exts_init (&e,TCA_FLOW_ACT ,TCA_FLOW_POLICE ); -if (err <0 ) - goto err1; - err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &e, ovr); -if (err <0 ) - goto err1; - - err = -ENOBUFS ; fnew =kzalloc (sizeof (*fnew),GFP_KERNEL );if (!fnew) - goto err1; +return -ENOBUFS ; err =tcf_em_tree_validate (tp, tb[TCA_FLOW_EMATCHES ], &fnew->ematches);if (err <0 ) - goto err2; + goto err1; err =tcf_exts_init (&fnew->exts,TCA_FLOW_ACT ,TCA_FLOW_POLICE );if (err <0 ) - goto err3; + goto err2; + + err =tcf_exts_validate (net, tp, tb, tca[TCA_RATE ], &fnew->exts, ovr); +if (err <0 ) + goto err2; fold = (struct flow_filter *)*arg;if (fold) { err = -EINVAL ;if (fold->handle != handle && handle) - goto err3; + goto err2;/* Copy fold into fnew */ fnew->tp = fold->tp;
@@ -468,31 +463,31 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,if (tb[TCA_FLOW_MODE ]) mode =nla_get_u32 (tb[TCA_FLOW_MODE ]);if (mode !=FLOW_MODE_HASH && nkeys >1 ) - goto err3; + goto err2;if (mode ==FLOW_MODE_HASH ) perturb_period = fold->perturb_period;if (tb[TCA_FLOW_PERTURB ]) {if (mode !=FLOW_MODE_HASH ) - goto err3; + goto err2; perturb_period =nla_get_u32 (tb[TCA_FLOW_PERTURB ]) *HZ ; } }else { err = -EINVAL ;if (!handle) - goto err3; + goto err2;if (!tb[TCA_FLOW_KEYS ]) - goto err3; + goto err2; mode =FLOW_MODE_MAP ;if (tb[TCA_FLOW_MODE ]) mode =nla_get_u32 (tb[TCA_FLOW_MODE ]);if (mode !=FLOW_MODE_HASH && nkeys >1 ) - goto err3; + goto err2;if (tb[TCA_FLOW_PERTURB ]) {if (mode !=FLOW_MODE_HASH ) - goto err3; + goto err2; perturb_period =nla_get_u32 (tb[TCA_FLOW_PERTURB ]) *HZ ; }
@@ -510,8 +505,6 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,setup_deferrable_timer (&fnew->perturb_timer, flow_perturbation, (unsigned long )fnew); -tcf_exts_change (tp, &fnew->exts, &e); -netif_keep_dst (qdisc_dev (tp->q));if (tb[TCA_FLOW_KEYS ]) {
@@ -550,13 +543,11 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,call_rcu (&fold->rcu, flow_destroy_filter);return 0 ; -err3: +err2:tcf_exts_destroy (&fnew->exts);tcf_em_tree_destroy (&fnew->ematches); -err2: -kfree (fnew); err1: -tcf_exts_destroy (&e); +kfree (fnew);return err; }
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 18/20 net: sched: cls_route: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the f struct was allocated right before route4_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_route.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
net/sched/cls_route.c +9 -21
@@ -372,37 +372,32 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,struct route4_filter *fp;unsigned int h1;struct route4_bucket *b; -struct tcf_exts e;int err; - err =tcf_exts_init (&e,TCA_ROUTE4_ACT ,TCA_ROUTE4_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &f->exts, ovr);if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, est, &e, ovr); -if (err <0 ) - goto errout; - err = -EINVAL ;if (tb[TCA_ROUTE4_TO ]) {if (new && handle &0x8000 ) - goto errout; +return -EINVAL ; to =nla_get_u32 (tb[TCA_ROUTE4_TO ]);if (to >0xFF ) - goto errout; +return -EINVAL ; nhandle = to; }if (tb[TCA_ROUTE4_FROM ]) {if (tb[TCA_ROUTE4_IIF ]) - goto errout; +return -EINVAL ; id =nla_get_u32 (tb[TCA_ROUTE4_FROM ]);if (id >0xFF ) - goto errout; +return -EINVAL ; nhandle |= id <<16 ; }else if (tb[TCA_ROUTE4_IIF ]) { id =nla_get_u32 (tb[TCA_ROUTE4_IIF ]);if (id >0x7FFF ) - goto errout; +return -EINVAL ; nhandle |= (id |0x8000 ) <<16 ; }else nhandle |=0xFFFF <<16 ;
@@ -410,27 +405,25 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,if (handle && new) { nhandle |= handle &0x7F00 ;if (nhandle != handle) - goto errout; +return -EINVAL ; } h1 =to_hash (nhandle); b =rtnl_dereference (head->table[h1]);if (!b) { - err = -ENOBUFS ; b =kzalloc (sizeof (struct route4_bucket ),GFP_KERNEL );if (b ==NULL ) - goto errout; +return -ENOBUFS ;rcu_assign_pointer (head->table[h1], b); }else {unsigned int h2 =from_hash (nhandle >>16 ); - err = -EEXIST ;for (fp =rtnl_dereference (b->ht[h2]); fp; fp =rtnl_dereference (fp->next))if (fp->handle == f->handle) - goto errout; +return -EEXIST ; }if (tb[TCA_ROUTE4_TO ])
@@ -450,12 +443,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,tcf_bind_filter (tp, &f->res, base); } -tcf_exts_change (tp, &f->exts, &e); -return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static int route4_change(struct net *net, struct sk_buff *in_skb,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 19/20 net: sched: cls_u32: no need to call tcf_exts_change for newly allocated struct
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
As the n struct was allocated right before u32_set_parms call, no need to use tcf_exts_change to do atomic change, and we can just fill-up the unused exts struct directly by tcf_exts_validate.
--- net/sched/cls_u32.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
net/sched/cls_u32.c +4 -14
@@ -723,29 +723,24 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, struct tc_u_knode *n, struct nlattr **tb, struct nlattr *est, bool ovr) { - struct tcf_exts e; int err; - err =tcf_exts_init (&e,TCA_U32_ACT ,TCA_U32_POLICE ); + err =tcf_exts_validate (net, tp, tb, est, &n->exts, ovr);if (err <0 )return err; - err =tcf_exts_validate (net, tp, tb, est, &e, ovr); -if (err <0 ) - goto errout; - err = -EINVAL ;if (tb[TCA_U32_LINK ]) {u32 handle =nla_get_u32 (tb[TCA_U32_LINK ]);struct tc_u_hnode *ht_down =NULL , *ht_old;if (TC_U32_KEY (handle)) - goto errout; +return -EINVAL ;if (handle) { ht_down =u32_lookup_ht (ht->tp_c, handle);if (ht_down ==NULL ) - goto errout; +return -EINVAL ; ht_down->refcnt++; }
@@ -765,16 +760,11 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,int ret; ret =tcf_change_indev (net, tb[TCA_U32_INDEV ]);if (ret <0 ) - goto errout; +return -EINVAL ; n->ifindex = ret; }#endif -tcf_exts_change (tp, &n->exts, &e); -return 0 ; -errout: -tcf_exts_destroy (&e); -return err; } static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH v2 20/20 net: sched: avoid atomic swap in tcf_exts_change
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
tcf_exts_change is always called on newly created exts, which are not used on fastpath. Therefore, simple struct copy is enough.
--- include/net/pkt_cls.h | 3 +-- net/sched/cls_api.c | 10 ++-------- net/sched/cls_rsvp.h | 4 ++-- net/sched/cls_tcindex.c | 6 +++--- 4 files changed, 8 insertions(+), 15 deletions(-)
include/net/pkt_cls.h +1 -2
@@ -201,8 +201,7 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr);void tcf_exts_destroy (struct tcf_exts *exts); -void tcf_exts_change (struct tcf_proto *tp,struct tcf_exts *dst, -struct tcf_exts *src); +void tcf_exts_change (struct tcf_exts *dst,struct tcf_exts *src);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); int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,
net/sched/cls_api.c +2 -8
@@ -883,18 +883,12 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, }EXPORT_SYMBOL (tcf_exts_validate); -void tcf_exts_change (struct tcf_proto *tp,struct tcf_exts *dst, -struct tcf_exts *src) +void tcf_exts_change (struct tcf_exts *dst,struct tcf_exts *src) {#ifdef CONFIG_NET_CLS_ACT struct tcf_exts old = *dst; -tcf_tree_lock (tp); - dst->nr_actions = src->nr_actions; - dst->actions = src->actions; - dst->type = src->type; -tcf_tree_unlock (tp); - + *dst = *src;tcf_exts_destroy (&old);#endif }
net/sched/cls_rsvp.h +2 -2
@@ -518,7 +518,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,tcf_bind_filter (tp, &n->res, base); } -tcf_exts_change (tp, &n->exts, &e); +tcf_exts_change (&n->exts, &e);rsvp_replace (tp, n, handle);return 0 ; }
@@ -591,7 +591,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,if (f->tunnelhdr ==0 )tcf_bind_filter (tp, &f->res, base); -tcf_exts_change (tp, &f->exts, &e); +tcf_exts_change (&f->exts, &e); fp = &s->ht[h2]; for (nfp = rtnl_dereference(*fp); nfp;
net/sched/cls_tcindex.c +3 -3
@@ -419,9 +419,9 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, }if (old_r) -tcf_exts_change (tp, &r->exts, &e); +tcf_exts_change (&r->exts, &e);else -tcf_exts_change (tp, &cr.exts, &e); +tcf_exts_change (&cr.exts, &e);if (old_r && old_r != r) { err =tcindex_filter_result_init (old_r);
@@ -439,7 +439,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,struct tcindex_filter *nfp;struct tcindex_filter __rcu **fp; -tcf_exts_change (tp, &f->result.exts, &r->exts); +tcf_exts_change (&f->result.exts, &r->exts); fp = cp->h + (handle % cp->hash); for (nfp = rtnl_dereference(*fp);
Signature · 1 line
2.9.3
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Fri, 4 Aug 2017 14:28:55 +0200
Quoted 14 lines
From: Jiri Pirko <[email protected]>
This patchset is one of the couple cleanup patchsets I have in queue. The motivation aside the obvious need to "make things nicer" is also to prepare for shared filter blocks introduction. That requires
tp->qremoval, and therefore removal of alltp->qusers.Patch 1 is just some small thing I spotted on the way Patch 2 removes one user of
tp->q, namelytcf_em_tree_changePatches 3-8 do preparations forexts->nr_actionsremoval Patches 9-10 do simple renames of functions in cls* Patches 11-19 remove unnecessary calls oftcf_exts_changehelper The last patch changestcf_exts_changeto don't take lock
Quoted 6 lines
Tested by
tools/testing/selftests/tc-testing
v1->v2:
- removed conversion of action array to list as noted by Cong
- added the past patch instead
- small rebases of patches 11-19
Series applied, thanks Jiri.